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

« back to all changes in this revision

Viewing changes to muse/midiedit/dcanvas.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:
58
58
 
59
59
using MusEGlobal::debugMsg;
60
60
using MusEGlobal::heavyDebugMsg;
 
61
using MusECore::MidiTrack;
61
62
 
62
63
namespace MusEGui {
63
64
 
97
98
      
98
99
      int diff = event.endTick()-part->lenTick();
99
100
      if (diff > 0)  {// too short part? extend it
100
 
            //printf("addItem - this code should not be run!\n");  DELETETHIS
101
 
            //MusECore::Part* newPart = part->clone();
102
 
            //newPart->setLenTick(newPart->lenTick()+diff);
103
 
            //MusEGlobal::audio->msgChangePart(part, newPart,false);
104
 
            //part = newPart;
105
101
            part->setLenTick(part->lenTick()+diff);
106
102
            }
107
103
      
172
168
 
173
169
MusECore::Undo DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype)
174
170
{      
 
171
 
175
172
  if(editor->parts()->empty())
176
173
    return MusECore::Undo(); //return empty list
177
174
  
304
301
      MusECore::MidiPart* part   = (MusECore::MidiPart*)nevent->part();
305
302
      MusECore::MidiPart* dest_part   = part;
306
303
      
307
 
      int nheight       = y2pitch(pos.y());
308
 
      if (nheight<0) nheight=0;
309
 
      if (nheight>=getOurDrumMapSize()) nheight=getOurDrumMapSize()-1;
 
304
      int instrument       = y2pitch(pos.y());
 
305
      if (instrument<0) instrument=0;
 
306
      if (instrument>=getOurDrumMapSize()) instrument=getOurDrumMapSize()-1;
310
307
            
311
 
      if (!instrument_map[nheight].tracks.contains(dest_part->track()))
 
308
      if (!instrument_map[instrument].tracks.contains(dest_part->track()))
312
309
      {
313
310
        if (debugMsg)
314
311
          printf("trying to move an event into a different track. checking if curPart is set correctly...\n");
315
312
        
316
 
        if (!instrument_map[nheight].tracks.contains(curPart->track()))
 
313
        if (!instrument_map[instrument].tracks.contains(curPart->track()))
317
314
        {
318
315
          printf ("ERROR: tried to move an event into a track which is different from both the initial part's and the curPart's track! ignoring this one...\n");
319
316
          return false;
322
319
          dest_part=(MusECore::MidiPart*)curPart;
323
320
      }
324
321
 
 
322
 
325
323
      MusECore::Event event      = nevent->event();
 
324
 
326
325
      int x            = pos.x();
327
326
      if (x < 0)
328
327
            x = 0;
332
331
      MusECore::Event newEvent   = event.clone();
333
332
 
334
333
      
335
 
      int ev_pitch = instrument_map[nheight].pitch;
 
334
      int ev_pitch = instrument_map[instrument].pitch;
336
335
      
337
336
      newEvent.setPitch(ev_pitch);
338
337
      newEvent.setTick(ntick);
414
413
  e.setPitch(instrument_map[instrument].pitch);
415
414
  e.setVelo(velocity);
416
415
  e.setLenTick(ourDrumMap[instrument].len);
 
416
  if(_playEvents)
 
417
  {
 
418
    int port = old_style_drummap_mode ? ourDrumMap[instrument].port : dynamic_cast<MidiTrack*>(*instrument_map[instrument].tracks.begin())->outPort();
 
419
    int channel = old_style_drummap_mode ? ourDrumMap[instrument].channel : dynamic_cast<MidiTrack*>(*instrument_map[instrument].tracks.begin())->outChannel();
 
420
    startPlayEvent(e.pitch(),e.velo(), port, channel);
 
421
  }
417
422
 
418
423
  return new DEvent(e, curPart, instrument);
419
424
}
450
455
            x = editor->rasterVal(x);
451
456
      event.setTick(x - nevent->part()->tick());
452
457
      int npitch = event.pitch();
453
 
      //event.setPitch(npitch); // commented out by flo: has no effect
 
458
 
 
459
      if(_playEvents) {
 
460
         //stopPlayEvent();
 
461
         keyReleased(pitch2y(event.pitch()), true); // kinda backwards but this should pick the right port, stopPlayEvent does not know.
 
462
      }
454
463
 
455
464
      // check for existing event
456
465
      //    if found change command semantic from insert to delete
512
521
      }
513
522
 
514
523
//---------------------------------------------------------
 
524
//   itemPressed
 
525
//---------------------------------------------------------
 
526
 
 
527
void DrumCanvas::itemPressed(const MusEGui::CItem* item)
 
528
      {
 
529
      if (!_playEvents)
 
530
            return;
 
531
 
 
532
      MusECore::Event e = ((DEvent*)item)->event();
 
533
      int pitch = e.pitch();
 
534
 
 
535
      startPlayEvent(pitch, e.velo()); //, port, channel);
 
536
      }
 
537
 
 
538
//---------------------------------------------------------
 
539
//   itemReleased
 
540
//---------------------------------------------------------
 
541
 
 
542
void DrumCanvas::itemReleased(const MusEGui::CItem* item, const QPoint&)
 
543
      {
 
544
      if (!_playEvents)
 
545
              return;
 
546
      MusECore::Event e = ((DEvent*)item)->event();
 
547
      keyReleased(pitch2y(e.pitch()), true); // kinda backwards but this should pick the right port, stopPlayEvent does not know.
 
548
      //stopPlayEvent();
 
549
      }
 
550
 
 
551
 
 
552
//---------------------------------------------------------
515
553
//   drawItem
516
554
//---------------------------------------------------------
517
555
 
590
628
      p.setPen(Qt::black);
591
629
      p.setBrush(Qt::black);
592
630
      p.drawPolygon(pa);
 
631
 
 
632
      int instrument = y2pitch(y);
 
633
      int pitch = instrument_map[instrument].pitch;
 
634
      MusECore::Event e = ((DEvent*)item)->event();
 
635
      if (pitch != playedPitch && _playEvents) {
 
636
            keyReleased(playedPitch, true); // kinda backwards but this should pick the right port, stopPlayEvent does not know.
 
637
            if (moving.size() == 1) {
 
638
                int port = old_style_drummap_mode ? ourDrumMap[instrument].port : dynamic_cast<MidiTrack*>(*instrument_map[instrument].tracks.begin())->outPort();
 
639
                int channel = old_style_drummap_mode ? ourDrumMap[instrument].channel : dynamic_cast<MidiTrack*>(*instrument_map[instrument].tracks.begin())->outChannel();
 
640
                startPlayEvent(pitch, e.velo(), port, channel);
 
641
                }
 
642
            }
593
643
    }
594
644
 
595
645
//---------------------------------------------------------
869
919
      int port = old_style_drummap_mode ? ourDrumMap[index].port : dynamic_cast<MidiTrack*>(*instrument_map[index].tracks.begin())->outPort();
870
920
      int channel = old_style_drummap_mode ? ourDrumMap[index].channel : dynamic_cast<MidiTrack*>(*instrument_map[index].tracks.begin())->outChannel();
871
921
      int pitch = old_style_drummap_mode ? ourDrumMap[index].anote : instrument_map[index].pitch;
872
 
 
873
922
      // play note:
874
923
      if(_playEvents)
875
924
      {
876
 
        MusECore::MidiPlayEvent e(0, port, channel, 0x90, pitch, velocity);
877
 
        MusEGlobal::audio->msgPlayMidiEvent(&e);
 
925
        startPlayEvent(pitch,velocity, port, channel);
878
926
      }
879
927
      
880
928
      if (_steprec) /* && pos[0] >= start_tick && pos[0] < end_tick [removed by flo93: this is handled in steprec->record] */
899
947
//---------------------------------------------------------
900
948
 
901
949
void DrumCanvas::keyReleased(int index, bool)
902
 
      {
903
 
      using MusECore::MidiTrack;
904
 
      
 
950
      {    
905
951
      if ((index<0) || (index>=getOurDrumMapSize()))
906
952
        return;
907
953
      
915
961
      {
916
962
        MusECore::MidiPlayEvent e(0, port, channel, 0x90, pitch, 0);
917
963
        MusEGlobal::audio->msgPlayMidiEvent(&e);
 
964
        playedPitch=-1;
918
965
      }
919
966
      }
920
967