diff options
Diffstat (limited to 'muse2/muse/arranger/pcanvas.cpp')
-rw-r--r-- | muse2/muse/arranger/pcanvas.cpp | 169 |
1 files changed, 109 insertions, 60 deletions
diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index ef45c9df..094cf68a 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -25,6 +25,9 @@ #include "fastlog.h" #include "widgets/tools.h" +#include "arranger.h" +#include "arrangerview.h" +#include "structure.h" #include "pcanvas.h" #include "midieditor.h" #include "globals.h" @@ -157,15 +160,19 @@ void PartCanvas::leaveEvent(QEvent*) void PartCanvas::returnPressed() { lineEditor->hide(); - Part* oldPart = editPart->part(); - Part* newPart = oldPart->clone(); - //printf("PartCanvas::returnPressed before msgChangePart oldPart refs:%d Arefs:%d newPart refs:%d Arefs:%d\n", oldPart->events()->refCount(), oldPart->events()->arefCount(), newPart->events()->refCount(), newPart->events()->arefCount()); - - newPart->setName(lineEditor->text()); - // Indicate do undo, and do port controller values but not clone parts. - audio->msgChangePart(oldPart, newPart, true, true, false); - - editMode = false; + if (editMode) { + //this check is neccessary, because it returnPressed may be called + //twice. the second call would cause a crash, however! + Part* oldPart = editPart->part(); + Part* newPart = oldPart->clone(); + //printf("PartCanvas::returnPressed before msgChangePart oldPart refs:%d Arefs:%d newPart refs:%d Arefs:%d\n", oldPart->events()->refCount(), oldPart->events()->arefCount(), newPart->events()->refCount(), newPart->events()->arefCount()); + + newPart->setName(lineEditor->text()); + // Indicate do undo, and do port controller values but not clone parts. + audio->msgChangePart(oldPart, newPart, true, true, false); + + editMode = false; + } } //--------------------------------------------------------- @@ -188,6 +195,7 @@ void PartCanvas::viewMouseDoubleClickEvent(QMouseEvent* event) if (lineEditor == 0) { lineEditor = new QLineEdit(this); lineEditor->setFrame(true); + connect(lineEditor, SIGNAL(editingFinished()),SLOT(returnPressed())); } editMode = true; lineEditor->setGeometry(r); @@ -633,17 +641,17 @@ QMenu* PartCanvas::genItemPopup(CItem* item) partPopup->addSeparator(); switch(trackType) { case Track::MIDI: { - partPopup->addAction(muse->startPianoEditAction); - partPopup->addMenu(muse->scoreSubmenu); - partPopup->addAction(muse->startScoreEditAction); - partPopup->addAction(muse->startListEditAction); + partPopup->addAction(muse->arranger->parentWin->startPianoEditAction); + partPopup->addMenu(muse->arranger->parentWin->scoreSubmenu); + partPopup->addAction(muse->arranger->parentWin->startScoreEditAction); + partPopup->addAction(muse->arranger->parentWin->startListEditAction); QAction *act_mexport = partPopup->addAction(tr("save part to disk")); act_mexport->setData(16); } break; case Track::DRUM: { - partPopup->addAction(muse->startDrumEditAction); - partPopup->addAction(muse->startListEditAction); + partPopup->addAction(muse->arranger->parentWin->startDrumEditAction); + partPopup->addAction(muse->arranger->parentWin->startListEditAction); QAction *act_dexport = partPopup->addAction(tr("save part to disk")); act_dexport->setData(16); } @@ -690,6 +698,7 @@ void PartCanvas::itemPopup(CItem* item, int n, const QPoint& pt) if (lineEditor == 0) { lineEditor = new QLineEdit(this); lineEditor->setFrame(true); + connect(lineEditor, SIGNAL(editingFinished()),SLOT(returnPressed())); } lineEditor->setText(editPart->name()); lineEditor->setFocus(); @@ -831,25 +840,29 @@ void PartCanvas::mousePress(QMouseEvent* event) } QPoint pt = event->pos(); CItem* item = items.find(pt); - if (item == 0 && _tool!=AutomationTool) - return; + switch (_tool) { default: - emit trackChanged(item->part()->track()); + if (item) + emit trackChanged(item->part()->track()); + else + emit trackChanged(NULL); break; case CutTool: - splitItem(item, pt); + if (item) splitItem(item, pt); break; case GlueTool: - glueItem(item); + if (item) glueItem(item); break; case MuteTool: { - NPart* np = (NPart*) item; - Part* p = np->part(); - p->setMute(!p->mute()); - redraw(); - break; + if (item) { + NPart* np = (NPart*) item; + Part* p = np->part(); + p->setMute(!p->mute()); + redraw(); + break; + } } case AutomationTool: if (automation.controllerState != doNothing) @@ -928,7 +941,7 @@ void PartCanvas::keyPress(QKeyEvent* event) { if ( key == Qt::Key_Return || key == Qt::Key_Enter ) { - returnPressed(); + //returnPressed(); commented out by flo return; } else if ( key == Qt::Key_Escape ) @@ -2573,6 +2586,9 @@ void PartCanvas::cmd(int cmd) case CMD_COPY_PART: copy(&pl); break; + case CMD_COPY_PART_IN_RANGE: + copy_in_range(&pl); + break; case CMD_PASTE_PART: paste(false, false); break; @@ -2602,6 +2618,70 @@ void PartCanvas::cmd(int cmd) // cut copy paste //--------------------------------------------------------- +void PartCanvas::copy_in_range(PartList* pl_) +{ + PartList pl; + PartList result_pl; + unsigned int lpos = song->lpos(); + unsigned int rpos = song->rpos(); + + if (pl_->empty()) + { + for (iCItem i = items.begin(); i != items.end(); ++i) + { + Part* part=static_cast<NPart*>(i->second)->part(); + if ( (part->track()->isMidiTrack()) || (part->track()->type() == Track::WAVE) ) + pl.add(part); + } + } + else + { + for(ciPart p = pl_->begin(); p != pl_->end(); ++p) + if ( (p->second->track()->isMidiTrack()) || (p->second->track()->type() == Track::WAVE) ) + pl.add(p->second); + } + + if (!pl.empty() && (rpos>lpos)) + { + for(ciPart p = pl.begin(); p != pl.end(); ++p) + { + Part* part=p->second; + Track* track=part->track(); + + if ((part->tick() < rpos) && (part->endTick() > lpos)) //is the part in the range? + { + if ((lpos > part->tick()) && (lpos < part->endTick())) + { + Part* p1; + Part* p2; + + track->splitPart(part, lpos, p1, p2); + p1->events()->incARef(-1); + p2->events()->incARef(-1); + + part=p2; + } + + if ((rpos > part->tick()) && (rpos < part->endTick())) + { + Part* p1; + Part* p2; + + track->splitPart(part, rpos, p1, p2); + p1->events()->incARef(-1); + p2->events()->incARef(-1); + + part=p1; + } + + result_pl.add(part); + } + } + + copy(&result_pl); + } +} + void PartCanvas::copy(PartList* pl) { if (pl->empty()) @@ -2739,6 +2819,7 @@ Undo PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool if (p->tick()+p->lenTick()>finalPos) { finalPos=p->tick()+p->lenTick(); } + p->setSelected(true); operations.push_back(UndoOp(UndoOp::AddPart,p)); } else @@ -2859,6 +2940,7 @@ void PartCanvas::paste(bool clone, bool toTrack, bool doInsert) { int endPos=0; unsigned int startPos=song->vcpos(); + deselectAll(); Undo operations=pasteAt(txt, track, startPos, clone, toTrack, &endPos); Pos p(endPos, true); song->setPos(0, p); @@ -2873,40 +2955,6 @@ void PartCanvas::paste(bool clone, bool toTrack, bool doInsert) } //--------------------------------------------------------- -// movePartsToTheRight -//--------------------------------------------------------- -Undo PartCanvas::movePartsTotheRight(unsigned int startTicks, int length) -{ - Undo operations; - - // all parts that start after the pasted parts will be moved the entire length of the pasted parts - for (iCItem i = items.begin(); i != items.end(); ++i) { - if (!i->second->isSelected()) { - Part* part = i->second->part(); - if (part->tick() >= startTicks) { - Part *newPart = part->clone(); - newPart->setTick(newPart->tick()+length); - - operations.push_back(UndoOp(UndoOp::ModifyPart,part,newPart,false,false)); - } - } - } - // perhaps ask if markers should be moved? - MarkerList *markerlist = song->marker(); - for(iMarker i = markerlist->begin(); i != markerlist->end(); ++i) - { - Marker* m = &i->second; - if (m->tick() >= startTicks) { - Marker *oldMarker = new Marker(); - *oldMarker = *m; - m->setTick(m->tick()+length); - operations.push_back(UndoOp(UndoOp::ModifyMarker,oldMarker, m)); - } - } - - return operations; -} -//--------------------------------------------------------- // startDrag //--------------------------------------------------------- @@ -3029,6 +3077,7 @@ void PartCanvas::viewDropEvent(QDropEvent* event) track = tracks->index(trackNo); if (track) { + deselectAll(); Undo temp=pasteAt(text, track, x); song->applyOperationGroup(temp); } |