File: midicombobox.cpp

package info (click to toggle)
ams 1.8.7-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,880 kB
  • ctags: 2,171
  • sloc: cpp: 17,793; makefile: 433; sh: 101
file content (69 lines) | stat: -rw-r--r-- 1,936 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <qslider.h>
#include <qhbox.h>
#include <qvbox.h>
#include <qlabel.h>
#include <stdio.h>
#include <math.h>
#include <qstrlist.h>
#include "midicombobox.h"
#include "synthdata.h"
#include "midiwidget.h"
#include "midiguicomponent.h"

MidiComboBox::MidiComboBox(QObject *parentModule, int value, QWidget * parent, const char * name, SynthData
                           *p_synthdata, int *p_valueRef, QStrList *itemNames)
                           : MidiGUIcomponent(parentModule, p_synthdata, parent, name) {

  QString qs;

  componentType = GUIcomponentType_combobox;
  valueRef = p_valueRef;
  setSpacing(5);
  setMargin(5);
  new QWidget(this);
  QVBox *comboFrame = new QVBox(this);
  comboFrame->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed));
  QLabel *nameLabel = new QLabel(comboFrame);
  if (name) {
    nameLabel->setFixedHeight(nameLabel->sizeHint().height());
    nameLabel->setText(name);
  }
  nameLabel->setFixedHeight(nameLabel->sizeHint().height());
  comboBox = new QComboBox(comboFrame);  
  comboBox->insertStrList(itemNames);
  comboBox->setFixedSize(comboBox->sizeHint());
  QObject::connect(comboBox, SIGNAL(highlighted(int)), this, SLOT(updateValue(int)));
  updateValue(value);
}

MidiComboBox::~MidiComboBox(){
}

void MidiComboBox::setMidiValue(int value) {

  if (!controllerOK) {
    controllerOK = abs(getMidiValue() - value) < 4;
  }
  if (controllerOK) {
    if (midiSign == 1) {
      comboBox->setCurrentItem(int((float)(comboBox->count()-1) / 127.0 * (float)value));
    } else {
      comboBox->setCurrentItem(int((float)(comboBox->count()-1) / 127.0 * (float)(127-value)));
    }
  }
}

void MidiComboBox::updateValue(int value) {

  *valueRef = value;    
  comboBox->setCurrentItem(value);
  emit guiComponentTouched();
}

int MidiComboBox::getMidiValue() {

  int x;  
 
  x = rint(127.0 * comboBox->currentItem() / (comboBox->count()-1));
  return(x);
}