2339
2380
QCString subtype = 0;
2340
2381
QString txt = cb->text(subtype);
2383
int startPos=song->vcpos();
2343
Pos p(pasteAt(txt, track, song->vcpos(), clone, toTrack), true);
2387
endPos=pasteAt(txt, track, startPos, clone, toTrack);
2388
Pos p(endPos, true);
2344
2389
song->setPos(0, p);
2391
song->endUndo(SC_PART_INSERTED);
2396
int offset = endPos-startPos;
2397
movePartsTotheRight(startPos, offset);
2398
song->endUndo(SC_PART_INSERTED);
2348
2402
//---------------------------------------------------------
2403
// movePartsToTheRight
2404
//---------------------------------------------------------
2405
void PartCanvas::movePartsTotheRight(int startTicks, int length)
2407
// all parts that start after the pasted parts will be moved the entire length of the pasted parts
2408
for (iCItem i = items.begin(); i != items.end(); ++i) {
2409
if (!i->second->isSelected()) {
2410
Part* part = i->second->part();
2411
if (part->tick() >= startTicks) {
2412
//void Audio::msgChangePart(Part* oldPart, Part* newPart, bool doUndoFlag, bool doCtrls, bool doClones)
2413
Part *newPart = part->clone();
2414
newPart->setTick(newPart->tick()+length);
2415
if (part->track()->type() == Track::WAVE) {
2416
audio->msgChangePart((WavePart*)part,(WavePart*)newPart,false,false,false);
2418
audio->msgChangePart(part,newPart,false,false,false);
2424
// perhaps ask if markers should be moved?
2425
MarkerList *markerlist = song->marker();
2426
for(iMarker i = markerlist->begin(); i != markerlist->end(); ++i)
2428
Marker* m = &i->second;
2429
if (m->tick() >= startTicks) {
2430
Marker *oldMarker = new Marker();
2432
m->setTick(m->tick()+length);
2433
song->undoOp(UndoOp::ModifyMarker,oldMarker, m);
2437
//---------------------------------------------------------
2350
2439
//---------------------------------------------------------
2543
p.setPen(lightGray);
2634
QColor baseColor(config.partCanvasBg.light(104));
2635
p.setPen(baseColor);
2637
//--------------------------------
2639
//-------------------------------
2640
//printf("raster=%d\n", *_raster);
2641
if (config.canvasShowGrid) {
2645
sigmap.tickValues(x, &bar, &beat, &tick);
2647
int xt = sigmap.bar2tick(bar++, 0, 0);
2651
p.setPen(baseColor.dark(115));
2653
p.setPen(baseColor);
2654
p.drawLine(xt, y, xt, y+h);
2658
if (*_raster == config.division *2) // 1/2
2660
else if (*_raster== config.division) // 1/4
2662
else if (*_raster==config.division/2) // 1/8
2664
else if (*_raster==config.division/4) // 1/16
2666
else if (*_raster==config.division/8) // 1/16
2668
else if (*_raster==config.division/16) // 1/16
2677
noDivisors=noDivisors/2;
2679
p.setPen(baseColor);
2680
for (int t=1;t< noDivisors;t++)
2681
p.drawLine(xt+r*t, y, xt+r*t, y+h);
2545
2685
//--------------------------------
2546
2686
// horizontal lines
2547
2687
//--------------------------------
2552
2692
if (yy > y + h)
2554
2694
Track* track = *it;
2555
if (config.canvasShowGrid || !track->isMidiTrack())
2695
if (/*config.canvasShowGrid ||*/ !track->isMidiTrack()) {
2696
p.setPen(baseColor.dark(130));
2556
2697
p.drawLine(x, yy, x + w, yy);
2698
p.setPen(baseColor);
2557
2700
if (!track->isMidiTrack() && (track->type() != Track::WAVE)) {
2558
2701
QRect r = rect & QRect(x, yy, w, track->height());
2559
2702
drawAudioTrack(p, r, (AudioTrack*)track);
2703
p.setPen(baseColor);
2705
if (!track->isMidiTrack()) { // draw automation
2706
QRect r = rect & QRect(x, yy, w, track->height());
2707
drawAutomation(p, r, (AudioTrack*)track);
2708
p.setPen(baseColor);
2561
2711
yy += track->height();
2564
if (!config.canvasShowGrid)
2567
//--------------------------------
2569
//--------------------------------
2575
sigmap.tickValues(x, &bar, &beat, &tick);
2577
int xt = sigmap.bar2tick(bar++, 0, 0);
2580
p.drawLine(xt, y, xt, y+h);
2583
case 1: // no raster
2597
for (int xt = x; xt < (x + w); xt += r)
2598
p.drawLine(xt, y, xt+1, y+h);
2604
2715
//---------------------------------------------------------
2605
2716
// drawAudioTrack
2606
2717
//---------------------------------------------------------
2608
void PartCanvas::drawAudioTrack(QPainter& p, const QRect& r, AudioTrack*)
2719
void PartCanvas::drawAudioTrack(QPainter& p, const QRect& r, AudioTrack *t)
2610
2721
p.setPen(QPen(black, 2, SolidLine));
2611
2722
p.setBrush(gray);
2726
//---------------------------------------------------------
2728
//---------------------------------------------------------
2730
void PartCanvas::drawAutomation(QPainter& p, const QRect& r, AudioTrack *t)
2732
// printf("drawAudioTrack %d x %d y %d w %d h %d\n",t, r.x(), r.y(), r.width(), r.height());
2733
//int v2=r.x()+r.width();
2734
//printf("v2=%d mapx=%d rmapx=%d mapxdev=%d rmapxdev=%d\n",v2, mapx(v2),rmapx(v2),mapxDev(v2),rmapxDev(v2));
2737
p.setPen(QPen(black, 2, SolidLine));
2738
int height=r.bottom()-r.top()-4; // limit height
2740
CtrlListList* cll = t->controller();
2749
for(CtrlListList::iterator icll =cll->begin();icll!=cll->end();++icll)
2751
//iCtrlList *icl = icll->second;
2752
CtrlList *cl = icll->second;
2754
iCtrl ic=cl->begin();
2755
p.setPen(QPen(cols[colIndex++],1,SolidLine));
2757
if (ic!=cl->end()) { // if there are no automation values we don't draw at all
2758
CtrlVal cvFirst = ic->second;
2760
int prevPos=cvFirst.frame;
2761
prevVal = cvFirst.val;
2762
if (cl->id() == AC_VOLUME ) { // use db scale for volume
2763
prevVal = (20.0*log10(cvFirst.val)+60) / 70.0; // represent volume between 0 and 1
2764
if (prevVal < 0) prevVal = 0.0;
2767
// we need to set curVal between 0 and 1
2769
cl->range(&min,&max);
2770
prevVal = (prevVal- min)/(max-min);
2772
for (; ic !=cl->end(); ++ic)
2774
CtrlVal cv = ic->second;
2775
double nextVal = cv.val; // was curVal
2776
if (cl->id() == AC_VOLUME ) { // use db scale for volume
2777
nextVal = (20.0*log10(cv.val)+60) / 70.0; // represent volume between 0 and 1
2778
if (nextVal < 0) nextVal = 0.0;
2781
// we need to set curVal between 0 and 1
2783
cl->range(&min,&max);
2784
nextVal = (nextVal- min)/(max-min);
2786
//printf("volume automation event %d %f %f %d\n",cv.frame,cv.val, tempomap.frame2tick(cv.frame));
2787
//p.drawLine(r.x(),(r.bottom()-2)-lastVal*height,r.x()+r.width(),(r.bottom()-2)-curVal*height); // debuggingtest
2788
int leftX=tempomap.frame2tick(prevPos);
2789
if (firstRun && leftX>r.x()) {
2790
printf("first run\n");
2794
printf("inner draw\n");
2795
p.drawLine(leftX,(r.bottom()-2)-prevVal*height,tempomap.frame2tick(cv.frame),(r.bottom()-2)-prevVal*height);
2797
//printf("draw line: %d %f %d %f\n",tempomap.frame2tick(lastPos),r.bottom()-lastVal*height,tempomap.frame2tick(cv.frame),r.bottom()-curVal*height);
2801
printf("outer draw %f\n", cvFirst.val);
2802
p.drawLine(tempomap.frame2tick(prevPos),(r.bottom()-2)-prevVal*height,tempomap.frame2tick(prevPos)+r.width(),(r.bottom()-2)-prevVal*height);
2803
//printf("draw last line: %d %f %d %f\n",tempomap.frame2tick(lastPos),r.bottom()-lastVal*height,150000,r.bottom()-lastVal*height);
2805
// if (height >100) {
2806
// p.drawText(tempomap.frame2tick(0)+1000,40,"FOOO");
2807
// printf("drawText %s\n", cl->name().latin1());
2813
void PartCanvas::controllerChanged(Track *t)