154
156
//---------------------------------------------------------
158
//---------------------------------------------------------
160
int PartCanvas::y2height(int y) const
162
MusECore::TrackList* tl = MusEGlobal::song->tracks();
164
for (MusECore::ciTrack it = tl->begin(); it != tl->end(); ++it) {
165
int h = (*it)->height();
173
//---------------------------------------------------------
156
175
//---------------------------------------------------------
276
295
// moveCanvasItems
277
296
//---------------------------------------------------------
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)
281
300
MusECore::Undo operations;
285
304
CItem* ci = ici->second;
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);
294
306
int x = ci->pos().x();
295
307
int y = ci->pos().y();
297
309
int ny = pitch2y(y2pitch(y) + dp);
298
QPoint newpos = raster(QPoint(nx, ny));
310
QPoint newpos = QPoint(nx, ny);
312
newpos = raster(newpos);
299
313
selectItem(ci, true);
301
315
bool result=moveItem(operations, ci, newpos, dtype);
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
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);
525
539
// first create local Item
526
540
//---------------------------------------------------------
528
CItem* PartCanvas::newItem(const QPoint& pos, int)
542
CItem* PartCanvas::newItem(const QPoint& pos, int key_modifiers)
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;
534
552
unsigned trackIndex = y2pitch(pos.y());
535
553
if (trackIndex >= tracks->size())
573
591
void PartCanvas::newItem(CItem* i, bool noSnap)
575
MusECore::Part* p = ((NPart*)(i))->part();
595
NPart* npart = (NPart*)(i);
596
MusECore::Part* p = npart->part();
599
MusECore::Track* part_track = p->track();
607
x = AL::sigmap.raster1(x, *_raster);
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);
616
if(track != part_track)
618
if(track->type() == part_track->type())
621
p->setName(track->name());
625
MusECore::Part* new_part = 0;
626
switch(track->type())
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);
633
case MusECore::Track::WAVE:
634
new_part = new MusECore::WavePart((MusECore::WaveTrack*)track);
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:
645
new_part->setTick(p->tick());
646
new_part->setName(track->name());
647
new_part->setColorIndex(curColorIndex);
649
npart->setPart(new_part);
577
655
int len = i->width();
579
657
len = AL::sigmap.raster(len, *_raster);
880
967
QPoint pt = event->pos();
968
Qt::MouseButton button = event->button();
881
969
CItem* item = items.find(pt);
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);
891
if (item) splitItem(item, pt);
980
if (item && button == Qt::LeftButton) splitItem(item, pt);
894
if (item) glueItem(item);
983
if (item && button == Qt::LeftButton) glueItem(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());
906
996
case AutomationTool:
907
if (event->button() & Qt::RightButton ||
908
event->button() & Qt::MidButton) {
912
if (event->button() & Qt::MidButton) // mid-click
997
if (button == Qt::RightButton ||
998
button == Qt::MidButton) {
1000
bool do_delete = false;
1002
if (button == Qt::MidButton) // mid-click
914
1004
else // right-click
916
1006
QMenu *automationMenu = new QMenu(this);
1008
automationMenu->addAction(new MenuTitleItem(tr("Automation:"), automationMenu));
918
1009
act = automationMenu->addAction(tr("Remove selected"));
1011
genCanvasPopup(automationMenu);
919
1012
act = automationMenu->exec(event->globalPos());
1015
int n = act->data().toInt();
1019
if(n >= TOOLS_ID_BASE)
1022
delete automationMenu;
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);
933
1031
if (automation.controllerState != doNothing)
1953
2060
if(het == (MusECore::Part::LeftEventsHidden | MusECore::Part::RightEventsHidden))
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);
1966
2062
points[pts++] = QPoint(xs_0, y0);
1967
2063
points[pts++] = QPoint(xe_0, y0);
1968
2064
points[pts++] = QPoint(xe_j, y2);
1976
2072
if(het == MusECore::Part::LeftEventsHidden)
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);
1986
2074
points[pts++] = QPoint(xs_0, y0);
1987
2075
points[pts++] = QPoint(xe_0, y0);
1988
2076
points[pts++] = QPoint(xe_0, y4);
1995
2083
if(het == MusECore::Part::RightEventsHidden)
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);
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;
2020
//if ((brightness < 12000 || part->selected()) && !part->mute() && !item->isMoving())
2021
// color_brightness=223; // too dark: use lighter color
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
2030
2105
if(het & MusECore::Part::RightEventsHidden)
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);
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)
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);
2054
2117
points[pts++] = QPoint(xs_0, y0);
2055
2118
points[pts++] = QPoint(xs_j, y2);
2056
2119
points[pts++] = QPoint(xs_0, y4);
2094
2157
p.setWorldMatrixEnabled(false);
2096
#if 0 // DELETETHIS 13
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.
2102
QPen pen(part->selected() ? MusEGlobal::config.partColors[i] : Qt::black, 2.0, clone ? Qt::DotLine : Qt::SolidLine);
2103
pen.setCosmetic(true);
2105
p.setBrush(Qt::NoBrush);
2111
2159
#if 1 // DELETETHIS remove wrapping #if
2113
2161
// Now draw the borders, using custom segments...
2179
//if(het & MusECore::Part::RightEventsHidden)
2180
// p.setPen(((NPart*)item)->rightBorderTouches ? penHidden1 : penHidden2);
2183
if(((NPart*)item)->rightBorderTouches)
2184
p.setPen(part->selected() ? penSelect1V : penNormal1V);
2186
p.setPen(part->selected() ? penSelect2V : penNormal2V);
2220
if(((NPart*)item)->rightBorderTouches)
2221
p.setPen(part->selected() ? penSelect1V : penNormal1V);
2223
p.setPen(part->selected() ? penSelect2V : penNormal2V);
2189
2225
if(rbx >= mrxs_0 && rbx <= mrxe_0) // Respect the requested drawing rectangle. Gives speed boost!
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
2196
int xx = rbt?xe_1:xe_0;
2200
for(int yy = (rbt?ys_1:ys_2); yy < ye_2; yy += yinc)
2205
p.drawLine(QPoint(xx, yy), QPoint(xx, yy + yi)); // Right dashed line
2209
p.drawLine(QPoint(xx, rbt?ys_1:ys_2), QPoint(xx, rbt?ye_1:ye_2)); // Right line
2212
//if(het & MusECore::Part::LeftEventsHidden)
2213
// p.setPen(((NPart*)item)->leftBorderTouches ? penHidden1 : penHidden2);
2216
if(((NPart*)item)->leftBorderTouches)
2217
p.setPen(part->selected() ? penSelect1V : penNormal1V);
2219
p.setPen(part->selected() ? penSelect2V : penNormal2V);
2231
if(((NPart*)item)->leftBorderTouches)
2232
p.setPen(part->selected() ? penSelect1V : penNormal1V);
2234
p.setPen(part->selected() ? penSelect2V : penNormal2V);
2222
2236
if(xs_0 >= mrxs_0 && xs_0 <= mrxe_0)
2224
2238
QLine l4(xs_0, ys_0, xs_0, ye_0); // Left
2225
2239
p.drawLine(l4); // Left line
2233
for(int yy = (lbt?ys_1:ys_2); yy < ye_2; yy += yinc)
2238
p.drawLine(QPoint(xx, yy), QPoint(xx, yy + yi)); // Left dashed line
2242
p.drawLine(QPoint(xx, lbt?ys_1:ys_2), QPoint(xx, lbt?ye_1:ye_2)); // Left line
2245
p.setPen(part->selected() ? penSelect2H : penNormal2H);
2242
p.setPen(part->selected() ? penSelect2H : penNormal2H);
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
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.
2296
p.drawRect(item->mp().x(), item->mp().y(), item->width(), item->height());
2292
MusECore::TrackList* tl = MusEGlobal::song->tracks();
2294
int y = item->mp().y();
2295
int ih = item->height();
2296
for(MusECore::ciTrack it = tl->begin(); it != tl->end(); ++it)
2298
int h = (*it)->height();
2306
p.drawRect(item->mp().x(), item->mp().y(), item->width(), ih);
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)
2308
2317
int color_brightness;
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
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
2330
eventColor=MusEGlobal::config.partMidiLightEventColor;
2322
2331
color_brightness=200; //160; // too dark: use lighter color
2335
eventColor=QColor(80,80,80);
2325
2336
color_brightness=80;
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.
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);
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);
3994
4006
// 2 move only vertical
3995
4007
//---------------------------------------------------------
3997
void PartCanvas::endMoveItems(const QPoint& pos, DragType dragtype, int dir)
4009
void PartCanvas::endMoveItems(const QPoint& pos, DragType dragtype, int dir, bool rasterize)
3999
4011
int dp = y2pitch(pos.y()) - y2pitch(start.y());
4000
4012
int dx = pos.x() - start.x();