~ubuntu-branches/ubuntu/raring/muse/raring-proposed

« back to all changes in this revision

Viewing changes to muse/widgets/midi_audio_control.cpp

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2012-11-22 01:16:59 UTC
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: package-import@ubuntu.com-20121122011659-a2fwbf33ceqe1s0t
Tags: upstream-2.1~rc1
ImportĀ upstreamĀ versionĀ 2.1~rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
{
46
46
  setupUi(this);
47
47
 
 
48
  controlTypeComboBox->addItem(tr("Control7"), MusECore::MidiController::Controller7);
 
49
  controlTypeComboBox->addItem(tr("Control14"), MusECore::MidiController::Controller14);
 
50
  controlTypeComboBox->addItem(tr("RPN"), MusECore::MidiController::RPN);
 
51
  controlTypeComboBox->addItem(tr("NPRN"), MusECore::MidiController::NRPN);
 
52
  controlTypeComboBox->addItem(tr("RPN14"), MusECore::MidiController::RPN14);
 
53
  controlTypeComboBox->addItem(tr("NRPN14"), MusECore::MidiController::NRPN14);
 
54
  controlTypeComboBox->addItem(tr("Pitch"), MusECore::MidiController::Pitch);
 
55
  controlTypeComboBox->addItem(tr("Program"), MusECore::MidiController::Program);
 
56
  //controlTypeComboBox->addItem(tr("PolyAftertouch"), MusECore::MidiController::PolyAftertouch); // Not supported yet. Need a way to select pitch.
 
57
  controlTypeComboBox->addItem(tr("Aftertouch"), MusECore::MidiController::Aftertouch);
 
58
  controlTypeComboBox->setCurrentIndex(0);
 
59
  
48
60
  _port = port;
49
61
  _chan = chan;
50
62
  _ctrl = ctrl;
88
100
 
89
101
    if(MusEGlobal::midiLearnCtrl != -1)
90
102
    {
91
 
      int type = MusECore::midiControllerType(MusEGlobal::midiLearnCtrl);
92
 
      if(type < controlTypeComboBox->count() && type != controlTypeComboBox->currentIndex())
 
103
      MusECore::MidiController::ControllerType type = MusECore::midiControllerType(MusEGlobal::midiLearnCtrl);
 
104
      int idx = controlTypeComboBox->findData(type);
 
105
      if(idx != -1 && idx != controlTypeComboBox->currentIndex())
93
106
      {
94
107
        controlTypeComboBox->blockSignals(true);
95
 
        controlTypeComboBox->setCurrentIndex(type);
 
108
        controlTypeComboBox->setCurrentIndex(idx);
96
109
        controlTypeComboBox->blockSignals(false);
97
110
      }
98
111
 
99
112
      int hv = (MusEGlobal::midiLearnCtrl >> 8) & 0xff;
100
113
      int lv = MusEGlobal::midiLearnCtrl & 0xff;
101
 
      if(type == MusECore::MidiController::Program || type == MusECore::MidiController::Pitch)
102
 
      {
103
 
        ctrlHiSpinBox->setEnabled(false);
104
 
        ctrlLoSpinBox->setEnabled(false);
105
 
        ctrlHiSpinBox->blockSignals(true);
106
 
        ctrlLoSpinBox->blockSignals(true);
107
 
        ctrlHiSpinBox->setValue(0);
108
 
        ctrlLoSpinBox->setValue(0);
109
 
        ctrlHiSpinBox->blockSignals(false);
110
 
        ctrlLoSpinBox->blockSignals(false);
111
 
      }
112
 
      else if(type == MusECore::MidiController::Controller7)
113
 
      {
114
 
        ctrlHiSpinBox->setEnabled(false);
115
 
        ctrlLoSpinBox->setEnabled(true);
116
 
 
117
 
        ctrlHiSpinBox->blockSignals(true);
118
 
        ctrlHiSpinBox->setValue(0);
119
 
        ctrlHiSpinBox->blockSignals(false);
120
 
        
121
 
        if(lv != ctrlLoSpinBox->value())
122
 
        {
123
 
          ctrlLoSpinBox->blockSignals(true);
124
 
          ctrlLoSpinBox->setValue(lv);
125
 
          ctrlLoSpinBox->blockSignals(false);
126
 
        }
127
 
      }
128
 
      else
129
 
      {
130
 
        ctrlHiSpinBox->setEnabled(true);
131
 
        ctrlLoSpinBox->setEnabled(true);
132
 
        if(hv != ctrlHiSpinBox->value())
133
 
        {
134
 
          ctrlHiSpinBox->blockSignals(true);
135
 
          ctrlHiSpinBox->setValue(hv);
136
 
          ctrlHiSpinBox->blockSignals(false);
137
 
        }
138
 
        if(lv != ctrlLoSpinBox->value())
139
 
        {
140
 
          ctrlLoSpinBox->blockSignals(true);
141
 
          ctrlLoSpinBox->setValue(lv);
142
 
          ctrlLoSpinBox->blockSignals(false);
143
 
        }
144
 
      }  
 
114
 
 
115
      switch(type)
 
116
      {
 
117
        case MusECore::MidiController::Program:
 
118
        case MusECore::MidiController::Pitch:
 
119
        case MusECore::MidiController::PolyAftertouch: // Unsupported yet. Need a way to select pitch.
 
120
        case MusECore::MidiController::Aftertouch:
 
121
          ctrlHiSpinBox->setEnabled(false);
 
122
          ctrlLoSpinBox->setEnabled(false);
 
123
          ctrlHiSpinBox->blockSignals(true);
 
124
          ctrlLoSpinBox->blockSignals(true);
 
125
          ctrlHiSpinBox->setValue(0);
 
126
          ctrlLoSpinBox->setValue(0);
 
127
          ctrlHiSpinBox->blockSignals(false);
 
128
          ctrlLoSpinBox->blockSignals(false);
 
129
          break;
 
130
        case MusECore::MidiController::Controller7:
 
131
          ctrlHiSpinBox->setEnabled(false);
 
132
          ctrlLoSpinBox->setEnabled(true);
 
133
 
 
134
          ctrlHiSpinBox->blockSignals(true);
 
135
          ctrlHiSpinBox->setValue(0);
 
136
          ctrlHiSpinBox->blockSignals(false);
 
137
 
 
138
          if(lv != ctrlLoSpinBox->value())
 
139
          {
 
140
            ctrlLoSpinBox->blockSignals(true);
 
141
            ctrlLoSpinBox->setValue(lv);
 
142
            ctrlLoSpinBox->blockSignals(false);
 
143
          }
 
144
          break;
 
145
        case MusECore::MidiController::Controller14:  
 
146
        case MusECore::MidiController::RPN:
 
147
        case MusECore::MidiController::RPN14:
 
148
        case MusECore::MidiController::NRPN:
 
149
        case MusECore::MidiController::NRPN14:
 
150
          ctrlHiSpinBox->setEnabled(true);
 
151
          ctrlLoSpinBox->setEnabled(true);
 
152
          if(hv != ctrlHiSpinBox->value())
 
153
          {
 
154
            ctrlHiSpinBox->blockSignals(true);
 
155
            ctrlHiSpinBox->setValue(hv);
 
156
            ctrlHiSpinBox->blockSignals(false);
 
157
          }
 
158
          if(lv != ctrlLoSpinBox->value())
 
159
          {
 
160
            ctrlLoSpinBox->blockSignals(true);
 
161
            ctrlLoSpinBox->setValue(lv);
 
162
            ctrlLoSpinBox->blockSignals(false);
 
163
          }
 
164
          break;
 
165
        default:
 
166
          printf("FIXME: MidiAudioControl::heartbeat: Unknown control type: %d\n", type);
 
167
          break;
 
168
      }
145
169
      
146
170
      _ctrl = MusECore::midiCtrlTerms2Number(type, (ctrlHiSpinBox->value() << 8) + ctrlLoSpinBox->value());
147
171
    }
184
208
 
185
209
void MidiAudioControl::updateCtrlBoxes()
186
210
{
187
 
  int idx = controlTypeComboBox->currentIndex();
188
 
  if(idx == -1)
 
211
  if(controlTypeComboBox->currentIndex() == -1)
189
212
    return;
190
 
  
191
 
  if(idx == MusECore::MidiController::Program || idx == MusECore::MidiController::Pitch)
192
 
  {
193
 
    ctrlHiSpinBox->setEnabled(false);
194
 
    ctrlLoSpinBox->setEnabled(false);
195
 
    ctrlHiSpinBox->blockSignals(true);
196
 
    ctrlLoSpinBox->blockSignals(true);
197
 
    ctrlHiSpinBox->setValue(0);
198
 
    ctrlLoSpinBox->setValue(0);
199
 
    ctrlHiSpinBox->blockSignals(false);
200
 
    ctrlLoSpinBox->blockSignals(false);
201
 
  }
202
 
  else if(idx == MusECore::MidiController::Controller7)
203
 
  {
204
 
    ctrlHiSpinBox->setEnabled(false);
205
 
    ctrlLoSpinBox->setEnabled(true);
 
213
  MusECore::MidiController::ControllerType t = (MusECore::MidiController::ControllerType)controlTypeComboBox->itemData(controlTypeComboBox->currentIndex()).toInt();
206
214
 
207
 
    ctrlHiSpinBox->blockSignals(true);
208
 
    ctrlHiSpinBox->setValue(0);
209
 
    ctrlHiSpinBox->blockSignals(false);
 
215
  switch(t)
 
216
  {
 
217
    case MusECore::MidiController::Program:
 
218
    case MusECore::MidiController::Pitch:
 
219
    case MusECore::MidiController::PolyAftertouch: // Unsupported yet. Need a way to select pitch.
 
220
    case MusECore::MidiController::Aftertouch:
 
221
      ctrlHiSpinBox->setEnabled(false);
 
222
      ctrlLoSpinBox->setEnabled(false);
 
223
      ctrlHiSpinBox->blockSignals(true);
 
224
      ctrlLoSpinBox->blockSignals(true);
 
225
      ctrlHiSpinBox->setValue(0);
 
226
      ctrlLoSpinBox->setValue(0);
 
227
      ctrlHiSpinBox->blockSignals(false);
 
228
      ctrlLoSpinBox->blockSignals(false);
 
229
      break;
 
230
    case MusECore::MidiController::Controller7:
 
231
      ctrlHiSpinBox->setEnabled(false);
 
232
      ctrlLoSpinBox->setEnabled(true);
 
233
      ctrlHiSpinBox->blockSignals(true);
 
234
      ctrlHiSpinBox->setValue(0);
 
235
      ctrlHiSpinBox->blockSignals(false);
 
236
      break;
 
237
    case MusECore::MidiController::Controller14:
 
238
    case MusECore::MidiController::RPN:
 
239
    case MusECore::MidiController::RPN14:
 
240
    case MusECore::MidiController::NRPN:
 
241
    case MusECore::MidiController::NRPN14:
 
242
      ctrlHiSpinBox->setEnabled(true);
 
243
      ctrlLoSpinBox->setEnabled(true);
 
244
      break;
 
245
    default:
 
246
      printf("FIXME: MidiAudioControl::updateCtrlBoxes: Unknown control type: %d\n", t);
 
247
      break;
210
248
  }
211
 
  else
212
 
  {
213
 
    ctrlHiSpinBox->setEnabled(true);
214
 
    ctrlLoSpinBox->setEnabled(true);
215
 
  }  
216
249
}
217
250
 
218
251
void MidiAudioControl::ctrlTypeChanged(int idx)
219
252
{
220
253
  if(idx == -1)
221
254
    return;
222
 
  
 
255
 
223
256
  updateCtrlBoxes();
224
257
  
225
258
  _ctrl = (ctrlHiSpinBox->value() << 8) + ctrlLoSpinBox->value();
226
 
  _ctrl = MusECore::midiCtrlTerms2Number(idx, _ctrl);
 
259
  _ctrl = MusECore::midiCtrlTerms2Number((MusECore::MidiController::ControllerType)controlTypeComboBox->itemData(idx).toInt(), _ctrl);
227
260
 
228
261
  resetLearn();
229
262
}
233
266
  if(controlTypeComboBox->currentIndex() == -1)
234
267
    return;
235
268
  _ctrl = (ctrlHiSpinBox->value() << 8) + ctrlLoSpinBox->value();
236
 
  _ctrl = MusECore::midiCtrlTerms2Number(controlTypeComboBox->currentIndex(), _ctrl);
 
269
  _ctrl = MusECore::midiCtrlTerms2Number((MusECore::MidiController::ControllerType)controlTypeComboBox->itemData(controlTypeComboBox->currentIndex()).toInt(), _ctrl);
237
270
 
238
271
  resetLearn();
239
272
}
243
276
  if(controlTypeComboBox->currentIndex() == -1)
244
277
    return;
245
278
  _ctrl = (ctrlHiSpinBox->value() << 8) + ctrlLoSpinBox->value();
246
 
  _ctrl = MusECore::midiCtrlTerms2Number(controlTypeComboBox->currentIndex(), _ctrl);
 
279
  _ctrl = MusECore::midiCtrlTerms2Number((MusECore::MidiController::ControllerType)controlTypeComboBox->itemData(controlTypeComboBox->currentIndex()).toInt(), _ctrl);
247
280
 
248
281
  resetLearn();
249
282
}
282
315
  channelSpinBox->blockSignals(false);
283
316
 
284
317
  int type = MusECore::midiControllerType(_ctrl);
285
 
  if(type < controlTypeComboBox->count())
 
318
  int idx = controlTypeComboBox->findData(type);
 
319
  if(idx != -1 && idx != controlTypeComboBox->currentIndex())
286
320
  {
287
321
    controlTypeComboBox->blockSignals(true);
288
 
    controlTypeComboBox->setCurrentIndex(type);
 
322
    controlTypeComboBox->setCurrentIndex(idx);
289
323
    controlTypeComboBox->blockSignals(false);
290
324
  }
291
325
 
292
326
  int hv = (_ctrl >> 8) & 0xff;
293
327
  int lv = _ctrl & 0xff;
294
 
  if(type == MusECore::MidiController::Program || type == MusECore::MidiController::Pitch)
295
 
  {
296
 
    ctrlHiSpinBox->setEnabled(false);
297
 
    ctrlLoSpinBox->setEnabled(false);
298
 
    ctrlHiSpinBox->blockSignals(true);
299
 
    ctrlLoSpinBox->blockSignals(true);
300
 
    ctrlHiSpinBox->setValue(0);
301
 
    ctrlLoSpinBox->setValue(0);
302
 
    ctrlHiSpinBox->blockSignals(false);
303
 
    ctrlLoSpinBox->blockSignals(false);
304
 
  }
305
 
  else if(type == MusECore::MidiController::Controller7)
306
 
  {
307
 
    ctrlHiSpinBox->setEnabled(false);
308
 
    ctrlLoSpinBox->setEnabled(true);
309
 
 
310
 
    ctrlHiSpinBox->blockSignals(true);
311
 
    ctrlHiSpinBox->setValue(0);
312
 
    ctrlHiSpinBox->blockSignals(false);
313
 
    
314
 
    if(lv != ctrlLoSpinBox->value())
315
 
    {
316
 
      ctrlLoSpinBox->blockSignals(true);
317
 
      ctrlLoSpinBox->setValue(lv);
318
 
      ctrlLoSpinBox->blockSignals(false);
319
 
    }
320
 
  }
321
 
  else
322
 
  {
323
 
    ctrlHiSpinBox->setEnabled(true);
324
 
    ctrlLoSpinBox->setEnabled(true);
325
 
    if(hv != ctrlHiSpinBox->value())
326
 
    {
327
 
      ctrlHiSpinBox->blockSignals(true);
328
 
      ctrlHiSpinBox->setValue(hv);
329
 
      ctrlHiSpinBox->blockSignals(false);
330
 
    }
331
 
    if(lv != ctrlLoSpinBox->value())
332
 
    {
333
 
      ctrlLoSpinBox->blockSignals(true);
334
 
      ctrlLoSpinBox->setValue(lv);
335
 
      ctrlLoSpinBox->blockSignals(false);
336
 
    }
337
 
  }
338
 
}
339
 
 
340
 
}
 
328
 
 
329
  switch(type)
 
330
  {
 
331
    case MusECore::MidiController::Program:
 
332
    case MusECore::MidiController::Pitch:
 
333
    case MusECore::MidiController::PolyAftertouch:  // Unsupported yet. Need a way to select pitch.
 
334
    case MusECore::MidiController::Aftertouch:
 
335
      ctrlHiSpinBox->setEnabled(false);
 
336
      ctrlLoSpinBox->setEnabled(false);
 
337
      ctrlHiSpinBox->blockSignals(true);
 
338
      ctrlLoSpinBox->blockSignals(true);
 
339
      ctrlHiSpinBox->setValue(0);
 
340
      ctrlLoSpinBox->setValue(0);
 
341
      ctrlHiSpinBox->blockSignals(false);
 
342
      ctrlLoSpinBox->blockSignals(false);
 
343
      break;
 
344
    case MusECore::MidiController::Controller7:  
 
345
      ctrlHiSpinBox->setEnabled(false);
 
346
      ctrlLoSpinBox->setEnabled(true);
 
347
 
 
348
      ctrlHiSpinBox->blockSignals(true);
 
349
      ctrlHiSpinBox->setValue(0);
 
350
      ctrlHiSpinBox->blockSignals(false);
 
351
 
 
352
      if(lv != ctrlLoSpinBox->value())
 
353
      {
 
354
        ctrlLoSpinBox->blockSignals(true);
 
355
        ctrlLoSpinBox->setValue(lv);
 
356
        ctrlLoSpinBox->blockSignals(false);
 
357
      }
 
358
      break;
 
359
    case MusECore::MidiController::Controller14:
 
360
    case MusECore::MidiController::RPN:
 
361
    case MusECore::MidiController::RPN14:
 
362
    case MusECore::MidiController::NRPN:
 
363
    case MusECore::MidiController::NRPN14:
 
364
      ctrlHiSpinBox->setEnabled(true);
 
365
      ctrlLoSpinBox->setEnabled(true);
 
366
      if(hv != ctrlHiSpinBox->value())
 
367
      {
 
368
        ctrlHiSpinBox->blockSignals(true);
 
369
        ctrlHiSpinBox->setValue(hv);
 
370
        ctrlHiSpinBox->blockSignals(false);
 
371
      }
 
372
      if(lv != ctrlLoSpinBox->value())
 
373
      {
 
374
        ctrlLoSpinBox->blockSignals(true);
 
375
        ctrlLoSpinBox->setValue(lv);
 
376
        ctrlLoSpinBox->blockSignals(false);
 
377
      }
 
378
      break;
 
379
    default:
 
380
      printf("FIXME: MidiAudioControl::updateCtrlBoxes: Unknown control type: %d\n", type);
 
381
      break;
 
382
  }
 
383
}
 
384
 
 
385
}  // namespace MusEGui