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

« back to all changes in this revision

Viewing changes to muse/liste/editevent.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:
27
27
#include <QGridLayout>
28
28
#include <QLabel>
29
29
#include <QListWidget>
 
30
#include <QListWidgetItem>
30
31
#include <QMessageBox>
31
32
#include <QPushButton>
32
33
#include <QRadioButton>
147
148
      return nevent;
148
149
      }
149
150
 
150
 
MusECore::Event EditCAfterDialog::getEvent(int tick, const MusECore::Event& event, QWidget* parent)
151
 
      {
152
 
      EditEventDialog* dlg = new EditCAfterDialog(tick, event, parent);
153
 
      MusECore::Event nevent;
154
 
      if (dlg->exec() == QDialog::Accepted) {
155
 
            nevent = dlg->event();
156
 
            }
157
 
      delete dlg;
158
 
      return nevent;
159
 
      }
160
 
 
161
 
MusECore::Event EditPAfterDialog::getEvent(int tick, const MusECore::Event& event, QWidget* parent)
162
 
      {
163
 
      EditEventDialog* dlg = new EditPAfterDialog(tick, event, parent);
164
 
      MusECore::Event nevent;
165
 
      if (dlg->exec() == QDialog::Accepted) {
166
 
            nevent = dlg->event();
167
 
            }
168
 
      delete dlg;
169
 
      return nevent;
170
 
      }
171
 
 
172
151
//---------------------------------------------------------
173
152
//   EditEventDialog
174
153
//---------------------------------------------------------
433
412
      }
434
413
 
435
414
//---------------------------------------------------------
436
 
//   EditCAfterDialog
437
 
//---------------------------------------------------------
438
 
 
439
 
EditCAfterDialog::EditCAfterDialog(int tick, const MusECore::Event& event,
440
 
   QWidget* parent)
441
 
   : EditEventDialog(parent)
442
 
      {
443
 
      setWindowTitle(tr("MusE: Enter Channel Aftertouch"));
444
 
 
445
 
      QLabel* l1 = new QLabel(tr("Time Position"));
446
 
      epos = new Awl::PosEdit;
447
 
 
448
 
      QLabel* l2 = new QLabel(tr("Pressure"));
449
 
      il2  = new MusEGui::IntLabel(-1, 0, 127, this, -1);
450
 
      il2->setFrame(true);
451
 
      il2->setDark();
452
 
 
453
 
      QSlider* slider = new QSlider(Qt::Horizontal);
454
 
      slider->setMinimum(0);
455
 
      slider->setMaximum(127);
456
 
      slider->setPageStep(1);
457
 
      slider->setValue(0);
458
 
 
459
 
      connect(slider, SIGNAL(valueChanged(int)), il2, SLOT(setValue(int)));
460
 
      connect(il2, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
461
 
 
462
 
      if (!event.empty()) {
463
 
            epos->setValue(tick);
464
 
            il2->setValue(event.dataA());
465
 
            slider->setValue(event.dataA());
466
 
            }
467
 
      else {
468
 
            epos->setValue(tick);
469
 
            il2->setValue(64);
470
 
            slider->setValue(64);
471
 
            }
472
 
 
473
 
      layout1->addWidget(l1,   0, 0);
474
 
      layout1->addWidget(epos,  0, 1, Qt::AlignLeft);
475
 
      layout1->addWidget(l2,   1, 0);
476
 
      layout1->addWidget(il2,  1, 1, Qt::AlignLeft);
477
 
      //layout1->addMultiCellWidget(slider, 2, 2, 0, 1);
478
 
      layout1->addWidget(slider, 2, 0, 1, 2);
479
 
      }
480
 
 
481
 
//---------------------------------------------------------
482
 
//   EditCAfterDialog::event
483
 
//---------------------------------------------------------
484
 
 
485
 
MusECore::Event EditCAfterDialog::event()
486
 
      {
487
 
      MusECore::Event event(MusECore::CAfter);
488
 
      event.setTick(epos->pos().tick());
489
 
      event.setA(il2->value());
490
 
      return event;
491
 
      }
492
 
 
493
 
//---------------------------------------------------------
494
 
//   EditPAfterDialog
495
 
//---------------------------------------------------------
496
 
 
497
 
EditPAfterDialog::EditPAfterDialog(int tick, const MusECore::Event& event,
498
 
   QWidget* parent)
499
 
   : EditEventDialog(parent)
500
 
      {
501
 
      setWindowTitle(tr("MusE: Enter Poly Aftertouch"));
502
 
 
503
 
      QLabel* l1 = new QLabel(tr("Time Position"));
504
 
      epos = new Awl::PosEdit;
505
 
 
506
 
      QLabel* l2 = new QLabel(tr("Pitch"));
507
 
      pl = new MusEGui::PitchEdit;
508
 
      QLabel* l3 = new QLabel(tr("Pressure"));
509
 
      il2  = new MusEGui::IntLabel(-1, 0, 127, this, -1);
510
 
      il2->setFrame(true);
511
 
      il2->setDark();
512
 
 
513
 
      QSlider* slider = new QSlider(Qt::Horizontal);
514
 
      slider->setMinimum(0);
515
 
      slider->setMaximum(127);
516
 
      slider->setPageStep(1);
517
 
      slider->setValue(0);
518
 
 
519
 
      connect(slider, SIGNAL(valueChanged(int)), il2, SLOT(setValue(int)));
520
 
      connect(il2, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
521
 
 
522
 
      if (!event.empty()) {
523
 
            epos->setValue(tick);
524
 
            pl->setValue(event.pitch());
525
 
            il2->setValue(event.dataB());
526
 
            slider->setValue(event.dataB());
527
 
            }
528
 
      else {
529
 
            epos->setValue(tick);
530
 
            pl->setValue(64);
531
 
            il2->setValue(64);
532
 
            slider->setValue(64);
533
 
            }
534
 
 
535
 
      layout1->addWidget(l1,  0, 0);
536
 
      layout1->addWidget(epos, 0, 1, Qt::AlignLeft);
537
 
      layout1->addWidget(l2,  1, 0);
538
 
      layout1->addWidget(pl,  1, 1, Qt::AlignLeft);
539
 
      layout1->addWidget(l3,  2, 0);
540
 
      layout1->addWidget(il2, 2, 1, Qt::AlignLeft);
541
 
      //layout1->addMultiCellWidget(slider, 3, 3, 0, 1);
542
 
      layout1->addWidget(slider, 3, 0, 1, 2);
543
 
      }
544
 
 
545
 
//---------------------------------------------------------
546
 
//   EditPAfterDialog::event
547
 
//---------------------------------------------------------
548
 
 
549
 
MusECore::Event EditPAfterDialog::event()
550
 
      {
551
 
      MusECore::Event event(MusECore::PAfter);
552
 
      event.setTick(epos->pos().tick());
553
 
      event.setA(pl->value());
554
 
      event.setB(il2->value());
555
 
      return event;
556
 
      }
557
 
//---------------------------------------------------------
558
415
//   getEvent
559
416
//---------------------------------------------------------
560
417
 
578
435
      {
579
436
      MusECore::Event event(MusECore::Controller);
580
437
      event.setTick(timePos->pos().tick());
581
 
      event.setA(num);
582
 
      if (num == MusECore::CTRL_PROGRAM)
583
 
            event.setB(val);
 
438
 
 
439
      int cnum = 0;
 
440
      QListWidgetItem* item = ctrlList->currentItem();
 
441
      if(item != 0)
 
442
        cnum = item->data(Qt::UserRole).toInt();
 
443
 
 
444
      MusECore::MidiTrack* track  = part->track();
 
445
      bool isDrum                 = track->type() == MusECore::Track::DRUM;
 
446
      MusECore::MidiPort* port    = &MusEGlobal::midiPorts[track->outPort()];
 
447
      int channel                 = track->outChannel();
 
448
 
 
449
      int evnum = cnum;
 
450
      int num = cnum;
 
451
      if((cnum & 0xff) == 0xff)
 
452
      {
 
453
        evnum = (cnum & ~0xff) | (noteSpinBox->value() & 0x7f);
 
454
        num = evnum;
 
455
        if(isDrum)
 
456
        {
 
457
          MusECore::DrumMap* dm = &MusEGlobal::drumMap[noteSpinBox->value() & 0x7f];
 
458
          num     = (cnum & ~0xff) | dm->anote;
 
459
          port    = &MusEGlobal::midiPorts[dm->port];
 
460
          channel = dm->channel;
 
461
        }
 
462
      }
 
463
 
 
464
      MusECore::MidiController* c = port->midiController(cnum);
 
465
      MusECore::MidiCtrlValListList* cll = port->controller();
 
466
 
 
467
      if(cll->find(channel, num) == cll->end())
 
468
      {
 
469
        MusECore::MidiCtrlValList* vl = new MusECore::MidiCtrlValList(num);
 
470
        cll->add(channel, vl);
 
471
      }
 
472
                        
 
473
      event.setA(evnum);
 
474
      if(cnum == MusECore::CTRL_PROGRAM)
 
475
      {
 
476
        int hb   = hbank->value();
 
477
        int lb   = lbank->value();
 
478
        int prog = program->value();
 
479
        if (hb > 0 && hb < 129)
 
480
              hb -= 1;
 
481
        else
 
482
              hb = 0xff;
 
483
        if (lb > 0 && lb < 129)
 
484
              lb -= 1;
 
485
        else
 
486
              lb = 0xff;
 
487
        if (prog > 0 && prog < 129)
 
488
              prog -= 1;
 
489
        else
 
490
              prog = 0xff;
 
491
        int val = (hb << 16) + (lb << 8) + prog;
 
492
        event.setB(val);
 
493
      }
584
494
      else
585
 
            event.setB(valSlider->value() + MusEGlobal::midiPorts[part->track()->outPort()].midiController(num)->bias());
 
495
        event.setB(valSlider->value() + c->bias());
586
496
      return event;
587
497
      }
588
498
 
596
506
//    QPushButton* buttonNewController;
597
507
//---------------------------------------------------------
598
508
 
 
509
struct CI {
 
510
            int num;
 
511
            QString s;
 
512
            bool used;
 
513
            bool off;
 
514
            bool instrument;
 
515
            CI(int n, const QString& ss, bool u, bool o, bool i) : num(n), s(ss), used(u), off(o), instrument(i) {}
 
516
            };
 
517
 
599
518
EditCtrlDialog::EditCtrlDialog(int tick, const MusECore::Event& event,
600
519
   const MusECore::MidiPart* p, QWidget* parent)
601
520
   : QDialog(parent), part(p)
602
521
      {
603
522
      setupUi(this);
604
523
      widgetStack->setAutoFillBackground(true);
605
 
      val = 0;
606
 
      num = 0;
607
 
      if (!event.empty()) {
608
 
            num = event.dataA();
609
 
            val = event.dataB();
610
 
            }
611
 
 
612
 
      ///pop = new QMenu(this);
613
 
      //pop->setCheckable(false);//not necessary in Qt4
614
524
 
615
525
      MusECore::MidiTrack* track   = part->track();
616
 
      int portn          = track->outPort();
617
 
      MusECore::MidiPort* port     = &MusEGlobal::midiPorts[portn];
 
526
      MusECore::MidiPort* port   = &MusEGlobal::midiPorts[track->outPort()];
618
527
      bool isDrum        = track->type() == MusECore::Track::DRUM;
 
528
      bool isNewDrum     = track->type() == MusECore::Track::NEW_DRUM;
 
529
      bool isMidi        = track->type() == MusECore::Track::MIDI;
619
530
      MusECore::MidiCtrlValListList* cll = port->controller();
 
531
      int channel        = track->outChannel();
 
532
      MusECore::MidiInstrument* instr = port->instrument();
 
533
      MusECore::MidiControllerList* mcl = instr->controller();
 
534
      int val = 0;
 
535
      int ev_num = 0;
 
536
      int num = 0;
 
537
      int ev_cnum = 0;
 
538
      int ev_note = -1;
 
539
      if (!event.empty()) {
 
540
            ev_num = event.dataA();
 
541
            num = ev_num;
 
542
            ev_cnum = ev_num;
 
543
            val = event.dataB();
 
544
            if(port->drumController(ev_num))
 
545
            {
 
546
              ev_cnum |= 0xff;
 
547
              if(isDrum)
 
548
                num = (ev_num & ~0xff) | MusEGlobal::drumMap[ev_num & 0xff].anote;
 
549
              ev_note = ev_num & 0xff;
 
550
            }
 
551
          }
620
552
 
 
553
      MusECore::MidiController* mc = port->midiController(ev_num);
 
554
      
621
555
      ctrlList->clear();
622
556
      ctrlList->setSelectionMode(QAbstractItemView::SingleSelection);
623
557
 
624
 
      //
625
 
      // populate list of available controller
626
 
      //
 
558
      //---------------------------------------------------
 
559
      // build list of midi controllers for current
 
560
      // MusECore::MidiPort/channel
 
561
      //---------------------------------------------------
627
562
 
628
 
      std::list<QString> sList;
629
 
      typedef std::list<QString>::iterator isList;
 
563
      std::list<CI> sList;
 
564
      typedef std::list<CI>::iterator isList;
 
565
      std::set<int> already_added_nums;
630
566
 
631
567
      for (MusECore::iMidiCtrlValList it = cll->begin(); it != cll->end(); ++it) {
632
568
            MusECore::MidiCtrlValList* cl = it->second;
633
 
            int num             = cl->num();
634
 
 
635
 
            // dont show drum specific controller if not a drum track
636
 
            if ((num & 0xff) == 0xff) {
637
 
                  if (!isDrum)
638
 
                        continue;
639
 
                  }
640
 
            MusECore::MidiController* c = port->midiController(num);
641
 
            {
 
569
            int ch = it->first >> 24;
 
570
            if(ch != channel)
 
571
              continue;
 
572
            MusECore::MidiController* c   = port->midiController(cl->num());
 
573
            bool isDrumCtrl = (c->isPerNoteController());
 
574
            int show = c->showInTracks();
 
575
            int cnum = c->num();
 
576
            int clnum = cl->num();
642
577
            isList i = sList.begin();
643
578
            for (; i != sList.end(); ++i) {
644
 
                  if (*i == c->name())
 
579
                  if (i->num == cnum)
645
580
                        break;
646
581
                  }
647
 
            if (i == sList.end())
648
 
                  sList.push_back(c->name());
649
 
            }
650
 
            }
651
 
      MusECore::MidiController* mc = port->midiController(num);
652
 
      int idx = 0;
653
 
      int selectionIndex = 0;
654
 
      for (isList i = sList.begin(); i != sList.end(); ++i, ++idx) {
655
 
            ctrlList->addItem(*i);
656
 
            if (mc->name() == *i)
657
 
                  selectionIndex = idx;
658
 
            }
659
 
      ctrlList->item(selectionIndex)->setSelected(true);
660
 
 
 
582
 
 
583
            if (i == sList.end()) {
 
584
                  bool used = (clnum == num);
 
585
                  bool off = cl->hwVal() == MusECore::CTRL_VAL_UNKNOWN;  // Does it have a value or is it 'off'?
 
586
                  // Filter if not used and off. But if there's something there, we must show it.
 
587
                  //if(!used && off &&
 
588
                  if(!used && //off &&
 
589
                     (((isDrumCtrl || isNewDrum) && !(show & MusECore::MidiController::ShowInDrum)) ||
 
590
                     (isMidi && !(show & MusECore::MidiController::ShowInMidi))))
 
591
                    continue;
 
592
                  bool isinstr = mcl->find(cnum) != mcl->end();
 
593
                  // Need to distinguish between global default controllers and
 
594
                  //  instrument defined controllers. Instrument takes priority over global
 
595
                  //  ie they 'overtake' definition of a global controller such that the
 
596
                  //  global def is no longer available.
 
597
                  //sList.push_back(CI(num,
 
598
                  sList.push_back(CI(cnum,
 
599
                                  isinstr ? MusECore::midiCtrlNumString(cnum, true) + c->name() : MusECore::midiCtrlName(cnum, true),
 
600
                                  used, off, isinstr));
 
601
                  already_added_nums.insert(num);
 
602
                  }
 
603
            }
 
604
 
 
605
      // Add instrument-defined controllers:
 
606
      QListWidgetItem* sel_item = 0; 
 
607
      for (isList i = sList.begin(); i != sList.end(); ++i)
 
608
      {
 
609
        // Filter if not used and off. But if there's something there, we must show it.
 
610
        if(!i->instrument && !i->used && i->off)
 
611
          continue;
 
612
        QListWidgetItem* item = new QListWidgetItem(i->s, ctrlList);
 
613
        item->setData(Qt::UserRole, i->num);
 
614
        if(i->num == ev_cnum)
 
615
          sel_item = item;
 
616
      }
 
617
      if(sel_item)
 
618
        ctrlList->setCurrentItem(sel_item);  
 
619
      
661
620
      valSlider->setRange(mc->minVal(), mc->maxVal());
662
621
      valSpinBox->setRange(mc->minVal(), mc->maxVal());
663
622
      
665
624
 
666
625
      if(!event.empty())
667
626
      {
668
 
        if(num == MusECore::CTRL_PROGRAM)
 
627
        if(ev_num == MusECore::CTRL_PROGRAM)
669
628
        {
670
629
          widgetStack->setCurrentIndex(1);
671
 
          updatePatch();
 
630
          updatePatch(val);
672
631
        }  
673
632
        else  
674
633
        {
675
634
          widgetStack->setCurrentIndex(0);
676
635
          valSlider->setValue(val - mc->bias());
 
636
          
 
637
          if(mc->isPerNoteController())
 
638
          {
 
639
            noteSpinBox->setVisible(true);
 
640
            noteSpinBox->setEnabled(true);
 
641
            noteLabel->setVisible(true);
 
642
            noteLabel->setEnabled(true);
 
643
            if(ev_note != -1)
 
644
              noteSpinBox->setValue(ev_note);
 
645
          }
 
646
          else
 
647
          {
 
648
            noteSpinBox->setEnabled(false);
 
649
            noteSpinBox->setVisible(false);
 
650
            noteLabel->setEnabled(false);
 
651
            noteLabel->setVisible(false);
 
652
          }
677
653
        }  
678
654
      }
679
655
      else
680
 
        ctrlListClicked(ctrlList->selectedItems()[0]);
 
656
      {
 
657
        noteSpinBox->setEnabled(false);
 
658
        noteSpinBox->setVisible(false);
 
659
        noteLabel->setEnabled(false);
 
660
        noteLabel->setVisible(false);
 
661
        if(sel_item)
 
662
          ctrlListClicked(sel_item);
 
663
      }
681
664
      connect(ctrlList, SIGNAL(itemClicked(QListWidgetItem*)), SLOT(ctrlListClicked(QListWidgetItem*)));
682
665
      connect(buttonNewController, SIGNAL(clicked()), SLOT(newController()));
683
666
      connect(hbank,   SIGNAL(valueChanged(int)), SLOT(programChanged()));
703
686
      MusECore::MidiTrack* track        = part->track();
704
687
      int portn               = track->outPort();
705
688
      MusECore::MidiPort* port          = &MusEGlobal::midiPorts[portn];
 
689
      bool isDrum      = track->type() == MusECore::Track::DRUM;
 
690
      bool isNewDrum   = track->type() == MusECore::Track::NEW_DRUM;
 
691
      bool isMidi      = track->type() == MusECore::Track::MIDI;
706
692
      MusECore::MidiInstrument* instr   = port->instrument();
707
693
      MusECore::MidiControllerList* mcl = instr->controller();
708
694
      
709
695
      MusECore::MidiCtrlValListList* cll = port->controller();
710
696
      int channel              = track->outChannel();
711
 
      int nn = 0;
712
697
      for (MusECore::iMidiController ci = mcl->begin(); ci != mcl->end(); ++ci)
713
698
      {
714
 
            if(cll->find(channel, ci->second->num()) == cll->end())
715
 
            {
716
 
                    QAction* act = pup->addAction(ci->second->name());
717
 
                    act->setData(nn);
718
 
                    ++nn;
719
 
            }
 
699
          MusECore::MidiController* c = ci->second;
 
700
          int cnum = c->num();
 
701
          int show = c->showInTracks();
 
702
          if(((isDrum || isNewDrum) && !(show & MusECore::MidiController::ShowInDrum)) ||
 
703
             (isMidi && !(show & MusECore::MidiController::ShowInMidi)))
 
704
            continue;
 
705
          // If it's not already in the parent menu...
 
706
          int idx = 0;
 
707
          for(; idx < ctrlList->count(); ++idx) {
 
708
            if(ctrlList->item(idx)->data(Qt::UserRole).toInt() == cnum)
 
709
              break;
 
710
          }
 
711
          if(idx >= ctrlList->count()) {
 
712
            QAction* act = pup->addAction(MusECore::midiCtrlNumString(cnum, true) + c->name());
 
713
            act->setData(cnum);
 
714
          }
720
715
      }
721
 
      QAction* rv = pup->exec(buttonNewController->mapToGlobal(QPoint(0,0)));
722
 
      if (rv) {
723
 
            QString s = rv->text();
 
716
      
 
717
      QAction* act = pup->exec(buttonNewController->mapToGlobal(QPoint(0,0)));
 
718
      if (act && act->data().toInt() != -1) {
 
719
            int rv = act->data().toInt();
 
720
            int cnum = rv;
724
721
            for (MusECore::iMidiController ci = mcl->begin(); ci != mcl->end(); ++ci) {
725
722
                  MusECore::MidiController* mc = ci->second;
726
 
                  if (mc->name() == s) {
727
 
                        if(cll->find(channel, mc->num()) == cll->end())
 
723
                  if (mc->num() == cnum) {
 
724
                        // Create a new controller list if it does not exist.
 
725
                        // FIXME: Sorry no per-pitch controller lists created here
 
726
                        //         (meaning you should only create one 'new' one at a time)
 
727
                        //         because the user has not had a chance to choose a pitch yet.
 
728
                        //        They are handled in accept(), where there are more checks and creations.
 
729
                        if(!mc->isPerNoteController() && cll->find(channel, rv) == cll->end())
728
730
                        {
729
 
                          MusECore::MidiCtrlValList* vl = new MusECore::MidiCtrlValList(mc->num());
 
731
                          MusECore::MidiCtrlValList* vl = new MusECore::MidiCtrlValList(rv);
730
732
                          cll->add(channel, vl);
731
733
                        }
732
734
                        int idx = 0;
733
 
                        for (; idx < ctrlList->count() ;++idx) {   // p4.0.25 Fix segfault 
734
 
                              QString str = ctrlList->item(idx)->text();
735
 
                              if (s == str)
 
735
                        for (; idx < ctrlList->count() ;++idx) {  
 
736
                              QListWidgetItem* item = ctrlList->item(idx);
 
737
                              int item_data = item->data(Qt::UserRole).toInt();
 
738
                              if(item_data == cnum)
736
739
                              {
737
 
                                    ctrlList->item(idx)->setSelected(true);
738
 
                                    ctrlListClicked(ctrlList->item(idx));
 
740
                                    ctrlList->setCurrentItem(item);
 
741
                                    ctrlListClicked(item);
739
742
                                    break;
740
743
                              }      
741
744
                              }
742
 
                        if (idx >= ctrlList->count()) {                       // p4.0.25 Fix segfault 
743
 
                              ctrlList->addItem(s);
744
 
                              ctrlList->item(idx)->setSelected(true);
745
 
                              ctrlListClicked(ctrlList->item(idx));
 
745
                        if (idx >= ctrlList->count()) {                       
 
746
                              QListWidgetItem* new_item = new QListWidgetItem(act->text(), ctrlList);
 
747
                              new_item->setData(Qt::UserRole, cnum);
 
748
                              ctrlList->setCurrentItem(new_item);
 
749
                              ctrlListClicked(new_item);
746
750
                              break;
747
751
                              }
748
 
                              
749
 
                              
750
752
                        break;
751
753
                        }
752
754
                  }
759
761
 
760
762
void EditCtrlDialog::ctrlListClicked(QListWidgetItem* item)
761
763
      {
762
 
      if (item == 0)
763
 
            return;
764
 
      QString s(item->text());
765
 
 
766
 
      MusECore::MidiTrack* track         = part->track();
767
 
      int portn                = track->outPort();
768
 
      MusECore::MidiPort* port           = &MusEGlobal::midiPorts[portn];
769
 
      MusECore::MidiCtrlValListList* cll = port->controller();
770
 
      
771
 
      MusECore::iMidiCtrlValList i;
772
 
      for (i = cll->begin(); i != cll->end(); ++i) {
773
 
            MusECore::MidiCtrlValList* cl = i->second;
774
 
            num                 = cl->num();
775
 
            MusECore::MidiController* c   = port->midiController(num);
776
 
            if (s == c->name()) {
777
 
                  if (num == MusECore::CTRL_PROGRAM) {
778
 
                        widgetStack->setCurrentIndex(1);
779
 
                        
780
 
                        val = c->initVal();
781
 
                        if(val == MusECore::CTRL_VAL_UNKNOWN)
782
 
                          val = 0;
783
 
                        updatePatch();
784
 
                        }
785
 
                  else {
786
 
                        widgetStack->setCurrentIndex(0);
787
 
                        valSlider->setRange(c->minVal(), c->maxVal());
788
 
                        valSpinBox->setRange(c->minVal(), c->maxVal());
789
 
                        controllerName->setText(s);
790
 
                        val = c->initVal();
791
 
                        
792
 
                        if(val == MusECore::CTRL_VAL_UNKNOWN || val == 0)
793
 
                        {
794
 
                          switch(num)
795
 
                          {
796
 
                            case MusECore::CTRL_PANPOT:
797
 
                              val = 64 - c->bias();
798
 
                            break;
799
 
                            case MusECore::CTRL_VOLUME:
800
 
                              val = 100;
801
 
                            break;
802
 
                            default:  
803
 
                              val = 0;
804
 
                            break;  
805
 
                          } 
806
 
                        }
807
 
                        valSlider->setValue(val);
808
 
                        }
809
 
                  break;
810
 
                  }
811
 
            }
812
 
      if (i == cll->end())
813
 
            printf("controller %s not found!\n", s.toLatin1().constData());
 
764
      if(item == 0)
 
765
        return;
 
766
      int cnum = item->data(Qt::UserRole).toInt();
 
767
      MusECore::MidiTrack* track  = part->track();
 
768
      int portn                   = track->outPort();
 
769
      MusECore::MidiPort* port    = &MusEGlobal::midiPorts[portn];
 
770
      MusECore::MidiController* c = port->midiController(cnum);
 
771
      int val;
 
772
      if (cnum == MusECore::CTRL_PROGRAM) {
 
773
            widgetStack->setCurrentIndex(1);
 
774
 
 
775
            val = c->initVal();
 
776
            if(val == MusECore::CTRL_VAL_UNKNOWN)
 
777
              val = 0;
 
778
            updatePatch(val);
 
779
            }
 
780
      else {
 
781
            widgetStack->setCurrentIndex(0);
 
782
            if(c->isPerNoteController())
 
783
            {
 
784
              noteSpinBox->setEnabled(true);
 
785
              noteSpinBox->setVisible(true);
 
786
              noteLabel->setEnabled(true);
 
787
              noteLabel->setVisible(true);
 
788
            }
 
789
            else
 
790
            {
 
791
              noteSpinBox->setEnabled(false);
 
792
              noteSpinBox->setVisible(false);
 
793
              noteLabel->setEnabled(false);
 
794
              noteLabel->setVisible(false);
 
795
            }
 
796
            valSlider->setRange(c->minVal(), c->maxVal());
 
797
            valSpinBox->setRange(c->minVal(), c->maxVal());
 
798
            controllerName->setText(c->name());
 
799
            val = c->initVal();
 
800
 
 
801
            if(val == MusECore::CTRL_VAL_UNKNOWN || val == 0)
 
802
            {
 
803
              switch(cnum)
 
804
              {
 
805
                case MusECore::CTRL_PANPOT:
 
806
                  val = 64 - c->bias();
 
807
                break;
 
808
                case MusECore::CTRL_VOLUME:
 
809
                  val = 100;
 
810
                break;
 
811
                default:
 
812
                  val = 0;
 
813
                break;
 
814
              }
 
815
            }
 
816
            valSlider->setValue(val);
 
817
            }
814
818
      }
815
819
 
816
820
//---------------------------------------------------------
817
821
//   updatePatch
818
822
//---------------------------------------------------------
819
823
 
820
 
void EditCtrlDialog::updatePatch()
 
824
void EditCtrlDialog::updatePatch(int val)
821
825
      {
822
826
      MusECore::MidiTrack* track      = part->track();
823
827
      int port              = track->outPort();
824
828
      int channel           = track->outChannel();
825
829
      MusECore::MidiInstrument* instr = MusEGlobal::midiPorts[port].instrument();
826
 
      patchName->setText(instr->getPatchName(channel, val, MusEGlobal::song->mtype(), track->type() == MusECore::Track::DRUM));
 
830
      patchName->setText(instr->getPatchName(channel, val, track->isDrumTrack()));
827
831
 
828
832
      int hb = ((val >> 16) & 0xff) + 1;
829
833
      if (hb == 0x100)
860
864
      MusECore::MidiInstrument* instr = MusEGlobal::midiPorts[port].instrument();
861
865
      
862
866
      MusEGui::PopupMenu* pup = new MusEGui::PopupMenu(this);
863
 
      instr->populatePatchPopup(pup, channel, MusEGlobal::song->mtype(), track->type() == MusECore::Track::DRUM);
 
867
      instr->populatePatchPopup(pup, channel, track->isDrumTrack());
864
868
 
865
869
      if(pup->actions().count() == 0)
866
870
      {
870
874
      
871
875
      QAction* rv = pup->exec(patchName->mapToGlobal(QPoint(10,5)));
872
876
      if (rv) {
873
 
            val = rv->data().toInt();
874
 
            updatePatch();
 
877
            updatePatch(rv->data().toInt());
875
878
            }
876
879
            
877
880
      delete pup;      
900
903
      else
901
904
            prog = 0xff;
902
905
 
903
 
      val = (hb << 16) + (lb << 8) + prog;
904
 
      updatePatch();
 
906
      int val = (hb << 16) + (lb << 8) + prog;
 
907
      updatePatch(val);
905
908
      }
906
909
 
907
910
} // namespace MusEGui