~ubuntu-branches/ubuntu/trusty/muse/trusty

« back to all changes in this revision

Viewing changes to muse/arranger/pcanvas.cpp

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2013-08-28 16:25:57 UTC
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: package-import@ubuntu.com-20130828162557-knls3ip7j262eepx
Tags: upstream-2.1.2
ImportĀ upstreamĀ versionĀ 2.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include <QMessageBox>
37
37
#include <QUrl>
38
38
#include <QPoint>
 
39
#include <QIcon>
39
40
 
40
41
#include "fastlog.h"
41
42
#include "widgets/tools.h"
55
56
#include "functions.h"
56
57
#include "filedialog.h"
57
58
#include "marker/marker.h"
 
59
#include "menutitleitem.h"
58
60
#include "mpevent.h"
59
61
#include "midievent.h"
60
62
#include "midi.h"
125
127
      MusECore::TrackList* tl = MusEGlobal::song->tracks();
126
128
      int yy  = 0;
127
129
      int idx = 0;
128
 
      for (MusECore::iTrack it = tl->begin(); it != tl->end(); ++it, ++idx) {
 
130
      for (MusECore::ciTrack it = tl->begin(); it != tl->end(); ++it, ++idx) {
129
131
            int h = (*it)->height();
130
132
            if (y < yy+h)
131
133
                  break;
143
145
      MusECore::TrackList* tl = MusEGlobal::song->tracks();
144
146
      int yy  = 0;
145
147
      int idx = 0;
146
 
      for (MusECore::iTrack it = tl->begin(); it != tl->end(); ++it, ++idx) {
 
148
      for (MusECore::ciTrack it = tl->begin(); it != tl->end(); ++it, ++idx) {
147
149
            if (idx == p)
148
150
                  break;
149
151
            yy += (*it)->height();
152
154
      }
153
155
 
154
156
//---------------------------------------------------------
 
157
//   y2height
 
158
//---------------------------------------------------------
 
159
 
 
160
int PartCanvas::y2height(int y) const
 
161
{
 
162
      MusECore::TrackList* tl = MusEGlobal::song->tracks();
 
163
      int yy  = 0;
 
164
      for (MusECore::ciTrack it = tl->begin(); it != tl->end(); ++it) {
 
165
            int h = (*it)->height();
 
166
            if (y < yy+h)
 
167
                  return h;
 
168
            yy += h;
 
169
            }
 
170
      return 20;
 
171
}
 
172
 
 
173
//---------------------------------------------------------
155
174
//   leaveEvent
156
175
//---------------------------------------------------------
157
176
 
223
242
 
224
243
      else {
225
244
            MusECore::TrackList* tl = MusEGlobal::song->tracks();
226
 
            MusECore::iTrack it;
 
245
            MusECore::ciTrack it;
227
246
            int yy = 0;
228
247
            int y = event->y();
229
248
            for (it = tl->begin(); it != tl->end(); ++it) {
276
295
//   moveCanvasItems
277
296
//---------------------------------------------------------
278
297
 
279
 
void PartCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype)
 
298
void PartCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype, bool rasterize)
280
299
{      
281
300
  MusECore::Undo operations;
282
301
  
284
303
  {
285
304
    CItem* ci = ici->second;
286
305
    
287
 
    // DELETETHIS 5
288
 
    // If this item's part is in the parts2change list, change the item's part to the new part.
289
 
    //MusECore::Part* pt = ci->part();
290
 
    //iP2C ip2c = parts2change.find(pt);
291
 
    //if(ip2c != parts2change.end())
292
 
    //  ci->setPart(ip2c->second);
293
 
    
294
306
    int x = ci->pos().x();
295
307
    int y = ci->pos().y();
296
308
    int nx = x + dx;
297
309
    int ny = pitch2y(y2pitch(y) + dp);
298
 
    QPoint newpos = raster(QPoint(nx, ny));
 
310
    QPoint newpos = QPoint(nx, ny);
 
311
    if(rasterize)
 
312
      newpos = raster(newpos);
299
313
    selectItem(ci, true);
300
314
    
301
315
    bool result=moveItem(operations, ci, newpos, dtype);
450
464
      curItem=NULL;     
451
465
      
452
466
      items.clearDelete();
453
 
      for (MusECore::iTrack t = tracks->begin(); t != tracks->end(); ++t) {
 
467
      for (MusECore::ciTrack t = tracks->begin(); t != tracks->end(); ++t) {
454
468
         if ((*t)->isVisible()) //ignore parts from hidden tracks
455
469
         {
456
470
            MusECore::PartList* pl = (*t)->parts();
457
 
            for (MusECore::iPart i = pl->begin(); i != pl->end(); ++i) {
 
471
            for (MusECore::ciPart i = pl->begin(); i != pl->end(); ++i) {
458
472
                  MusECore::Part* part = i->second;
459
473
                  NPart* np = new NPart(part);
460
474
                  items.add(np);
509
523
      MusECore::Part*  p = ((NPart*)(i))->part();
510
524
 
511
525
      int pos = p->tick() + i->width();
512
 
      int snappedpos = p->tick();
 
526
      int snappedpos = pos;
513
527
      if (!noSnap) {
514
528
            snappedpos = AL::sigmap.raster(pos, *_raster);
515
529
            }
525
539
//    first create local Item
526
540
//---------------------------------------------------------
527
541
 
528
 
CItem* PartCanvas::newItem(const QPoint& pos, int)
 
542
CItem* PartCanvas::newItem(const QPoint& pos, int key_modifiers)
529
543
      {
530
544
      int x = pos.x();
531
545
      if (x < 0)
532
546
            x = 0;
533
 
      x = AL::sigmap.raster(x, *_raster);
 
547
      if(!(key_modifiers & Qt::ShiftModifier))
 
548
        x = AL::sigmap.raster1(x, *_raster);
 
549
      int len   = pos.x() - x;
 
550
      if(len < 0)
 
551
        len = 0;
534
552
      unsigned trackIndex = y2pitch(pos.y());
535
553
      if (trackIndex >= tracks->size())
536
554
            return 0;
546
564
            case MusECore::Track::NEW_DRUM:
547
565
                  pa = new MusECore::MidiPart((MusECore::MidiTrack*)track);
548
566
                  pa->setTick(x);
549
 
                  pa->setLenTick(0);
 
567
                  pa->setLenTick(len);
550
568
                  break;
551
569
            case MusECore::Track::WAVE:
552
570
                  pa = new MusECore::WavePart((MusECore::WaveTrack*)track);
553
571
                  pa->setTick(x);
554
 
                  pa->setLenTick(0);
 
572
                  pa->setLenTick(len);
555
573
                  break;
556
574
            case MusECore::Track::AUDIO_OUTPUT:
557
575
            case MusECore::Track::AUDIO_INPUT:
572
590
 
573
591
void PartCanvas::newItem(CItem* i, bool noSnap)
574
592
      {
575
 
      MusECore::Part*  p = ((NPart*)(i))->part();
576
 
 
 
593
      if(!i)
 
594
        return;
 
595
      NPart* npart = (NPart*)(i);
 
596
      MusECore::Part* p = npart->part();
 
597
      if(!p)
 
598
        return;
 
599
      MusECore::Track* part_track = p->track();
 
600
      if(!part_track)
 
601
        return;
 
602
 
 
603
      int x = i->x();
 
604
      if (x < 0)
 
605
            x = 0;
 
606
      if(!noSnap)
 
607
        x = AL::sigmap.raster1(x, *_raster);
 
608
      p->setTick(x);
 
609
      
 
610
      unsigned trackIndex = y2pitch(i->y());
 
611
      unsigned int tsize = tracks->size();
 
612
      if (trackIndex >= tsize)
 
613
        trackIndex = (tsize > 0 ? tsize - 1 : 0);
 
614
      MusECore::Track* track = tracks->index(trackIndex);
 
615
 
 
616
      if(track != part_track)
 
617
      {
 
618
        if(track->type() == part_track->type())
 
619
        {
 
620
          p->setTrack(track);
 
621
          p->setName(track->name());
 
622
        }
 
623
        else
 
624
        {
 
625
          MusECore::Part* new_part = 0;
 
626
          switch(track->type())
 
627
          {
 
628
                case MusECore::Track::MIDI:
 
629
                case MusECore::Track::DRUM:
 
630
                case MusECore::Track::NEW_DRUM:
 
631
                      new_part = new MusECore::MidiPart((MusECore::MidiTrack*)track);
 
632
                      break;
 
633
                case MusECore::Track::WAVE:
 
634
                      new_part = new MusECore::WavePart((MusECore::WaveTrack*)track);
 
635
                      break;
 
636
                case MusECore::Track::AUDIO_OUTPUT:
 
637
                case MusECore::Track::AUDIO_INPUT:
 
638
                case MusECore::Track::AUDIO_GROUP:
 
639
                case MusECore::Track::AUDIO_AUX:
 
640
                case MusECore::Track::AUDIO_SOFTSYNTH:
 
641
                      break;
 
642
          }
 
643
          if(new_part)
 
644
          {
 
645
            new_part->setTick(p->tick());
 
646
            new_part->setName(track->name());
 
647
            new_part->setColorIndex(curColorIndex);
 
648
            delete p;
 
649
            npart->setPart(new_part);
 
650
            p = new_part;
 
651
          }
 
652
        }
 
653
      }
 
654
      
577
655
      int len = i->width();
578
656
      if (!noSnap)
579
657
            len = AL::sigmap.raster(len, *_raster);
633
711
 
634
712
      QMenu* partPopup = new QMenu(this);
635
713
 
 
714
      partPopup->addAction(new MenuTitleItem(tr("Part:"), partPopup));
 
715
      
636
716
      QAction *act_cut = partPopup->addAction(*editcutIconSet, tr("C&ut"));
637
717
      act_cut->setData(4);
638
718
      act_cut->setShortcut(Qt::CTRL+Qt::Key_X);
713
793
      act_delete->setEnabled( true);
714
794
      act_cut->setEnabled( true);
715
795
      act_declone->setEnabled( rc > 1);
716
 
      
 
796
 
 
797
      genCanvasPopup(partPopup);
717
798
      return partPopup;
718
799
      }
719
800
 
723
804
 
724
805
void PartCanvas::itemPopup(CItem* item, int n, const QPoint& pt)
725
806
      {
 
807
      if(n >= TOOLS_ID_BASE)
 
808
      {
 
809
        canvasPopup(n);
 
810
        return;
 
811
      }
 
812
      
726
813
      MusECore::PartList* pl = new MusECore::PartList;
727
814
      NPart* npart = (NPart*)(item);
728
815
      pl->add(npart->part());
878
965
            return true;
879
966
            }
880
967
      QPoint pt = event->pos();
 
968
      Qt::MouseButton button = event->button();
881
969
      CItem* item = items.find(pt);
882
970
 
883
971
      switch (_tool) {
884
972
            default:
885
 
                  if (item)
 
973
                  break; 
 
974
            case PointerTool:
 
975
            case PencilTool:
 
976
                  if (item && button == Qt::LeftButton)
886
977
                      emit trackChanged(item->part()->track());
887
 
                  //else -- don't see the point of removing track selection, commenting out (rj)
888
 
                  //    emit trackChanged(NULL);
889
978
                  break;
890
979
            case CutTool:
891
 
                  if (item) splitItem(item, pt);
 
980
                  if (item && button == Qt::LeftButton) splitItem(item, pt);
892
981
                  break;
893
982
            case GlueTool:
894
 
                  if (item) glueItem(item);
 
983
                  if (item && button == Qt::LeftButton) glueItem(item);
895
984
                  break;
896
985
            case MuteTool:
897
986
                  {
898
 
                  if (item) {
 
987
                  if (item && button == Qt::LeftButton) {
899
988
                      NPart* np = (NPart*) item;
900
989
                      MusECore::Part*  p = np->part();
901
990
                      p->setMute(!p->mute());
903
992
                      break;
904
993
                      }
905
994
                  }
 
995
                  break;
906
996
            case AutomationTool:
907
 
                  if (event->button() & Qt::RightButton  || 
908
 
                      event->button() & Qt::MidButton) {
909
 
                      
910
 
                      bool do_delete;
911
 
                      
912
 
                      if (event->button() & Qt::MidButton) // mid-click
 
997
                  if (button == Qt::RightButton  ||
 
998
                      button == Qt::MidButton) {
 
999
                      
 
1000
                      bool do_delete = false;
 
1001
                      
 
1002
                      if (button == Qt::MidButton) // mid-click
913
1003
                        do_delete=true;
914
1004
                      else // right-click
915
1005
                      {
916
1006
                        QMenu *automationMenu = new QMenu(this);
917
1007
                        QAction* act;
 
1008
                        automationMenu->addAction(new MenuTitleItem(tr("Automation:"), automationMenu));
918
1009
                        act = automationMenu->addAction(tr("Remove selected"));
 
1010
                        act->setData(0);
 
1011
                        genCanvasPopup(automationMenu);
919
1012
                        act = automationMenu->exec(event->globalPos());
920
 
                        if (act)
921
 
                          do_delete=true;
922
 
                        else
923
 
                          do_delete=false;
 
1013
                        if(act)
 
1014
                        {
 
1015
                          int n = act->data().toInt();
 
1016
                          if(n == 0)
 
1017
                            do_delete = true;
 
1018
                          else
 
1019
                          if(n >= TOOLS_ID_BASE)
 
1020
                            canvasPopup(n);
 
1021
                        }
 
1022
                        delete automationMenu;
924
1023
                      }
925
1024
                      if (do_delete && automation.currentTrack) {
926
1025
                          foreach(int frame, automation.currentCtrlFrameList)
927
1026
                              MusEGlobal::audio->msgEraseACEvent((MusECore::AudioTrack*)automation.currentTrack,
928
1027
                                       automation.currentCtrlList->id(), frame);
929
1028
                      }
930
 
 
931
1029
                  }
932
1030
                  else {
933
1031
                      if (automation.controllerState != doNothing)
978
1076
      {
979
1077
      MusECore::TrackList* l = MusEGlobal::song->tracks();
980
1078
      int ty = 0;
981
 
      for (MusECore::iTrack it = l->begin(); it != l->end(); ++it) {
 
1079
      for (MusECore::ciTrack it = l->begin(); it != l->end(); ++it) {
982
1080
            int h = (*it)->height();
983
1081
            if (y >= ty && y < ty + h)
984
1082
                  return *it;
1092
1190
      else if (key == shortcuts[SHRT_TOOL_LINEDRAW].key) {
1093
1191
            emit setUsedTool(AutomationTool);
1094
1192
            return;
1095
 
            }      else if (key == shortcuts[SHRT_TOOL_GLUE].key) {
 
1193
            }
 
1194
      else if (key == shortcuts[SHRT_TOOL_GLUE].key) {
1096
1195
            emit setUsedTool(GlueTool);
1097
1196
            return;
1098
1197
            }
1100
1199
            emit setUsedTool(MuteTool);
1101
1200
            return;
1102
1201
            }
 
1202
      else if (key == shortcuts[SHRT_TOOL_PAN].key) {
 
1203
            emit setUsedTool(PanTool);
 
1204
            return;
 
1205
            }
 
1206
      else if (key == shortcuts[SHRT_TOOL_ZOOM].key) {
 
1207
            emit setUsedTool(ZoomTool);
 
1208
            return;
 
1209
            }
1103
1210
      else if (key == shortcuts[SHRT_SEL_TRACK_ABOVE].key) {
1104
1211
            emit selectTrackAbove();
1105
1212
            return;
1951
2058
        
1952
2059
        pts = 0;
1953
2060
        if(het == (MusECore::Part::LeftEventsHidden | MusECore::Part::RightEventsHidden))
1954
 
        {
1955
 
          //points[pts++] = QPoint(xs_0, y0); DELETETHIS 11
1956
 
          //points[pts++] = QPoint(xe_0, y0);
1957
 
          //points[pts++] = QPoint(xe_j, y1);
1958
 
          //points[pts++] = QPoint(xe_0, y2);
1959
 
          //points[pts++] = QPoint(xe_j, y3);
1960
 
          //points[pts++] = QPoint(xe_0, y4);
1961
 
          //points[pts++] = QPoint(xs_0, y4);
1962
 
          //points[pts++] = QPoint(xs_j, y3);
1963
 
          //points[pts++] = QPoint(xs_0, y2);
1964
 
          //points[pts++] = QPoint(xs_j, y1);
1965
 
          
 
2061
        {          
1966
2062
          points[pts++] = QPoint(xs_0, y0);
1967
2063
          points[pts++] = QPoint(xe_0, y0);
1968
2064
          points[pts++] = QPoint(xe_j, y2);
1975
2071
        else
1976
2072
        if(het == MusECore::Part::LeftEventsHidden)
1977
2073
        {
1978
 
          //points[pts++] = QPoint(xs_0, y0); DELETETHIS 7
1979
 
          //points[pts++] = QPoint(xe_0, y0);
1980
 
          //points[pts++] = QPoint(xe_0, y4);
1981
 
          //points[pts++] = QPoint(xs_0, y4);
1982
 
          //points[pts++] = QPoint(xs_j, y3);
1983
 
          //points[pts++] = QPoint(xs_0, y2);
1984
 
          //points[pts++] = QPoint(xs_j, y1);
1985
 
          
1986
2074
          points[pts++] = QPoint(xs_0, y0);
1987
2075
          points[pts++] = QPoint(xe_0, y0);
1988
2076
          points[pts++] = QPoint(xe_0, y4);
1994
2082
        else
1995
2083
        if(het == MusECore::Part::RightEventsHidden)
1996
2084
        {
1997
 
          //points[pts++] = QPoint(xs_0, y0); DELETETHIS 7
1998
 
          //points[pts++] = QPoint(xe_0, y0);
1999
 
          //points[pts++] = QPoint(xe_j, y1);
2000
 
          //points[pts++] = QPoint(xe_0, y2);
2001
 
          //points[pts++] = QPoint(xe_j, y3);
2002
 
          //points[pts++] = QPoint(xe_0, y4);
2003
 
          //points[pts++] = QPoint(xs_0, y4);
2004
 
          
2005
2085
          points[pts++] = QPoint(xs_0, y0);
2006
2086
          points[pts++] = QPoint(xe_0, y0);
2007
2087
          points[pts++] = QPoint(xe_j, y2);
2016
2096
        int part_r, part_g, part_b, brightness, color_brightness;
2017
2097
        MusEGlobal::config.partColors[cidx].getRgb(&part_r, &part_g, &part_b);
2018
2098
        brightness =  part_r*29 + part_g*59 + part_b*12;
2019
 
        // DELETETHIS 4 ??
2020
 
        //if ((brightness < 12000 || part->selected()) && !part->mute() && !item->isMoving())
2021
 
        //  color_brightness=223;   // too dark: use lighter color 
2022
 
        //else
2023
 
        //  color_brightness=32;  // otherwise use dark color 
2024
2099
        if ((brightness >= 12000 && !part->selected()))
2025
2100
          color_brightness=96; //0;    // too light: use dark color 
2026
2101
        else
2030
2105
        if(het & MusECore::Part::RightEventsHidden)
2031
2106
        {
2032
2107
          pts = 0;
2033
 
          //points[pts++] = QPoint(xe_0, y0); DELETETHIS 5
2034
 
          //points[pts++] = QPoint(xe_0, y4);
2035
 
          //points[pts++] = QPoint(xe_j, y3);
2036
 
          //points[pts++] = QPoint(xe_0, y2);
2037
 
          //points[pts++] = QPoint(xe_j, y1);
2038
 
          
2039
2108
          points[pts++] = QPoint(xe_0, y0);
2040
2109
          points[pts++] = QPoint(xe_0, y4);
2041
2110
          points[pts++] = QPoint(xe_j, y2);
2045
2114
        if(het & MusECore::Part::LeftEventsHidden)
2046
2115
        {
2047
2116
          pts = 0;
2048
 
          //points[pts++] = QPoint(xs_0, y0); DELETETHIS 5
2049
 
          //points[pts++] = QPoint(xs_j, y1);
2050
 
          //points[pts++] = QPoint(xs_0, y2);
2051
 
          //points[pts++] = QPoint(xs_j, y3);
2052
 
          //points[pts++] = QPoint(xs_0, y4);
2053
 
          
2054
2117
          points[pts++] = QPoint(xs_0, y0);
2055
2118
          points[pts++] = QPoint(xs_j, y2);
2056
2119
          points[pts++] = QPoint(xs_0, y4);
2092
2155
      }
2093
2156
 
2094
2157
      p.setWorldMatrixEnabled(false);
2095
 
      
2096
 
  #if 0 // DELETETHIS 13
2097
 
        //
2098
 
        // Now draw the borders...
2099
 
        // Works great but requires clones be drawn with the highest priority on top of all other parts, in Canvas::draw.
2100
 
        //
2101
 
        
2102
 
        QPen pen(part->selected() ? MusEGlobal::config.partColors[i] : Qt::black, 2.0, clone ? Qt::DotLine : Qt::SolidLine);
2103
 
        pen.setCosmetic(true);
2104
 
        p.setPen(pen); 
2105
 
        p.setBrush(Qt::NoBrush);
2106
 
        p.drawRect(r);
2107
 
        
2108
 
  //#else 
2109
 
  #endif
2110
 
  
 
2158
        
2111
2159
  #if 1 // DELETETHIS remove wrapping #if
2112
2160
        //
2113
2161
        // Now draw the borders, using custom segments...
2134
2182
        penNormal2H.setCosmetic(true);
2135
2183
        penNormal1V.setCosmetic(true);
2136
2184
        penNormal2V.setCosmetic(true);
2137
 
        
2138
 
        //pc = Qt::white;
2139
 
        //pc = Qt::darkGray;
2140
 
        //QPen penHidden1(pc);
2141
 
        //QPen penHidden2(pc, 2.0);
2142
 
        //penHidden2.setCosmetic(true);
2143
 
        
 
2185
                
2144
2186
        QVector<qreal> customDashPattern;
2145
 
        
2146
2187
        if(clone)
2147
2188
        {
2148
2189
          customDashPattern << 4.0 << 6.0;
2176
2217
          }
2177
2218
        }  
2178
2219
        
2179
 
        //if(het & MusECore::Part::RightEventsHidden)
2180
 
        //  p.setPen(((NPart*)item)->rightBorderTouches ? penHidden1 : penHidden2); 
2181
 
        //else  
2182
 
        {
2183
 
          if(((NPart*)item)->rightBorderTouches)              
2184
 
            p.setPen(part->selected() ? penSelect1V : penNormal1V); 
2185
 
          else  
2186
 
            p.setPen(part->selected() ? penSelect2V : penNormal2V); 
2187
 
        }  
 
2220
        if(((NPart*)item)->rightBorderTouches)
 
2221
          p.setPen(part->selected() ? penSelect1V : penNormal1V);
 
2222
        else
 
2223
          p.setPen(part->selected() ? penSelect2V : penNormal2V);
2188
2224
        
2189
2225
        if(rbx >= mrxs_0 && rbx <= mrxe_0)  // Respect the requested drawing rectangle. Gives speed boost!
2190
2226
        {
2191
 
          QLine l2(rbx, ys_0, rbx, ye_0);            // Right 
 
2227
          QLine l2(rbx, ys_0, rbx, ye_0);            // Right
2192
2228
          p.drawLine(l2);        // Right line
2193
2229
        }
2194
 
        
2195
 
        /*
2196
 
        int xx = rbt?xe_1:xe_0; 
2197
 
        if(clone)
2198
 
        {
2199
 
          int yinc = 7;
2200
 
          for(int yy = (rbt?ys_1:ys_2); yy < ye_2; yy += yinc)
2201
 
          {
2202
 
            int yi = rbt?3:2;
2203
 
            if(yy + yi > ye_2)
2204
 
              yi = ye_2 - yy;
2205
 
            p.drawLine(QPoint(xx, yy), QPoint(xx, yy + yi));      // Right dashed line
2206
 
          }   
2207
 
        }
2208
 
        else  
2209
 
          p.drawLine(QPoint(xx, rbt?ys_1:ys_2), QPoint(xx, rbt?ye_1:ye_2));      // Right line
2210
 
        */
2211
 
        
2212
 
        //if(het & MusECore::Part::LeftEventsHidden)
2213
 
        //  p.setPen(((NPart*)item)->leftBorderTouches ? penHidden1 : penHidden2); 
2214
 
        //else  
2215
 
        {
2216
 
          if(((NPart*)item)->leftBorderTouches)              
2217
 
            p.setPen(part->selected() ? penSelect1V : penNormal1V); 
2218
 
          else  
2219
 
            p.setPen(part->selected() ? penSelect2V : penNormal2V); 
2220
 
        }  
 
2230
 
 
2231
        if(((NPart*)item)->leftBorderTouches)
 
2232
          p.setPen(part->selected() ? penSelect1V : penNormal1V);
 
2233
        else
 
2234
          p.setPen(part->selected() ? penSelect2V : penNormal2V);
2221
2235
        
2222
2236
        if(xs_0 >= mrxs_0 && xs_0 <= mrxe_0)
2223
2237
        {
2224
2238
          QLine l4(xs_0, ys_0, xs_0, ye_0);            // Left
2225
2239
          p.drawLine(l4);        //  Left line
2226
2240
        }
2227
 
        
2228
 
        /*
2229
 
        xx = xs_0;
2230
 
        if(clone)
2231
 
        {
2232
 
          int yinc = 7;
2233
 
          for(int yy = (lbt?ys_1:ys_2); yy < ye_2; yy += yinc)
2234
 
          {
2235
 
            int yi = lbt?3:2;
2236
 
            if(yy + yi > ye_2)
2237
 
              yi = ye_2 - yy;
2238
 
            p.drawLine(QPoint(xx, yy), QPoint(xx, yy + yi));      // Left dashed line
2239
 
          }   
2240
 
        }
2241
 
        else  
2242
 
          p.drawLine(QPoint(xx, lbt?ys_1:ys_2), QPoint(xx, lbt?ye_1:ye_2));      // Left line
2243
 
        */
2244
 
        
2245
 
        p.setPen(part->selected() ? penSelect2H : penNormal2H); 
 
2241
                
 
2242
        p.setPen(part->selected() ? penSelect2H : penNormal2H);
2246
2243
        
2247
2244
        // Respect the requested drawing rectangle. Gives speed boost!
2248
 
        QLine l1(lbx_c, ys_0, rbx_c, ys_0);  
 
2245
        QLine l1(lbx_c, ys_0, rbx_c, ys_0);
2249
2246
        p.drawLine(l1);  // Top line
2250
 
        QLine l3(lbx_c, ye_0, rbx_c, ye_0);  
 
2247
        QLine l3(lbx_c, ye_0, rbx_c, ye_0);
2251
2248
        p.drawLine(l3);  // Bottom line
2252
2249
        
2253
2250
  #endif
2290
2287
        p.setPen( Qt::black);
2291
2288
        MusECore::Part* part = ((NPart*)item)->part();
2292
2289
        QColor c(part->mute() ? Qt::white : MusEGlobal::config.partColors[part->colorIndex()]);        
2293
 
        //c.setAlpha(MusEGlobal::config.globalAlphaBlend); DELETETHIS
2294
 
        c.setAlpha(128);  // Fix this regardless of global setting. Should be OK.
 
2290
        c.setAlpha(128);  // Fix this regardless of config.globalAlphaBlend setting. Should be OK.
2295
2291
        p.setBrush(c);
2296
 
        p.drawRect(item->mp().x(), item->mp().y(), item->width(), item->height());
 
2292
        MusECore::TrackList* tl = MusEGlobal::song->tracks();
 
2293
        int yy  = 0;
 
2294
        int y = item->mp().y();
 
2295
        int ih = item->height();
 
2296
        for(MusECore::ciTrack it = tl->begin(); it != tl->end(); ++it)
 
2297
        {
 
2298
          int h = (*it)->height();
 
2299
          if(y < yy+h)
 
2300
          {
 
2301
            ih = h;
 
2302
            break;
 
2303
          }
 
2304
          yy += h;
 
2305
        }
 
2306
        p.drawRect(item->mp().x(), item->mp().y(), item->width(), ih);
2297
2307
      }
2298
2308
 
2299
 
 
2300
2309
//---------------------------------------------------------
2301
2310
//   drawMidiPart
2302
2311
//    bb - bounding box of paint area
2306
2315
void PartCanvas::drawMidiPart(QPainter& p, const QRect&, MusECore::EventList* events, MusECore::MidiTrack *mt, MusECore::MidiPart *pt, const QRect& r, int pTick, int from, int to)
2307
2316
{
2308
2317
  int color_brightness;
 
2318
  QColor eventColor;
2309
2319
  
2310
2320
  if(pt) 
2311
2321
  {
2312
2322
    int part_r, part_g, part_b, brightness;
2313
2323
    MusEGlobal::config.partColors[pt->colorIndex()].getRgb(&part_r, &part_g, &part_b);
2314
2324
    brightness =  part_r*29 + part_g*59 + part_b*12;
2315
 
    //if ((brightness < 12000 || pt->selected()) && !pt->mute()) DELETETHIS 4
2316
 
    //  color_brightness=192;   // too dark: use lighter color 
2317
 
    //else
2318
 
    //  color_brightness=64;  // otherwise use dark color 
2319
 
    if (brightness >= 12000 && !pt->selected())
 
2325
    if (brightness >= 12000 && !pt->selected()) {
 
2326
      eventColor=MusEGlobal::config.partMidiDarkEventColor;
2320
2327
      color_brightness=54; // 96;    // too bright: use dark color
2321
 
    else
 
2328
    }
 
2329
    else {
 
2330
      eventColor=MusEGlobal::config.partMidiLightEventColor;
2322
2331
      color_brightness=200; //160;   // too dark: use lighter color
 
2332
    }
2323
2333
  }
2324
 
  else
 
2334
  else {
 
2335
    eventColor=QColor(80,80,80);
2325
2336
    color_brightness=80;
 
2337
  }
2326
2338
    
2327
2339
  if (MusEGlobal::config.canvasShowPartType & 2) {      // show events
2328
 
            p.setPen(QColor(color_brightness,color_brightness,color_brightness));
 
2340
            p.setPen(eventColor);
2329
2341
            // Do not allow this, causes segfault.
2330
2342
            if(from <= to)
2331
2343
            {
2501
2513
        if (MusEGlobal::heavyDebugMsg) printf("DEBUG: arranger: cakewalk enabled, y-stretch disabled\n");
2502
2514
      }
2503
2515
 
2504
 
      p.setPen(QColor(color_brightness,color_brightness,color_brightness));      
 
2516
      p.setPen(eventColor);
2505
2517
      for (MusECore::iEvent i = events->begin(); i != ito; ++i) {
2506
2518
            int t  = i->first + pTick;
2507
2519
            int te = t + i->second.lenTick();
2609
2621
                        rms /= channels;
2610
2622
                        peak = (peak * (hh-2)) >> 9;
2611
2623
                        rms  = (rms  * (hh-2)) >> 9;
2612
 
                        p.setPen(QColor(Qt::darkGray));
 
2624
                        p.setPen(MusEGlobal::config.partWaveColorPeak);
2613
2625
                        p.drawLine(i, y - peak - cc, i, y + peak);
2614
 
                        p.setPen(QColor(Qt::darkGray).darker());
 
2626
                        p.setPen(MusEGlobal::config.partWaveColorRms);
2615
2627
                        p.drawLine(i, y - rms - cc, i, y + rms);
2616
2628
                        }
2617
2629
                  }
2629
2641
                        for (unsigned k = 0; k < channels; ++k) {
2630
2642
                              int peak = (sa[k].peak * (hm - 1)) >> 8;
2631
2643
                              int rms  = (sa[k].rms  * (hm - 1)) >> 8;
2632
 
                              p.setPen(QColor(Qt::darkGray));
 
2644
                              p.setPen(MusEGlobal::config.partWaveColorPeak);
2633
2645
                              p.drawLine(i, y - peak - cc, i, y + peak);
2634
 
                              p.setPen(QColor(Qt::darkGray).darker());
 
2646
                              p.setPen(MusEGlobal::config.partWaveColorRms);
2635
2647
                              p.drawLine(i, y - rms - cc, i, y + rms);
2636
2648
                              
2637
2649
                              y  += 2 * hm;
2944
2956
      if (to_single_track)
2945
2957
      {  
2946
2958
        MusECore::TrackList* tl = MusEGlobal::song->tracks();
2947
 
        for (MusECore::iTrack i = tl->begin(); i != tl->end(); ++i) {
 
2959
        for (MusECore::ciTrack i = tl->begin(); i != tl->end(); ++i) {
2948
2960
              if ((*i)->selected()) {
2949
2961
                    if (track) {
2950
2962
                          QMessageBox::critical(this, QString("MusE"),
3337
3349
      MusECore::TrackList* tl = MusEGlobal::song->tracks();
3338
3350
      int yy = -rmapy(yorg) - ypos;
3339
3351
      int th;
3340
 
      for (MusECore::iTrack it = tl->begin(); it != tl->end(); ++it) {
 
3352
      for (MusECore::ciTrack it = tl->begin(); it != tl->end(); ++it) {
3341
3353
            if (yy > my + mh)
3342
3354
                  break;
3343
3355
            MusECore::Track* track = *it;
3392
3404
    int yoff = -rmapy(yorg) - ypos;
3393
3405
    int yy = yoff;
3394
3406
    int th;
3395
 
    for (MusECore::iTrack it = tl->begin(); it != tl->end(); ++it) {
 
3407
    for (MusECore::ciTrack it = tl->begin(); it != tl->end(); ++it) {
3396
3408
          if (yy > my + mh)
3397
3409
                break;
3398
3410
          MusECore::Track* track = *it;
3428
3440
    // should be enhanced with solution that draws waveform also
3429
3441
    int yPos = yoff;
3430
3442
    if (MusEGlobal::song->record() && MusEGlobal::audio->isPlaying()) {
3431
 
      for (MusECore::iTrack it = tl->begin(); it != tl->end(); ++it) {
 
3443
      for (MusECore::ciTrack it = tl->begin(); it != tl->end(); ++it) {
3432
3444
        MusECore::Track* track = *it;
3433
3445
        th = track->height();
3434
3446
        if (!th)
3454
3466
    // draw midi events on
3455
3467
    yPos=0;
3456
3468
    if (MusEGlobal::song->record() && MusEGlobal::audio->isPlaying()) {
3457
 
      for (MusECore::iTrack it = tl->begin(); it != tl->end(); ++it) {
 
3469
      for (MusECore::ciTrack it = tl->begin(); it != tl->end(); ++it) {
3458
3470
           MusECore::Track* track = *it;
3459
3471
 
3460
3472
           if (track->isMidiTrack() && track->recordFlag()) {
3464
3476
               MusECore::MPEventList *el = mt->mpevents();
3465
3477
               if (el->size()) {
3466
3478
 
3467
 
                 for (MusECore::iMPEvent i = el->begin(); i != el->end(); ++i) {
 
3479
                 for (MusECore::ciMPEvent i = el->begin(); i != el->end(); ++i) {
3468
3480
                    MusECore::MidiPlayEvent pe = *i;
3469
3481
 
3470
3482
                    if (pe.isNote() && !pe.isNoteOff()) {
3994
4006
//          2     move only vertical
3995
4007
//---------------------------------------------------------
3996
4008
 
3997
 
void PartCanvas::endMoveItems(const QPoint& pos, DragType dragtype, int dir)
 
4009
void PartCanvas::endMoveItems(const QPoint& pos, DragType dragtype, int dir, bool rasterize)
3998
4010
      {
3999
4011
      int dp = y2pitch(pos.y()) - y2pitch(start.y());
4000
4012
      int dx = pos.x() - start.x();
4004
4016
      else if (dir == 2)
4005
4017
            dx = 0;
4006
4018
 
4007
 
      moveCanvasItems(moving, dp, dx, dragtype);
 
4019
      moveCanvasItems(moving, dp, dx, dragtype, rasterize);
4008
4020
      
4009
4021
      moving.clear();
4010
4022
      updateSelection();