diff options
-rw-r--r-- | muse2/muse/miditransform.cpp | 97 | ||||
-rw-r--r-- | muse2/muse/miditransform.h | 5 | ||||
-rw-r--r-- | muse2/muse/song.cpp | 2 |
3 files changed, 27 insertions, 77 deletions
diff --git a/muse2/muse/miditransform.cpp b/muse2/muse/miditransform.cpp index 75e6f4f7..3f0f9235 100644 --- a/muse2/muse/miditransform.cpp +++ b/muse2/muse/miditransform.cpp @@ -41,6 +41,9 @@ #include "gconfig.h" #include "midictrl.h" +using MusECore::Undo; +using MusECore::UndoOp; + namespace MusECore { // @@ -483,8 +486,7 @@ void MidiTransformerDialog::accept() // subfunction of processEvent() //--------------------------------------------------------- -void MidiTransformerDialog::transformEvent(MusECore::Event& event, MusECore::MidiPart* part, - MusECore::MidiPart* newPart) +void MidiTransformerDialog::transformEvent(MusECore::Event& event, MusECore::MidiPart* part, MusECore::MidiPart* newPart, MusECore::Undo& operations) { MusECore::MidiTransformation* cmt = data->cmt; MusECore::Event newEvent = event.clone(); @@ -670,33 +672,16 @@ void MidiTransformerDialog::transformEvent(MusECore::Event& event, MusECore::Mid pos = 0; newEvent.setTick(pos); - MusECore::Event dummy; switch(data->cmt->funcOp) { case MusECore::Transform: - // Indicate do clone parts. - removePortCtrlEvents(event, part, true); - MusEGlobal::song->changeEvent(event, newEvent, part); - // Indicate do clone parts. - addPortCtrlEvents(newEvent, part, true); - // Indicate do port controller values and clone parts. - MusEGlobal::song->addUndo(MusECore::UndoOp(MusECore::UndoOp::ModifyEvent, newEvent, event, part, true, true)); - MusEGlobal::song->addUpdateFlags(SC_EVENT_MODIFIED); + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, true, true)); break; case MusECore::Insert: // Indicate do port controller values and clone parts. - MusEGlobal::song->addUndo(MusECore::UndoOp(MusECore::UndoOp::AddEvent, dummy, newEvent, part, true, true)); - MusEGlobal::song->addEvent(newEvent, part); - // Indicate do clone parts. - addPortCtrlEvents(newEvent, part, true); - MusEGlobal::song->addUpdateFlags(SC_EVENT_INSERTED); + operations.push_back(UndoOp(UndoOp::AddEvent, newEvent, part, true, true)); break; case MusECore::Extract: - // Indicate do port controller values and clone parts. - MusEGlobal::song->addUndo(MusECore::UndoOp(MusECore::UndoOp::DeleteEvent, dummy, event, part, true, true)); - // Indicate do clone parts. - removePortCtrlEvents(event, part, true); - MusEGlobal::song->deleteEvent(event, part); - MusEGlobal::song->addUpdateFlags(SC_EVENT_REMOVED); + operations.push_back(UndoOp(UndoOp::DeleteEvent, event, part, true, true)); case MusECore::Copy: newPart->addEvent(newEvent); break; @@ -709,7 +694,7 @@ void MidiTransformerDialog::transformEvent(MusECore::Event& event, MusECore::Mid // processEvent //--------------------------------------------------------- -void MidiTransformerDialog::processEvent(MusECore::Event& event, MusECore::MidiPart* part, MusECore::MidiPart* newPart) +void MidiTransformerDialog::processEvent(MusECore::Event& event, MusECore::MidiPart* part, MusECore::MidiPart* newPart, MusECore::Undo& operations) { switch(data->cmt->funcOp) { case MusECore::Select: @@ -719,35 +704,22 @@ void MidiTransformerDialog::processEvent(MusECore::Event& event, MusECore::MidiP int tick = event.tick(); int rt = AL::sigmap.raster(tick, data->cmt->quantVal) - tick; if (tick != rt) { - // Indicate do clone parts. - removePortCtrlEvents(event, part, true); MusECore::Event newEvent = event.clone(); newEvent.setTick(rt); - MusEGlobal::song->changeEvent(event, newEvent, part); - // Indicate do clone parts. - addPortCtrlEvents(newEvent, part, true); - // Indicate do port controller values and clone parts. - MusEGlobal::song->addUndo(MusECore::UndoOp(MusECore::UndoOp::ModifyEvent, newEvent, event, part, true, true)); - MusEGlobal::song->addUpdateFlags(SC_EVENT_MODIFIED); + operations.push_back(UndoOp(UndoOp::ModifyEvent,newEvent,event,part,true,true)); } } break; case MusECore::Delete: { - MusECore::Event ev; - // Indicate do port controller values and clone parts. - MusEGlobal::song->addUndo(MusECore::UndoOp(MusECore::UndoOp::DeleteEvent, ev, event, part, true, true)); - // Indicate do clone parts. - removePortCtrlEvents(event, part, true); - MusEGlobal::song->deleteEvent(event, part); - MusEGlobal::song->addUpdateFlags(SC_EVENT_REMOVED); + operations.push_back(UndoOp(UndoOp::DeleteEvent, event, part, true, true)); } break; case MusECore::Transform: case MusECore::Insert: case MusECore::Copy: case MusECore::Extract: - transformEvent(event, part, newPart); + transformEvent(event, part, newPart, operations); break; } } @@ -921,8 +893,8 @@ bool MidiTransformerDialog::isSelected(const MusECore::Event& event) void MidiTransformerDialog::apply() { MusECore::SongChangedFlags_t flags = 0; - MusEGlobal::song->startUndo(); - MusEGlobal::audio->msgIdle(true); + + Undo operations; bool copyExtract = (data->cmt->funcOp == MusECore::Copy) || (data->cmt->funcOp == MusECore::Extract); @@ -944,7 +916,7 @@ void MidiTransformerDialog::apply() const MusECore::EventList& el = part->events(); // Check if the event list has already been done. Skip repeated clones. if (doneList.contains(part->clonemaster_sn())) - break; + continue; doneList.insert(part->clonemaster_sn()); for (MusECore::ciEvent i = el.begin(); i != el.end(); ++i) { @@ -969,7 +941,7 @@ void MidiTransformerDialog::apply() const MusECore::EventList& el = part->events(); // Check if the event list has already been done. Skip repeated clones. if (doneList.contains(part->clonemaster_sn())) - break; + continue; doneList.insert(part->clonemaster_sn()); if (copyExtract) { @@ -985,7 +957,7 @@ void MidiTransformerDialog::apply() newPart->setColorIndex(part->colorIndex()); newPart->setTick(part->tick()); newPart->setLenTick(part->lenTick()); - MusEGlobal::song->addPart(newPart); + operations.push_back(UndoOp(UndoOp::AddPart,newPart)); flags |= SC_PART_INSERTED; break; } @@ -999,46 +971,23 @@ void MidiTransformerDialog::apply() continue; int flag = isSelected(event); if (data->cmt->funcOp == MusECore::Select) - event.setSelected(flag); + operations.push_back(UndoOp(UndoOp::SelectEvent, event,flag, event.selected())); else if (flag) - pel.add(event); + pel.add(const_cast<MusECore::Event&>(event)); // ough, FIXME, what an ugly hack. } for (MusECore::iEvent i = pel.begin(); i != pel.end(); ++i) { MusECore::Event event = i->second; - processEvent(event, part, newPart); + processEvent(event, part, newPart, operations); } } } if (!tl.empty()) { flags |= SC_TRACK_INSERTED; - for (MusECore::iTrack t = tl.begin(); t != tl.end(); ++t) { - MusEGlobal::song->insertTrack0(*t, -1); - } - } + for (MusECore::iTrack t = tl.begin(); t != tl.end(); ++t) + operations.push_back(UndoOp(UndoOp::AddTrack, -1, *t)); + } - switch(data->cmt->funcOp) { - case MusECore::Select: - flags |= SC_SELECTION; - break; - case MusECore::Quantize: - flags |= SC_EVENT_MODIFIED; - break; - case MusECore::Delete: - flags |= SC_EVENT_REMOVED; - break; - case MusECore::Transform: - flags |= SC_EVENT_MODIFIED; - break; - case MusECore::Insert: - flags |= SC_EVENT_INSERTED; - break; - case MusECore::Copy: - flags |= SC_EVENT_INSERTED; - case MusECore::Extract: - break; - } - MusEGlobal::audio->msgIdle(false); - MusEGlobal::song->endUndo(flags); + MusEGlobal::song->applyOperationGroup(operations); } //--------------------------------------------------------- diff --git a/muse2/muse/miditransform.h b/muse2/muse/miditransform.h index 997c144d..626c83c5 100644 --- a/muse2/muse/miditransform.h +++ b/muse2/muse/miditransform.h @@ -32,6 +32,7 @@ class QDialog; namespace MusECore { +class Undo; class Event; class MidiPart; class MidiTransformation; @@ -70,9 +71,9 @@ class MidiTransformerDialog : public QDialog, public Ui::MidiTransformDialogBase virtual void accept(); void setValOp(QWidget* a, QWidget* b, MusECore::ValOp op); - void processEvent(MusECore::Event&, MusECore::MidiPart*, MusECore::MidiPart*); + void processEvent(MusECore::Event&, MusECore::MidiPart*, MusECore::MidiPart*, MusECore::Undo& operations); bool isSelected(const MusECore::Event&); - void transformEvent(MusECore::Event&, MusECore::MidiPart*, MusECore::MidiPart*); + void transformEvent(MusECore::Event&, MusECore::MidiPart*, MusECore::MidiPart*, MusECore::Undo& operations); bool typesMatch(const MusECore::Event& e, unsigned selType); void updatePresetList(); diff --git a/muse2/muse/song.cpp b/muse2/muse/song.cpp index 4e70adf5..be913b78 100644 --- a/muse2/muse/song.cpp +++ b/muse2/muse/song.cpp @@ -2979,7 +2979,7 @@ void Song::connectJackRoutes(AudioTrack* track, bool disconnect) void Song::insertTrack0(Track* track, int idx) { insertTrack1(track, idx); - insertTrack2(track, idx); // MusEGlobal::audio->msgInsertTrack(track, idx, false); DELETETHIS or is this somehow explanatory? + insertTrack2(track, idx); // the same as MusEGlobal::audio->msgInsertTrack(track, idx, false); insertTrack3(track, idx); } |