summaryrefslogtreecommitdiff
path: root/muse_qt4_evolution/synti/organ/organgui.cpp
blob: c00d23fb3a64ce6c35f0e749e8f2f7c61f6b1a83 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//=========================================================
//  MusE
//  Linux Music Editor
//  $Id: organgui.cpp,v 1.21 2005/12/16 15:36:51 wschweer Exp $
//
//    This is a simple GUI implemented with QT for
//    organ software synthesizer.
//
//  (C) Copyright 2001-2007 Werner Schweer (ws@seh.de)
//=========================================================

#include "organgui.h"
#include "muse/midi.h"
#include "muse/midictrl.h"
#include "awl/knob.h"

//---------------------------------------------------------
//   OrganGui
//---------------------------------------------------------

OrganGui::OrganGui()
   : QWidget(0),
     MessGui()
      {
      setupUi(this);
      QSocketNotifier* s = new QSocketNotifier(readFd, QSocketNotifier::Read);
      connect(s, SIGNAL(activated(int)), SLOT(readMessage(int)));

      map = new QSignalMapper(this);
      QList<QWidget*> wl = findChildren<QWidget*>();
      foreach(QWidget* w, wl) {
            int idx = Mess2::controllerIdx(w->objectName().toAscii().data());
            if (idx == -1)
                  continue;
            w->setProperty("ctrlIdx", idx);
            map->setMapping(w, w);
            const char* cname = w->metaObject()->className();
            if (strcmp(cname, "QSlider") == 0) {
                  QSlider* slider = (QSlider*)w;
                  w->setProperty("ctrlType", 0);
                  connect(slider, SIGNAL(valueChanged(int)), map, SLOT(map()));
                  }
            else if (strcmp(cname, "QCheckBox") == 0) {
                  w->setProperty("ctrlType", 1);
                  connect(w, SIGNAL(toggled(bool)), map, SLOT(map()));
                  }
            else if (strcmp(cname, "QGroupBox") == 0) {
                  w->setProperty("ctrlType", 2);
                  connect(w, SIGNAL(toggled(bool)), map, SLOT(map()));
                  }
            else if (strcmp(cname, "Awl::Knob") == 0) {
                  w->setProperty("ctrlType", 3);
                  connect(w, SIGNAL(valueChanged(double,int)), map, SLOT(map()));
                  }
            else if (strcmp(cname, "QPushButton") == 0) {
                  w->setProperty("ctrlType", 4);
                  connect(w, SIGNAL(toggled(bool)), map, SLOT(map()));
                  }
            else if (strcmp(cname, "Awl::Drawbar") == 0) {
                  Awl::Drawbar* drawbar = (Awl::Drawbar*)w;
                  w->setProperty("ctrlType", 5);
                  connect(drawbar, SIGNAL(valueChanged(double,int)), map, SLOT(map()));
                  }
            else
                  printf("Gui Element <%s> not supported\n", cname);
            }
      ignoreControllerChange = false;
      connect(map, SIGNAL(mapped(QWidget*)), this, SLOT(ctrlChanged(QWidget*)));
      }

//---------------------------------------------------------
//   ctrlChanged
//---------------------------------------------------------

void OrganGui::ctrlChanged(QWidget* w)
      {
      if (ignoreControllerChange)
            return;
      int ctrlIdx  = w->property("ctrlIdx").toInt();
      int ctrlType = w->property("ctrlType").toInt();
      int value    = 0;

      switch(ctrlType) {
            case 0:     // QSlider
                  value = ((QSlider*)w)->value();
                  break;
            case 1:
                  value = ((QCheckBox*)w)->isChecked();
                  break;
            case 2:
                  value = ((QGroupBox*)w)->isChecked();
                  break;
            case 3:
                  value = lrint(((Awl::Knob*)w)->value());
                  break;
            case 4:
                  value = ((QPushButton*)w)->isChecked();
                  break;
            case 5:
                  value = lrint(((Awl::Drawbar*)w)->value());
                  break;
            default:
                  printf("OrganGui::ctrlChanged: illegal ctrlType %d\n", ctrlType);
                  break;
            }
      int id = Mess2::controllerId(ctrlIdx);
      sendController(0, id, value);      // to synth
      }

//---------------------------------------------------------
//   setParam
//---------------------------------------------------------

void OrganGui::setParam(int ctrlId, int val)
      {
      int ctrlIdx = Mess2::controllerIdx(ctrlId);
      if (ctrlIdx == -1)
            return;
      setParamIdx(ctrlIdx, val);
      }

//---------------------------------------------------------
//   setParamIdx
//    set controller value in gui
//---------------------------------------------------------

void OrganGui::setParamIdx(int ctrlIdx, int val)
      {
      const char* name = Organ::controllerName(ctrlIdx);
      if (name == 0)
            return;
      ignoreControllerChange = true;
      QList<QWidget*> wl = findChildren<QWidget*>(name);

      foreach(QWidget* w, wl) {
            int ctrlType = w->property("ctrlType").toInt();
            switch(ctrlType) {
                  case 0:
                        ((QSlider*)w)->setValue(val);
                        break;
                  case 1:
                        ((QCheckBox*)w)->setChecked(val);
                        break;
                  case 2:
                        ((QGroupBox*)w)->setChecked(val);
                        break;
                  case 3:
                        ((Awl::Knob*)w)->setValue(double(val));
                        break;
                  case 4:
                        ((QPushButton*)w)->setChecked(val);
                        break;
                  case 5:
                        ((Awl::Drawbar*)w)->setValue(double(val));
                        break;
                  default:
                        printf("OrganGui::setParamIdx: illegal ctrlType %d\n", ctrlType);
                        break;
                  }
            }
      ignoreControllerChange = false;
      }

//---------------------------------------------------------
//   processEvent
//---------------------------------------------------------

void OrganGui::processEvent(const MidiEvent& ev)
      {
      if (ev.type() == ME_CONTROLLER)
            setParam(ev.dataA(), ev.dataB());
      else
            printf("OrganGui::illegal event type received\n");
      }

//---------------------------------------------------------
//   readMessage
//---------------------------------------------------------

void OrganGui::readMessage(int)
      {
      MessGui::readMessage();
      }