~ubuntu-branches/ubuntu/quantal/muse/quantal

« back to all changes in this revision

Viewing changes to muse/instruments/editinstrument.cpp

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2012-07-18 16:07:06 UTC
  • mto: (10.1.11 sid) (1.1.12)
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: package-import@ubuntu.com-20120718160706-yc6332ishfcq7b7g
ImportĀ upstreamĀ versionĀ 2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
      toolBar->addAction(QWhatsThis::createAction(this));
67
67
      Help->addAction(QWhatsThis::createAction(this));
68
68
 
69
 
      ///patchpopup = new QMenu(patchButton);
70
 
      //patchpopup->setCheckable(false);// Qt4 doc says this is unnecessary.
71
 
      
72
69
      // populate instrument list
73
70
      // Populate common controller list.
74
71
      for(int i = 0; i < 128; ++i)
75
 
        {
76
 
          QListWidgetItem *lci = new QListWidgetItem(MusECore::midiCtrlName(i));
77
 
          listController->addItem(lci);
78
 
        }
 
72
      {
 
73
        QListWidgetItem *lci = new QListWidgetItem(MusECore::midiCtrlName(i));
 
74
        listController->addItem(lci);
 
75
      }
79
76
      oldMidiInstrument = 0;
80
77
      oldPatchItem = 0;
81
78
      for (MusECore::iMidiInstrument i = MusECore::midiInstruments.begin(); i != MusECore::midiInstruments.end(); ++i) {
95
92
      instrumentList->setSelectionMode(QAbstractItemView::SingleSelection);
96
93
      if(instrumentList->item(0))
97
94
        instrumentList->setCurrentItem(instrumentList->item(0));
 
95
      //DELETETHIS
98
96
      //oldMidiInstrument = (MusECore::MidiInstrument*)((ListBoxData*)instrumentList->item(0))->data();
99
97
      //oldMidiInstrument = (ListBoxData*)instrumentList->item(0);
100
98
      //oldMidiInstrument = (ListBoxData*)instrumentList->selectedItem();
108
106
      connect(instrumentList, SIGNAL(itemSelectionChanged()), SLOT(instrumentChanged()));
109
107
      connect(patchView, SIGNAL(itemSelectionChanged()), SLOT(patchChanged()));
110
108
      
111
 
      //instrumentChanged();
112
109
      changeInstrument();
113
110
      
114
 
      //connect(listController, SIGNAL(selectionChanged()), SLOT(controllerChanged()));
115
111
      connect(viewController, SIGNAL(itemSelectionChanged()), SLOT(controllerChanged()));
116
112
      
117
 
      //connect(instrumentName, SIGNAL(textChanged(const QString&)), SLOT(instrumentNameChanged(const QString&)));
118
113
      connect(instrumentName, SIGNAL(returnPressed()), SLOT(instrumentNameReturn()));
119
114
      connect(instrumentName, SIGNAL(lostFocus()), SLOT(instrumentNameReturn()));
120
115
      
123
118
      connect(patchDelete, SIGNAL(clicked()), SLOT(deletePatchClicked()));
124
119
      connect(patchNew, SIGNAL(clicked()), SLOT(newPatchClicked()));
125
120
      connect(patchNewGroup, SIGNAL(clicked()), SLOT(newGroupClicked()));
126
 
      //connect(newCategory, SIGNAL(clicked()), SLOT(newCategoryClicked()));
127
121
      
128
122
      connect(patchButton, SIGNAL(clicked()), SLOT(patchButtonClicked()));
129
123
      connect(defPatchH, SIGNAL(valueChanged(int)), SLOT(defPatchChanged(int)));
136
130
      connect(ctrlType,SIGNAL(activated(int)), SLOT(ctrlTypeChanged(int)));
137
131
      connect(ctrlName, SIGNAL(returnPressed()), SLOT(ctrlNameReturn()));
138
132
      connect(ctrlName, SIGNAL(lostFocus()), SLOT(ctrlNameReturn()));
139
 
      //connect(ctrlName, SIGNAL(textChanged(const QString&)), SLOT(ctrlNameChanged(const QString&)));
140
133
      connect(spinBoxHCtrlNo, SIGNAL(valueChanged(int)), SLOT(ctrlHNumChanged(int)));
141
134
      connect(spinBoxLCtrlNo, SIGNAL(valueChanged(int)), SLOT(ctrlLNumChanged(int)));
142
135
      connect(spinBoxMin, SIGNAL(valueChanged(int)), SLOT(ctrlMinChanged(int)));
146
139
      connect(nullParamSpinBoxL, SIGNAL(valueChanged(int)), SLOT(ctrlNullParamLChanged(int)));
147
140
      
148
141
      connect(tabWidget3, SIGNAL(currentChanged(QWidget*)), SLOT(tabChanged(QWidget*)));
149
 
      //connect(sysexList, SIGNAL(selectionChanged()), SLOT(sysexChanged()));
 
142
      //connect(sysexList, SIGNAL(selectionChanged()), SLOT(sysexChanged())); DELETETHIS or is it needed later?
150
143
      //connect(deleteSysex, SIGNAL(clicked()), SLOT(deleteSysexClicked()));
151
144
      //connect(newSysex, SIGNAL(clicked()), SLOT(newSysexClicked()));
152
145
      }
181
174
                        }
182
175
                  }
183
176
            if (!found) {
184
 
                  //if(oldMidiInstrument)
185
 
                  //{
186
177
                        MusECore::MidiInstrument* oi = 0;
187
178
                        if(oldMidiInstrument)
188
179
                          oi = (MusECore::MidiInstrument*)oldMidiInstrument->data(Qt::UserRole).value<void*>();
189
180
                        MusECore::MidiInstrument* wip = &workingInstrument;
190
 
                        //checkDirty(oi);
191
 
                        //if(checkDirty(oi))
192
 
                        if(checkDirty(wip))
193
 
                        // No save was chosen. Restore the actual instrument name.
 
181
                        if(checkDirty(wip)) // No save was chosen. Restore the actual instrument name.
194
182
                        {
195
183
                          if(oi)
196
184
                          {
197
185
                            oldMidiInstrument->setText(oi->iname());
198
 
                            //workingInstrument.setIName(oi->iname());
199
186
                            
200
187
                            // No file path? Only a new unsaved instrument can do that. So delete it.
201
188
                            if(oi->filePath().isEmpty())
204
191
                            
205
192
                          }  
206
193
                        }
207
 
                        //else  
208
 
                        //{
209
 
                        //  if(oi)
210
 
                            // Save was chosen. Assign the working instrument to the actual instrument.
211
 
                        //    oi->assign(workingInstrument);
212
 
                        //}  
213
 
                        
214
 
                        //oi->setDirty(false);
215
194
                        workingInstrument.setDirty(false);
216
 
                  //}
217
195
                        
218
196
                  MusECore::MidiInstrument* ni = new MusECore::MidiInstrument(s);
219
 
                  //MusECore::midiInstruments.append(ni);
220
197
                  MusECore::midiInstruments.push_back(ni);
221
 
                  //QListWidgetItem* item = new QListWidgetItem(ni->iname());
222
 
                  //InstrumentListItem* item = new InstrumentListItem(ni->iname());
223
198
                  QListWidgetItem* item = new QListWidgetItem(ni->iname());
224
199
                  
225
 
                  //oldMidiInstrument = item;
226
200
                  workingInstrument.assign( *ni );
227
 
                  //workingInstrument.setDirty(false);
228
 
                  
229
 
                  //item->setText(ni->iname());
 
201
 
230
202
                  QVariant v = qVariantFromValue((void*)(ni));
231
203
                  item->setData(Qt::UserRole, v);
232
204
                  instrumentList->addItem(item);
252
224
//   fileOpen
253
225
//---------------------------------------------------------
254
226
 
255
 
void EditInstrument::fileOpen()
 
227
void EditInstrument::fileOpen() //DELETETHIS?
256
228
      {
257
 
      // Allow these to update...
258
 
      //instrumentNameReturn();
259
 
      //patchNameReturn();
260
 
      //ctrlNameReturn();
261
 
      
262
 
      
263
229
      }
264
230
 
265
231
//---------------------------------------------------------
268
234
 
269
235
void EditInstrument::fileSave()
270
236
{
271
 
      //if (instrument->filePath().isEmpty())
272
237
      if (workingInstrument.filePath().isEmpty())
273
238
      {
274
 
        //fileSaveAs();
275
239
        saveAs();
276
240
        return;
277
241
      }      
280
244
      QFileInfo qfi(workingInstrument.filePath());
281
245
      if(qfi.absolutePath() == MusEGlobal::museInstruments)
282
246
      {
283
 
        //fileSaveAs();
284
247
        saveAs();
285
248
        return;
286
249
      }
287
250
      
288
 
      //QFile f(instrument->filePath());
289
 
      //if (!f.open(QIODevice::WriteOnly)) {
290
 
      //FILE* f = fopen(instrument->filePath().toLatin1().constData(), "w");
291
251
      FILE* f = fopen(workingInstrument.filePath().toLatin1().constData(), "w");
292
252
      if(f == 0)
293
253
      {
294
 
        //fileSaveAs();
295
254
        saveAs();
296
255
        return;
297
256
      }  
301
260
      patchNameReturn();
302
261
      ctrlNameReturn();
303
262
      
304
 
      //f.close();
305
263
      if(fclose(f) != 0)
306
264
      {
307
 
        //QString s = QString("Creating file:\n") + instrument->filePath() + QString("\nfailed: ")
308
265
        QString s = QString("Creating file:\n") + workingInstrument.filePath() + QString("\nfailed: ")
309
 
          //+ f.errorString();
310
266
          + QString(strerror(errno) );
311
 
        //fprintf(stderr, "poll failed: %s\n", strerror(errno));
312
267
        QMessageBox::critical(this, tr("MusE: Create file failed"), s);
313
268
        return;
314
269
      }
315
270
      
316
 
      //if(fileSave(instrument, instrument->filePath()))
317
 
      //  instrument->setDirty(false);
318
271
      if(fileSave(&workingInstrument, workingInstrument.filePath()))
319
272
        workingInstrument.setDirty(false);
320
273
}
325
278
 
326
279
bool EditInstrument::fileSave(MusECore::MidiInstrument* instrument, const QString& name)
327
280
    {
328
 
      //QFile f(name);
 
281
      //QFile f(name);                                  DELETETHIS
329
282
      //if (!f.open(QIODevice::WriteOnly)) {
330
283
      //      QString s("Creating file failed: ");
331
284
      //      s += strerror(errno);
338
291
      FILE* f = fopen(name.toAscii().constData(), "w");
339
292
      if(f == 0)
340
293
      {
341
 
        //if(debugMsg)
342
 
        //  printf("READ IDF %s\n", fi->filePath().toLatin1().constData());
343
294
        QString s("Creating file failed: ");
344
295
        s += QString(strerror(errno));
345
296
        QMessageBox::critical(this,
351
302
      
352
303
      updateInstrument(instrument);
353
304
      
354
 
      //instrument->write(xml);
355
305
      instrument->write(0, xml);
356
306
      
357
307
      // Assign the working instrument values to the actual current selected instrument...
364
314
          
365
315
          // Now signal the rest of the app so stuff can change...
366
316
          MusEGlobal::song->update(SC_CONFIG | SC_MIDI_CONTROLLER);
367
 
          //MusEGlobal::song->update(SC_CONFIG | SC_MIDI_CONTROLLER | SC_MIDI_CONTROLLER_ADD);
368
317
        }  
369
318
      }
370
319
      
371
 
      //f.close();
372
 
      //if (f.error()) {
373
320
      if(fclose(f) != 0)
374
321
      {
375
322
            QString s = QString("Write File\n") + name + QString("\nfailed: ")
376
 
               //+ f.errorString();
377
323
               + QString(strerror(errno));
378
 
            //fprintf(stderr, "poll failed: %s\n", strerror(errno));
379
324
            QMessageBox::critical(this, tr("MusE: Write File failed"), s);
380
325
            return false;
381
326
      }
393
338
      patchNameReturn();
394
339
      ctrlNameReturn();
395
340
      
396
 
      //QListWidgetItem* item = instrumentList->currentItem();
 
341
      //QListWidgetItem* item = instrumentList->currentItem();              DELETETHIS
397
342
//      ListBoxData* item = (ListBoxData*)instrumentList->selectedItem();
398
343
//      if (item == 0)
399
344
//            return;
409
354
      {
410
355
        printf("MusE Error! User instrument directory: %s does not exist. Should be created at startup!\n", MusEGlobal::museUserInstruments.toLatin1().constData());
411
356
        
412
 
        //path = MusEGlobal::museUser;
 
357
        //path = MusEGlobal::museUser; DELETETHIS?
413
358
        //path = MusEGlobal::configPath;  
414
359
      }
415
360
        
416
 
      //if (instrument->filePath().isEmpty())
417
361
      if (workingInstrument.filePath().isEmpty())
418
362
            path += QString("/%1.idf").arg(workingInstrument.iname());
419
363
      else {
420
 
            //QFileInfo fi(instrument->filePath());
421
364
            QFileInfo fi(workingInstrument.filePath());
422
365
            
423
366
            // Prompt for a new instrument name if the name has not been changed, to avoid duplicates.
432
375
                  // This will still allow a user instrument to override a built-in instrument with the same name.
433
376
                  if(fi.absolutePath() != MusEGlobal::museInstruments)
434
377
                  {
435
 
                    //QMessageBox::critical(this,
 
378
                    //QMessageBox::critical(this,             DELETETHIS???
436
379
                    //    tr("MusE: Bad instrument name"),
437
380
                    //    tr("Please change the instrument name to a new unique name before saving, to avoid duplicates"),
438
381
                    //    QMessageBox::Ok,
446
389
            }  
447
390
            path += QString("/%1.idf").arg(fi.baseName());
448
391
           }
449
 
      //QString s = QFileDialog::getSaveFileName(this,
450
 
      //   tr("MusE: Save Instrument Definition"),
451
 
      //   path,
452
 
      //   tr("Instrument Definition (*.idf)"));
453
 
      
 
392
 
454
393
      QString s = QFileDialog::getSaveFileName(this, tr("MusE: Save Instrument Definition").toLatin1().constData(), 
455
394
         path, tr("Instrument Definition (*.idf)"));
456
395
      if (s.isEmpty())
457
396
            return;
458
 
      //instrument->setFilePath(s);
459
397
      workingInstrument.setFilePath(s);
460
398
      
461
 
      //if (fileSave(instrument, s))
462
 
      //      instrument->setDirty(false);
463
399
      if(fileSave(&workingInstrument, s))
464
400
        workingInstrument.setDirty(false);
465
401
    }
491
427
      {
492
428
        // No save:
493
429
        case 1:
494
 
          //item->setText(instrument->iname());
495
 
          //instrumentList->triggerUpdate(true);
496
 
          //instrument->setDirty(false);
497
430
          workingInstrument.setDirty(false);
498
431
          if(oi)
499
432
          {
500
433
            oldMidiInstrument->setText(oi->iname());
501
 
            //workingInstrument.setIName(oi->iname());
502
 
            
503
 
            //workingInstrument.assign(*oi);
504
434
            
505
435
            // No file path? Only a new unsaved instrument can do that. So delete it.
506
436
            if(oi->filePath().isEmpty())
523
453
          
524
454
        // Save:
525
455
        case 0:
526
 
            //if(oi)
527
 
            //  oi->assign(workingInstrument);
528
456
            workingInstrument.setDirty(false);
529
457
        break;
530
458
      }
531
459
      
532
 
      //QListWidgetItem* item = instrumentList->currentItem();
 
460
      //QListWidgetItem* item = instrumentList->currentItem(); DELETETHIS
533
461
//      ListBoxData* item = (ListBoxData*)instrumentList->selectedItem();
534
462
//      if (item == 0)
535
463
//            return;
610
538
                  break;
611
539
                }
612
540
              }
613
 
              // Assign the found instrument to the working instrument.
614
 
              //workingInstrument.assign(*(*imi));
 
541
 
615
542
              // Assign the found instrument name to the working instrument name.
616
543
              workingInstrument.setIName(s);
617
544
              
642
569
          ni->assign(workingInstrument);
643
570
          ni->setIName(so);
644
571
          ni->setFilePath(QString());
645
 
          //MusECore::midiInstruments.append(ni);
646
572
          MusECore::midiInstruments.push_back(ni);
647
 
          //QListWidgetItem* item = new QListWidgetItem(ni->iname());
648
 
          //InstrumentListItem* item = new InstrumentListItem(ni->iname());
649
 
          //ListBoxData* item = new ListBoxData(ni->iname());
650
573
          QListWidgetItem* item = new QListWidgetItem(so);
651
574
          
652
 
          //oldMidiInstrument = item;
653
575
          workingInstrument.assign( *ni );
654
 
          //workingInstrument.setDirty(false);
655
 
          
656
 
          //item->setText(ni->iname());
657
 
          //item->setData((void*)ni);
 
576
 
658
577
          QVariant v = qVariantFromValue((void*)(ni));
659
578
          item->setData(Qt::UserRole, v);
660
 
          //instrumentList->addItem(item);
661
579
          instrumentList->addItem(item);
662
580
          
663
581
          oldMidiInstrument = 0;
675
593
        break;
676
594
      }
677
595
      
678
 
      //QString path = QDir::homePath() + "/" + MusEGlobal::config.instrumentPath;
679
 
      //QString path = QDir::homeDirPath() + "/" + MusEGlobal::museGlobalShare;
680
 
      //QString path = MusEGlobal::museInstruments;
681
596
      QString path = MusEGlobal::museUserInstruments;
682
597
      
683
598
      if(!QDir(MusEGlobal::museUserInstruments).exists())
684
599
      {
685
600
        printf("MusE Error! User instrument directory: %s does not exist. Should be created at startup!\n", MusEGlobal::museUserInstruments.toLatin1().constData());
686
601
        
687
 
        //path = MusEGlobal::museUser;
 
602
        //path = MusEGlobal::museUser; DELETETHIS
688
603
        //path = MusEGlobal::configPath;  
689
604
      }
690
605
      path += QString("/%1.idf").arg(so);
691
 
      
692
 
      //QString s = QFileDialog::getSaveFileName(this,
693
 
      //   tr("MusE: Save Instrument Definition"),
694
 
      //   path,
695
 
      //   tr("Instrument Definition (*.idf)"));
696
 
      
 
606
            
697
607
      QString sfn;
698
608
      // If we are overwriting a user instrument just force the path.
699
609
      if(isuser)
704
614
           path, tr("Instrument Definition (*.idf)"));
705
615
        if (sfn.isEmpty())
706
616
              return;
707
 
        //instrument->setFilePath(s);
708
617
        workingInstrument.setFilePath(sfn);
709
618
      }  
710
619
      
711
 
      //if (fileSave(instrument, s))
712
 
      //      instrument->setDirty(false);
713
620
      if(fileSave(&workingInstrument, sfn))
714
621
        workingInstrument.setDirty(false);
715
622
    }
734
641
      patchNameReturn();
735
642
      ctrlNameReturn();
736
643
      
737
 
      //QListWidgetItem* item = instrumentList->currentItem();
 
644
      //QListWidgetItem* item = instrumentList->currentItem(); DELETETHIS
738
645
      
739
646
//      ListBoxData* item = (ListBoxData*)instrumentList->selectedItem();
740
647
      
752
659
        {
753
660
          // No save:
754
661
          case 1:
755
 
            //item->setText(instrument->iname());
756
 
            //instrumentList->triggerUpdate(true);
757
 
            //instrument->setDirty(false);
758
662
            workingInstrument.setDirty(false);
759
663
            if(oi)
760
664
            {
761
665
              oldMidiInstrument->setText(oi->iname());
762
 
              //workingInstrument.setIName(oi->iname());
763
 
              
764
 
              //workingInstrument.assign(*oi);
765
666
              
766
667
              // No file path? Only a new unsaved instrument can do that. So delete it.
767
668
              if(oi->filePath().isEmpty())
784
685
            
785
686
          // Save:
786
687
          case 0:
787
 
              //if(oi)
788
 
              //  oi->assign(workingInstrument);
789
688
              workingInstrument.setDirty(false);
790
689
          break;
791
690
          
792
691
        }
793
 
        
794
 
//      }
795
692
      
796
693
      QMainWindow::closeEvent(ev);
797
694
      }
807
704
  if(!sel)
808
705
    return;
809
706
 
810
 
  //oldMidiInstrument = (MusECore::MidiInstrument*)sel->data();
811
707
  oldMidiInstrument = sel;
812
708
  // Assignment
813
 
  //workingInstrument = *((MusECore::MidiInstrument*)sel->data());
814
709
  
815
710
  // Assign will 'delete' any existing patches, groups, or controllers.
816
711
  workingInstrument.assign( *((MusECore::MidiInstrument*)sel->data(Qt::UserRole).value<void*>()) );
824
719
  patchView->clear();
825
720
  patchView->blockSignals(false);
826
721
 
827
 
  //viewController->blockSignals(true);
828
722
  for (int i = 0; i < viewController->topLevelItemCount(); ++i)
829
723
    qDeleteAll(viewController->topLevelItem(i)->takeChildren());
830
724
  viewController->clear();
831
 
  //viewController->blockSignals(false);
832
 
  
833
 
  //listController->clear();
834
 
  //category->clear();
835
 
  //sysexList->clear();
836
 
 
837
 
 
838
 
  //MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)sel->data(Qt::UserRole).value<void*>();
839
 
  //MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)sel->data();
840
 
  //instrument->setDirty(false);
841
725
 
842
726
  instrumentName->blockSignals(true);
843
 
  //instrumentName->setText(instrument->iname());
844
727
  instrumentName->setText(workingInstrument.iname());
845
728
  instrumentName->blockSignals(false);
846
729
  
868
751
  nullParamSpinBoxH->blockSignals(false);
869
752
  nullParamSpinBoxL->blockSignals(false);
870
753
  
871
 
  //std::vector<MusECore::PatchGroup>* pg = instrument->groups();
872
 
  //MusECore::PatchGroupList* pg = instrument->groups();
873
754
  MusECore::PatchGroupList* pg = workingInstrument.groups();
874
 
  //for (std::vector<MusECore::PatchGroup>::iterator g = pg->begin(); g != pg->end(); ++g) {
875
755
  for (MusECore::ciPatchGroup g = pg->begin(); g != pg->end(); ++g) {
876
756
        MusECore::PatchGroup* pgp = *g; 
877
757
        if(pgp)
878
758
        {
879
 
          //QTreeWidgetItem* item = new QTreeWidgetItem;
880
759
          QTreeWidgetItem* item = new QTreeWidgetItem(patchView);
881
760
          
882
 
          //item->setText(0, g->name);
883
761
          item->setText(0, pgp->name);
884
 
          //QVariant v = QVariant::fromValue((void*)0);
885
 
          //item->setData(0, Qt::UserRole, v);
886
 
          //item->setData((void*)*g);
887
 
          //item->setData((void*)0);
888
 
          //item->setData((void*)&*g);
889
 
          //item->setData((void*)pgp);
890
762
          QVariant v = qVariantFromValue((void*)(pgp));
891
763
          item->setData(0, Qt::UserRole, v);
892
 
          //patchView->addTopLevelItem(item);
893
764
          
894
 
          //for (MusECore::ciPatch p = g->patches.begin(); p != g->patches.end(); ++p) 
895
765
          for (MusECore::ciPatch p = pgp->patches.begin(); p != pgp->patches.end(); ++p) 
896
766
          {
897
 
            //const Patch& patch = *p;
898
767
            MusECore::Patch* patch = *p;
899
768
            if(patch)
900
769
            {
901
 
              //QTreeWidgetItem* sitem = new QTreeWidgetItem;
902
770
              QTreeWidgetItem* sitem = new QTreeWidgetItem(item);
903
 
              //printf("%s \n", qPrintable(patch->name));
904
 
 
905
 
              //sitem->setText(0, patch.name);
906
 
              //sitem->setText(0, p->name);
907
771
              sitem->setText(0, patch->name);
908
 
              //QVariant v = QVariant::fromValue((void*)patch);
909
 
              //sitem->setData(0, Qt::UserRole, v);
910
 
              //sitem->setData((void*)&*p);
911
 
              //sitem->setData((void*)patch);
912
772
              QVariant v = QVariant::fromValue((void*)patch);
913
773
              sitem->setData(0, Qt::UserRole, v);
914
 
              //item->addChild(sitem);
915
774
            }  
916
775
          }  
917
776
        }
918
777
      }  
919
 
  //patchView->setSelected(patchView->item(0), true);
920
778
  
921
779
  oldPatchItem = 0;
922
780
  
924
782
  if(fc)
925
783
  {
926
784
    // This may cause a patchChanged call.
927
 
    //if(patchView->selectedItem() != fc)
 
785
    //if(patchView->selectedItem() != fc) DELETETHIS
928
786
    patchView->blockSignals(true);
929
787
    fc->setSelected(true);
930
788
    patchView->blockSignals(false);
931
789
    //else  
932
 
    //  patchChanged();
 
790
    //  patchChanged(); DELETETHIS
933
791
 
934
 
    //patchView->firstChild()->setSelected(true);
 
792
    //patchView->firstChild()->setSelected(true); DELETETHIS
935
793
    //patchView->triggerUpdate(true);
936
794
  }
937
795
      
938
796
  patchChanged();
939
797
  
940
 
//      oldPatchItem = (ListViewData*)patchView->selectedItem();
 
798
//      oldPatchItem = (ListViewData*)patchView->selectedItem(); DELETETHIS
941
799
      //patchChanged();
942
800
//      if(oldPatchItem)
943
801
//      {
952
810
  MusECore::MidiControllerList* cl = workingInstrument.controller();
953
811
  for (MusECore::ciMidiController ic = cl->begin(); ic != cl->end(); ++ic) {
954
812
        MusECore::MidiController* c = ic->second;
955
 
        //QListWidgetItem* item = new QListWidgetItem(c->name());
 
813
        //QListWidgetItem* item = new QListWidgetItem(c->name()); DELETETHIS
956
814
     //   ListBoxData* item = new ListBoxData(c->name());
957
815
        //QVariant v = QVariant::fromValue((void*)c);
958
816
        //item->setData(Qt::UserRole, v);
963
821
        }
964
822
  
965
823
  
966
 
  //listController->setItemSelected(listController->item(0), true);
 
824
  //listController->setItemSelected(listController->item(0), true); DELETETHIS
967
825
  
968
826
//  oldController = 0;
969
827
  
973
831
 
974
832
  if(ci)
975
833
  {
976
 
    // This may cause a controllerChanged call.
 
834
    // This may cause a controllerChanged call. DELETETHIS
977
835
    //if(listController->selectedItem != ci)
978
836
  //  listController->blockSignals(true);
979
837
  //  listController->setSelected(ci, true);
988
846
  
989
847
  controllerChanged();
990
848
  
991
 
  //oldController = (ListBoxData*)listController->selectedItem();
 
849
  //oldController = (ListBoxData*)listController->selectedItem(); DELETETHIS
992
850
  
993
851
  
994
852
  //controllerChanged(listController->item(0), 0);
995
853
  //controllerChanged();
996
854
  
997
 
/*
 
855
/* DELETETHIS
998
856
      category->addItems(instrument->categories());
999
857
 
1000
858
      foreach(const SysEx* s, instrument->sysex()) {
1027
885
      if(!sel)
1028
886
        return;
1029
887
           
1030
 
      //printf("instrument changed: %s\n", sel->text().toLatin1().constData());
1031
 
      
1032
 
      //if (old) {
1033
 
      //if(oldMidiInstrument)
1034
 
      //{
1035
888
        MusECore::MidiInstrument* oi = 0;
1036
889
        if(oldMidiInstrument)
1037
890
          oi = (MusECore::MidiInstrument*)oldMidiInstrument->data(Qt::UserRole).value<void*>();
1038
891
        MusECore::MidiInstrument* wip = &workingInstrument;
1039
892
        // Returns true if aborted.
1040
 
        //checkDirty(oi);
1041
 
        //if(checkDirty(oi))
1042
893
        if(checkDirty(wip))
1043
894
        {
1044
895
          // No save was chosen. Abandon changes, or delete if it is new...
1045
896
          if(oi)
1046
897
          {
1047
898
            oldMidiInstrument->setText(oi->iname());
1048
 
            //wip->setText(oi->iname());
1049
899
            
1050
900
            // No file path? Only a new unsaved instrument can do that. So delete it.
1051
901
            if(oi->filePath().isEmpty())
1057
907
            
1058
908
          }  
1059
909
        }
1060
 
        //else
1061
 
        //{
1062
 
          // Save was chosen. 
1063
 
        //  if(oi)
1064
 
        //    oi->assign(workingInstrument);
1065
 
        //}    
1066
 
        
1067
 
        //oi->setDirty(false);
1068
 
        //wip->setDirty(false);
1069
910
        workingInstrument.setDirty(false);
1070
 
      //}
1071
911
 
1072
912
        changeInstrument();
1073
 
        
1074
913
      }
1075
914
 
1076
915
//---------------------------------------------------------
1078
917
//---------------------------------------------------------
1079
918
 
1080
919
void EditInstrument::instrumentNameReturn()
1081
 
//void EditInstrument::instrumentNameChanged(const QString& s)
1082
920
{
1083
 
  //instrumentNameChanged(instrumentName->text());
1084
921
  QListWidgetItem* item = instrumentList->currentItem();
1085
922
 
1086
923
  if (item == 0)
1098
935
    {
1099
936
      instrumentName->blockSignals(true);
1100
937
      // Grab the last valid name from the item text, since the instrument has not been updated yet.
1101
 
      //instrumentName->setText(curins->iname());
1102
938
      instrumentName->setText(item->text());
1103
939
      instrumentName->blockSignals(false);
1104
940
      
1113
949
    }
1114
950
  }      
1115
951
  
1116
 
  //if (s != workingInstrument.iname()) {
1117
 
        item->setText(s);
1118
 
        //MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)item->data(Qt::UserRole).value<void*>();
1119
 
        //MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)item->data();
1120
 
        //instrument->setDirty(true);
1121
 
        workingInstrument.setIName(s);
1122
 
        workingInstrument.setDirty(true);
1123
 
        //instrumentList->updateItem(item);
1124
 
        //instrumentList->update();
1125
 
  //      }
 
952
  item->setText(s);
 
953
  workingInstrument.setIName(s);
 
954
  workingInstrument.setDirty(true);
1126
955
}
1127
956
 
1128
957
//---------------------------------------------------------
1134
963
  if(!item)
1135
964
    return;
1136
965
 
1137
 
  //ListBoxData* curritem = (ListBoxData*)instrumentList->selectedItem();
1138
 
  
1139
966
  MusECore::MidiInstrument* ins = (MusECore::MidiInstrument*)item->data(Qt::UserRole).value<void*>();
1140
967
  
1141
 
  // Be kind to the list item, just in case we install a delete handler or something.
1142
 
  //item->setData(0);
1143
 
  
1144
968
  // Delete the list item.
1145
969
  // Test this: Is this going to change the current selection?
1146
970
  instrumentList->blockSignals(true);
1147
971
  delete item;
1148
972
  instrumentList->blockSignals(false);
1149
973
  
1150
 
  // Test this: Neccessary?
 
974
  // Test this: Neccessary? DELETETHIS
1151
975
  // if(curritem)
1152
976
  //  instrumentList->setCurrentItem(curritem);
1153
977
  
1235
1059
        {
1236
1060
          patchNameEdit->blockSignals(true);
1237
1061
          // Grab the last valid name from the item text, since the patch has not been updated yet.
1238
 
          //patchNameEdit->setText(curp->name);
1239
1062
          patchNameEdit->setText(item->text(0));
1240
1063
          patchNameEdit->blockSignals(false);
1241
1064
          
1258
1081
      {
1259
1082
        patchNameEdit->blockSignals(true);
1260
1083
        // Grab the last valid name from the item text, since the patch group has not been updated yet.
1261
 
        //patchNameEdit->setText(curpg->name);
1262
1084
        patchNameEdit->setText(item->text(0));
1263
1085
        patchNameEdit->blockSignals(false);
1264
1086
        
1277
1099
    item->setText(0, s);
1278
1100
    workingInstrument.setDirty(true);
1279
1101
    
 
1102
  // DELETETHIS
1280
1103
  // Since the name of the patch/group in the working instrument will be updated later,
1281
1104
  //  there's no need to do manually set the name here now. 
1282
1105
  /*
1312
1135
//---------------------------------------------------------
1313
1136
void EditInstrument::patchChanged()
1314
1137
    {
1315
 
      //if (old && old->data(0, Qt::UserRole).value<void*>()) {
1316
1138
      if(oldPatchItem)
1317
1139
      {
1318
 
            //QListWidgetItem* item = instrumentList->currentItem();
1319
 
            //if (item == 0)
1320
 
            //      return;
1321
 
            //MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)item->data(Qt::UserRole).value<void*>();
1322
 
            //MusECore::Patch* p = (MusECore::Patch*)old->data(0, Qt::UserRole).value<void*>();
1323
 
            //updatePatch(instrument, p);
1324
1140
            if(oldPatchItem->parent())
1325
1141
                    updatePatch(&workingInstrument, (MusECore::Patch*)oldPatchItem->data(0, Qt::UserRole).value<void*>());
1326
1142
            else
1362
1178
        spinBoxHBank->setValue(hb);
1363
1179
        spinBoxLBank->setValue(lb);
1364
1180
        spinBoxProgram->setValue(pr);
1365
 
        //checkBoxDrum->setChecked(p->drumMap);
1366
1181
        checkBoxDrum->setChecked(p->drum);
1367
1182
        checkBoxGM->setChecked(p->typ & 1);
1368
1183
        checkBoxGS->setChecked(p->typ & 2);
1369
1184
        checkBoxXG->setChecked(p->typ & 4);
1370
 
        //category->setCurrentIndex(p->categorie);
1371
1185
      }  
1372
1186
      else
1373
1187
      // The item is a patch group item.
1398
1212
      
1399
1213
      int val = getDefaultPatchNumber();
1400
1214
      
1401
 
      //if(val == c->minVal() - 1)
1402
 
      //  c->setInitVal(MusECore::CTRL_VAL_UNKNOWN);
1403
 
      //else
1404
 
        c->setInitVal(val);
 
1215
      c->setInitVal(val);
1405
1216
      
1406
1217
      setDefaultPatchName(val);
1407
1218
      
1415
1226
 
1416
1227
void EditInstrument::patchButtonClicked()
1417
1228
{
1418
 
      //MidiTrack* track = (MidiTrack*)selected;
1419
 
      //int channel = track->outChannel();
1420
 
      //int port    = track->outPort();
1421
 
      //MusECore::MidiInstrument* instr = midiPorts[port].instrument();
1422
 
      
1423
 
      //patchpopup->clear();
1424
 
 
1425
1229
      QMenu* patchpopup = new QMenu;
1426
1230
      
1427
1231
      MusECore::PatchGroupList* pg = workingInstrument.groups();
1435
1239
                  const MusECore::PatchList& pl = pgp->patches;
1436
1240
                  for (MusECore::ciPatch ipl = pl.begin(); ipl != pl.end(); ++ipl) {
1437
1241
                        const MusECore::Patch* mp = *ipl;
1438
 
                        //if ((mp->typ & mask) && 
1439
 
                        //    ((drum && songType != MT_GM) || 
1440
 
                        //    (mp->drum == drumchan)) )  
1441
 
                            
1442
 
                        //    {
1443
1242
                              int id = ((mp->hbank & 0xff) << 16)
1444
1243
                                         + ((mp->lbank & 0xff) << 8) + (mp->prog & 0xff);
1445
1244
                              QAction *ac1 = pm->addAction(mp->name);
1446
 
                              ac1->setData(id);
1447
 
                        //    }
1448
 
                              
 
1245
                              ac1->setData(id);
1449
1246
                        }
1450
1247
                  }
1451
1248
            }
1454
1251
            const MusECore::PatchList& pl = pg->front()->patches;
1455
1252
            for (MusECore::ciPatch ipl = pl.begin(); ipl != pl.end(); ++ipl) {
1456
1253
                  const MusECore::Patch* mp = *ipl;
1457
 
                  //if (mp->typ & mask) {
1458
1254
                        int id = ((mp->hbank & 0xff) << 16)
1459
1255
                                 + ((mp->lbank & 0xff) << 8) + (mp->prog & 0xff);
1460
1256
                        QAction *ac2 = patchpopup->addAction(mp->name);
1461
1257
                        ac2->setData(id);
1462
 
                  //      }
1463
1258
                  }
1464
1259
            }
1465
1260
 
1481
1276
 
1482
1277
      if (rv != -1) 
1483
1278
      {
1484
 
        //if(rv != workingInstrument.
1485
 
        
1486
1279
        setDefaultPatchControls(rv);
1487
1280
        
1488
1281
        QTreeWidgetItem* item = viewController->currentItem();
1512
1305
      QString def;
1513
1306
      int defval = mctrl->initVal();
1514
1307
      int n = mctrl->num();
1515
 
      //int h = (n >> 7) & 0x7f;
1516
1308
      int h = (n >> 8) & 0x7f;
1517
1309
      int l = n & 0x7f;
1518
1310
      if((n & 0xff) == 0xff)
1522
1314
      switch(t)
1523
1315
      {
1524
1316
          case MusECore::MidiController::Controller7:
1525
 
          //case MusECore::MidiController::RPN:
1526
 
          //case MusECore::MidiController::NRPN:
1527
1317
                hnum = "---";
1528
1318
                if(l == -1)
1529
1319
                  lnum = "*";
1574
1364
          default:
1575
1365
                hnum = "---";
1576
1366
                lnum = "---";
1577
 
                //min.setNum(0);
1578
 
                //max.setNum(0);
1579
1367
                min = "---";
1580
1368
                max = "---";
1581
1369
                def = "---";
1583
1371
      }
1584
1372
 
1585
1373
        QTreeWidgetItem* ci =  new QTreeWidgetItem(viewController, QStringList() <<  mctrl->name() << int2ctrlType(t) << hnum << lnum << min << max << def);
1586
 
        //ListViewData* ci =  new ListViewData(viewController, mctrl->name(), int2ctrlType(t),
1587
 
        //                                    hnum, lnum, min, max, def);
1588
 
      //ci->setData((void*)mctrl);
1589
1374
      QVariant v = qVariantFromValue((void*)(mctrl));
1590
1375
      ci->setData(0, Qt::UserRole, v);
1591
 
      //setModified(true);
1592
1376
      
1593
1377
      return ci;
1594
1378
}
1599
1383
 
1600
1384
void EditInstrument::controllerChanged()
1601
1385
      {
1602
 
      //if (old) {
1603
 
//      if(oldController) 
1604
 
//      {
1605
 
            //QListWidgetItem* item = instrumentList->currentItem();
1606
 
            //if (item == 0)
1607
 
            //      return;
1608
 
            //MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)item->data(Qt::UserRole).value<void*>();
1609
 
            //MusECore::MidiController* oc = (MusECore::MidiController*)old->data(Qt::UserRole).value<void*>();
1610
 
            //updateController(instrument, oc);
1611
 
//            updateController(&workingInstrument, (MusECore::MidiController*)oldController->data());
1612
 
//      }
1613
 
      
1614
 
    //  ListBoxData* sel = (ListBoxData*)listController->selectedItem();
1615
 
 
1616
1386
        QTreeWidgetItem* sel = viewController->selectedItems().size() ? viewController->selectedItems()[0] : 0;
1617
 
//      oldController = sel;
1618
1387
      
1619
1388
        if(!sel || !sel->data(0, Qt::UserRole).value<void*>()) 
1620
1389
      {
1621
1390
        ctrlName->blockSignals(true);
1622
1391
        ctrlName->setText("");
1623
1392
        ctrlName->blockSignals(false);
1624
 
        //ctrlComment->setText("");
1625
1393
        return;
1626
1394
      }
1627
1395
      
1631
1399
      ctrlName->setText(c->name());
1632
1400
      ctrlName->blockSignals(false);
1633
1401
      
1634
 
      //ctrlComment->setText(c->comment());
1635
1402
      int ctrlH = (c->num() >> 8) & 0x7f;
1636
1403
      int ctrlL = c->num() & 0x7f;
1637
1404
      if((c->num() & 0xff) == 0xff)
1638
1405
        ctrlL = -1;
1639
1406
        
1640
 
      //int type = int(c->type());
1641
1407
      MusECore::MidiController::ControllerType type = MusECore::midiControllerType(c->num());
1642
1408
      
1643
 
      //ctrlType->setCurrentIndex(type);
1644
1409
      ctrlType->blockSignals(true);
1645
1410
      ctrlType->setCurrentIndex(type);
1646
1411
      ctrlType->blockSignals(false);
1647
1412
      
1648
 
      //ctrlTypeChanged(type);
1649
 
      
1650
1413
      spinBoxHCtrlNo->blockSignals(true);
1651
1414
      spinBoxLCtrlNo->blockSignals(true);
1652
1415
      spinBoxMin->blockSignals(true);
1653
1416
      spinBoxMax->blockSignals(true);
1654
1417
      spinBoxDefault->blockSignals(true);
1655
1418
     
1656
 
      //ctrlTypeChanged(type);
1657
 
      
1658
1419
      switch (type) {
1659
 
            //case MusECore::MidiController::RPN:
1660
 
            //case MusECore::MidiController::NRPN:
1661
1420
            case MusECore::MidiController::Controller7:
1662
1421
                  spinBoxHCtrlNo->setEnabled(false);
1663
1422
                  spinBoxLCtrlNo->setEnabled(true);
1745
1504
      {
1746
1505
        spinBoxDefault->setRange(c->minVal() - 1, c->maxVal());
1747
1506
        if(c->initVal() == MusECore::CTRL_VAL_UNKNOWN)
1748
 
          //spinBoxDefault->setValue(c->minVal() - 1);
1749
1507
          spinBoxDefault->setValue(spinBoxDefault->minimum());
1750
1508
        else  
1751
1509
          spinBoxDefault->setValue(c->initVal());
1752
1510
      }
1753
1511
      
1754
 
      //moveWithPart->setChecked(c->moveWithPart());
1755
 
      
1756
1512
      spinBoxHCtrlNo->blockSignals(false);
1757
1513
      spinBoxLCtrlNo->blockSignals(false);
1758
1514
      spinBoxMin->blockSignals(false);
1765
1521
//---------------------------------------------------------
1766
1522
 
1767
1523
void EditInstrument::ctrlNameReturn()
1768
 
//void EditInstrument::ctrlNameChanged(const QString& s)
1769
1524
{
1770
1525
      QTreeWidgetItem* item = viewController->currentItem();
1771
1526
 
1777
1532
      
1778
1533
      if(c->name() == cName)
1779
1534
        return;
1780
 
      
1781
 
      //MusECore::MidiControllerList* cl = instrument->controller();
 
1535
 
1782
1536
      MusECore::MidiControllerList* cl = workingInstrument.controller();
1783
1537
      for(MusECore::ciMidiController ic = cl->begin(); ic != cl->end(); ++ic) 
1784
1538
      {
1802
1556
      
1803
1557
      c->setName(ctrlName->text());
1804
1558
      item->setText(COL_NAME, ctrlName->text());
1805
 
      //c->setName(s);
1806
 
      //item->setText(COL_NAME, s);
1807
1559
      workingInstrument.setDirty(true);
1808
1560
}
1809
1561
 
1823
1575
      if(t == MusECore::midiControllerType(c->num()))
1824
1576
         return;
1825
1577
      
1826
 
      //if(item)
1827
 
        item->setText(COL_TYPE, ctrlType->currentText());
 
1578
      item->setText(COL_TYPE, ctrlType->currentText());
1828
1579
      
1829
1580
      int hnum = 0, lnum = 0;
1830
 
      //int rng = 0;
1831
 
      //int min = 0, max = 0;
1832
1581
      
1833
1582
      spinBoxMin->blockSignals(true);
1834
1583
      spinBoxMax->blockSignals(true);
1835
1584
      spinBoxDefault->blockSignals(true);
1836
1585
      
1837
1586
      switch (t) {
1838
 
            //case MusECore::MidiController::RPN:
1839
 
            //case MusECore::MidiController::NRPN:
1840
1587
            case MusECore::MidiController::Controller7:
1841
1588
                  spinBoxHCtrlNo->setEnabled(false);
1842
1589
                  spinBoxLCtrlNo->setEnabled(true);
1852
1599
                  
1853
1600
                  spinBoxDefault->setValue(spinBoxDefault->minimum());
1854
1601
                  lnum = spinBoxLCtrlNo->value();
1855
 
                  //rng = 127;
1856
 
                  //min = -128;
1857
 
                  //max = 127;
1858
 
                  //if(item)
1859
 
                  //{
1860
 
                    //item->setText(COL_LNUM, QString().setNum(spinBoxLCtrlNo->value()));
1861
 
                    if(lnum == -1)
1862
 
                      item->setText(COL_LNUM, QString("*"));
1863
 
                    else  
1864
 
                      item->setText(COL_LNUM, QString().setNum(lnum));
1865
 
                    item->setText(COL_HNUM, QString("---"));
1866
 
                    item->setText(COL_MIN, QString().setNum(spinBoxMin->value()));
1867
 
                    item->setText(COL_MAX, QString().setNum(spinBoxMax->value()));
1868
 
                    item->setText(COL_DEF, QString("---"));
1869
 
                  //}  
 
1602
 
 
1603
                  if(lnum == -1)
 
1604
                    item->setText(COL_LNUM, QString("*"));
 
1605
                  else  
 
1606
                    item->setText(COL_LNUM, QString().setNum(lnum));
 
1607
                  item->setText(COL_HNUM, QString("---"));
 
1608
                  item->setText(COL_MIN, QString().setNum(spinBoxMin->value()));
 
1609
                  item->setText(COL_MAX, QString().setNum(spinBoxMax->value()));
 
1610
                  item->setText(COL_DEF, QString("---"));
1870
1611
                  break;
 
1612
 
1871
1613
            case MusECore::MidiController::RPN:
1872
1614
            case MusECore::MidiController::NRPN:
1873
1615
                  spinBoxHCtrlNo->setEnabled(true);
1885
1627
                  
1886
1628
                  hnum = spinBoxHCtrlNo->value();
1887
1629
                  lnum = spinBoxLCtrlNo->value();
1888
 
                  //rng = 127;
1889
 
                  //min = -128;
1890
 
                  //max = 127;
1891
 
                  //if(item)
1892
 
                  //{
1893
 
                    //item->setText(COL_LNUM, QString().setNum(spinBoxLCtrlNo->value()));
1894
 
                    //item->setText(COL_HNUM, QString().setNum(spinBoxHCtrlNo->value()));
1895
 
                    if(lnum == -1)
1896
 
                      item->setText(COL_LNUM, QString("*"));
1897
 
                    else  
1898
 
                      item->setText(COL_LNUM, QString().setNum(lnum));
1899
 
                    item->setText(COL_HNUM, QString().setNum(hnum));
1900
 
                    item->setText(COL_MIN, QString().setNum(spinBoxMin->value()));
1901
 
                    item->setText(COL_MAX, QString().setNum(spinBoxMax->value()));
1902
 
                    item->setText(COL_DEF, QString("---"));
1903
 
                  //}  
 
1630
 
 
1631
                  if(lnum == -1)
 
1632
                    item->setText(COL_LNUM, QString("*"));
 
1633
                  else  
 
1634
                    item->setText(COL_LNUM, QString().setNum(lnum));
 
1635
                  item->setText(COL_HNUM, QString().setNum(hnum));
 
1636
                  item->setText(COL_MIN, QString().setNum(spinBoxMin->value()));
 
1637
                  item->setText(COL_MAX, QString().setNum(spinBoxMax->value()));
 
1638
                  item->setText(COL_DEF, QString("---"));
1904
1639
                  break;
 
1640
 
1905
1641
            case MusECore::MidiController::Controller14:
1906
1642
            case MusECore::MidiController::RPN14:
1907
1643
            case MusECore::MidiController::NRPN14:
1920
1656
                  
1921
1657
                  hnum = spinBoxHCtrlNo->value();
1922
1658
                  lnum = spinBoxLCtrlNo->value();
1923
 
                  //rng = 16383;
1924
 
                  //min = -16384;
1925
 
                  //max = 16383;
1926
 
                  //if(item)
1927
 
                  //{
1928
 
                    //item->setText(COL_LNUM, QString().setNum(spinBoxLCtrlNo->value()));
1929
 
                    //item->setText(COL_HNUM, QString().setNum(spinBoxHCtrlNo->value()));
1930
 
                    if(lnum == -1)
1931
 
                      item->setText(COL_LNUM, QString("*"));
1932
 
                    else  
1933
 
                      item->setText(COL_LNUM, QString().setNum(lnum));
1934
 
                    item->setText(COL_HNUM, QString().setNum(hnum));
1935
 
                    item->setText(COL_MIN, QString().setNum(spinBoxMin->value()));
1936
 
                    item->setText(COL_MAX, QString().setNum(spinBoxMax->value()));
1937
 
                    item->setText(COL_DEF, QString("---"));
1938
 
                  //}  
 
1659
                  if(lnum == -1)
 
1660
                    item->setText(COL_LNUM, QString("*"));
 
1661
                  else  
 
1662
                    item->setText(COL_LNUM, QString().setNum(lnum));
 
1663
                  item->setText(COL_HNUM, QString().setNum(hnum));
 
1664
                  item->setText(COL_MIN, QString().setNum(spinBoxMin->value()));
 
1665
                  item->setText(COL_MAX, QString().setNum(spinBoxMax->value()));
 
1666
                  item->setText(COL_DEF, QString("---"));
1939
1667
                  break;
 
1668
 
1940
1669
            case MusECore::MidiController::Pitch:
1941
1670
                  spinBoxHCtrlNo->setEnabled(false);
1942
1671
                  spinBoxLCtrlNo->setEnabled(false);
1951
1680
                  spinBoxDefault->setRange(spinBoxMin->value() - 1, spinBoxMax->value());
1952
1681
                  spinBoxDefault->setValue(spinBoxDefault->minimum());
1953
1682
                  
1954
 
                  //rng = 8191;
1955
 
                  //min = -8192;
1956
 
                  //max = 8191;
1957
 
                  //if(item)
1958
 
                  //{
1959
1683
                    item->setText(COL_LNUM, QString("---"));
1960
1684
                    item->setText(COL_HNUM, QString("---"));
1961
1685
                    item->setText(COL_MIN, QString().setNum(spinBoxMin->value()));
1962
1686
                    item->setText(COL_MAX, QString().setNum(spinBoxMax->value()));
1963
1687
                    item->setText(COL_DEF, QString("---"));
1964
 
                  //}  
1965
1688
                  break;
 
1689
 
1966
1690
            case MusECore::MidiController::Program:
1967
1691
                  spinBoxHCtrlNo->setEnabled(false);
1968
1692
                  spinBoxLCtrlNo->setEnabled(false);
1977
1701
                  spinBoxDefault->setRange(0, 0);
1978
1702
                  spinBoxDefault->setValue(0);
1979
1703
                  
1980
 
                  //if(item)
1981
 
                  //{
1982
1704
                    item->setText(COL_LNUM, QString("---"));
1983
1705
                    item->setText(COL_HNUM, QString("---"));
1984
1706
                    item->setText(COL_MIN, QString("---"));
1985
1707
                    item->setText(COL_MAX, QString("---"));
1986
 
                    
1987
 
                    //item->setText(COL_DEF, QString("0-0-0"));
1988
1708
                    item->setText(COL_DEF, QString("---"));
1989
 
                  //}  
1990
1709
                  break;
 
1710
 
1991
1711
            // Shouldn't happen...
1992
1712
            default:
1993
1713
                  spinBoxHCtrlNo->setEnabled(false);
2027
1747
      }  
2028
1748
      
2029
1749
      
2030
 
      /*
 
1750
      /* DELETETHIS
2031
1751
      
2032
1752
      if(rng != 0)
2033
1753
      {
2116
1836
      QString s;
2117
1837
      s.setNum(val);
2118
1838
      MusECore::MidiController* c = (MusECore::MidiController*)item->data(0, Qt::UserRole).value<void*>();
2119
 
      //int n = c->num() & 0xff;
2120
1839
      int n = c->num() & 0x7fff00ff;
2121
1840
      c->setNum(n | ((val & 0xff) << 8));
2122
1841
      item->setText(COL_HNUM, s);
2134
1853
      if (item == 0)
2135
1854
            return;
2136
1855
      MusECore::MidiController* c = (MusECore::MidiController*)item->data(0, Qt::UserRole).value<void*>();
2137
 
      //int n = c->num() & 0xff00;
2138
1856
      int n = c->num() & ~0xff;
2139
1857
      c->setNum(n | (val & 0xff));
2140
1858
      if(val == -1)
2167
1885
      c->setMinVal(val);
2168
1886
      
2169
1887
      int rng = 0;
2170
 
      //switch((MusECore::MidiController::ControllerType)ctrlType->currentItem())
2171
1888
      switch(MusECore::midiControllerType(c->num()))
2172
1889
      {
2173
1890
            case MusECore::MidiController::Controller7:
2187
1904
      
2188
1905
      int mx = c->maxVal();
2189
1906
      
2190
 
      //if(val > item->text(COL_MAX).toInt())
2191
1907
      if(val > mx)
2192
1908
      {
2193
1909
        c->setMaxVal(val);
2253
1969
      c->setMaxVal(val);
2254
1970
      
2255
1971
      int rng = 0;
2256
 
      //switch((MusECore::MidiController::ControllerType)ctrlType->currentItem())
2257
1972
      switch(MusECore::midiControllerType(c->num()))
2258
1973
      {
2259
1974
            case MusECore::MidiController::Controller7:
2273
1988
      
2274
1989
      int mn = c->minVal();
2275
1990
      
2276
 
      //if(val < item->text(COL_MIN).toInt())
2277
1991
      if(val < mn)
2278
1992
      {
2279
1993
        c->setMinVal(val);
2414
2128
 
2415
2129
void EditInstrument::deletePatchClicked()
2416
2130
      {
2417
 
      //QListWidgetItem* item = instrumentList->currentItem();
2418
 
//      ListBoxData* item = (ListBoxData*)instrumentList->selectedItem();
2419
 
//      if (item == 0)
2420
 
//            return;
2421
 
      //MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)item->data(Qt::UserRole).value<void*>();
2422
 
//      MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)item->data();
2423
 
      //QTreeWidgetItem* pi = patchView->currentItem();
2424
2131
      QTreeWidgetItem* pi = patchView->currentItem();
2425
2132
 
2426
2133
      if (pi == 0)
2427
2134
            return;
2428
2135
      
2429
 
      //void* p = pi->data(0, Qt::UserRole).value<void*>();
2430
 
//      MusECore::Patch* patch = (MusECore::Patch*)pi->data();
2431
 
      //if (p == 0)
2432
 
      // If patch is zero it's a patch group.
2433
 
//      if(patch == 0)
2434
 
      
2435
2136
      // If the item has a parent item, it's a patch item...
2436
2137
      if(pi->parent())
2437
2138
      {
2438
 
        MusECore::PatchGroup* group = (MusECore::PatchGroup*)(pi->parent())->data(0, Qt::UserRole).value<void*>();
 
2139
        MusECore::PatchGroup* group = (MusECore::PatchGroup*)(pi->parent())->data(0, Qt::UserRole).value<void*>();
2439
2140
        
2440
2141
        // If there is an allocated patch in the data, delete it.
2441
 
        //MusECore::Patch* patch = (MusECore::Patch*)pi->auxData();
2442
2142
        MusECore::Patch* patch = (MusECore::Patch*)pi->data(0, Qt::UserRole).value<void*>();
2443
2143
        if(patch)
2444
2144
        {
2445
2145
          if(group)
2446
 
          {
2447
 
            //for(iPatch ip = group->patches.begin(); ip != group->patches.end(); ++ip)
2448
 
            //  if(&*ip == patch)
2449
 
            //  if(*ip == patch)
2450
 
            //  {
2451
 
            //    
2452
 
            //    printf("deletePatchClicked: erasing patch\n");
2453
 
            //    
2454
 
            //    group->patches.erase(ip);
2455
 
            //    break;
2456
 
            //  }      
2457
 
            //group->patches.remove( (const Patch&)(*patch) );
2458
2146
            group->patches.remove(patch);
2459
 
          }  
 
2147
 
2460
2148
          delete patch;
2461
2149
        }  
2462
2150
      }
2464
2152
      // The item has no parent item, it's a patch group item...
2465
2153
      {
2466
2154
        // Is there an allocated patch group in the data?
2467
 
        //MusECore::PatchGroup* group = (MusECore::PatchGroup*)pi->auxData();
2468
2155
        MusECore::PatchGroup* group = (MusECore::PatchGroup*)pi->data(0, Qt::UserRole).value<void*>();
2469
2156
        if(group)
2470
2157
        {
2471
2158
          
2472
2159
          MusECore::PatchGroupList* pg = workingInstrument.groups();
2473
 
          //for(MusECore::ciPatchGroup ipg = pg->begin(); ipg != pg->end(); ++ipg)
2474
2160
          for(MusECore::iPatchGroup ipg = pg->begin(); ipg != pg->end(); ++ipg)
2475
2161
          {
2476
2162
            
2477
 
            //printf("deletePatchClicked: working patch group name:%s ad:%X group name:%s ad:%X\n", (*ipg)->name.toLatin1().constData(), (unsigned int)(*ipg), group->name.toLatin1().constData(), (unsigned int) group);
2478
 
            
2479
 
            //if(&*ipg == group)
2480
2163
            if(*ipg == group)
2481
2164
            {
2482
2165
              pg->erase(ipg);
2484
2167
            }  
2485
2168
          }
2486
2169
          
2487
 
          // Iterate all child list view (patch) items. Find and delete any allocated patches in the items' data.
2488
 
//          for(ListViewData* i = (ListViewData*)pi->firstChild(); i; i = (ListViewData*)i->nextSibling()) 
2489
 
//          {
2490
 
            //MusECore::Patch* patch = (MusECore::Patch*)i->auxData();
2491
 
//            MusECore::Patch* patch = (MusECore::Patch*)i->data();
2492
 
//            if(patch)
2493
 
//            {
2494
 
              //delete patch;
2495
 
              //group->patches.remove(*patch);
2496
2170
              const MusECore::PatchList& pl = group->patches;
2497
2171
              for(MusECore::ciPatch ip = pl.begin(); ip != pl.end(); ++ip)
2498
2172
              {
2499
 
//                if(&*ip == patch)
2500
 
//                {
2501
 
//                  group->patches.erase(ip);
2502
 
//                  break;
2503
 
//                }
2504
 
 
2505
2173
                // Delete the patch.
2506
2174
                if(*ip)
2507
2175
                  delete *ip;  
2508
2176
              }
2509
2177
              
2510
 
              //group->patches.clear();  
2511
 
              
2512
 
//            }  
2513
 
//          }
2514
 
          
2515
2178
          // Now delete the group.
2516
2179
          delete group;
2517
2180
          
2518
2181
        }  
2519
2182
      }
2520
2183
      
2521
 
      //oldPatchItem = (ListViewData*)patchView->selectedItem();
2522
 
      //oldPatchItem = 0;
2523
 
      
2524
2184
      // Now delete the patch or group item (and any child patch items) from the list view tree.
2525
2185
      // !!! This will trigger a patchChanged call. 
2526
2186
      patchView->blockSignals(true);
2532
2192
      oldPatchItem = 0;
2533
2193
      patchChanged();
2534
2194
      
2535
 
      //MusECore::Patch* patch = (MusECore::Patch*)p;
2536
 
      
2537
 
      //std::vector<MusECore::PatchGroup>* pg = instrument->groups();
2538
 
      //for (std::vector<MusECore::PatchGroup>::iterator g = pg->begin(); g != pg->end(); ++g) {
2539
 
      //      for (MusECore::iPatch p = g->patches.begin(); p != g->patches.end(); ++p) {
2540
 
      //            if (patch == *p) {
2541
 
      //                  g->patches.erase(p);
2542
 
      //                  delete pi;
2543
 
      //                  instrument->setDirty(true);
2544
 
      //                  return;
2545
 
      //                  }
2546
 
      //            }
2547
 
      //      }
2548
 
      //printf("fatal: patch not found\n");      
2549
 
      //delete patch;
2550
 
      //delete pi;
2551
 
      
2552
 
      
2553
2195
      workingInstrument.setDirty(true);
2554
2196
      }
2555
2197
 
2559
2201
 
2560
2202
void EditInstrument::newPatchClicked()
2561
2203
      {
2562
 
      //QListWidgetItem* item = instrumentList->currentItem();
2563
 
//      ListBoxData* item = (ListBoxData*)instrumentList->selectedItem();
2564
 
//      if (item == 0)
2565
 
//            return;
2566
 
      
2567
2204
      if(oldPatchItem)
2568
2205
      {
2569
2206
        if(oldPatchItem->parent())
2571
2208
        else  
2572
2209
          updatePatchGroup(&workingInstrument, (MusECore::PatchGroup*)oldPatchItem->data(0, Qt::UserRole).value<void*>());
2573
2210
      }  
2574
 
      
2575
 
      //MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)item->data(Qt::UserRole).value<void*>();
2576
 
//      MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)item->data();
2577
 
      //std::vector<MusECore::PatchGroup>* pg = instrument->groups();
2578
 
//      MusECore::PatchGroupList* pg = instrument->groups();
 
2211
 
2579
2212
      MusECore::PatchGroupList* pg = workingInstrument.groups();
2580
2213
      QString patchName;
2581
2214
      for (int i = 1;; ++i) {
2582
2215
            patchName = QString("Patch-%1").arg(i);
2583
2216
            bool found = false;
2584
2217
 
2585
 
            //for (std::vector<MusECore::PatchGroup>::iterator g = pg->begin(); g != pg->end(); ++g) {
2586
2218
            for (MusECore::iPatchGroup g = pg->begin(); g != pg->end(); ++g) {
2587
2219
                  MusECore::PatchGroup* pgp = *g;
2588
 
                  //for (MusECore::iPatch p = g->patches.begin(); p != g->patches.end(); ++p) {
2589
2220
                  for (MusECore::iPatch p = pgp->patches.begin(); p != pgp->patches.end(); ++p) {
2590
 
                        //if (p->name == patchName) {
2591
2221
                        if ((*p)->name == patchName) {
2592
2222
                              found = true;
2593
2223
                              break;
2600
2230
                  break;
2601
2231
            }
2602
2232
 
2603
 
      //
2604
2233
      // search current patch group
2605
 
      //
2606
 
      //MusECore::PatchGroup* pGroup = 0;
2607
 
      //QTreeWidgetItem* pi = patchView->currentItem();
2608
2234
      QTreeWidgetItem* pi = patchView->currentItem();
2609
2235
 
2610
2236
      if (pi == 0)
2611
2237
            return;
2612
2238
      
2613
 
      // If there is data then pi is a patch item, and there must be a parent patch group item (with null data).
2614
 
      //if (pi->data(0, Qt::UserRole).value<void*>())
2615
 
      //if (pi->data())
2616
 
      
2617
2239
      MusECore::Patch* selpatch = 0;
2618
2240
      
2619
2241
      // If there is a parent item then pi is a patch item, and there must be a parent patch group item.
2629
2251
      if(!group)
2630
2252
        return;
2631
2253
        
2632
 
      //for (std::vector<MusECore::PatchGroup>::iterator g = pg->begin(); g != pg->end(); ++g) {
2633
 
//      for (MusECore::ciPatchGroup g = pg->begin(); g != pg->end(); ++g) {
2634
 
//            if (g->name == pi->text(0)) {
2635
 
//                  pGroup = &*g;
2636
 
//                  break;
2637
 
//                  }            
2638
 
//            }
2639
 
//      if (pGroup == 0) {
2640
 
//            printf("group not found\n");
2641
 
//            return;
2642
 
//            }
2643
2254
      
2644
2255
      // Create a new Patch, then store its pointer in a new patch item, 
2645
2256
      //  to be added later to the patch group only upon save...
2678
2289
 
2679
2290
            for(MusECore::iPatchGroup g = pg->begin(); g != pg->end(); ++g) 
2680
2291
            {
2681
 
              MusECore::PatchGroup* pgp = *g;
 
2292
              MusECore::PatchGroup* pgp = *g;
2682
2293
              for(MusECore::iPatch ip = pgp->patches.begin(); ip != pgp->patches.end(); ++ip) 
2683
2294
              {
2684
 
                MusECore::Patch* p = *ip;
 
2295
                MusECore::Patch* p = *ip;
2685
2296
                if((p->prog  == ((prg + i) & 0x7f)) && 
2686
2297
                   ((p->lbank == -1 && lb == -1) || (p->lbank == ((lb + j) & 0x7f))) && 
2687
2298
                   ((p->hbank == -1 && hb == -1) || (p->hbank == ((hb + k) & 0x7f)))) 
2707
2318
              else    
2708
2319
                patch->hbank = (hb + k) & 0x7f;
2709
2320
                
2710
 
              //patch->typ = selpatch->typ;                     
2711
 
              //patch->drum = selpatch->drum;                     
2712
2321
              break;
2713
2322
            } 
2714
2323
              
2723
2332
      patch->name = patchName;
2724
2333
 
2725
2334
      group->patches.push_back(patch);
2726
 
      //MusECore::Patch* pp = &(group->patches.back());
2727
 
      
2728
 
      //QTreeWidgetItem* sitem = new QTreeWidgetItem;
 
2335
 
2729
2336
      QTreeWidgetItem* sitem = new QTreeWidgetItem(pi);
2730
 
      //sitem->setText(0, patch->name);
2731
2337
      sitem->setText(0, patchName);
2732
2338
      
2733
2339
      patchNameEdit->setText(patchName);
2734
2340
      
2735
 
      //QVariant v = QVariant::fromValue((void*)(patch));
2736
 
      //sitem->setData(0, Qt::UserRole, v);
2737
 
      
2738
 
      // Set the list view item's data. 
2739
 
      //sitem->setData((void*)patch);
2740
2341
      QVariant v = qVariantFromValue((void*)(patch));
2741
2342
      sitem->setData(0, Qt::UserRole, v);
2742
 
      //sitem->setAuxData((void*)patch);
2743
 
      //sitem->setData((void*)pp);
2744
 
 
2745
 
      //pi->addChild(sitem);
2746
 
      
2747
 
      //printf("newPatchClicked: before patchView->setCurrentItem\n");
2748
 
      
2749
 
      //patchView->setCurrentItem(sitem);
2750
 
      
2751
 
      //printf("newPatchClicked: after patchView->setCurrentItem\n");
2752
 
      
2753
 
      //oldPatchItem = 0;
2754
2343
      
2755
2344
      // May cause patchChanged call.
2756
2345
      patchView->blockSignals(true);
2758
2347
      patchView->scrollToItem((QTreeWidgetItem*)sitem, QAbstractItemView::EnsureVisible);
2759
2348
      patchView->blockSignals(false);
2760
2349
      
2761
 
      //oldPatchItem = (ListViewData*)patchView->selectedItem();
2762
 
      //oldPatchItem = sitem;
2763
 
      //oldPatchItem = 0;
2764
 
      
2765
2350
      spinBoxHBank->setEnabled(true);
2766
2351
      spinBoxLBank->setEnabled(true);
2767
2352
      spinBoxProgram->setEnabled(true);
2773
2358
      oldPatchItem = 0;
2774
2359
      patchChanged();
2775
2360
      
2776
 
      //instrument->setDirty(true);
2777
2361
      workingInstrument.setDirty(true);
2778
2362
      }
2779
2363
 
2783
2367
 
2784
2368
void EditInstrument::newGroupClicked()
2785
2369
      {
2786
 
      //QListWidgetItem* item = instrumentList->currentItem();
2787
 
//      ListBoxData* item = (ListBoxData*)instrumentList->selectedItem();
2788
 
//      if (item == 0)
2789
 
//            return;
2790
 
      
2791
2370
      if(oldPatchItem)
2792
2371
      {
2793
2372
        if(oldPatchItem->parent())
2796
2375
          updatePatchGroup(&workingInstrument, (MusECore::PatchGroup*)oldPatchItem->data(0, Qt::UserRole).value<void*>());
2797
2376
      }  
2798
2377
      
2799
 
      //MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)item->data(Qt::UserRole).value<void*>();
2800
 
//      MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)item->data();
2801
 
      //std::vector<MusECore::PatchGroup>* pg = instrument->groups();
2802
 
//      MusECore::PatchGroupList* pg = instrument->groups();
2803
2378
      MusECore::PatchGroupList* pg = workingInstrument.groups();
2804
2379
      QString groupName;
2805
2380
      for (int i = 1;; ++i) {
2806
2381
            groupName = QString("Group-%1").arg(i);
2807
2382
            bool found = false;
2808
2383
 
2809
 
            //for (std::vector<MusECore::PatchGroup>::iterator g = pg->begin(); g != pg->end(); ++g) {
2810
2384
            for (MusECore::ciPatchGroup g = pg->begin(); g != pg->end(); ++g) {
2811
 
                  //if (g->name == groupName) {
2812
2385
                  if ((*g)->name == groupName) {
2813
2386
                        found = true;
2814
2387
                        break;
2822
2395
      //  to be added later to the instrument only upon save...
2823
2396
      MusECore::PatchGroup* group = new MusECore::PatchGroup;
2824
2397
      group->name = groupName;
2825
 
      //MusECore::PatchGroup group;
2826
 
      //group.name = groupName;
2827
2398
      
2828
2399
      pg->push_back(group);
2829
 
      //MusECore::PatchGroup* pgp = &(pg->back());
2830
2400
      
2831
2401
      QTreeWidgetItem* sitem = new QTreeWidgetItem(patchView);
2832
2402
      sitem->setText(0, groupName);
2833
2403
      
2834
2404
      patchNameEdit->setText(groupName);
2835
2405
      
2836
 
      //QVariant v = QVariant::fromValue((void*)0);
2837
 
      //sitem->setData(0, Qt::UserRole, v);
2838
 
      //sitem->setData((void*)0);
2839
 
      
2840
2406
      // Set the list view item's data. 
2841
2407
      QVariant v = qVariantFromValue((void*)(group));
2842
2408
      sitem->setData(0, Qt::UserRole, v);
2843
2409
      //sitem->setAuxData((void*)pgp);
2844
2410
      
2845
 
      //patchView->addTopLevelItem(sitem);
2846
 
      //patchView->setCurrentItem(sitem);
2847
 
      
2848
 
      //oldPatchItem = 0;
2849
 
      
2850
2411
      // May cause patchChanged call.
2851
2412
      patchView->blockSignals(true);
2852
2413
      sitem->setSelected(true);
2853
2414
      patchView->blockSignals(false);
2854
2415
      
2855
 
      //oldPatchItem = (ListViewData*)patchView->selectedItem();
2856
2416
      oldPatchItem = sitem;
2857
 
      //oldPatchItem = 0;
2858
 
      //patchChanged();
2859
2417
      
2860
2418
      spinBoxHBank->setEnabled(false);
2861
2419
      spinBoxLBank->setEnabled(false);
2865
2423
      checkBoxGS->setEnabled(false);
2866
2424
      checkBoxXG->setEnabled(false);
2867
2425
      
2868
 
      //instrument->setDirty(true);
2869
2426
      workingInstrument.setDirty(true);
2870
2427
      }
2871
2428
 
2875
2432
 
2876
2433
void EditInstrument::deleteControllerClicked()
2877
2434
      {
2878
 
      //QListWidgetItem* item = instrumentList->currentItem();
2879
 
      //ListBoxData* item = (ListBoxData*)instrumentList->selectedItem();
2880
 
      //QListWidgetItem* item2 = listController->currentItem();
2881
 
//      ListBoxData* item = (ListBoxData*)listController->selectedItem();
2882
2435
      QTreeWidgetItem* item = viewController->currentItem();
2883
2436
      
2884
 
      //if (item == 0 || item2 == 0)
2885
2437
      if(!item)
2886
2438
        return;
2887
 
      //MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)item->data(Qt::UserRole).value<void*>();
2888
 
//      MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)item->data();
2889
 
      //MusECore::MidiController* ctrl       = (MusECore::MidiController*)item2->data(Qt::UserRole).value<void*>();
2890
 
      //MusECore::MidiController* ctrl       = (MusECore::MidiController*)item2->data();
2891
 
      //MusECore::MidiControllerList* cl     = instrument->controller();
2892
 
      //cl->removeAll(ctrl);
2893
2439
      
2894
2440
      MusECore::MidiController* ctrl = (MusECore::MidiController*)item->data(0, Qt::UserRole).value<void*>();
2895
2441
      if(!ctrl)
2901
2447
      
2902
2448
      // Now remove the controller item from the list.
2903
2449
      // This may cause a controllerChanged call.
2904
 
//      listController->blockSignals(true);
2905
2450
      viewController->blockSignals(true);
2906
2451
      delete item;
2907
2452
      if(viewController->currentItem())
2908
2453
        viewController->currentItem()->setSelected(true);
2909
 
//      listController->blockSignals(false);
2910
2454
      viewController->blockSignals(false);
2911
2455
      
2912
 
      //oldController = (ListBoxData*)listController->selectedItem();
2913
 
//      oldController = 0;
2914
 
      
2915
2456
      controllerChanged();
2916
2457
      
2917
 
      //instrument->setDirty(true);
2918
2458
      workingInstrument.setDirty(true);
2919
2459
      }
2920
2460
 
2923
2463
//---------------------------------------------------------
2924
2464
 
2925
2465
void EditInstrument::newControllerClicked()
2926
 
      {
2927
 
      //QListWidgetItem* item = instrumentList->currentItem();
2928
 
      //if (item == 0)
2929
 
      //      return;
2930
 
      //MusECore::MidiInstrument* instrument = (MusECore::MidiInstrument*)item->data(Qt::UserRole).value<void*>();
2931
 
 
2932
 
//      if(oldController)
2933
 
//        updateController(&workingInstrument, (MusECore::MidiController*)oldController->data());
2934
 
      
 
2466
      {      
2935
2467
      QString cName;
2936
 
      //MusECore::MidiControllerList* cl = instrument->controller();
2937
2468
      MusECore::MidiControllerList* cl = workingInstrument.controller();
2938
2469
      for (int i = 1;; ++i) {
2939
 
            //ctrlName = QString("Controller-%d").arg(i);
2940
2470
            cName = QString("Controller-%1").arg(i);
2941
2471
            bool found = false;
2942
2472
            for (MusECore::iMidiController ic = cl->begin(); ic != cl->end(); ++ic) {
2964
2494
      if(ci)
2965
2495
      {
2966
2496
        MusECore::MidiController* selctl = (MusECore::MidiController*)ci->data(0, Qt::UserRole).value<void*>();
2967
 
        // Assign.
2968
 
        // *ctrl = *selctl;
2969
2497
        
2970
2498
        // Auto increment controller number.
2971
 
        //int l = ctrl->num() & 0x7f;
2972
 
        //int h = ctrl->num() & 0xffffff00;
2973
2499
        int l = selctl->num() & 0x7f;
2974
2500
        int h = selctl->num() & 0xffffff00;
2975
2501
          
2976
2502
        // Ignore internal controllers and wild cards.
2977
 
        //if(((h & 0xff0000) != 0x40000) && ((ctrl->num() & 0xff) != 0xff))
2978
2503
        if(((h & 0xff0000) != 0x40000) && ((selctl->num() & 0xff) != 0xff))
2979
2504
        {
2980
2505
          // Assign.
2982
2507
          
2983
2508
          for (int i = 1; i < 128; ++i) 
2984
2509
          {
2985
 
            //ctrlName = QString("Controller-%d").arg(i);
2986
 
            //cName = QString("Controller-%1").arg(i);
2987
2510
            int j = ((i + l) & 0x7f) | h;
2988
2511
            found = false;
2989
2512
            for (MusECore::iMidiController ic = cl->begin(); ic != cl->end(); ++ic) 
3006
2529
      
3007
2530
      ctrl->setName(cName);
3008
2531
      
3009
 
      //item = new QListWidgetItem(ctrlName);
3010
 
//      ListBoxData* item = new ListBoxData(ctrlName);
3011
 
      
3012
 
      //QVariant v = qVariantFromValue((void*)(ctrl));
3013
 
      //item->setData(Qt::UserRole, v);
3014
 
//      item->setData((void*)ctrl);
3015
 
      //listController->addItem(item);
3016
 
//      listController->insertItem(item);
3017
 
      //listController->setCurrentItem(item);
3018
 
      
3019
2532
      workingInstrument.controller()->add(ctrl);   
3020
2533
      QTreeWidgetItem* item = addControllerToView(ctrl);
3021
2534
      
3022
 
//      listController->blockSignals(true);
3023
 
//      listController->setSelected(item, true);
3024
 
//      listController->blockSignals(false);
3025
2535
      viewController->blockSignals(true);
3026
2536
      item->setSelected(true);
3027
2537
      viewController->blockSignals(false);
3028
2538
      
3029
 
      //oldController = (ListBoxData*)listController->selectedItem();
3030
 
//      oldController = item;
3031
 
      //oldController = 0;
3032
 
      // MidiController is a class, with itialized values. We have to call this to show the values.
3033
 
      // To make multiple entries easier, don't bother calling this.
3034
2539
      controllerChanged();
3035
 
      
3036
 
      //instrument->setDirty(true);
 
2540
 
3037
2541
      workingInstrument.setDirty(true);
3038
2542
      }
3039
2543
 
3043
2547
 
3044
2548
void EditInstrument::addControllerClicked()
3045
2549
{
3046
 
  //int lnum = listController->currentItem();
3047
 
  //if(lnum == -1)
3048
 
  //  return;
3049
 
    
3050
 
  //QString name = midiCtrlName(lnum);
3051
 
  
3052
2550
  QListWidgetItem* idx = listController->currentItem();
3053
2551
  if(idx == 0)
3054
2552
    return;
3120
2618
  workingInstrument.setDirty(true);
3121
2619
}
3122
2620
 
3123
 
/*
 
2621
/* DELETETHIS or later needed???
3124
2622
//---------------------------------------------------------
3125
2623
//   deleteSysexClicked
3126
2624
//---------------------------------------------------------
3178
2676
            }
3179
2677
      
3180
2678
      signed char hb = (spinBoxHBank->value() - 1) & 0xff;
3181
 
      //if (p->hbank != (spinBoxHBank->value() & 0xff)) {
3182
 
      //      p->hbank = spinBoxHBank->value() & 0xff;
3183
2679
      if (p->hbank != hb) {
3184
2680
            p->hbank = hb;
3185
2681
            
3187
2683
            }
3188
2684
      
3189
2685
      signed char lb = (spinBoxLBank->value() - 1) & 0xff;
3190
 
      //if (p->lbank != (spinBoxLBank->value() & 0xff)) {
3191
 
      //      p->lbank = spinBoxLBank->value() & 0xff;
3192
2686
      if (p->lbank != lb) {
3193
2687
            p->lbank = lb;
3194
2688
            
3225
2719
            p->typ = value;
3226
2720
            instrument->setDirty(true);
3227
2721
            }
3228
 
      
3229
 
      //if (p->categorie != category->currentIndex()) {
3230
 
      //      p->categorie = category->currentIndex();
3231
 
      //      instrument->setDirty(true);
3232
 
      //      }
3233
2722
      }
3234
2723
 
3235
 
/*
 
2724
/* DELETETHIS
3236
2725
//---------------------------------------------------------
3237
2726
//   updateController
3238
2727
//---------------------------------------------------------
3320
2809
 
3321
2810
void EditInstrument::updateInstrument(MusECore::MidiInstrument* instrument)
3322
2811
      {
3323
 
      //QListWidgetItem* sysexItem = sysexList->currentItem();
3324
 
      //ListBoxData* sysexItem = sysexList->currentItem();
3325
 
      //if (sysexItem) {
3326
 
      //      SysEx* so = (SysEx*)sysexItem->data(Qt::UserRole).value<void*>();
3327
 
      //      updateSysex(instrument, so);
3328
 
      //      }
3329
 
      
3330
 
      //QListWidgetItem* ctrlItem = listController->currentItem();
3331
 
      //ListBoxData* ctrlItem = (ListBoxData*)listController->currentItem();
3332
 
      //ListBoxData* ctrlItem = (ListBoxData*)listController->selectedItem();
3333
 
//      ListViewData* ctrlItem = (ListViewData*)viewController->selectedItem();
3334
 
      
3335
 
//      if (ctrlItem) {
3336
 
            //MusECore::MidiController* ctrl = (MusECore::MidiController*)ctrlItem->data(Qt::UserRole).value<void*>();
3337
 
            
3338
 
//            printf("updateInstrument: AB\n");
3339
 
      
3340
 
//            MusECore::MidiController* ctrl = (MusECore::MidiController*)ctrlItem->data();
3341
 
            
3342
 
//            printf("updateInstrument: AC\n");
3343
 
            
3344
 
//            updateController(instrument, ctrl);
3345
 
//            }
3346
 
      
3347
 
//      printf("updateInstrument: B\n");
3348
 
      
3349
2812
      QTreeWidgetItem* patchItem = patchView->currentItem();
3350
2813
 
3351
2814
      if (patchItem) 
3352
2815
      {      
3353
 
        //MusECore::Patch* p = (MusECore::Patch*)patchItem->data(0, Qt::UserRole).value<void*>();
3354
 
        
3355
2816
        // If the item has a parent, it's a patch item.
3356
2817
        if(patchItem->parent())
3357
2818
          updatePatch(instrument, (MusECore::Patch*)patchItem->data(0, Qt::UserRole).value<void*>());
3370
2831
      {
3371
2832
      updateInstrument(i);
3372
2833
      if (!i->dirty())
3373
 
            //return false;
3374
2834
            return 0;
 
2835
 
3375
2836
      int n;
3376
2837
      if(isClose) 
3377
2838
        n = QMessageBox::warning(this, tr("MusE"),
3386
2847
      if (n == 0) {
3387
2848
            if (i->filePath().isEmpty())
3388
2849
            {
3389
 
                  //fileSaveAs();
3390
2850
                  saveAs();
3391
2851
            }      
3392
2852
            else {
3393
 
                  //QFile f(i->filePath());
3394
 
                  //if (!f.open(QIODevice::WriteOnly))
3395
2853
                  FILE* f = fopen(i->filePath().toLatin1().constData(), "w");
3396
2854
                  if(f == 0)
3397
 
                        //fileSaveAs();
3398
2855
                        saveAs();
3399
2856
                  else {
3400
 
                        //f.close();
3401
2857
                        if(fclose(f) != 0)
3402
2858
                          printf("EditInstrument::checkDirty: Error closing file\n");
3403
2859
                          
3405
2861
                              i->setDirty(false);
3406
2862
                        }
3407
2863
                  }
3408
 
            //return false;
3409
2864
            return 0;
3410
2865
            }
3411
 
      //return n == 2;
3412
2866
      return n;
3413
2867
      }
3414
2868
 
3515
2969
  defPatchH->blockSignals(true);
3516
2970
  defPatchL->blockSignals(true);
3517
2971
  defPatchProg->blockSignals(true);
3518
 
 defPatchH->setValue(hb);  
 
2972
  defPatchH->setValue(hb);  
3519
2973
  defPatchL->setValue(lb);  
3520
2974
  defPatchProg->setValue(pr);
3521
2975
  defPatchH->blockSignals(false);
3543
2997
      if(prog == MusECore::CTRL_VAL_UNKNOWN || pr == 0xff)
3544
2998
            return "---";
3545
2999
      
3546
 
      //int hbank = (prog >> 16) & 0x7f;
3547
 
      //int lbank = (prog >> 8) & 0x7f;
3548
3000
      int hbank = (prog >> 16) & 0xff;
3549
3001
      int lbank = (prog >> 8) & 0xff;
3550
3002
 
3554
3006
            const MusECore::PatchList& pl = (*i)->patches;
3555
3007
            for (MusECore::ciPatch ipl = pl.begin(); ipl != pl.end(); ++ipl) {
3556
3008
                  const MusECore::Patch* mp = *ipl;
3557
 
                  if (//(mp->typ & tmask) &&
 
3009
                  if (//(mp->typ & tmask) && DELETETHIS
3558
3010
                    (pr == mp->prog)
3559
 
                    //&& ((drum && mode != MT_GM) || 
 
3011
                    //&& ((drum && mode != MT_GM) ||  DELETETHIS
3560
3012
                    //   (mp->drum == drumchan))   
3561
3013
                    
3562
3014
                    //&& (hbank == mp->hbank || !hb || mp->hbank == -1)