~ubuntu-branches/ubuntu/saucy/muse/saucy

« back to all changes in this revision

Viewing changes to muse/midiedit/prcanvas.cpp

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2013-01-07 10:27:14 UTC
  • mfrom: (1.1.14)
  • Revision ID: package-import@ubuntu.com-20130107102714-fajkwjbz02aqupbh
Tags: 2.1-1
* New upstream release.
* Refresh 1001-buildsystem.patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
      setBBox(QRect(tick, y, e.lenTick(), KH/2));
68
68
      }
69
69
 
 
70
 
70
71
//---------------------------------------------------------
71
72
//   addItem
72
73
//---------------------------------------------------------
83
84
 
84
85
      int diff = event.tick()-part->lenTick();
85
86
      if (diff > 0)  {// too short part? extend it
86
 
            //printf("addItem - this code should not be run!\n"); DELETETHIS
87
 
            //MusECore::Part* newPart = part->clone();
88
 
            //newPart->setLenTick(newPart->lenTick()+diff);
89
 
            //MusEGlobal::audio->msgChangePart(part, newPart,false);
90
 
            //part = newPart;
91
87
            part->setLenTick(part->lenTick()+diff);
92
88
            }
93
89
      
248
244
      int mey = mer.y();
249
245
      int mew = mer.width();
250
246
      int meh = mer.height();
251
 
      //int mfx = mx; DELETETHIS 
252
 
      //if(mfx == mex) mfx += 1;
253
 
      //int mfy = my;
254
 
      //if(mfy == mey) mfy += 1;
255
 
      //int mfw = mw;
256
 
      //if(mfw == mew) mfw -= 1;
257
 
      //if(mfx == mex) mfw -= 1;
258
 
      //int mfh = mh;
259
 
      //if(mfh == meh) mfh -= 1;
260
 
      //if(mfy == mey) mfh -= 1;
261
247
      color.setAlpha(MusEGlobal::config.globalAlphaBlend);
262
 
      //QLinearGradient gradient(mex + 1, mey + 1, mex + 1, mey + meh - 2);    // Inside the border DELETETHIS
263
 
      //gradient.setColorAt(0, color);
264
 
      //gradient.setColorAt(1, color.darker());
265
 
      //QBrush brush(gradient);
266
248
      QBrush brush(color);
267
249
      p.fillRect(mr, brush);       
268
 
      //p.fillRect(mfx, mfy, mfw, mfh, brush);     DELETETHIS   
269
250
      
270
251
      if(mex >= mx && mex <= mx + mw)
271
252
        p.drawLine(mex, my, mex, my + mh - 1);                       // The left edge
451
432
      if (x < 0)
452
433
            x = 0;
453
434
      if (event.pitch() != npitch && _playEvents) {
454
 
            int port    = track()->outPort();
455
 
            int channel = track()->outChannel();
456
 
            // release note:
457
 
            MusECore::MidiPlayEvent ev1(0, port, channel, 0x90, event.pitch() + track()->transposition, 0);
458
 
            MusEGlobal::audio->msgPlayMidiEvent(&ev1);
459
 
            MusECore::MidiPlayEvent ev2(0, port, channel, 0x90, npitch + track()->transposition, event.velo());
460
 
            MusEGlobal::audio->msgPlayMidiEvent(&ev2);
 
435
            stopPlayEvent();
 
436
            if (moving.size() == 1) {
 
437
                startPlayEvent(npitch, event.velo());
 
438
                }
461
439
            }
462
440
      
463
441
      MusECore::Part* part = nevent->part();
502
480
 
503
481
      NEvent *newEvent = new NEvent(e, curPart, pitch2y(pitch));
504
482
      if(_playEvents)
505
 
              startPlayEvent(newEvent);
 
483
              startPlayEvent(e.pitch(), e.velo());
506
484
      return newEvent;
507
485
      }
508
486
 
713
691
 
714
692
void PianoCanvas::pianoPressed(int pitch, int velocity, bool shift)
715
693
      {
716
 
      int port      = track()->outPort();
717
 
      int channel   = track()->outChannel();
718
 
      pitch        += track()->transposition;
719
 
 
720
694
      // play note:
721
695
      if(_playEvents)
722
696
      {
723
 
        MusECore::MidiPlayEvent e(0, port, channel, 0x90, pitch, velocity);
724
 
        MusEGlobal::audio->msgPlayMidiEvent(&e);
 
697
        startPlayEvent(pitch, velocity);
725
698
      }
726
699
      
727
700
      if (_steprec && curPart) // && pos[0] >= start_tick && pos[0] < end_tick [removed by flo93: this is handled in steprec->record]
732
705
//   pianoReleased
733
706
//---------------------------------------------------------
734
707
 
735
 
void PianoCanvas::pianoReleased(int pitch, bool)
 
708
void PianoCanvas::pianoReleased(int /*pitch*/, bool)
736
709
      {
737
 
      int port    = track()->outPort();
738
 
      int channel = track()->outChannel();
739
 
      pitch      += track()->transposition;
740
 
 
741
710
      // release key:
742
711
      if(_playEvents)
743
 
      {
744
 
        MusECore::MidiPlayEvent e(0, port, channel, 0x90, pitch, 0);
745
 
        MusEGlobal::audio->msgPlayMidiEvent(&e);
746
 
      }
 
712
        stopPlayEvent();
747
713
      }
748
714
 
749
715
//---------------------------------------------------------
757
723
      int w = rect.width();
758
724
      int h = rect.height();
759
725
 
760
 
      //DELETETHIS whoa, clean up the whole function. remove every commented out code line
761
 
 
762
 
      // Changed to draw in device coordinate space instead of virtual, transformed space.     Tim. p4.0.30  
763
 
      
764
 
      //int mx = mapx(x);
765
 
      //int my = mapy(y);
766
 
      //int mw = mapx(x + w) - mx;
767
 
      //int mw = mapx(x + w) - mx - 1;
768
 
      //int mh = mapy(y + h) - my;
769
 
      //int mh = mapy(y + h) - my - 1;
770
 
      
771
 
      // p.save();
772
 
      // FIXME Can't get horizontal lines quite right yet. Draw in virtual space for now...
773
 
      ///p.setWorldMatrixEnabled(false);
774
726
      
775
727
      //---------------------------------------------------
776
728
      //  horizontal lines
777
729
      //---------------------------------------------------
778
730
 
779
731
      int yy  = ((y-1) / KH) * KH + KH;
780
 
      //int yy  = my + KH;
781
 
      //int yy  = ((my-1) / KH) * KH + KH;
782
 
      //int yoff = -rmapy(yorg) - ypos;
783
732
      int key = 75 - (yy / KH);
784
733
      
785
 
      //printf("PianoCanvas::drawCanvas x:%d y:%d w:%d h:%d mx:%d my:%d mw:%d mh:%d yy:%d key:%d\n", x, y, w, h, mx, my, mw, mh, yy, key);  
786
734
      
787
735
      for (; yy < y + h; yy += KH) {
788
 
      //for (; yy + yoff < my + mh; yy += KH) {
789
 
      //for (; yy < my + mh; yy += KH) {
790
736
            switch (key % 7) {
791
737
                  case 0:
792
738
                  case 3:
793
739
                        p.setPen(Qt::black);
794
740
                        p.drawLine(x, yy, x + w, yy);
795
 
                        //p.drawLine(mx, yy + yoff, mx + mw, yy + yoff);
796
 
                        //p.drawLine(mx, yy, mx + mw, yy);
797
741
                        break;
798
742
                  default:
799
743
                        p.fillRect(x, yy-3, w, 6, QBrush(QColor(230,230,230)));
800
 
                        //p.fillRect(mx, yy-3 + yoff, mw, 6, QBrush(QColor(230,230,230)));
801
 
                        //p.fillRect(mx, yy-3, mw, 6, QBrush(QColor(230,230,230)));
802
744
                        break;
803
745
                  }
804
746
            --key;
805
747
            }
806
 
      //p.restore();
807
 
      ///p.setWorldMatrixEnabled(true);
808
 
      
809
 
      //p.setWorldMatrixEnabled(false);
810
748
      
811
749
      //---------------------------------------------------
812
750
      // vertical lines
814
752
 
815
753
      drawTickRaster(p, x, y, w, h, editor->raster());
816
754
      
817
 
      //p.restore();
818
 
      //p.setWorldMatrixEnabled(true);
819
755
      }
820
756
 
821
757
//---------------------------------------------------------
989
925
 
990
926
void PianoCanvas::dragMoveEvent(QDragMoveEvent*)
991
927
      {
992
 
      //printf("drag move %x\n", this); DELETETHIS (whole function?)
993
 
      //event->acceptProposedAction();  
994
928
      }
995
929
 
996
930
//---------------------------------------------------------
999
933
 
1000
934
void PianoCanvas::dragLeaveEvent(QDragLeaveEvent*)
1001
935
      {
1002
 
      //printf("drag leave\n");         DELETETHIS (whole function?)
1003
 
      //event->acceptProposedAction();  
1004
936
      }
1005
937
 
1006
938
//---------------------------------------------------------
1011
943
      {
1012
944
      if (!_playEvents)
1013
945
            return;
1014
 
      startPlayEvent(item);
 
946
      MusECore::Event e = ((NEvent*)item)->event();
 
947
      startPlayEvent(e.pitch(), e.velo());
1015
948
      }
1016
949
 
1017
950
//---------------------------------------------------------
1033
966
      {
1034
967
      int npitch = y2pitch(pos.y());
1035
968
      if ((playedPitch != -1) && (playedPitch != npitch)) {
1036
 
            int port         = track()->outPort();
1037
 
            int channel      = track()->outChannel();
1038
969
            NEvent* nevent   = (NEvent*) item;
1039
970
            MusECore::Event event      = nevent->event();
1040
971
 
1041
972
            // release note:
1042
 
            MusECore::MidiPlayEvent ev1(0, port, channel, 0x90, playedPitch, 0);
1043
 
            MusEGlobal::audio->msgPlayMidiEvent(&ev1);
1044
 
            // play note:
1045
 
            MusECore::MidiPlayEvent e2(0, port, channel, 0x90, npitch + track()->transposition, event.velo());
1046
 
            MusEGlobal::audio->msgPlayMidiEvent(&e2);
1047
 
            playedPitch = npitch + track()->transposition;
 
973
            stopPlayEvent();
 
974
 
 
975
            if (moving.size() == 1) { // items moving
 
976
                // play note:
 
977
                startPlayEvent(npitch, event.velo());
 
978
                }
1048
979
            }
1049
980
      }
1050
981
 
1164
1095
      EventCanvas::resizeEvent(ev);
1165
1096
      }
1166
1097
 
1167
 
//---------------------------------------------------------
1168
 
//   startPlayEvent
1169
 
//---------------------------------------------------------
1170
 
 
1171
 
void PianoCanvas::startPlayEvent(const MusEGui::CItem* item)
1172
 
      {
1173
 
      int port         = track()->outPort();
1174
 
      int channel      = track()->outChannel();
1175
 
      NEvent* nevent   = (NEvent*) item;
1176
 
      MusECore::Event event      = nevent->event();
1177
 
      playedPitch      = event.pitch() + track()->transposition;
1178
 
      int velo         = event.velo();
1179
 
 
1180
 
      // play note:
1181
 
      MusECore::MidiPlayEvent e(0, port, channel, 0x90, playedPitch, velo);
1182
 
      MusEGlobal::audio->msgPlayMidiEvent(&e);
1183
 
      }
1184
 
 
1185
 
//---------------------------------------------------------
1186
 
//   stopPlayEvent
1187
 
//---------------------------------------------------------
1188
 
 
1189
 
void PianoCanvas::stopPlayEvent()
1190
 
      {
1191
 
      int port    = track()->outPort();
1192
 
      int channel = track()->outChannel();
1193
 
 
1194
 
      // release note:
1195
 
      MusECore::MidiPlayEvent ev(0, port, channel, 0x90, playedPitch, 0);
1196
 
      MusEGlobal::audio->msgPlayMidiEvent(&ev);
1197
 
      playedPitch = -1;
1198
 
      }
 
1098
 
1199
1099
 
1200
1100
} // namespace MusEGui