From 1701c520500b9198c1aaca29e7bdcd891cb0e971 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 22 May 2011 13:24:13 +0000 Subject: changed Song::undoOp(foo) to Song::addUndo(UndoOp(foo)). changed all these undoOps into a UndoOp-constructor. should not have affected muse's behaviour. should not introduce bugs or fix stuff. --- muse2/muse/arranger/pcanvas.cpp | 2 +- muse2/muse/functions.cpp | 1 + muse2/muse/midiedit/dcanvas.cpp | 4 +- muse2/muse/midiedit/prcanvas.cpp | 4 +- muse2/muse/miditransform.cpp | 20 ++--- muse2/muse/seqmsg.cpp | 2 +- muse2/muse/song.cpp | 68 ++++++++-------- muse2/muse/song.h | 20 ++--- muse2/muse/structure.cpp | 4 +- muse2/muse/undo.cpp | 163 +++++++++++++++++---------------------- muse2/muse/undo.h | 13 ++++ 11 files changed, 143 insertions(+), 158 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index daaf2d28..ed52cc03 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -2775,7 +2775,7 @@ void PartCanvas::movePartsTotheRight(unsigned int startTicks, int length) Marker *oldMarker = new Marker(); *oldMarker = *m; m->setTick(m->tick()+length); - song->undoOp(UndoOp::ModifyMarker,oldMarker, m); + song->addUndo(UndoOp(UndoOp::ModifyMarker,oldMarker, m)); } } } diff --git a/muse2/muse/functions.cpp b/muse2/muse/functions.cpp index 3c6bbc89..5498c6d1 100644 --- a/muse2/muse/functions.cpp +++ b/muse2/muse/functions.cpp @@ -357,6 +357,7 @@ void quantize_notes(const set& parts, int range, int raster, int strength newEvent.setTick(begin_tick - part->tick()); newEvent.setLenTick(len); // Indicate no undo, and do not do port controller values and clone parts. + //audio->msgChangeEvent(event, newEvent, part, false, false, false); audio->msgChangeEvent(event, newEvent, part, false, false, false); } } diff --git a/muse2/muse/midiedit/dcanvas.cpp b/muse2/muse/midiedit/dcanvas.cpp index eea29b46..fa7da753 100644 --- a/muse2/muse/midiedit/dcanvas.cpp +++ b/muse2/muse/midiedit/dcanvas.cpp @@ -1292,8 +1292,8 @@ void DrumCanvas::modifySelected(NoteInfo::ValType type, int delta) } song->changeEvent(event, newEvent, part); // Indicate do not do port controller values and clone parts. - //song->undoOp(UndoOp::ModifyEvent, newEvent, event, part); - song->undoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false); + //song->addUndo(UndoOp(UndoOp::ModifyEvent, newEvent, event, part)); + song->addUndo(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false)); } song->endUndo(SC_EVENT_MODIFIED); audio->msgIdle(false); diff --git a/muse2/muse/midiedit/prcanvas.cpp b/muse2/muse/midiedit/prcanvas.cpp index 84cac135..e59e8beb 100644 --- a/muse2/muse/midiedit/prcanvas.cpp +++ b/muse2/muse/midiedit/prcanvas.cpp @@ -1536,8 +1536,8 @@ void PianoCanvas::modifySelected(NoteInfo::ValType type, int delta) } song->changeEvent(event, newEvent, part); // Indicate do not do port controller values and clone parts. - //song->undoOp(UndoOp::ModifyEvent, newEvent, event, part); - song->undoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false); + //song->addUndo(UndoOp(UndoOp::ModifyEvent, newEvent, event, part)); + song->addUndo(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false)); } song->endUndo(SC_EVENT_MODIFIED); audio->msgIdle(false); diff --git a/muse2/muse/miditransform.cpp b/muse2/muse/miditransform.cpp index 1c73b7c2..9e9c87c0 100644 --- a/muse2/muse/miditransform.cpp +++ b/muse2/muse/miditransform.cpp @@ -662,14 +662,14 @@ void MidiTransformerDialog::transformEvent(Event& event, MidiPart* part, // Indicate do clone parts. addPortCtrlEvents(newEvent, part, true); // Indicate do port controller values and clone parts. - //song->undoOp(UndoOp::ModifyEvent, newEvent, event, part); - song->undoOp(UndoOp::ModifyEvent, newEvent, event, part, true, true); + //song->addUndo(UndoOp(UndoOp::ModifyEvent, newEvent, event, part)); + song->addUndo(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, true, true)); song->addUpdateFlags(SC_EVENT_MODIFIED); break; case Insert: // Indicate do port controller values and clone parts. - //song->undoOp(UndoOp::AddEvent, dummy, newEvent, part); - song->undoOp(UndoOp::AddEvent, dummy, newEvent, part, true, true); + //song->addUndo(UndoOp(UndoOp::AddEvent, dummy, newEvent, part)); + song->addUndo(UndoOp(UndoOp::AddEvent, dummy, newEvent, part, true, true)); song->addEvent(newEvent, part); // Indicate do clone parts. addPortCtrlEvents(newEvent, part, true); @@ -677,8 +677,8 @@ void MidiTransformerDialog::transformEvent(Event& event, MidiPart* part, break; case Extract: // Indicate do port controller values and clone parts. - //song->undoOp(UndoOp::DeleteEvent, dummy, event, part); - song->undoOp(UndoOp::DeleteEvent, dummy, event, part, true, true); + //song->addUndo(UndoOp(UndoOp::DeleteEvent, dummy, event, part)); + song->addUndo(UndoOp(UndoOp::DeleteEvent, dummy, event, part, true, true)); // Indicate do clone parts. removePortCtrlEvents(event, part, true); song->deleteEvent(event, part); @@ -713,8 +713,8 @@ void MidiTransformerDialog::processEvent(Event& event, MidiPart* part, MidiPart* // Indicate do clone parts. addPortCtrlEvents(newEvent, part, true); // Indicate do port controller values and clone parts. - //song->undoOp(UndoOp::ModifyEvent, newEvent, event, part); - song->undoOp(UndoOp::ModifyEvent, newEvent, event, part, true, true); + //song->addUndo(UndoOp(UndoOp::ModifyEvent, newEvent, event, part)); + song->addUndo(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, true, true)); song->addUpdateFlags(SC_EVENT_MODIFIED); } } @@ -723,8 +723,8 @@ void MidiTransformerDialog::processEvent(Event& event, MidiPart* part, MidiPart* { Event ev; // Indicate do port controller values and clone parts. - //song->undoOp(UndoOp::DeleteEvent, ev, event, part, true, true); - song->undoOp(UndoOp::DeleteEvent, ev, event, part, true, true); + //song->addUndo(UndoOp(UndoOp::DeleteEvent, ev, event, part, true, true)); + song->addUndo(UndoOp(UndoOp::DeleteEvent, ev, event, part, true, true)); // Indicate do clone parts. removePortCtrlEvents(event, part, true); song->deleteEvent(event, part); diff --git a/muse2/muse/seqmsg.cpp b/muse2/muse/seqmsg.cpp index 950015b2..3fb91293 100644 --- a/muse2/muse/seqmsg.cpp +++ b/muse2/muse/seqmsg.cpp @@ -751,7 +751,7 @@ void Song::msgInsertTrack(Track* track, int idx, bool doUndoFlag) msg.ival = idx; if (doUndoFlag) { song->startUndo(); - undoOp(UndoOp::AddTrack, idx, track); + addUndo(UndoOp(UndoOp::AddTrack, idx, track)); } audio->sendMsg(&msg); if (doUndoFlag) diff --git a/muse2/muse/song.cpp b/muse2/muse/song.cpp index 1c451f55..f781b8f0 100644 --- a/muse2/muse/song.cpp +++ b/muse2/muse/song.cpp @@ -350,7 +350,7 @@ Track* Song::addTrack(int t) void Song::cmdRemoveTrack(Track* track) { int idx = _tracks.index(track); - undoOp(UndoOp::DeleteTrack, idx, track); + addUndo(UndoOp(UndoOp::DeleteTrack, idx, track)); removeTrack2(track); updateFlags |= SC_TRACK_REMOVED; } @@ -395,8 +395,8 @@ void Song::changeTrack(Track* oldTrack, Track* newTrack) oldTrack->setSelected(false); //?? int idx = _tracks.index(newTrack); - //undoOp(UndoOp::ModifyTrack, oldTrack, newTrack); - undoOp(UndoOp::ModifyTrack, idx, oldTrack, newTrack); + //addUndo(UndoOp(UndoOp::ModifyTrack, oldTrack, newTrack)); + addUndo(UndoOp(UndoOp::ModifyTrack, idx, oldTrack, newTrack)); updateFlags |= SC_TRACK_MODIFIED; } @@ -863,7 +863,7 @@ void Song::cmdAddRecordedEvents(MidiTrack* mt, EventList* events, unsigned start // Now add all of the new part's port controller values. Indicate do not do clone parts. addPortCtrlEvents(newPart, false); // Create an undo op. Indicate do port controller values but not clone parts. - undoOp(UndoOp::ModifyPart, part, newPart, true, false); + addUndo(UndoOp(UndoOp::ModifyPart, part, newPart, true, false)); updateFlags |= SC_PART_MODIFIED; if (_recMode == REC_REPLACE) @@ -874,7 +874,7 @@ void Song::cmdAddRecordedEvents(MidiTrack* mt, EventList* events, unsigned start { Event event = i->second; // Create an undo op. Indicate do port controller values and clone parts. - undoOp(UndoOp::DeleteEvent, event, newPart, true, true); + addUndo(UndoOp(UndoOp::DeleteEvent, event, newPart, true, true)); // Remove the event from the new part's port controller values, and do all clone parts. removePortCtrlEvents(event, newPart, true); } @@ -886,7 +886,7 @@ void Song::cmdAddRecordedEvents(MidiTrack* mt, EventList* events, unsigned start event.setTick(event.tick() - partTick); Event e; // Create an undo op. Indicate do port controller values and clone parts. - undoOp(UndoOp::AddEvent, e, event, newPart, true, true); + addUndo(UndoOp(UndoOp::AddEvent, e, event, newPart, true, true)); if(newPart->events()->find(event) == newPart->events()->end()) newPart->events()->add(event); @@ -906,8 +906,8 @@ void Song::cmdAddRecordedEvents(MidiTrack* mt, EventList* events, unsigned start { Event event = i->second; // Create an undo op. Indicate do port controller values and clone parts. - //undoOp(UndoOp::DeleteEvent, event, part); - undoOp(UndoOp::DeleteEvent, event, part, true, true); + //addUndo(UndoOp(UndoOp::DeleteEvent, event, part)); + addUndo(UndoOp(UndoOp::DeleteEvent, event, part, true, true)); //if (event.type() == Controller) { // MidiTrack* track = (MidiTrack*)part->track(); @@ -938,8 +938,8 @@ void Song::cmdAddRecordedEvents(MidiTrack* mt, EventList* events, unsigned start event.setTick(tick); Event e; // Create an undo op. Indicate do port controller values and clone parts. - //undoOp(UndoOp::AddEvent, e, event, newPart); - undoOp(UndoOp::AddEvent, e, event, newPart, true, true); + //addUndo(UndoOp(UndoOp::AddEvent, e, event, newPart)); + addUndo(UndoOp(UndoOp::AddEvent, e, event, newPart, true, true)); // addEvent also adds port controller values. So does msgChangePart, below. Let msgChangePart handle them. //addEvent(event, (MidiPart*)newPart); @@ -965,9 +965,9 @@ void Song::cmdAddRecordedEvents(MidiTrack* mt, EventList* events, unsigned start //printf("Song::cmdAddRecordedEvents after changePart part:%p events:%p refs:%d Arefs:%d newPart:%p events:%p refs:%d Arefs:%d\n", part, part->events(), part->events()->refCount(), part->events()->arefCount(), newPart, newPart->events(), newPart->events()->refCount(), newPart->events()->arefCount()); - //undoOp(UndoOp::ModifyPart, part, newPart); + //addUndo(UndoOp(UndoOp::ModifyPart, part, newPart)); // Create an undo op. Indicate do not do port controller values and clone parts. - undoOp(UndoOp::ModifyPart, part, newPart, false, false); + addUndo(UndoOp(UndoOp::ModifyPart, part, newPart, false, false)); // Removed by T356. //part->events()->incARef(-1); @@ -985,8 +985,8 @@ void Song::cmdAddRecordedEvents(MidiTrack* mt, EventList* events, unsigned start for (iEvent i = si; i != ei; ++i) { Event event = i->second; // Create an undo op. Indicate that controller values and clone parts were handled. - //undoOp(UndoOp::DeleteEvent, event, part); - undoOp(UndoOp::DeleteEvent, event, part, true, true); + //addUndo(UndoOp(UndoOp::DeleteEvent, event, part)); + addUndo(UndoOp(UndoOp::DeleteEvent, event, part, true, true)); /* if (event.type() == Controller) { MidiTrack* track = (MidiTrack*)part->track(); @@ -1007,8 +1007,8 @@ void Song::cmdAddRecordedEvents(MidiTrack* mt, EventList* events, unsigned start event.setTick(tick); // Create an undo op. Indicate that controller values and clone parts were handled. - //undoOp(UndoOp::AddEvent, event, part); - undoOp(UndoOp::AddEvent, event, part, true, true); + //addUndo(UndoOp(UndoOp::AddEvent, event, part)); + addUndo(UndoOp(UndoOp::AddEvent, event, part, true, true)); //addEvent(event, part); if(part->events()->find(event) == part->events()->end()) @@ -1286,7 +1286,7 @@ void Song::setStopPlay(bool f) void Song::swapTracks(int i1, int i2) { - undoOp(UndoOp::SwapTrack, i1, i2); + addUndo(UndoOp(UndoOp::SwapTrack, i1, i2)); Track* track = _tracks[i1]; _tracks[i1] = _tracks[i2]; _tracks[i2] = track; @@ -1906,8 +1906,8 @@ void Song::processMsg(AudioMsg* msg) updateFlags = SC_EVENT_INSERTED; if (addEvent(msg->ev1, (MidiPart*)msg->p2)) { Event ev; - //undoOp(UndoOp::AddEvent, ev, msg->ev1, (Part*)msg->p2); - undoOp(UndoOp::AddEvent, ev, msg->ev1, (Part*)msg->p2, msg->a, msg->b); + //addUndo(UndoOp(UndoOp::AddEvent, ev, msg->ev1, (Part*)msg->p2)); + addUndo(UndoOp(UndoOp::AddEvent, ev, msg->ev1, (Part*)msg->p2, msg->a, msg->b)); } else updateFlags = 0; @@ -1921,8 +1921,8 @@ void Song::processMsg(AudioMsg* msg) if(msg->a) removePortCtrlEvents(event, part, msg->b); Event e; - //undoOp(UndoOp::DeleteEvent, e, event, (Part*)part); - undoOp(UndoOp::DeleteEvent, e, event, (Part*)part, msg->a, msg->b); + //addUndo(UndoOp(UndoOp::DeleteEvent, e, event, (Part*)part)); + addUndo(UndoOp(UndoOp::DeleteEvent, e, event, (Part*)part, msg->a, msg->b)); deleteEvent(event, part); updateFlags = SC_EVENT_REMOVED; } @@ -1933,21 +1933,21 @@ void Song::processMsg(AudioMsg* msg) changeEvent(msg->ev1, msg->ev2, (MidiPart*)msg->p3); if(msg->a) addPortCtrlEvents(msg->ev2, (Part*)msg->p3, msg->b); - //undoOp(UndoOp::ModifyEvent, msg->ev2, msg->ev1, (Part*)msg->p3); - undoOp(UndoOp::ModifyEvent, msg->ev2, msg->ev1, (Part*)msg->p3, msg->a, msg->b); + //addUndo(UndoOp(UndoOp::ModifyEvent, msg->ev2, msg->ev1, (Part*)msg->p3)); + addUndo(UndoOp(UndoOp::ModifyEvent, msg->ev2, msg->ev1, (Part*)msg->p3, msg->a, msg->b)); updateFlags = SC_EVENT_MODIFIED; break; case SEQM_ADD_TEMPO: //printf("processMsg (SEQM_ADD_TEMPO) UndoOp::AddTempo. adding tempo at: %d with tempo=%d\n", msg->a, msg->b); - undoOp(UndoOp::AddTempo, msg->a, msg->b); + addUndo(UndoOp(UndoOp::AddTempo, msg->a, msg->b)); tempomap.addTempo(msg->a, msg->b); updateFlags = SC_TEMPO; break; case SEQM_SET_TEMPO: //printf("processMsg (SEQM_SET_TEMPO) UndoOp::AddTempo. adding tempo at: %d with tempo=%d\n", msg->a, msg->b); - undoOp(UndoOp::AddTempo, msg->a, msg->b); + addUndo(UndoOp(UndoOp::AddTempo, msg->a, msg->b)); tempomap.setTempo(msg->a, msg->b); updateFlags = SC_TEMPO; break; @@ -1958,31 +1958,31 @@ void Song::processMsg(AudioMsg* msg) case SEQM_REMOVE_TEMPO: //printf("processMsg (SEQM_REMOVE_TEMPO) UndoOp::DeleteTempo. adding tempo at: %d with tempo=%d\n", msg->a, msg->b); - undoOp(UndoOp::DeleteTempo, msg->a, msg->b); + addUndo(UndoOp(UndoOp::DeleteTempo, msg->a, msg->b)); tempomap.delTempo(msg->a); updateFlags = SC_TEMPO; break; case SEQM_ADD_SIG: - undoOp(UndoOp::AddSig, msg->a, msg->b, msg->c); + addUndo(UndoOp(UndoOp::AddSig, msg->a, msg->b, msg->c)); AL::sigmap.add(msg->a, AL::TimeSignature(msg->b, msg->c)); updateFlags = SC_SIG; break; case SEQM_REMOVE_SIG: - undoOp(UndoOp::DeleteSig, msg->a, msg->b, msg->c); + addUndo(UndoOp(UndoOp::DeleteSig, msg->a, msg->b, msg->c)); AL::sigmap.del(msg->a); updateFlags = SC_SIG; break; case SEQM_ADD_KEY: - undoOp(UndoOp::AddKey, msg->a, msg->b); + addUndo(UndoOp(UndoOp::AddKey, msg->a, msg->b)); keymap.addKey(msg->a, (key_enum) msg->b); updateFlags = SC_KEY; break; case SEQM_REMOVE_KEY: - undoOp(UndoOp::DeleteKey, msg->a, msg->b); + addUndo(UndoOp(UndoOp::DeleteKey, msg->a, msg->b)); keymap.delKey(msg->a); updateFlags = SC_KEY; break; @@ -2000,7 +2000,7 @@ void Song::processMsg(AudioMsg* msg) void Song::cmdAddPart(Part* part) { addPart(part); - undoOp(UndoOp::AddPart, part); + addUndo(UndoOp(UndoOp::AddPart, part)); updateFlags = SC_PART_INSERTED; } @@ -2011,7 +2011,7 @@ void Song::cmdAddPart(Part* part) void Song::cmdRemovePart(Part* part) { removePart(part); - undoOp(UndoOp::DeletePart, part); + addUndo(UndoOp(UndoOp::DeletePart, part)); part->events()->incARef(-1); //part->unchainClone(); unchainClone(part); @@ -2032,8 +2032,8 @@ void Song::cmdChangePart(Part* oldPart, Part* newPart, bool doCtrls, bool doClon changePart(oldPart, newPart); - //undoOp(UndoOp::ModifyPart, oldPart, newPart); - undoOp(UndoOp::ModifyPart, oldPart, newPart, doCtrls, doClones); + //addUndo(UndoOp(UndoOp::ModifyPart, oldPart, newPart)); + addUndo(UndoOp(UndoOp::ModifyPart, oldPart, newPart, doCtrls, doClones)); // Changed by T356. Do not decrement ref count if the new part is a clone of the old part, since the event list // will still be active. diff --git a/muse2/muse/song.h b/muse2/muse/song.h index e1378480..cb9d0f9d 100644 --- a/muse2/muse/song.h +++ b/muse2/muse/song.h @@ -147,6 +147,8 @@ class Song : public QObject { Song(const char* name = 0); ~Song(); + void applyOperationGroup(Undo& group); + void putEvent(int pv); void endMsgCmd(); void processMsg(AudioMsg* msg); @@ -316,21 +318,9 @@ class Song : public QObject { void startUndo(); void endUndo(int); - //void undoOp(UndoOp::UndoType, Track* oTrack, Track* nTrack); - void undoOp(UndoOp::UndoType, int n, Track* oTrack, Track* nTrack); - void undoOp(UndoOp::UndoType, int, Track*); - void undoOp(UndoOp::UndoType, int, int, int = 0); - void undoOp(UndoOp::UndoType, Part*); - //void undoOp(UndoOp::UndoType, Event& nevent, Part*); - void undoOp(UndoOp::UndoType, Event& nevent, Part*, bool doCtrls, bool doClones); - //void undoOp(UndoOp::UndoType, Event& oevent, Event& nevent, Part*); - void undoOp(UndoOp::UndoType, Event& oevent, Event& nevent, Part*, bool doCtrls, bool doClones); - void undoOp(UndoOp::UndoType, SigEvent* oevent, SigEvent* nevent); - void undoOp(UndoOp::UndoType, int channel, int ctrl, int oval, int nval); - //void undoOp(UndoOp::UndoType, Part* oPart, Part* nPart); - void undoOp(UndoOp::UndoType, Part* oPart, Part* nPart, bool doCtrls, bool doClones); + void undoOp(UndoOp::UndoType type, const char* changedFile, const char* changeData, int startframe, int endframe); - void undoOp(UndoOp::UndoType type, Marker* copyMarker, Marker* realMarker); + bool doUndo1(); void doUndo2(); void doUndo3(); @@ -338,7 +328,7 @@ class Song : public QObject { void doRedo2(); void doRedo3(); - void addUndo(UndoOp& i); + void addUndo(UndoOp i); //----------------------------------------- // Configuration diff --git a/muse2/muse/structure.cpp b/muse2/muse/structure.cpp index f0a4308a..27246315 100644 --- a/muse2/muse/structure.cpp +++ b/muse2/muse/structure.cpp @@ -99,12 +99,12 @@ void MusE::adjustGlobalLists(int startPos, int diff) Marker *oldMarker = new Marker(); *oldMarker = *m; markerlist->remove(m); - song->undoOp(UndoOp::ModifyMarker,oldMarker, 0); + song->addUndo(UndoOp(UndoOp::ModifyMarker,oldMarker, 0)); } else { Marker *oldMarker = new Marker(); *oldMarker = *m; m->setTick(tick + diff); - song->undoOp(UndoOp::ModifyMarker,oldMarker, m); + song->addUndo(UndoOp(UndoOp::ModifyMarker,oldMarker, m)); } } } diff --git a/muse2/muse/undo.cpp b/muse2/muse/undo.cpp index a31b8e7a..ea9ea8d6 100644 --- a/muse2/muse/undo.cpp +++ b/muse2/muse/undo.cpp @@ -200,6 +200,16 @@ void Song::endUndo(int flags) undoMode = false; } + +void Song::applyOperationGroup(Undo& group) + { + //this is a HACK! but it works :) + redoList->push_back(group); + redo(); + } + + + //--------------------------------------------------------- // doUndo2 // real time part @@ -688,134 +698,105 @@ void Song::doRedo2() } } -void Song::undoOp(UndoOp::UndoType type, int a, int b, int c) +UndoOp::UndoOp(UndoType type_, int a_, int b_, int c_) { - UndoOp i; - i.type = type; - i.a = a; - i.b = b; - i.c = c; - addUndo(i); + type = type_; + a = a_; + b = b_; + c = c_; } -//void Song::undoOp(UndoOp::UndoType type, Track* oldTrack, Track* newTrack) -void Song::undoOp(UndoOp::UndoType type, int n, Track* oldTrack, Track* newTrack) +UndoOp::UndoOp(UndoType type_, int n, Track* oldTrack, Track* newTrack) { - UndoOp i; - i.type = type; - i.trackno = n; - i.oTrack = oldTrack; - i.nTrack = newTrack; - // Added by Tim. p3.3.6 - //printf("Song::undoOp ModifyTrack oTrack %p %s nTrack %p %s\n", i.oTrack, i.oTrack->name().toLatin1().constData(), i.nTrack, i.nTrack->name().toLatin1().constData()); - - addUndo(i); + type = type_; + trackno = n; + oTrack = oldTrack; + nTrack = newTrack; } -void Song::undoOp(UndoOp::UndoType type, int n, Track* track) +UndoOp::UndoOp(UndoType type_, int n, Track* track) { - UndoOp i; - i.type = type; - i.trackno = n; - i.oTrack = track; - if (type == UndoOp::AddTrack) - updateFlags |= SC_TRACK_INSERTED; - addUndo(i); + type = type_; + trackno = n; + oTrack = track; } -void Song::undoOp(UndoOp::UndoType type, Part* part) +UndoOp::UndoOp(UndoType type_, Part* part) { - UndoOp i; - i.type = type; - i.oPart = part; - addUndo(i); + type = type_; + oPart = part; } -//void Song::undoOp(UndoOp::UndoType type, Event& oev, Event& nev, Part* part) -void Song::undoOp(UndoOp::UndoType type, Event& oev, Event& nev, Part* part, bool doCtrls, bool doClones) +UndoOp::UndoOp(UndoType type_, Event& oev, Event& nev, Part* part_, bool doCtrls_, bool doClones_) { - UndoOp i; - i.type = type; - i.nEvent = nev; - i.oEvent = oev; - i.part = part; - i.doCtrls = doCtrls; - i.doClones = doClones; - addUndo(i); + type = type_; + nEvent = nev; + oEvent = oev; + part = part_; + doCtrls = doCtrls_; + doClones = doClones_; } -void Song::undoOp(UndoOp::UndoType type, Event& nev, Part* part, bool doCtrls, bool doClones) +UndoOp::UndoOp(UndoType type_, Event& nev, Part* part_, bool doCtrls_, bool doClones_) { - UndoOp i; - i.type = type; - i.nEvent = nev; - i.part = part; - i.doCtrls = doCtrls; - i.doClones = doClones; - addUndo(i); + type = type_; + nEvent = nev; + part = part_; + doCtrls = doCtrls_; + doClones = doClones_; } -//void Song::undoOp(UndoOp::UndoType type, Part* oPart, Part* nPart) -void Song::undoOp(UndoOp::UndoType type, Part* oPart, Part* nPart, bool doCtrls, bool doClones) +UndoOp::UndoOp(UndoType type_, Part* oPart_, Part* nPart_, bool doCtrls_, bool doClones_) { - UndoOp i; - i.type = type; - i.oPart = nPart; - i.nPart = oPart; - i.doCtrls = doCtrls; - i.doClones = doClones; - addUndo(i); + type = type_; + oPart = nPart_; + nPart = oPart_; + doCtrls = doCtrls_; + doClones = doClones_; } -void Song::undoOp(UndoOp::UndoType type, int c, int ctrl, int ov, int nv) +UndoOp::UndoOp(UndoType type_, int c, int ctrl_, int ov, int nv) { - UndoOp i; - i.type = type; - i.channel = c; - i.ctrl = ctrl; - i.oVal = ov; - i.nVal = nv; - addUndo(i); + type = type_; + channel = c; + ctrl = ctrl_; + oVal = ov; + nVal = nv; } -void Song::undoOp(UndoOp::UndoType type, SigEvent* oevent, SigEvent* nevent) +UndoOp::UndoOp(UndoType type_, SigEvent* oevent, SigEvent* nevent) { - UndoOp i; - i.type = type; - i.oSignature = oevent; - i.nSignature = nevent; - addUndo(i); + type = type_; + oSignature = oevent; + nSignature = nevent; } - -void Song::undoOp(UndoOp::UndoType type, const char* changedFile, const char* changeData, int startframe, int endframe) +UndoOp::UndoOp(UndoType type_, Marker* copyMarker_, Marker* realMarker_) { - UndoOp i; - i.type = type; - i.filename = changedFile; - i.tmpwavfile = changeData; - i.startframe = startframe; - i.endframe = endframe; - addUndo(i); - temporaryWavFiles.push_back(QString(changeData)); - - //printf("Adding ModifyClip undo-operation: origfile=%s tmpfile=%s sf=%d ef=%d\n", changedFile, changeData, startframe, endframe); + type = type_; + realMarker = realMarker_; + copyMarker = copyMarker_; } -void Song::undoOp(UndoOp::UndoType type, Marker* copyMarker, Marker* realMarker) +UndoOp::UndoOp(UndoType type_, const char* changedFile, const char* changeData, int startframe_, int endframe_) { - UndoOp i; - i.type = type; - i.realMarker = realMarker; - i.copyMarker = copyMarker; + type = type_; + filename = changedFile; + tmpwavfile = changeData; + startframe = startframe_; + endframe = endframe_; + } - addUndo(i); +void Song::undoOp(UndoOp::UndoType type, const char* changedFile, const char* changeData, int startframe, int endframe) + { + addUndo(UndoOp(type,changedFile,changeData,startframe,endframe)); + temporaryWavFiles.push_back(QString(changeData)); } //--------------------------------------------------------- // addUndo //--------------------------------------------------------- -void Song::addUndo(UndoOp& i) +void Song::addUndo(UndoOp i) { if (!undoMode) { printf("internal error: undoOp without startUndo()\n"); diff --git a/muse2/muse/undo.h b/muse2/muse/undo.h index eb5600ef..b048b9e6 100644 --- a/muse2/muse/undo.h +++ b/muse2/muse/undo.h @@ -83,8 +83,21 @@ struct UndoOp { Event nEvent; bool doCtrls; bool doClones; + const char* typeName(); void dump(); + + UndoOp(UndoType type, int a, int b, int c=0); + UndoOp(UndoType type, int n, Track* oldTrack, Track* newTrack); + UndoOp(UndoType type, int n, Track* track); + UndoOp(UndoType type, Part* part); + UndoOp(UndoType type, Event& oev, Event& nev, Part* part, bool doCtrls, bool doClones); + UndoOp(UndoType type, Event& nev, Part* part, bool doCtrls, bool doClones); + UndoOp(UndoType type, Part* oPart, Part* nPart, bool doCtrls, bool doClones); + UndoOp(UndoType type, int c, int ctrl, int ov, int nv); + UndoOp(UndoType type, SigEvent* oevent, SigEvent* nevent); + UndoOp(UndoType type, const char* changedFile, const char* changeData, int startframe, int endframe); + UndoOp(UndoType type, Marker* copyMarker, Marker* realMarker); }; class Undo : public std::list { -- cgit v1.2.3 From 18ffe91b0c57250770c098bd39ff79a0983c2ab2 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 22 May 2011 13:24:44 +0000 Subject: functions.cpp has been massively speeded up by using operation groups --- muse2/muse/functions.cpp | 95 ++++++++++++++++----------------------- muse2/muse/midiedit/scoreedit.cpp | 11 +++++ 2 files changed, 50 insertions(+), 56 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/functions.cpp b/muse2/muse/functions.cpp index 5498c6d1..ba16640c 100644 --- a/muse2/muse/functions.cpp +++ b/muse2/muse/functions.cpp @@ -7,6 +7,7 @@ #include "functions.h" #include "song.h" +#include "undo.h" #include "event.h" #include "audio.h" @@ -184,11 +185,10 @@ bool crescendo(const set& parts) void modify_velocity(const set& parts, int range, int rate, int offset) { map events = get_events(parts, range); + Undo operations; if ( (!events.empty()) && ((rate!=100) || (offset!=0)) ) { - song->startUndo(); - for (map::iterator it=events.begin(); it!=events.end(); it++) { Event& event=*(it->first); @@ -208,23 +208,22 @@ void modify_velocity(const set& parts, int range, int rate, int offset) { Event newEvent = event.clone(); newEvent.setVelo(velo); - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgChangeEvent(event, newEvent, part, false, false, false); + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false)); } } - song->endUndo(SC_EVENT_MODIFIED); + if (!operations.empty()) + song->applyOperationGroup(operations); } } void modify_off_velocity(const set& parts, int range, int rate, int offset) { map events = get_events(parts, range); + Undo operations; if ( (!events.empty()) && ((rate!=100) || (offset!=0)) ) { - song->startUndo(); - for (map::iterator it=events.begin(); it!=events.end(); it++) { Event& event=*(it->first); @@ -244,23 +243,22 @@ void modify_off_velocity(const set& parts, int range, int rate, int offse { Event newEvent = event.clone(); newEvent.setVeloOff(velo); - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgChangeEvent(event, newEvent, part, false, false, false); + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false)); } } - - song->endUndo(SC_EVENT_MODIFIED); + + if (!operations.empty()) + song->applyOperationGroup(operations); } } void modify_notelen(const set& parts, int range, int rate, int offset) { map events = get_events(parts, range); + Undo operations; if ( (!events.empty()) && ((rate!=100) || (offset!=0)) ) { - song->startUndo(); - for (map::iterator it=events.begin(); it!=events.end(); it++) { Event& event=*(it->first); @@ -278,12 +276,12 @@ void modify_notelen(const set& parts, int range, int rate, int offset) { Event newEvent = event.clone(); newEvent.setLenTick(len); - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgChangeEvent(event, newEvent, part, false, false, false); + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false)); } } - song->endUndo(SC_EVENT_MODIFIED); + if (!operations.empty()) + song->applyOperationGroup(operations); } } @@ -317,7 +315,7 @@ unsigned quantize_tick(unsigned tick, unsigned raster, int swing) void quantize_notes(const set& parts, int range, int raster, int strength, int swing, int threshold) { map events = get_events(parts, range); - bool undo_started=false; + Undo operations; if (!events.empty()) { @@ -347,53 +345,45 @@ void quantize_notes(const set& parts, int range, int raster, int strength if ( (event.lenTick() != len) || (event.tick() + part->tick() != begin_tick) ) { - if (!undo_started) - { - song->startUndo(); - undo_started=true; - } - Event newEvent = event.clone(); newEvent.setTick(begin_tick - part->tick()); newEvent.setLenTick(len); - // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgChangeEvent(event, newEvent, part, false, false, false); - audio->msgChangeEvent(event, newEvent, part, false, false, false); + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false)); } } - if (undo_started) song->endUndo(SC_EVENT_MODIFIED); + if (!operations.empty()) + song->applyOperationGroup(operations); } } void erase_notes(const set& parts, int range) { map events = get_events(parts, range); + Undo operations; if (!events.empty()) { - song->startUndo(); - for (map::iterator it=events.begin(); it!=events.end(); it++) { Event& event=*(it->first); Part* part=it->second; - audio->msgDeleteEvent(event, part, false, false, false); + operations.push_back(UndoOp(UndoOp::DeleteEvent, event, part, false, false)); } - song->endUndo(SC_EVENT_REMOVED); + if (!operations.empty()) + song->applyOperationGroup(operations); } } void transpose_notes(const set& parts, int range, signed int halftonesteps) { map events = get_events(parts, range); + Undo operations; if ( (!events.empty()) && (halftonesteps!=0) ) { - song->startUndo(); - for (map::iterator it=events.begin(); it!=events.end(); it++) { Event& event=*(it->first); @@ -404,25 +394,24 @@ void transpose_notes(const set& parts, int range, signed int halftonestep if (pitch > 127) pitch=127; if (pitch < 0) pitch=0; newEvent.setPitch(pitch); - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgChangeEvent(event, newEvent, part, false, false, false); + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false)); } - song->endUndo(SC_EVENT_MODIFIED); + if (!operations.empty()) + song->applyOperationGroup(operations); } } void crescendo(const set& parts, int range, int start_val, int end_val, bool absolute) { map events = get_events(parts, range); + Undo operations; int from=song->lpos(); int to=song->rpos(); if ( (!events.empty()) && (to>from) ) { - song->startUndo(); - for (map::iterator it=events.begin(); it!=events.end(); it++) { Event& event=*(it->first); @@ -442,22 +431,21 @@ void crescendo(const set& parts, int range, int start_val, int end_val, b if (velo > 127) velo=127; if (velo <= 0) velo=1; newEvent.setVelo(velo); - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgChangeEvent(event, newEvent, part, false, false, false); + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false)); } - song->endUndo(SC_EVENT_MODIFIED); + if (!operations.empty()) + song->applyOperationGroup(operations); } } void move_notes(const set& parts, int range, signed int ticks) //TODO FINDMICH: safety checks { map events = get_events(parts, range); + Undo operations; if ( (!events.empty()) && (ticks!=0) ) { - song->startUndo(); - for (map::iterator it=events.begin(); it!=events.end(); it++) { Event& event=*(it->first); @@ -465,18 +453,18 @@ void move_notes(const set& parts, int range, signed int ticks) //TODO FIN Event newEvent = event.clone(); newEvent.setTick(event.tick()+ticks); - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgChangeEvent(event, newEvent, part, false, false, false); + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false)); } - song->endUndo(SC_EVENT_MODIFIED); + if (!operations.empty()) + song->applyOperationGroup(operations); } } void delete_overlaps(const set& parts, int range) { map events = get_events(parts, range); - bool undo_started=false; + Undo operations; set deleted_events; @@ -503,17 +491,11 @@ void delete_overlaps(const set& parts, int range) (event1.tick() <= event2.tick()) && (event1.endTick() > event2.tick()) ) //they overlap { - if (undo_started==false) - { - song->startUndo(); - undo_started=true; - } - int new_len = event2.tick() - event1.tick(); if (new_len==0) { - audio->msgDeleteEvent(event1, part1, false, false, false); + operations.push_back(UndoOp(UndoOp::DeleteEvent, event1, part1, false, false)); deleted_events.insert(&event1); } else @@ -521,14 +503,15 @@ void delete_overlaps(const set& parts, int range) Event new_event1 = event1.clone(); new_event1.setLenTick(new_len); - audio->msgChangeEvent(event1, new_event1, part1, false, false, false); + operations.push_back(UndoOp(UndoOp::ModifyEvent, new_event1, event1, part1, false, false)); } } } } } - if (undo_started) song->endUndo(SC_EVENT_MODIFIED); + if (!operations.empty()) + song->applyOperationGroup(operations); } } diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp index bbdd3d6f..b60b6dbd 100644 --- a/muse2/muse/midiedit/scoreedit.cpp +++ b/muse2/muse/midiedit/scoreedit.cpp @@ -4218,6 +4218,17 @@ void staff_t::apply_lasso(QRect rect, set& already_processed) * between, for example, when a cis is tied to a des * * CURRENT TODO + * o rename stuff: UndoOp -> Operation, Undo -> OpList, + * UndoType -> OpType, iUndoOp, riUndoOp -> iOperation, + * undo.cpp/.h -> operations.cpp/.h + * o resizing a part is slow, because events get erased + * o drag'n'drop in canvases is slow + * o drawing controller lines is slow + * o cut,copy'n'paste is slow + * o reordering drum list is dead slow + * o reordering drum list creates unneccessary, actually wrong undo entry + * + * * o drum list: scroll while dragging * * IMPORTANT TODO -- cgit v1.2.3 From 14f8a08279d9266467d457707166b439fd080fa2 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 22 May 2011 13:25:15 +0000 Subject: code cleanup; only removed comments --- muse2/muse/midiedit/dcanvas.cpp | 315 +-------------------------------------- muse2/muse/midiedit/dlist.cpp | 21 +-- muse2/muse/midiedit/prcanvas.cpp | 291 ------------------------------------ muse2/muse/part.cpp | 243 ------------------------------ 4 files changed, 2 insertions(+), 868 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/midiedit/dcanvas.cpp b/muse2/muse/midiedit/dcanvas.cpp index fa7da753..a7e33bd1 100644 --- a/muse2/muse/midiedit/dcanvas.cpp +++ b/muse2/muse/midiedit/dcanvas.cpp @@ -138,34 +138,6 @@ void DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp if(npartoffset > 0) { - // Create new part... - // if there are several events that are moved outside the part, it will be recreated for each - // so the part _in_ the event will not be valid, ask the authority. -// Part* newPart = part->clone(); - //Part* newPart = Canvas::part()->clone(); - -// newPart->setLenTick(newPart->lenTick() + npartoffset); - //audio->msgChangePart(part, newPart,false); - -// modified = SC_PART_MODIFIED; - - // BUG FIX: #1650953 - // Added by T356. - // Fixes posted "select and drag past end of part - crashing" bug -// for(iPart ip = editor->parts()->begin(); ip != editor->parts()->end(); ++ip) -// { -// if(ip->second == part) -// { -// editor->parts()->erase(ip); -// break; -// } -// } - -// editor->parts()->add(newPart); -// audio->msgChangePart(part, newPart,false); - -// if(parts2change.find(part) == parts2change.end()) -// parts2change.insert(std::pair (part, newPart)); iPartToChange ip2c = parts2change.find(part); if(ip2c == parts2change.end()) { @@ -174,14 +146,6 @@ void DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp } else ip2c->second.xdiff = npartoffset; - - - //part = newPart; // reassign - //item->setPart(part); - //item->setEvent(newEvent); - //curPart = part; - //curPartId = curPart->sn(); - } } @@ -210,7 +174,6 @@ void DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp editor->parts()->add(newPart); // Indicate no undo, and do port controller values but not clone parts. - //audio->msgChangePart(opart, newPart, false); audio->msgChangePart(opart, newPart, false, true, false); ip2c->second.npart = newPart; @@ -251,7 +214,6 @@ void DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp break; // Do not process if the event has already been processed (meaning it's an event in a clone part)... - //if(moveItem(ci, newpos, dtype)) if(idl != doneList.end()) // Just move the canvas item. ci->move(newpos); @@ -282,14 +244,10 @@ void DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp // moveItem //--------------------------------------------------------- -// Changed by T356. -//bool DrumCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype, int* pflags) bool DrumCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype) { DEvent* nevent = (DEvent*) item; - // Changed by T356. - //MidiPart* part = (MidiPart*)Canvas::part(); // part can be dynamically recreated, ask the authority MidiPart* part = (MidiPart*)nevent->part(); Event event = nevent->event(); @@ -305,40 +263,6 @@ bool DrumCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype) newEvent.setPitch(npitch); newEvent.setTick(ntick); - // Removed by T356. - /* - // Added by T356. - int modified = 0; - //song->startUndo(); - int diff = newEvent.endTick()-part->lenTick(); - if (diff > 0) // too short part? extend it - { - // if there are several events that are moved outside the part, it will be recreated for each - // so the part _in_ the event will not be valid, ask the authority. - //Part* newPart = part->clone(); - MidiPart* newPart = (MidiPart*)Canvas::part()->clone(); - newPart->setLenTick(newPart->lenTick()+diff); - audio->msgChangePart(Canvas::part(), newPart,false); - - modified = SC_PART_MODIFIED; - part = newPart; // reassign - for(iPart i = editor->parts()->begin(); i != editor->parts()->end(); ++i) - { - if(i->second == Canvas::part()) - { - editor->parts()->erase(i); - break; - } - } - editor->parts()->add(part); - item->setPart(part); - item->setEvent(newEvent); - curPart = part; - curPartId = curPart->sn(); - } - */ - - // Added by T356. // msgAddEvent and msgChangeEvent (below) will set these, but set them here first? //item->setPart(part); item->setEvent(newEvent); @@ -349,19 +273,13 @@ bool DrumCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype) if (dtype == MOVE_COPY || dtype == MOVE_CLONE) { // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgAddEvent(newEvent, part, false); audio->msgAddEvent(newEvent, part, false, false, false); } else { // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgChangeEvent(event, newEvent, part, false); audio->msgChangeEvent(event, newEvent, part, false, false, false); } - // Removed by T356. - //if(pflags) - // *pflags = modified; - return true; } @@ -407,7 +325,6 @@ void DrumCanvas::resizeItem(CItem* item, bool) DEvent* nevent = (DEvent*) item; Event ev = nevent->event(); // Indicate do undo, and do not do port controller values and clone parts. - //audio->msgDeleteEvent(ev, nevent->part()); audio->msgDeleteEvent(ev, nevent->part(), true, false, false); } @@ -426,7 +343,6 @@ void DrumCanvas::newItem(CItem* item, bool noSnap, bool replace) if (!noSnap) x = editor->rasterVal(x); event.setTick(x - nevent->part()->tick()); - //int npitch = drumMap[y2pitch(item->y())].enote; int npitch = event.pitch(); event.setPitch(npitch); @@ -446,7 +362,6 @@ void DrumCanvas::newItem(CItem* item, bool noSnap, bool replace) if (ev.pitch() == npitch) { // Indicate do undo, and do not do port controller values and clone parts. - //audio->msgDeleteEvent(ev, nevent->part()); audio->msgDeleteEvent(ev, nevent->part(), true, false, false); if (replace) break; @@ -465,13 +380,11 @@ void DrumCanvas::newItem(CItem* item, bool noSnap, bool replace) Part* newPart = part->clone(); newPart->setLenTick(newPart->lenTick()+diff); // Indicate no undo, and do port controller values but not clone parts. - //audio->msgChangePart(part, newPart,false); audio->msgChangePart(part, newPart, false, true, false); modified=modified|SC_PART_MODIFIED; part = newPart; // reassign } // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgAddEvent(event, part,false); audio->msgAddEvent(event, part, false, false, false); song->endUndo(modified); @@ -485,7 +398,6 @@ bool DrumCanvas::deleteItem(CItem* item) { Event ev = ((DEvent*)item)->event(); // Indicate do undo, and do not do port controller values and clone parts. - //audio->msgDeleteEvent(ev, ((DEvent*)item)->part()); audio->msgDeleteEvent(ev, ((DEvent*)item)->part(), true, false, false); return false; } @@ -554,10 +466,6 @@ void DrumCanvas::drawItem(QPainter&p, const CItem*item, const QRect& rect) void DrumCanvas::drawMoving(QPainter& p, const CItem* item, const QRect& rect) { - //if(((DEvent*)item)->part() != curPart) - // return; - //if(!item->isMoving()) - // return; QPolygon pa(4); QPoint pt = map(item->mp()); int x = pt.x(); @@ -658,7 +566,6 @@ void DrumCanvas::cmd(int cmd) DEvent* e = (DEvent*)(i->second); Event event = e->event(); // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgDeleteEvent(event, e->part(), false); audio->msgDeleteEvent(event, e->part(), false, false, false); } song->endUndo(SC_EVENT_REMOVED); @@ -760,7 +667,6 @@ void DrumCanvas::cmd(int cmd) Event newEvent = event.clone(); newEvent.setLenTick(drumMap[event.pitch()].len); // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgChangeEvent(event, newEvent, devent->part() , false); audio->msgChangeEvent(event, newEvent, devent->part(), false, false, false); } } @@ -800,8 +706,6 @@ void DrumCanvas::cmd(int cmd) case CMD_RIGHT_NOSNAP: { Pos p(pos[0] + editor->rasterStep(pos[0]), true); - //if (p > part->tick()) - // p = part->tick(); song->setPos(0, p, true, true, true); //CDW } break; @@ -810,68 +714,6 @@ void DrumCanvas::cmd(int cmd) redraw(); } -/* -//--------------------------------------------------------- -// getTextDrag -//--------------------------------------------------------- - -Q3TextDrag* DrumCanvas::getTextDrag(QWidget* parent) - { - //--------------------------------------------------- - // generate event list from selected events - //--------------------------------------------------- - - EventList el; - unsigned startTick = MAXINT; - for (iCItem i = items.begin(); i != items.end(); ++i) { - if (!i->second->isSelected()) - continue; - DEvent* ne = (DEvent*)(i->second); - Event e = ne->event(); - if (startTick == MAXINT) - startTick = e.tick(); - el.add(e); - } - - //--------------------------------------------------- - // write events as XML into tmp file - //--------------------------------------------------- - - FILE* tmp = tmpfile(); - if (tmp == 0) { - fprintf(stderr, "EventCanvas::copy() fopen failed: %s\n", - strerror(errno)); - return 0; - } - Xml xml(tmp); - - int level = 0; - for (ciEvent e = el.begin(); e != el.end(); ++e) - e->second.write(level, xml, -startTick); - - //--------------------------------------------------- - // read tmp file into QTextDrag Object - //--------------------------------------------------- - - fflush(tmp); - struct stat f_stat; - if (fstat(fileno(tmp), &f_stat) == -1) { - fprintf(stderr, "EventCanvas::copy() fstat failes:<%s>\n", - strerror(errno)); - fclose(tmp); - return 0; - } - int n = f_stat.st_size; - char* fbuf = (char*)mmap(0, n+1, PROT_READ|PROT_WRITE, - MAP_PRIVATE, fileno(tmp), 0); - fbuf[n] = 0; - Q3TextDrag* drag = new Q3TextDrag(QString(fbuf), parent); - drag->setSubtype("eventlist"); - munmap(fbuf, n); - fclose(tmp); - return drag; - } -*/ //--------------------------------------------------------- // copy @@ -886,67 +728,6 @@ void DrumCanvas::copy() QApplication::clipboard()->setMimeData(md, QClipboard::Clipboard); } -/* -//--------------------------------------------------------- -// paste -//--------------------------------------------------------- - -int DrumCanvas::pasteAt(const QString& pt, int pos) - { - QByteArray ba = pt.toLatin1(); - const char* p = ba.constData(); - Xml xml(p); - - // Added by T356. - int modified = SC_EVENT_INSERTED; - - song->startUndo(); - for (;;) { - Xml::Token token = xml.parse(); - QString tag = xml.s1(); - switch (token) { - case Xml::Error: - case Xml::End: - song->endUndo(modified); - return pos; - case Xml::TagStart: - if (tag == "event") { - Event e(Note); - e.read(xml); - - // Added by T356. - int tick = e.tick() + pos - curPart->tick(); - if (tick<0) { - printf("DrumCanvas::pasteAt ERROR: trying to add event before current part!\n"); - song->endUndo(SC_EVENT_INSERTED); - //delete el; - return pos; - } - e.setTick(tick); - int diff = e.endTick() - curPart->lenTick(); - if (diff > 0) {// too short part? extend it - Part* newPart = curPart->clone(); - newPart->setLenTick(newPart->lenTick()+diff); - // Indicate no undo, and do port controller values but not clone parts. - audio->msgChangePart(curPart, newPart, false, true, false); - - modified=modified|SC_PART_MODIFIED; - curPart = newPart; // reassign - } - - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgAddEvent(e, curPart, false, false, false); - } - else - xml.unknown("DCanvas::pasteAt"); - break; - case Xml::TagEnd: - default: - break; - } - } - } -*/ //--------------------------------------------------------- // paste @@ -972,10 +753,6 @@ void DrumCanvas::startDrag(CItem* /* item*/, bool copymode) QMimeData* md = getTextDrag(); if (md) { -// QApplication::clipboard()->setData(drag, QClipboard::Clipboard); // This line NOT enabled in muse-1 - //QApplication::clipboard()->setMimeData(md); // TODO CHECK Tim. - //QApplication::clipboard()->setMimeData(drag->mimeData()); // - // "Note that setMimeData() assigns ownership of the QMimeData object to the QDrag object. // The QDrag must be constructed on the heap with a parent QWidget to ensure that Qt can // clean up after the drag and drop operation has been completed. " @@ -1014,40 +791,6 @@ void DrumCanvas::dragLeaveEvent(QDragLeaveEvent*) { } -/* -//--------------------------------------------------------- -// dropEvent -//--------------------------------------------------------- - -void DrumCanvas::viewDropEvent(QDropEvent* event) - { - QString text; - if (event->source() == this) { - printf("local DROP\n"); - //event->acceptProposedAction(); - //event->ignore(); // TODO CHECK Tim. - return; - } - //if (event->mimeData()->hasText()) { - if (event->mimeData()->hasFormat("text/x-muse-eventlist")) { - - //text = event->mimeData()->text(); - text = QString(event->mimeData()->data("text/x-muse-eventlist")); - -// printf("drop <%s>\n", text.ascii()); - int x = editor->rasterVal(event->pos().x()); - if (x < 0) - x = 0; - pasteAt(text, x); - //event->accept(); // TODO - } - else { - printf("cannot decode drop\n"); - //event->acceptProposedAction(); - //event->ignore(); // TODO CHECK Tim. - } - } -*/ //--------------------------------------------------------- // keyPressed - called from DList @@ -1099,26 +842,7 @@ void DrumCanvas::mapChanged(int spitch, int dpitch) typedef std::vector< std::pair >::iterator idel_ev; typedef std::vector< std::pair >::iterator iadd_ev; - - /* - class delete_events : public std::vector< Part*, Event* > - { - public: - idel_ev find(Part* p, Event* e) - { - - }; - }; - class add_events : public std::vector< Part*, Event > - { - public: - iadd_ev find(Part* p, Event& e) - { - - }; - }; - */ - + MidiTrackList* tracks = song->midis(); for (ciMidiTrack t = tracks->begin(); t != tracks->end(); t++) { MidiTrack* curTrack = *t; @@ -1169,13 +893,9 @@ void DrumCanvas::mapChanged(int spitch, int dpitch) song->startUndo(); for (idel_ev i = delete_events.begin(); i != delete_events.end(); i++) { - //std::pair pair = *i; - //Part* thePart = pair.first; - //Event* theEvent = pair.second; Part* thePart = (*i).first; Event* theEvent = (*i).second; // Indicate no undo, and do port controller values but not clone parts. - //audio->msgDeleteEvent(*theEvent, thePart, false); audio->msgDeleteEvent(*theEvent, thePart, false, true, false); } @@ -1188,13 +908,9 @@ void DrumCanvas::mapChanged(int spitch, int dpitch) drumOutmap[int(drumMap[int(dpitch)].anote)] = dpitch; for (iadd_ev i = add_events.begin(); i != add_events.end(); i++) { - //std::pair pair = *i; - //Part* thePart = pair.first; - //Event& theEvent = pair.second; Part* thePart = (*i).first; Event& theEvent = (*i).second; // Indicate no undo, and do port controller values but not clone parts. - //audio->msgAddEvent(theEvent, thePart, false); audio->msgAddEvent(theEvent, thePart, false, true, false); } @@ -1243,40 +959,12 @@ void DrumCanvas::modifySelected(NoteInfo::ValType type, int delta) } break; case NoteInfo::VAL_LEN: - /* - { - int len = event.lenTick() + delta; - if (len < 1) - len = 1; - newEvent.setLenTick(len); - } - */ printf("DrumCanvas::modifySelected - NoteInfo::VAL_LEN not implemented\n"); break; case NoteInfo::VAL_VELON: - /* - { - int velo = event->velo() + delta; - if (velo > 127) - velo = 127; - else if (velo < 0) - velo = 0; - newEvent.setVelo(velo); - } - */ printf("DrumCanvas::modifySelected - NoteInfo::VAL_VELON not implemented\n"); break; case NoteInfo::VAL_VELOFF: - /* - { - int velo = event.veloOff() + delta; - if (velo > 127) - velo = 127; - else if (velo < 0) - velo = 0; - newEvent.setVeloOff(velo); - } - */ printf("DrumCanvas::modifySelected - NoteInfo::VAL_VELOFF not implemented\n"); break; case NoteInfo::VAL_PITCH: @@ -1292,7 +980,6 @@ void DrumCanvas::modifySelected(NoteInfo::ValType type, int delta) } song->changeEvent(event, newEvent, part); // Indicate do not do port controller values and clone parts. - //song->addUndo(UndoOp(UndoOp::ModifyEvent, newEvent, event, part)); song->addUndo(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false)); } song->endUndo(SC_EVENT_MODIFIED); diff --git a/muse2/muse/midiedit/dlist.cpp b/muse2/muse/midiedit/dlist.cpp index 3b8670db..0b8bf3aa 100644 --- a/muse2/muse/midiedit/dlist.cpp +++ b/muse2/muse/midiedit/dlist.cpp @@ -23,9 +23,6 @@ #include "song.h" #include "scrollscale.h" -// enum DCols { COL_MUTE=0, COL_NAME, COL_QNT, COL_ENOTE, COL_LEN, -// COL_ANOTE, COL_CHANNEL, COL_PORT, -// COL_LV1, COL_LV2, COL_LV3, COL_LV4, COL_NONE=-1}; //--------------------------------------------------------- // draw @@ -51,7 +48,6 @@ void DList::draw(QPainter& p, const QRect& rect) if (yy > y + h) break; DrumMap* dm = &drumMap[i]; -// if (dm->selected) if (dm == currentlySelected) p.fillRect(x, yy, w, TH, Qt::yellow); // else @@ -60,13 +56,11 @@ void DList::draw(QPainter& p, const QRect& rect) for (int k = 0; k < h->count(); ++k) { int x = h->sectionPosition(k); int w = h->sectionSize(k); - ///QRect r = p.xForm(QRect(x+2, yy, w-4, TH)); QRect r = p.combinedTransform().mapRect(QRect(x+2, yy, w-4, TH)); QString s; int align = Qt::AlignVCenter | Qt::AlignHCenter; p.save(); - ///p.setWorldXForm(false); p.setWorldMatrixEnabled(false); switch (k) { case COL_VOL: @@ -149,16 +143,13 @@ void DList::draw(QPainter& p, const QRect& rect) // vertical Lines //--------------------------------------------------- - ///p.setWorldXForm(false); p.setWorldMatrixEnabled(false); int n = header->count(); x = 0; for (int i = 0; i < n; i++) { - //x += header->sectionSize(i); x += header->sectionSize(header->visualIndex(i)); p.drawLine(x, 0, x, height()); } - ///p.setWorldXForm(true); p.setWorldMatrixEnabled(true); } @@ -178,7 +169,6 @@ void DList::devicesPopupMenu(DrumMap* t, int x, int y, bool changeAll) if(n != t->port) { audio->msgIdle(true); - //audio->msgRemapPortDrumCtlEvents(getSelectedInstrument(), -1, -1, n); song->remapPortDrumCtrlEvents(getSelectedInstrument(), -1, -1, n); audio->msgIdle(false); t->port = n; @@ -188,13 +178,11 @@ void DList::devicesPopupMenu(DrumMap* t, int x, int y, bool changeAll) else { audio->msgIdle(true); // Delete all port controller events. - //audio->msgChangeAllPortDrumCtrlEvents(false); song->changeAllPortDrumCtrlEvents(false); for (int i = 0; i < DRUM_MAPSIZE; i++) drumMap[i].port = n; // Add all port controller events. - //audio->msgChangeAllPortDrumCtrlEvents(true); song->changeAllPortDrumCtrlEvents(true); audio->msgIdle(false); @@ -328,13 +316,11 @@ void DList::viewMousePressEvent(QMouseEvent* ev) if (ev->modifiers() & Qt::ControlModifier) { audio->msgIdle(true); // Delete all port controller events. - //audio->msgChangeAllPortDrumCtrlEvents(false); song->changeAllPortDrumCtrlEvents(false, true); for (int i = 0; i < DRUM_MAPSIZE; i++) drumMap[i].channel = val; // Add all port controller events. - //audio->msgChangeAllPortDrumCtrlEvents(true); song->changeAllPortDrumCtrlEvents(true, true); audio->msgIdle(false); song->update(SC_DRUMMAP); @@ -344,7 +330,6 @@ void DList::viewMousePressEvent(QMouseEvent* ev) if(val != dm->channel) { audio->msgIdle(true); - //audio->msgRemapPortDrumCtlEvents(pitch, -1, val, -1); song->remapPortDrumCtrlEvents(pitch, -1, val, -1); audio->msgIdle(false); dm->channel = val; @@ -419,7 +404,6 @@ void DList::viewMouseDoubleClickEvent(QMouseEvent* ev) { int x = ev->x(); int y = ev->y(); -// int button = ev->button(); unsigned pitch = y / TH; int section = header->logicalIndexAt(x); @@ -485,7 +469,6 @@ void DList::lineEdit(int line, int section) break; } - // editor->setText(dm->name); editor->end(false); editor->setGeometry(colx, coly, colw, colh); // In all cases but the column name, select all text: @@ -648,7 +631,7 @@ DList::DList(QHeaderView* h, QWidget* parent, int ymag) { setBg(Qt::white); if (!h){ - h = new QHeaderView(Qt::Horizontal, parent);} + h = new QHeaderView(Qt::Horizontal, parent);} header = h; scroll = 0; //ORCAN- CHECK if really needed: header->setTracking(true); @@ -670,8 +653,6 @@ DList::DList(QHeaderView* h, QWidget* parent, int ymag) DList::~DList() { -// if (currentlySelected != 0) -// currentlySelected->selected = false; //Reset the global thingie } //--------------------------------------------------------- diff --git a/muse2/muse/midiedit/prcanvas.cpp b/muse2/muse/midiedit/prcanvas.cpp index e59e8beb..a38e0ee1 100644 --- a/muse2/muse/midiedit/prcanvas.cpp +++ b/muse2/muse/midiedit/prcanvas.cpp @@ -300,34 +300,6 @@ void PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dty if(npartoffset > 0) { - // Create new part... - // if there are several events that are moved outside the part, it will be recreated for each - // so the part _in_ the event will not be valid, ask the authority. -// Part* newPart = part->clone(); - //Part* newPart = Canvas::part()->clone(); - -// newPart->setLenTick(newPart->lenTick() + npartoffset); - //audio->msgChangePart(part, newPart,false); - -// modified = SC_PART_MODIFIED; - - // BUG FIX: #1650953 - // Added by T356. - // Fixes posted "select and drag past end of part - crashing" bug -// for(iPart ip = editor->parts()->begin(); ip != editor->parts()->end(); ++ip) -// { -// if(ip->second == part) -// { -// editor->parts()->erase(ip); -// break; -// } -// } - -// editor->parts()->add(newPart); -// audio->msgChangePart(part, newPart,false); - - //if(parts2change.find(part) == parts2change.end()) - // parts2change.insert(std::pair (part, newPart)); iPartToChange ip2c = parts2change.find(part); if(ip2c == parts2change.end()) { @@ -336,13 +308,6 @@ void PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dty } else ip2c->second.xdiff = npartoffset; - - //part = newPart; // reassign - //item->setPart(part); - //item->setEvent(newEvent); - //curPart = part; - //curPartId = curPart->sn(); - } } @@ -474,46 +439,6 @@ bool PianoCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype) newEvent.setTick(ntick); newEvent.setLenTick(event.lenTick()); - // Removed by T356. - /* - int modified=0; - //song->startUndo(); - int diff = newEvent.endTick()-part->lenTick(); - if (diff > 0){// too short part? extend it - // if there are several events that are moved outside the part, it will be recreated for each - // so the part _in_ the event will not be valid, ask the authority. - //Part* newPart = part->clone(); - Part* newPart = Canvas::part()->clone(); - - newPart->setLenTick(newPart->lenTick()+diff); - audio->msgChangePart(Canvas::part(), newPart,false); - - modified = SC_PART_MODIFIED; - part = newPart; // reassign - - // BUG FIX: #1650953 - // Added by T356. - // Fixes posted "select and drag past end of part - crashing" bug - for(iPart i = editor->parts()->begin(); i != editor->parts()->end(); ++i) - { - if(i->second == Canvas::part()) - { - editor->parts()->erase(i); - break; - } - } - editor->parts()->add(part); - item->setPart(part); - item->setEvent(newEvent); - curPart = part; - curPartId = curPart->sn(); - - } - */ - - // Added by T356. - // msgAddEvent and msgChangeEvent (below) will set these, but set them here first? - //item->setPart(part); item->setEvent(newEvent); // Added by T356. @@ -521,19 +446,11 @@ bool PianoCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype) printf("PianoCanvas::moveItem Error! New event end:%d exceeds length:%d of part:%s\n", newEvent.endTick(), part->lenTick(), part->name().toLatin1().constData()); if (dtype == MOVE_COPY || dtype == MOVE_CLONE) - // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgAddEvent(newEvent, part, false); audio->msgAddEvent(newEvent, part, false, false, false); else - // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgChangeEvent(event, newEvent, part, false); audio->msgChangeEvent(event, newEvent, part, false, false, false); //song->endUndo(modified); - // Removed by T356. - //if(pflags) - // *pflags = modified; - return true; } @@ -587,7 +504,6 @@ void PianoCanvas::newItem(CItem* item, bool noSnap) Part* newPart = part->clone(); newPart->setLenTick(newPart->lenTick()+diff); // Indicate no undo, and do port controller values but not clone parts. - //audio->msgChangePart(part, newPart,false); audio->msgChangePart(part, newPart, false, true, false); modified=modified|SC_PART_MODIFIED; part = newPart; // reassign @@ -623,14 +539,12 @@ void PianoCanvas::resizeItem(CItem* item, bool noSnap) // experimental c } song->startUndo(); int modified=SC_EVENT_MODIFIED; - //printf("event.tick()=%d len=%d part->lenTick()=%d\n",event.endTick(),len,part->lenTick()); int diff = event.tick()+len-part->lenTick(); if (diff > 0) {// too short part? extend it //printf("extend Part!\n"); Part* newPart = part->clone(); newPart->setLenTick(newPart->lenTick()+diff); // Indicate no undo, and do port controller values but not clone parts. - //audio->msgChangePart(part, newPart,false); audio->msgChangePart(part, newPart, false, true, false); modified=modified|SC_PART_MODIFIED; part = newPart; // reassign @@ -638,7 +552,6 @@ void PianoCanvas::resizeItem(CItem* item, bool noSnap) // experimental c newEvent.setLenTick(len); // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgChangeEvent(event, newEvent, nevent->part(),false); audio->msgChangeEvent(event, newEvent, nevent->part(), false, false, false); song->endUndo(modified); } @@ -653,7 +566,6 @@ bool PianoCanvas::deleteItem(CItem* item) if (nevent->part() == curPart) { Event ev = nevent->event(); // Indicate do undo, and do not do port controller values and clone parts. - //audio->msgDeleteEvent(ev, curPart); audio->msgDeleteEvent(ev, curPart, true, false, false); return true; } @@ -700,8 +612,6 @@ void PianoCanvas::pianoCmd(int cmd) case CMD_RIGHT_NOSNAP: { Pos p(pos[0] + editor->rasterStep(pos[0]), true); - //if (p > part->tick()) - // p = part->tick(); song->setPos(0, p, true, true, true); //CDW } break; @@ -724,7 +634,6 @@ void PianoCanvas::pianoCmd(int cmd) Event newEvent = event.clone(); newEvent.setTick(event.tick() + editor->raster());// - part->tick()); // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgChangeEvent(event, newEvent, part, false); audio->msgChangeEvent(event, newEvent, part, false, false, false); } song->endUndo(SC_EVENT_MODIFIED); @@ -750,7 +659,6 @@ void PianoCanvas::pianoCmd(int cmd) Event newEvent = event.clone(); newEvent.setTick(event.tick() - editor->raster() - part->tick()); // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgChangeEvent(event, newEvent, part, false); audio->msgChangeEvent(event, newEvent, part, false, false, false); } song->endUndo(SC_EVENT_MODIFIED); @@ -772,7 +680,6 @@ void PianoCanvas::pianoPressed(int pitch, int velocity, bool shift) pitch += track()->transposition; // play note: - //MidiPlayEvent e(0, port, channel, 0x90, pitch, 127); MidiPlayEvent e(0, port, channel, 0x90, pitch, velocity); audio->msgPlayMidiEvent(&e); @@ -788,7 +695,6 @@ void PianoCanvas::pianoPressed(int pitch, int velocity, bool shift) e.setVelo(127); e.setLenTick(len); // Indicate do undo, and do not do port controller values and clone parts. - //audio->msgAddEvent(e, curPart); audio->msgAddEvent(e, curPart, true, false, false); tick += editor->rasterStep(tick) + curPart->tick(); if (tick != song->cpos()) { @@ -838,14 +744,6 @@ void drawTickRaster(QPainter& p, int x, int y, int w, int h, int raster) int qq = raster; if (q < 8) // grid too dense qq *= 2; - //switch (quant) { - // case 32: - // case 48: - // case 64: - // case 96: - // case 192: // 8tel - // case 128: // 8tel Triolen - // case 288: p.setPen(Qt::lightGray); if (raster>=4) { int xx = x + qq; @@ -856,10 +754,6 @@ void drawTickRaster(QPainter& p, int x, int y, int w, int h, int raster) } xx = xxx; } - // break; - // default: - // break; - // } p.setPen(Qt::gray); for (int beat = 1; beat < z; beat++) { int xx = AL::sigmap.bar2tick(bar, beat, 0); @@ -894,9 +788,7 @@ void PianoCanvas::drawCanvas(QPainter& p, const QRect& rect) p.drawLine(x, yy, x + w, yy); break; default: - //p.setPen(lightGray); p.fillRect(x, yy-3, w, 6, QBrush(QColor(230,230,230))); - //p.drawLine(x, yy, x + w, yy); break; } --key; @@ -926,7 +818,6 @@ void PianoCanvas::cmd(int cmd) NEvent* e = (NEvent*)(i->second); Event ev = e->event(); // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgDeleteEvent(ev, e->part(), false); audio->msgDeleteEvent(ev, e->part(), false, false, false); } song->endUndo(SC_EVENT_REMOVED); @@ -1023,7 +914,6 @@ void PianoCanvas::cmd(int cmd) Event newEvent = event.clone(); newEvent.setLenTick(editor->raster()); // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgChangeEvent(event, newEvent, nevent->part() , false); audio->msgChangeEvent(event, newEvent, nevent->part(), false, false, false); } } @@ -1082,7 +972,6 @@ void PianoCanvas::midiNote(int pitch, int velo) Event e = ev.clone(); e.setLenTick(ev.lenTick() + editor->rasterStep(starttick)); // Indicate do undo, and do not do port controller values and clone parts. - //audio->msgChangeEvent(ev, e, curPart); audio->msgChangeEvent(ev, e, curPart, true, false, false); if (! (globalKeyState & Qt::ShiftModifier)) { @@ -1102,7 +991,6 @@ void PianoCanvas::midiNote(int pitch, int velo) Event ev = i->second; if (ev.isNote() && ev.pitch() == pitch) { // Indicate do undo, and do not do port controller values and clone parts. - //audio->msgDeleteEvent(ev, curPart); audio->msgDeleteEvent(ev, curPart, true, false, false); if (! (globalKeyState & Qt::ShiftModifier)) { @@ -1119,7 +1007,6 @@ void PianoCanvas::midiNote(int pitch, int velo) e.setVelo(velo); e.setLenTick(len); // Indicate do undo, and do not do port controller values and clone parts. - //audio->msgAddEvent(e, curPart); audio->msgAddEvent(e, curPart, true, false, false); if (! (globalKeyState & Qt::ShiftModifier)) { @@ -1138,71 +1025,6 @@ void PianoCanvas::chordTimerTimedOut() } } -/* -//--------------------------------------------------------- -// getTextDrag -//--------------------------------------------------------- - -Q3TextDrag* PianoCanvas::getTextDrag(QWidget* parent) - { - //--------------------------------------------------- - // generate event list from selected events - //--------------------------------------------------- - - EventList el; - unsigned startTick = MAXINT; - for (iCItem i = items.begin(); i != items.end(); ++i) { - if (!i->second->isSelected()) - continue; - NEvent* ne = (NEvent*)(i->second); - Event e = ne->event(); - if (startTick == MAXINT) - startTick = e.tick(); - el.add(e); - } - - //--------------------------------------------------- - // write events as XML into tmp file - //--------------------------------------------------- - - FILE* tmp = tmpfile(); - if (tmp == 0) { - fprintf(stderr, "PianoCanvas::copy() fopen failed: %s\n", - strerror(errno)); - return 0; - } - Xml xml(tmp); - - int level = 0; - xml.tag(level++, "eventlist"); - for (ciEvent e = el.begin(); e != el.end(); ++e) - e->second.write(level, xml, -startTick); - xml.etag(--level, "eventlist"); - - //--------------------------------------------------- - // read tmp file into QTextDrag Object - //--------------------------------------------------- - - fflush(tmp); - struct stat f_stat; - if (fstat(fileno(tmp), &f_stat) == -1) { - fprintf(stderr, "PianoCanvas::copy() fstat failes:<%s>\n", - strerror(errno)); - fclose(tmp); - return 0; - } - int n = f_stat.st_size; - char* fbuf = (char*)mmap(0, n+1, PROT_READ|PROT_WRITE, - MAP_PRIVATE, fileno(tmp), 0); - fbuf[n] = 0; - Q3TextDrag* drag = new Q3TextDrag(QString(fbuf), parent); - drag->setSubtype("eventlist"); - munmap(fbuf, n); - fclose(tmp); - return drag; - } -*/ - //--------------------------------------------------------- // copy // cut copy paste @@ -1217,68 +1039,6 @@ void PianoCanvas::copy() QApplication::clipboard()->setMimeData(drag, QClipboard::Clipboard); } -/* -//--------------------------------------------------------- -// pasteAt -//--------------------------------------------------------- - -void PianoCanvas::pasteAt(const QString& pt, int pos) - { - QByteArray ba = pt.toLatin1(); - const char* p = ba.constData(); - Xml xml(p); - for (;;) { - Xml::Token token = xml.parse(); - const QString& tag = xml.s1(); - switch (token) { - case Xml::Error: - case Xml::End: - return; - case Xml::TagStart: - if (tag == "eventlist") { - song->startUndo(); - EventList* el = new EventList(); - el->read(xml, "eventlist", true); - int modified = SC_EVENT_INSERTED; - for (iEvent i = el->begin(); i != el->end(); ++i) { - Event e = i->second; - int tick = e.tick() + pos - curPart->tick(); - if (tick<0) { - printf("ERROR: trying to add event before current part!\n"); - song->endUndo(SC_EVENT_INSERTED); - delete el; - return; - } - - e.setTick(tick); - int diff = e.endTick()-curPart->lenTick(); - if (diff > 0) {// too short part? extend it - Part* newPart = curPart->clone(); - newPart->setLenTick(newPart->lenTick()+diff); - // Indicate no undo, and do port controller values but not clone parts. - audio->msgChangePart(curPart, newPart, false, true, false); - modified=modified|SC_PART_MODIFIED; - curPart = newPart; // reassign - } - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgAddEvent(e, curPart, false, false, false); - } - song->endUndo(modified); - delete el; - return; - } - else - xml.unknown("pasteAt"); - break; - case Xml::Attribut: - case Xml::TagEnd: - default: - break; - } - } - } -*/ - //--------------------------------------------------------- // paste // paste events @@ -1286,17 +1046,6 @@ void PianoCanvas::pasteAt(const QString& pt, int pos) void PianoCanvas::paste() { -/* - //Q3CString subtype("eventlist"); ddskrjo - QString subtype("eventlist"); - QMimeSource* ms = QApplication::clipboard()->data(QClipboard::Clipboard); - QString pt; - if (!Q3TextDrag::decode(ms, pt, subtype)) { - printf("cannot paste: bad data type\n"); - return; - } - pasteAt(pt, song->cpos()); -*/ QString stype("x-muse-eventlist"); //QString s = QApplication::clipboard()->text(stype, QClipboard::Selection); @@ -1312,13 +1061,8 @@ void PianoCanvas::paste() void PianoCanvas::startDrag(CItem* /* item*/, bool copymode) { QMimeData* md = getTextDrag(); - //QDrag* drag = getTextDrag(); if (md) { -// QApplication::clipboard()->setData(drag, QClipboard::Clipboard); // This line NOT enabled in muse-1 - //QApplication::clipboard()->setMimeData(md); // TODO CHECK Tim. - //QApplication::clipboard()->setMimeData(drag->mimeData()); // - // "Note that setMimeData() assigns ownership of the QMimeData object to the QDrag object. // The QDrag must be constructed on the heap with a parent QWidget to ensure that Qt can // clean up after the drag and drop operation has been completed. " @@ -1362,41 +1106,6 @@ void PianoCanvas::dragLeaveEvent(QDragLeaveEvent*) //event->acceptProposedAction(); } -/* -//--------------------------------------------------------- -// dropEvent -//--------------------------------------------------------- - -void PianoCanvas::viewDropEvent(QDropEvent* event) - { - QString text; - if (event->source() == this) { - printf("local DROP\n"); - //event->acceptProposedAction(); - //event->ignore(); // TODO CHECK Tim. - return; - } - ///if (Q3TextDrag::decode(event, text)) { - //if (event->mimeData()->hasText()) { - if (event->mimeData()->hasFormat("text/x-muse-eventlist")) { - - //text = event->mimeData()->text(); - text = QString(event->mimeData()->data("text/x-muse-eventlist")); - - int x = editor->rasterVal(event->pos().x()); - if (x < 0) - x = 0; - pasteAt(text, x); - //event->accept(); // TODO - } - else { - printf("cannot decode drop\n"); - //event->acceptProposedAction(); - //event->ignore(); // TODO CHECK Tim. - } - } -*/ - //--------------------------------------------------------- // itemPressed //--------------------------------------------------------- diff --git a/muse2/muse/part.cpp b/muse2/muse/part.cpp index 99f070b2..d9346fbe 100644 --- a/muse2/muse/part.cpp +++ b/muse2/muse/part.cpp @@ -85,9 +85,6 @@ void chainCloneInternal(Part* p) const PartList* pl = mt->cparts(); for(ciPart ip = pl->begin(); ip != pl->end(); ++ip) { - // Added by Tim. p3.3.6 - //printf("chainCloneInternal track %p %s part %p %s evlist %p\n", (*imt), (*imt)->name().toLatin1().constData(), ip->second, ip->second->name().toLatin1().constData(), ip->second->cevents()); - if(ip->second != p && ip->second->cevents() == p->cevents()) { p1 = ip->second; @@ -224,16 +221,9 @@ void replaceClone(Part* p1, Part* p2) else p2->setNextClone(p2); - // Link the replacement... - //p2->setPrevClone(p1->prevClone()); - //p2->setNextClone(p1->nextClone()); - // Isolate the replaced part. p1->setNextClone(p1); p1->setPrevClone(p1); - // Added by Tim. p3.3.6 - //printf("replaceClone p1: %s %p arefs:%d p2: %s %p arefs:%d\n", p1->name().toLatin1().constData(), p1, ); - } //--------------------------------------------------------- @@ -278,9 +268,6 @@ void chainTrackParts(Track* t, bool incRefCount) if(incRefCount) p->events()->incARef(1); - // Added by Tim. p3.3.6 - //printf("chainTrackParts track %p %s part %p %s evlist %p\n", t, t->name().toLatin1().constData(), p, p->name().toLatin1().constData(), p->cevents()); - Part* p1 = 0; // Look for a part with the same event list, that we can chain to. @@ -296,9 +283,6 @@ void chainTrackParts(Track* t, bool incRefCount) const PartList* pl = mt->cparts(); for(ciPart ip = pl->begin(); ip != pl->end(); ++ip) { - // Added by Tim. p3.3.6 - //printf("chainTrackParts track %p %s part %p %s evlist %p\n", mt, mt->name().toLatin1().constData(), ip->second, ip->second->name().toLatin1().constData(), ip->second->cevents()); - if(ip->second != p && ip->second->cevents() == p->cevents()) { p1 = ip->second; @@ -381,21 +365,12 @@ void addPortCtrlEvents(Event& event, Part* part, bool doClones) //for(int i = 0; i < j; ++i) while(1) { - // Added by Tim. p3.3.6 - //printf("addPortCtrlEvents i:%d %s %p events %p refs:%d arefs:%d\n", i, p->name().toLatin1().constData(), p, part->cevents(), part->cevents()->refCount(), j); - Track* t = p->track(); if(t && t->isMidiTrack()) { MidiTrack* mt = (MidiTrack*)t; int port = mt->outPort(); - //const EventList* el = p->cevents(); unsigned len = p->lenTick(); - //for(ciEvent ie = el->begin(); ie != el->end(); ++ie) - //{ - //const Event& ev = ie->second; - // Added by Tim. p3.3.6 - //printf("addPortCtrlEvents %s len:%d end:%d etick:%d\n", p->name().toLatin1().constData(), p->lenTick(), p->endTick(), event.tick()); // Do not add events which are past the end of the part. if(event.tick() >= len) @@ -425,7 +400,6 @@ void addPortCtrlEvents(Event& event, Part* part, bool doClones) mp->setControllerVal(ch, tck, cntrl, val, p); } - //} } if(!doClones) @@ -456,9 +430,6 @@ void addPortCtrlEvents(Part* part, bool doClones) //for(int i = 0; i < j; ++i) while(1) { - // Added by Tim. p3.3.6 - //printf("addPortCtrlEvents i:%d %s %p events %p refs:%d arefs:%d\n", i, p->name().toLatin1().constData(), p, part->cevents(), part->cevents()->refCount(), j); - Track* t = p->track(); if(t && t->isMidiTrack()) { @@ -532,16 +503,6 @@ void removePortCtrlEvents(Event& event, Part* part, bool doClones) { MidiTrack* mt = (MidiTrack*)t; int port = mt->outPort(); - //const EventList* el = p->cevents(); - //unsigned len = p->lenTick(); - //for(ciEvent ie = el->begin(); ie != el->end(); ++ie) - //{ - //const Event& ev = ie->second; - // Added by T356. Do not remove events which are past the end of the part. - // No, actually, do remove ALL of them belonging to the part. - // Just in case there are stray values left after the part end. - //if(ev.tick() >= len) - // break; if(event.type() == Controller) { @@ -566,7 +527,6 @@ void removePortCtrlEvents(Event& event, Part* part, bool doClones) mp->deleteController(ch, tck, cntrl, p); } - //} } if(!doClones) @@ -734,14 +694,6 @@ MidiPart::MidiPart(const MidiPart& p) : Part(p) { _prevClone = this; _nextClone = this; - //setSn(newSn()); - //_sn = p._sn; - //_name = p._name; - //_selected = p._selected; - //_mute = p._mute; - //_colorIndex = p._colorIndex; - //_track = p._track; - //_events = p._events; } //--------------------------------------------------------- @@ -769,14 +721,6 @@ WavePart::WavePart(const WavePart& p) : Part(p) { _prevClone = this; _nextClone = this; - //setSn(newSn()); - //_sn = p._sn; - //_name = p._name; - //_selected = p._selected; - //_mute = p._mute; - //_colorIndex = p._colorIndex; - //_track = p._track; - //_events = p._events; } //--------------------------------------------------------- @@ -790,139 +734,6 @@ Part::~Part() delete _events; } -/* -//--------------------------------------------------------- -// unchainClone -//--------------------------------------------------------- - -void Part::unchainClone() -{ - chainCheckErr(); - - _prevClone->setNextClone(_nextClone); - _nextClone->setPrevClone(_prevClone); - - _prevClone = this; - _nextClone = this; -} - -//--------------------------------------------------------- -// chainClone -// The quick way - if part to chain to is known... -//--------------------------------------------------------- - -void Part::chainClone(const Part* p) -{ - chainCheckErr(); - - // Make sure the part is unchained first. - p->prevClone()->setNextClone(p->nextClone()); - p->nextClone()->setPrevClone(p->prevClone()); - - p->setPrevClone(this); - p->setNextClone(_nextClone->prevClone()); - - _nextClone->setPrevClone(p); - _nextClone = (Part*)p; -} - -//--------------------------------------------------------- -// chainClone -// The slow way - if part to chain to is not known... -//--------------------------------------------------------- - -void Part::chainClone() -{ - chainCheckErr(); - - // Look for a part with the same event list, that we can chain to... - Part* p = 0; - if(!_track || (_track && _track->isMidiTrack())) - { - MidiTrackList* mtl = song->midis(); - for(ciMidiTrack imt = mtl->begin(); imt != mtl->end(); ++imt) - { - const PartList* pl = (*imt)->cparts(); - for(ciPart ip = pl->begin(); ip != pl->end(); ++ip) - { - if(ip->second != this && ip->second->events() == _events) - { - p = ip->second; - break; - } - } - } - } - - if((!p && !_track) || (_track && _track->type() == Track::WAVE)) - { - WaveTrackList* wtl = song->waves(); - for(ciWaveTrack iwt = wtl->begin(); iwt != wtl->end(); ++iwt) - { - const PartList* pl = (*iwt)->cparts(); - for(ciPart ip = pl->begin(); ip != pl->end(); ++ip) - { - if(ip->second != this && ip->second->events() == _events) - { - p = ip->second; - break; - } - } - } - } - - // No part found with same event list? Done. - if(!p) - return; - - // Make sure this part is unchained first. - _prevClone->setNextClone(_nextClone); - _nextClone->setPrevClone(_prevClone); - - _prevClone = p; - _nextClone = p->nextClone(); - - p->nextClone()->setPrevClone(this); - p->setNextClone(this); -} - -//--------------------------------------------------------- -// replaceClone -//--------------------------------------------------------- - -void Part::replaceClone(const Part* p) -{ - chainCheckErr(); - - // Make sure the part is unchained first. - p->prevClone()->setNextClone(p->nextClone()); - p->nextClone()->setPrevClone(p->prevClone()); - - // If this part is a clone, not a single lone part... - if(_prevClone != this) - _prevClone->setNextClone(p); - if(_nextClone != this) - _nextClone->setPrevClone(p); - - p->setPrevClone(_prevClone); - p->setNextClone(_nextClone); - - _nextClone = this; - _prevClone = this; -} - -//--------------------------------------------------------- -// chainCheckErr -//--------------------------------------------------------- - -void Part::chainCheckErr() -{ - if(_nextClone->prevClone() != this) - printf("Part::chainCheckErr Error! Next clone:%s %x prev clone:%s %x != this:%s %x\n", _nextClone->name().toLatin1().constData(), _nextClone, _nextClone->prevClone()->name().toLatin1().constData(), _nextClone->prevClone(), name().toLatin1().constData(), this); - if(_prevClone->nextClone() != this) - printf("Part::chainCheckErr Error! Prev clone:%s %x next clone:%s %x != this:%s %x\n", _prevClone->name().toLatin1().constData(), _prevClone, _prevClone->nextClone()->name().toLatin1().constData(), _prevClone->nextClone(), name().toLatin1().constData(), this); -} -*/ //--------------------------------------------------------- // findPart @@ -988,7 +799,6 @@ void Song::addPart(Part* part) _len = epos; part->track()->addPart(part); - //part->addPortCtrlEvents(); // Indicate do not do clones. addPortCtrlEvents(part, false); } @@ -999,9 +809,7 @@ void Song::addPart(Part* part) void Song::removePart(Part* part) { - //part->removePortCtrlEvents(); // Indicate do not do clones. - //removePortCtrlEvents(part); removePortCtrlEvents(part, false); Track* track = part->track(); track->parts()->remove(part); @@ -1124,28 +932,6 @@ void Song::cmdResizePart(Track* track, Part* oPart, unsigned int len) } } - /* - // cut Events in nPart - // Changed by T356. Don't delete events if this is a clone part. - // The other clones might be longer than this one and need these events. - if(oPart->cevents()->arefCount() <= 1) - { - if (oPart->lenTick() > len) { - EventList* el = nPart->events(); - iEvent ie = el->lower_bound(len); - for (; ie != el->end();) { - iEvent i = ie; - ++ie; - // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgDeleteEvent(i->second, nPart, false); - audio->msgDeleteEvent(i->second, nPart, false, false, false); - } - } - } - // Indicate no undo, and do port controller values but not clone parts. - //audio->msgChangePart(oPart, nPart, false); - audio->msgChangePart(oPart, nPart, false, true, false); - */ endUndo(SC_PART_MODIFIED); break; @@ -1281,27 +1067,9 @@ void Song::changePart(Part* oPart, Part* nPart) Track* oTrack = oPart->track(); Track* nTrack = nPart->track(); - // Added by Tim. p3.3.6 - //printf("Song::changePart before oPart->removePortCtrlEvents oldPart refs:%d Arefs:%d newPart refs:%d Arefs:%d\n", oPart->events()->refCount(), oPart->events()->arefCount(), nPart->events()->refCount(), nPart->events()->arefCount()); - - // Removed. Port controller events will have to be add/removed separately from this routine. - //oPart->removePortCtrlEvents(); - //removePortCtrlEvents(oPart); - - // Added by Tim. p3.3.6 - //printf("Song::changePart after oPart->removePortCtrlEvents oldPart refs:%d Arefs:%d newPart refs:%d Arefs:%d\n", oPart->events()->refCount(), oPart->events()->arefCount(), nPart->events()->refCount(), nPart->events()->arefCount()); - oTrack->parts()->remove(oPart); nTrack->parts()->add(nPart); - // Added by Tim. p3.3.6 - //printf("Song::changePart after add(nPart) oldPart refs:%d Arefs:%d newPart refs:%d Arefs:%d\n", oPart->events()->refCount(), oPart->events()->arefCount(), nPart->events()->refCount(), nPart->events()->arefCount()); - - //nPart->addPortCtrlEvents(); - //addPortCtrlEvents(nPart); - - // Added by Tim. p3.3.6 - //printf("Song::changePart after nPart->addPortCtrlEvents() oldPart refs:%d Arefs:%d newPart refs:%d Arefs:%d\n", oPart->events()->refCount(), oPart->events()->arefCount(), nPart->events()->refCount(), nPart->events()->arefCount()); // Added by T356. // adjust song len: @@ -1309,9 +1077,6 @@ void Song::changePart(Part* oPart, Part* nPart) if (epos > len()) _len = epos; - // Added by Tim. p3.3.6 - //printf("Song::changePart after len adjust oldPart refs:%d Arefs:%d newPart refs:%d Arefs:%d\n", oPart->events()->refCount(), oPart->events()->arefCount(), nPart->events()->refCount(), nPart->events()->arefCount()); - } //--------------------------------------------------------- @@ -1350,13 +1115,6 @@ void Song::cmdGluePart(Track* track, Part* oPart) EventList* sl2 = nextPart->events(); - //int frameOffset = nextPart->frame() - oPart->frame(); - //for (iEvent ie = sl2->begin(); ie != sl2->end(); ++ie) { - // Event event = ie->second.clone(); - // event.setFrame(event.frame() + frameOffset); - // dl->add(event); - // } - // p3.3.54 Changed. if(track->type() == Track::WAVE) { int frameOffset = nextPart->frame() - oPart->frame(); @@ -1382,7 +1140,6 @@ void Song::cmdGluePart(Track* track, Part* oPart) startUndo(); audio->msgRemovePart(nextPart, false); // Indicate no undo, and do port controller values but not clone parts. - //audio->msgChangePart(oPart, nPart, false); audio->msgChangePart(oPart, nPart, false, true, false); endUndo(SC_PART_MODIFIED | SC_PART_REMOVED); } -- cgit v1.2.3 From 8fbfa07b464210054a177b1e92f47b5f2744d1cc Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 22 May 2011 13:26:40 +0000 Subject: moving events in canvases and reordering the drum map have been speeded up by using operation groups. HOWEVER: there might be bugs, in fact, i may even have messed up the whole thing! use with CAUTION and TEST intensively! --- muse2/muse/arranger/pcanvas.cpp | 165 ++++++++++++--------------------------- muse2/muse/arranger/pcanvas.h | 10 +-- muse2/muse/midiedit/dcanvas.cpp | 56 +++++-------- muse2/muse/midiedit/dcanvas.h | 6 +- muse2/muse/midiedit/ecanvas.cpp | 45 ++++++++--- muse2/muse/midiedit/ecanvas.h | 9 +-- muse2/muse/midiedit/prcanvas.cpp | 94 ++++++++-------------- muse2/muse/midiedit/prcanvas.h | 6 +- muse2/muse/part.cpp | 2 +- muse2/muse/undo.cpp | 6 +- muse2/muse/undo.h | 1 + muse2/muse/widgets/canvas.cpp | 50 ------------ muse2/muse/widgets/canvas.h | 11 +-- 13 files changed, 156 insertions(+), 305 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index ed52cc03..006b9333 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -299,21 +299,12 @@ void PartCanvas::viewMouseDoubleClickEvent(QMouseEvent* event) } //--------------------------------------------------------- -// startUndo +// update //--------------------------------------------------------- -void PartCanvas::startUndo(DragType) +void PartCanvas::updateSong(DragType t, int flags) { - song->startUndo(); - } - -//--------------------------------------------------------- -// endUndo -//--------------------------------------------------------- - -void PartCanvas::endUndo(DragType t, int flags) - { - song->endUndo(flags | ((t == MOVE_COPY || t == MOVE_CLONE) + song->update(flags | ((t == MOVE_COPY || t == MOVE_CLONE) ? SC_PART_INSERTED : SC_PART_MODIFIED)); } @@ -323,101 +314,6 @@ void PartCanvas::endUndo(DragType t, int flags) void PartCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype, int*) { - /* - if(editor->parts()->empty()) - return; - - //struct p2c - //{ - // Part* newp; - // int xdiff; - //} - - //std::set parts2change; - //typedef std::set::iterator iptc; - std::map parts2change; - typedef std::map::iterator iP2C; - - int modified = 0; - for(iPart ip = editor->parts()->begin(); ip != editor->parts()->end(); ++ip) - { - Part* part = ip->second; - if(!part) - continue; - - int npartoffset = 0; - for(iCItem ici = items.begin(); ici != items.end(); ++ici) - { - CItem* ci = ici->second; - //Part* pt = ci->part(); - //if(!pt) - if(ci->part() != part) - continue; - - int x = ci->pos().x() + dx; - int y = pitch2y(y2pitch(ci->pos().y()) + dp); - QPoint newpos = raster(QPoint(x, y)); - - // Test moving the item... - - //int offset = testMoveItem(ci, newpos, dragtype); - NEvent* nevent = (NEvent*) ci; - Event event = nevent->event(); - //int npitch = y2pitch(newpos.y()); - x = newpos.x(); - if (x < 0) - x = 0; - - int ntick = editor->rasterVal(x) - part->tick(); - if (ntick < 0) - ntick = 0; - int diff = ntick + event.lenTick() - part->lenTick(); - - // If moving the item would require a new part size... - if(diff > npartoffset) - npartoffset = diff; - } - - if(npartoffset > 0) - { - // Create new part... - // if there are several events that are moved outside the part, it will be recreated for each - // so the part _in_ the event will not be valid, ask the authority. - Part* newPart = part->clone(); - //Part* newPart = Canvas::part()->clone(); - - newPart->setLenTick(newPart->lenTick() + npartoffset); - audio->msgChangePart(part, newPart,false); - - modified = SC_PART_MODIFIED; - - // BUG FIX: #1650953 - // Added by T356. - // Fixes posted "select and drag past end of part - crashing" bug - for(iPart ip = editor->parts()->begin(); ip != editor->parts()->end(); ++ip) - { - if(ip->second == part) - { - editor->parts()->erase(ip); - break; - } - } - - editor->parts()->add(newPart); - if(parts2change.find(part) == parts2change.end()) - parts2change.insert(std::pair (part, newPart)); - -// part = newPart; // reassign -// item->setPart(part); -// item->setEvent(newEvent); -// curPart = part; -// curPartId = curPart->sn(); - - } - } -*/ - -// int modified = 0; for(iCItem ici = items.begin(); ici != items.end(); ++ici) { CItem* ci = ici->second; @@ -435,18 +331,15 @@ void PartCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp QPoint newpos = raster(QPoint(nx, ny)); selectItem(ci, true); - if(moveItem(ci, newpos, dtype)) - ci->move(newpos); + if (moveItem(ci, newpos, dtype)) + ci->move(newpos); + if(moving.size() == 1) { itemReleased(curItem, newpos); } if(dtype == MOVE_COPY || dtype == MOVE_CLONE) selectItem(ci, false); } - - - //if(pflags) - // *pflags = modified; } //--------------------------------------------------------- @@ -455,9 +348,9 @@ void PartCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp //--------------------------------------------------------- // Changed by T356. -//bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t, int*) bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) { + UndoOp result; NPart* npart = (NPart*) item; Part* spart = npart->part(); Track* track = npart->track(); @@ -465,7 +358,7 @@ bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) unsigned ntrack = y2pitch(item->mp().y()); Track::TrackType type = track->type(); if (tracks->index(track) == ntrack && (dtick == spart->tick())) { - return false; + return false; //FINDMICH } if (ntrack >= tracks->size()) { ntrack = tracks->size(); @@ -483,7 +376,7 @@ bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) if (dtrack->type() != type) { QMessageBox::critical(this, QString("MusE"), tr("Cannot copy/move/clone to different Track-Type")); - return false; + return false; //FINDMICH } Part* dpart; @@ -552,7 +445,8 @@ bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) if (song->len() < (dpart->lenTick() + dpart->tick())) song->setLen(dpart->lenTick() + dpart->tick()); //endUndo(t); - return true; + return true; //FINDMICH + //TODO FINDMICH returns nothing... should be fixed (flo93) } //--------------------------------------------------------- @@ -3608,3 +3502,40 @@ double PartCanvas::valToDb(double inV) { return exp10((inV*70.0-60.0)/20.0); } + +//--------------------------------------------------------- +// endMoveItems +// dir = 0 move in all directions +// 1 move only horizontal +// 2 move only vertical +//--------------------------------------------------------- + +void PartCanvas::endMoveItems(const QPoint& pos, DragType dragtype, int dir) + { + song->startUndo(); + + int dp = y2pitch(pos.y()) - y2pitch(start.y()); + int dx = pos.x() - start.x(); + + if (dir == 1) + dp = 0; + else if (dir == 2) + dx = 0; + + + + int modified = 0; + + moveCanvasItems(moving, dp, dx, dragtype, &modified); + + if (dragtype == MOVE_COPY || dragtype == MOVE_CLONE) + modified|=SC_PART_INSERTED; + else + modified|=SC_PART_MODIFIED; + + song->endUndo(modified); + moving.clear(); + updateSelection(); + redraw(); + } + diff --git a/muse2/muse/arranger/pcanvas.h b/muse2/muse/arranger/pcanvas.h index a3dd7900..e48af2d4 100644 --- a/muse2/muse/arranger/pcanvas.h +++ b/muse2/muse/arranger/pcanvas.h @@ -83,15 +83,14 @@ class PartCanvas : public Canvas { virtual int y2pitch(int y) const; virtual int pitch2y(int p) const; - virtual void moveCanvasItems(CItemList&, int, int, DragType, int*); - virtual bool moveItem(CItem*, const QPoint&, DragType); virtual CItem* newItem(const QPoint&, int); virtual void resizeItem(CItem*,bool); virtual void newItem(CItem*,bool); virtual bool deleteItem(CItem*); - virtual void startUndo(DragType); - - virtual void endUndo(DragType, int); + virtual void moveCanvasItems(CItemList&, int, int, DragType, int*); + virtual bool moveItem(CItem*, const QPoint&, DragType); + + virtual void updateSong(DragType, int); virtual void startDrag(CItem*, DragType); virtual void dragEnterEvent(QDragEnterEvent*); virtual void dragMoveEvent(QDragMoveEvent*); @@ -126,6 +125,7 @@ class PartCanvas : public Canvas { protected: virtual void drawCanvas(QPainter&, const QRect&); + virtual void endMoveItems(const QPoint&, DragType, int dir); signals: void timeChanged(unsigned); diff --git a/muse2/muse/midiedit/dcanvas.cpp b/muse2/muse/midiedit/dcanvas.cpp index a7e33bd1..a61b5001 100644 --- a/muse2/muse/midiedit/dcanvas.cpp +++ b/muse2/muse/midiedit/dcanvas.cpp @@ -95,12 +95,13 @@ DrumCanvas::DrumCanvas(MidiEditor* pr, QWidget* parent, int sx, // moveCanvasItems //--------------------------------------------------------- -void DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype, int* pflags) +Undo DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype, int* pflags) { if(editor->parts()->empty()) - return; + return Undo(); //return empty list PartsToChangeMap parts2change; + Undo operations; int modified = 0; for(iPart ip = editor->parts()->begin(); ip != editor->parts()->end(); ++ip) @@ -173,8 +174,8 @@ void DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp } editor->parts()->add(newPart); - // Indicate no undo, and do port controller values but not clone parts. - audio->msgChangePart(opart, newPart, false, true, false); + // Do port controller values but not clone parts. + operations.push_back(UndoOp(UndoOp::ModifyPart, opart, newPart, true, false)); ip2c->second.npart = newPart; @@ -214,20 +215,12 @@ void DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp break; // Do not process if the event has already been processed (meaning it's an event in a clone part)... - if(idl != doneList.end()) - // Just move the canvas item. - ci->move(newpos); - else + if (idl == doneList.end()) { - // Currently moveItem always returns true. - if(moveItem(ci, newpos, dtype)) - { - // Add the canvas item to the list of done items. - doneList.push_back(ci); - // Move the canvas item. - ci->move(newpos); - } + operations.push_back(moveItem(ci, newpos, dtype)); + doneList.push_back(ci); } + ci->move(newpos); if(moving.size() == 1) { itemReleased(curItem, newpos); @@ -238,13 +231,15 @@ void DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp if(pflags) *pflags = modified; + + return operations; } //--------------------------------------------------------- // moveItem //--------------------------------------------------------- -bool DrumCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype) +UndoOp DrumCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype) { DEvent* nevent = (DEvent*) item; @@ -271,16 +266,10 @@ bool DrumCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype) if(((int)newEvent.endTick() - (int)part->lenTick()) > 0) printf("DrumCanvas::moveItem Error! New event end:%d exceeds length:%d of part:%s\n", newEvent.endTick(), part->lenTick(), part->name().toLatin1().constData()); - if (dtype == MOVE_COPY || dtype == MOVE_CLONE) { - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgAddEvent(newEvent, part, false, false, false); - } - else { - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgChangeEvent(event, newEvent, part, false, false, false); - } - - return true; + if (dtype == MOVE_COPY || dtype == MOVE_CLONE) + return UndoOp(UndoOp::AddEvent, newEvent, part, false, false); + else + return UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false); } //--------------------------------------------------------- @@ -387,7 +376,6 @@ void DrumCanvas::newItem(CItem* item, bool noSnap, bool replace) // Indicate no undo, and do not do port controller values and clone parts. audio->msgAddEvent(event, part, false, false, false); song->endUndo(modified); - } //--------------------------------------------------------- @@ -836,7 +824,8 @@ void DrumCanvas::mapChanged(int spitch, int dpitch) // If start/stopundo is there, undo misbehaves since it doesn't undo but messes things up // Other solution: implement a specific undo-event for this (SC_DRUMMAP_MODIFIED or something) which undoes movement of // dlist-items (ml) - + + Undo operations; std::vector< std::pair > delete_events; std::vector< std::pair > add_events; @@ -891,12 +880,10 @@ void DrumCanvas::mapChanged(int spitch, int dpitch) } } - song->startUndo(); for (idel_ev i = delete_events.begin(); i != delete_events.end(); i++) { Part* thePart = (*i).first; Event* theEvent = (*i).second; - // Indicate no undo, and do port controller values but not clone parts. - audio->msgDeleteEvent(*theEvent, thePart, false, true, false); + operations.push_back(UndoOp(UndoOp::DeleteEvent, *theEvent, thePart, true, false)); } DrumMap dm = drumMap[spitch]; @@ -910,11 +897,10 @@ void DrumCanvas::mapChanged(int spitch, int dpitch) for (iadd_ev i = add_events.begin(); i != add_events.end(); i++) { Part* thePart = (*i).first; Event& theEvent = (*i).second; - // Indicate no undo, and do port controller values but not clone parts. - audio->msgAddEvent(theEvent, thePart, false, true, false); + operations.push_back(UndoOp(UndoOp::AddEvent, theEvent, thePart, true, false)); } - song->endUndo(SC_EVENT_MODIFIED); + song->applyOperationGroup(operations); song->update(SC_DRUMMAP); } diff --git a/muse2/muse/midiedit/dcanvas.h b/muse2/muse/midiedit/dcanvas.h index b86bc2d7..748dd74f 100644 --- a/muse2/muse/midiedit/dcanvas.h +++ b/muse2/muse/midiedit/dcanvas.h @@ -50,10 +50,8 @@ class DrumCanvas : public EventCanvas { virtual void drawItem(QPainter&, const CItem*, const QRect&); void drawTopItem(QPainter& p, const QRect& rect); virtual void drawMoving(QPainter&, const CItem*, const QRect&); - virtual void moveCanvasItems(CItemList&, int, int, DragType, int*); - // Changed by T356. - //virtual bool moveItem(CItem*, const QPoint&, DragType, int*); - virtual bool moveItem(CItem*, const QPoint&, DragType); + virtual Undo moveCanvasItems(CItemList&, int, int, DragType, int*); + virtual UndoOp moveItem(CItem*, const QPoint&, DragType); virtual CItem* newItem(const QPoint&, int); virtual void resizeItem(CItem*, bool); virtual void newItem(CItem*, bool); diff --git a/muse2/muse/midiedit/ecanvas.cpp b/muse2/muse/midiedit/ecanvas.cpp index 7a421411..e084c212 100644 --- a/muse2/muse/midiedit/ecanvas.cpp +++ b/muse2/muse/midiedit/ecanvas.cpp @@ -101,21 +101,12 @@ QPoint EventCanvas::raster(const QPoint& p) const } //--------------------------------------------------------- -// startUndo +// update //--------------------------------------------------------- -void EventCanvas::startUndo(DragType) +void EventCanvas::updateSong(DragType dtype, int flags) { - song->startUndo(); - } - -//--------------------------------------------------------- -// endUndo -//--------------------------------------------------------- - -void EventCanvas::endUndo(DragType dtype, int flags) - { - song->endUndo(flags | ((dtype == MOVE_COPY || dtype == MOVE_CLONE) + song->update(flags | ((dtype == MOVE_COPY || dtype == MOVE_CLONE) ? SC_EVENT_INSERTED : SC_EVENT_MODIFIED)); } @@ -545,3 +536,33 @@ void EventCanvas::viewDropEvent(QDropEvent* event) } } + +//--------------------------------------------------------- +// endMoveItems +// dir = 0 move in all directions +// 1 move only horizontal +// 2 move only vertical +//--------------------------------------------------------- + +void EventCanvas::endMoveItems(const QPoint& pos, DragType dragtype, int dir) + { + int dp = y2pitch(pos.y()) - y2pitch(Canvas::start.y()); + int dx = pos.x() - Canvas::start.x(); + + if (dir == 1) + dp = 0; + else if (dir == 2) + dx = 0; + + + + int modified = 0; + + Undo operations = moveCanvasItems(moving, dp, dx, dragtype, &modified); + song->applyOperationGroup(operations); + updateSong(dragtype, modified); + + moving.clear(); + updateSelection(); + redraw(); + } diff --git a/muse2/muse/midiedit/ecanvas.h b/muse2/muse/midiedit/ecanvas.h index 86e1c200..23875598 100644 --- a/muse2/muse/midiedit/ecanvas.h +++ b/muse2/muse/midiedit/ecanvas.h @@ -38,12 +38,7 @@ class EventCanvas : public Canvas { Q_OBJECT virtual void leaveEvent(QEvent*e); virtual void enterEvent(QEvent*e); - // Removed by T356. - //virtual QPoint raster(const QPoint&) const; - virtual void startUndo(DragType); - - virtual void endUndo(DragType, int flags = 0); virtual void mouseMove(QMouseEvent* event); protected: @@ -58,6 +53,10 @@ class EventCanvas : public Canvas { virtual void addItem(Part*, Event&) = 0; // Added by T356. virtual QPoint raster(const QPoint&) const; + virtual Undo moveCanvasItems(CItemList&, int, int, DragType, int*) = 0; + virtual UndoOp moveItem(CItem*, const QPoint&, DragType) = 0; + virtual void endMoveItems(const QPoint&, DragType, int dir); + virtual void updateSong(DragType, int flags = 0); public slots: void redrawGrid() { redraw(); } diff --git a/muse2/muse/midiedit/prcanvas.cpp b/muse2/muse/midiedit/prcanvas.cpp index a38e0ee1..6845bd12 100644 --- a/muse2/muse/midiedit/prcanvas.cpp +++ b/muse2/muse/midiedit/prcanvas.cpp @@ -34,6 +34,7 @@ #include "cmd.h" #include "song.h" #include "audio.h" +#include "functions.h" #define CHORD_TIMEOUT 75 @@ -257,11 +258,12 @@ void PianoCanvas::viewMouseDoubleClickEvent(QMouseEvent* event) // moveCanvasItems //--------------------------------------------------------- -void PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype, int* pflags) +Undo PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype, int* pflags) { if(editor->parts()->empty()) - return; - + return Undo(); //return empty list + + Undo operations; PartsToChangeMap parts2change; int modified = 0; @@ -335,8 +337,8 @@ void PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dty } editor->parts()->add(newPart); - // Indicate no undo, and do port controller values but not clone parts. - audio->msgChangePart(opart, newPart, false, true, false); + // Do port controller values but not clone parts. + operations.push_back(UndoOp(UndoOp::ModifyPart, opart, newPart, true, false)); ip2c->second.npart = newPart; @@ -352,6 +354,7 @@ void PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dty std::vector< CItem* > doneList; typedef std::vector< CItem* >::iterator iDoneList; + for(iCItem ici = items.begin(); ici != items.end(); ++ici) { CItem* ci = ici->second; @@ -376,21 +379,12 @@ void PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dty break; // Do not process if the event has already been processed (meaning it's an event in a clone part)... - //if(moveItem(ci, newpos, dtype)) - if(idl != doneList.end()) - // Just move the canvas item. - ci->move(newpos); - else + if (idl == doneList.end()) { - // Currently moveItem always returns true. - if(moveItem(ci, newpos, dtype)) - { - // Add the canvas item to the list of done items. - doneList.push_back(ci); - // Move the canvas item. - ci->move(newpos); - } + operations.push_back(moveItem(ci, newpos, dtype)); + doneList.push_back(ci); } + ci->move(newpos); if(moving.size() == 1) itemReleased(curItem, newpos); @@ -400,6 +394,8 @@ void PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dty if(pflags) *pflags = modified; + + return operations; } //--------------------------------------------------------- @@ -407,9 +403,7 @@ void PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dty // called after moving an object //--------------------------------------------------------- -// Changed by T356. -//bool PianoCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype, int* pflags) -bool PianoCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype) +UndoOp PianoCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype) { NEvent* nevent = (NEvent*) item; Event event = nevent->event(); @@ -430,7 +424,7 @@ bool PianoCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype) // Changed by T356. Part* part = nevent->part(); // - //Part * part = Canvas::part(); // part can be dynamically recreated, ask the authority + //Part* part = Canvas::part(); // part can be dynamically recreated, ask the authority newEvent.setPitch(npitch); int ntick = editor->rasterVal(x) - part->tick(); @@ -446,12 +440,9 @@ bool PianoCanvas::moveItem(CItem* item, const QPoint& pos, DragType dtype) printf("PianoCanvas::moveItem Error! New event end:%d exceeds length:%d of part:%s\n", newEvent.endTick(), part->lenTick(), part->name().toLatin1().constData()); if (dtype == MOVE_COPY || dtype == MOVE_CLONE) - audio->msgAddEvent(newEvent, part, false, false, false); + return UndoOp(UndoOp::AddEvent, newEvent, part, false, false); else - audio->msgChangeEvent(event, newEvent, part, false, false, false); - //song->endUndo(modified); - - return true; + return UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false); } //--------------------------------------------------------- @@ -509,7 +500,6 @@ void PianoCanvas::newItem(CItem* item, bool noSnap) part = newPart; // reassign } // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgAddEvent(event, part,false); audio->msgAddEvent(event, part, false, false, false); song->endUndo(modified); } @@ -623,8 +613,9 @@ void PianoCanvas::pianoCmd(int cmd) if (part == 0) break; - song->startUndo(); + EventList* el = part->events(); + Undo operations; std::list elist; for (iEvent e = el->lower_bound(pos[0] - part->tick()); e != el->end(); ++e) @@ -633,10 +624,11 @@ void PianoCanvas::pianoCmd(int cmd) Event event = *i; Event newEvent = event.clone(); newEvent.setTick(event.tick() + editor->raster());// - part->tick()); - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgChangeEvent(event, newEvent, part, false, false, false); + // Do not do port controller values and clone parts. + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false)); } - song->endUndo(SC_EVENT_MODIFIED); + song->applyOperationGroup(operations); + Pos p(editor->rasterVal(pos[0] + editor->rasterStep(pos[0])), true); song->setPos(0, p, true, false, true); } @@ -648,7 +640,8 @@ void PianoCanvas::pianoCmd(int cmd) MidiPart* part = (MidiPart*)curPart; if (part == 0) break; - song->startUndo(); + + Undo operations; EventList* el = part->events(); std::list elist; @@ -658,10 +651,10 @@ void PianoCanvas::pianoCmd(int cmd) Event event = *i; Event newEvent = event.clone(); newEvent.setTick(event.tick() - editor->raster() - part->tick()); - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgChangeEvent(event, newEvent, part, false, false, false); + // Do not do port controller values and clone parts. + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, event, part, false, false)); } - song->endUndo(SC_EVENT_MODIFIED); + song->applyOperationGroup(operations); Pos p(editor->rasterVal(pos[0] - editor->rasterStep(pos[0])), true); song->setPos(0, p, true, false, true); } @@ -811,16 +804,7 @@ void PianoCanvas::cmd(int cmd) switch (cmd) { case CMD_CUT: copy(); - song->startUndo(); - for (iCItem i = items.begin(); i != items.end(); ++i) { - if (!(i->second->isSelected())) - continue; - NEvent* e = (NEvent*)(i->second); - Event ev = e->event(); - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgDeleteEvent(ev, e->part(), false, false, false); - } - song->endUndo(SC_EVENT_REMOVED); + erase_notes(partlist_to_set(editor->parts()),1); //FINDMICH is this correct? or must i do this on current_part? break; case CMD_COPY: copy(); @@ -903,23 +887,7 @@ void PianoCanvas::cmd(int cmd) } break; - case CMD_FIXED_LEN: //Set notes to the length specified in the drummap - if (!selectionSize()) - break; - song->startUndo(); - for (iCItem k = items.begin(); k != items.end(); ++k) { - if (k->second->isSelected()) { - NEvent* nevent = (NEvent*)(k->second); - Event event = nevent->event(); - Event newEvent = event.clone(); - newEvent.setLenTick(editor->raster()); - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgChangeEvent(event, newEvent, nevent->part(), false, false, false); - } - } - song->endUndo(SC_EVENT_MODIFIED); - break; - + case CMD_FIXED_LEN: case CMD_CRESCENDO: case CMD_TRANSPOSE: case CMD_THIN_OUT: diff --git a/muse2/muse/midiedit/prcanvas.h b/muse2/muse/midiedit/prcanvas.h index a04ca514..94827354 100644 --- a/muse2/muse/midiedit/prcanvas.h +++ b/muse2/muse/midiedit/prcanvas.h @@ -49,10 +49,8 @@ class PianoCanvas : public EventCanvas { virtual void drawItem(QPainter&, const CItem*, const QRect&); void drawTopItem(QPainter &p, const QRect &rect); virtual void drawMoving(QPainter&, const CItem*, const QRect&); - virtual void moveCanvasItems(CItemList&, int, int, DragType, int*); - // Changed by T356. - //virtual bool moveItem(CItem*, const QPoint&, DragType, int*); - virtual bool moveItem(CItem*, const QPoint&, DragType); + virtual Undo moveCanvasItems(CItemList&, int, int, DragType, int*); + virtual UndoOp moveItem(CItem*, const QPoint&, DragType); virtual CItem* newItem(const QPoint&, int); virtual void resizeItem(CItem*, bool noSnap); virtual void newItem(CItem*, bool noSnap); diff --git a/muse2/muse/part.cpp b/muse2/muse/part.cpp index d9346fbe..c9459c1f 100644 --- a/muse2/muse/part.cpp +++ b/muse2/muse/part.cpp @@ -927,7 +927,7 @@ void Song::cmdResizePart(Track* track, Part* oPart, unsigned int len) iEvent i = ie; ++ie; // Indicate no undo, and do port controller values and clone parts. - audio->msgDeleteEvent(i->second, nPart, false, true, true); + audio->msgDeleteEvent(i->second, nPart, false, true, true); //FINDMICH } } } diff --git a/muse2/muse/undo.cpp b/muse2/muse/undo.cpp index ea9ea8d6..2b90e26f 100644 --- a/muse2/muse/undo.cpp +++ b/muse2/muse/undo.cpp @@ -203,7 +203,7 @@ void Song::endUndo(int flags) void Song::applyOperationGroup(Undo& group) { - //this is a HACK! but it works :) + //this is a HACK! but it works :) (added by flo93) redoList->push_back(group); redo(); } @@ -698,6 +698,10 @@ void Song::doRedo2() } } +UndoOp::UndoOp() +{ +} + UndoOp::UndoOp(UndoType type_, int a_, int b_, int c_) { type = type_; diff --git a/muse2/muse/undo.h b/muse2/muse/undo.h index b048b9e6..88810b80 100644 --- a/muse2/muse/undo.h +++ b/muse2/muse/undo.h @@ -87,6 +87,7 @@ struct UndoOp { const char* typeName(); void dump(); + UndoOp(); UndoOp(UndoType type, int a, int b, int c=0); UndoOp(UndoType type, int n, Track* oldTrack, Track* newTrack); UndoOp(UndoType type, int n, Track* track); diff --git a/muse2/muse/widgets/canvas.cpp b/muse2/muse/widgets/canvas.cpp index 18de985b..fc0b1b6f 100644 --- a/muse2/muse/widgets/canvas.cpp +++ b/muse2/muse/widgets/canvas.cpp @@ -1210,56 +1210,6 @@ void Canvas::selectLasso(bool toggle) } } -//--------------------------------------------------------- -// endMoveItems -// dir = 0 move in all directions -// 1 move only horizontal -// 2 move only vertical -//--------------------------------------------------------- - -void Canvas::endMoveItems(const QPoint& pos, DragType dragtype, int dir) - { - startUndo(dragtype); - - int dp = y2pitch(pos.y()) - y2pitch(start.y()); - int dx = pos.x() - start.x(); - - if (dir == 1) - dp = 0; - else if (dir == 2) - dx = 0; - - - - int modified = 0; - - // Removed by T356. - /* - for (iCItem i = moving.begin(); i != moving.end(); ++i) { - int x = i->second->pos().x(); - int y = i->second->pos().y(); - int nx = x + dx; - int ny = pitch2y(y2pitch(y) + dp); - QPoint newpos = raster(QPoint(nx, ny)); - selectItem(i->second, true); - - if (moveItem(i->second, newpos, dragtype, &modified)) - i->second->move(newpos); - if (moving.size() == 1) { - itemReleased(curItem, newpos); - } - if (dragtype == MOVE_COPY || dragtype == MOVE_CLONE) - selectItem(i->second, false); - } - */ - - moveCanvasItems(moving, dp, dx, dragtype, &modified); - - endUndo(dragtype, modified); - moving.clear(); - updateSelection(); - redraw(); - } //--------------------------------------------------------- // getCurrentDrag diff --git a/muse2/muse/widgets/canvas.h b/muse2/muse/widgets/canvas.h index 6e8b9fa8..5037bf37 100644 --- a/muse2/muse/widgets/canvas.h +++ b/muse2/muse/widgets/canvas.h @@ -11,6 +11,7 @@ #include "citem.h" #include "view.h" #include "tools.h" +#include "undo.h" #include #include @@ -100,17 +101,11 @@ class Canvas : public View { virtual int y2pitch(int) const = 0; //CDW virtual int pitch2y(int) const = 0; //CDW - virtual void moveCanvasItems(CItemList&, int, int, DragType, int*) = 0; - // Changed by T356. - //virtual bool moveItem(CItem*, const QPoint&, DragType, int*) = 0; - virtual bool moveItem(CItem*, const QPoint&, DragType) = 0; virtual CItem* newItem(const QPoint&, int state) = 0; virtual void resizeItem(CItem*, bool noSnap=false) = 0; virtual void newItem(CItem*, bool noSnap=false) = 0; virtual bool deleteItem(CItem*) = 0; - virtual void startUndo(DragType) = 0; - - virtual void endUndo(DragType, int flags) = 0; + virtual void updateSong(DragType, int flags) = 0; int getCurrentDrag(); /*! @@ -153,7 +148,7 @@ class Canvas : public View { void startMoving(const QPoint&, DragType); void moveItems(const QPoint&, int dir, bool rasterize = true); - void endMoveItems(const QPoint&, DragType, int dir); + virtual void endMoveItems(const QPoint&, DragType, int dir) = 0; virtual void selectLasso(bool toggle); -- cgit v1.2.3 From def4fdb391f5207ebbe61881416f39f3d896cc5d Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 22 May 2011 13:29:19 +0000 Subject: - speeded up pasting, shrinking parts, drawing controllers in the ctrlcanvas and reordering the drum list - applyOperationGroup() now doesn't apply empty opGroups any more - reordering the drum list doesn't cause undo be triggered any more - removed unneccessary song->update() calls after a song->applyOperationGroup() call - cleaned up (removed some commented out code blocks) --- muse2/muse/ctrl/ctrlcanvas.cpp | 399 +++----------------------------------- muse2/muse/midiedit/dcanvas.cpp | 19 +- muse2/muse/midiedit/dcanvas.h | 2 +- muse2/muse/midiedit/ecanvas.cpp | 28 +-- muse2/muse/midiedit/ecanvas.h | 3 +- muse2/muse/midiedit/prcanvas.cpp | 8 +- muse2/muse/midiedit/prcanvas.h | 2 +- muse2/muse/midiedit/scoreedit.cpp | 8 - muse2/muse/part.cpp | 48 ++--- muse2/muse/song.h | 2 +- muse2/muse/undo.cpp | 19 +- muse2/muse/widgets/canvas.h | 1 - 12 files changed, 77 insertions(+), 462 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/ctrl/ctrlcanvas.cpp b/muse2/muse/ctrl/ctrlcanvas.cpp index f2f335cf..d1d6b2fa 100644 --- a/muse2/muse/ctrl/ctrlcanvas.cpp +++ b/muse2/muse/ctrl/ctrlcanvas.cpp @@ -545,14 +545,6 @@ void CtrlCanvas::partControllers(const MidiPart* part, int num, int* dnum, int* } *mcvl = tmcvl; - // Removed by T356. - // MidiCtrlValList not found is now an acceptable state (for multiple part editing). - //if (i == cvll->end()) { - // printf("CtrlCanvas::setController(0x%x): not found\n", num); - // for (i = cvll->begin(); i != cvll->end(); ++i) - // printf(" 0x%x\n", i->second->num()); - // return; - // } } } } @@ -566,98 +558,9 @@ void CtrlCanvas::updateItems() selection.clear(); items.clearDelete(); - /* - if(ctrl) - { - for(ciMidiCtrlVal imcv = ctrl->begin(); imcv != ctrl->end(); ++imcv) - { - MidiPart* part = (MidiPart*)imcv->part; - int val = imcv->val; - - bool edpart = false; - if(editor->parts()->index(part) != -1) - edpart = true; - - MidiController* mc; - MidiCtrlValList* mcvl; - partControllers(part, _cnum, 0, 0, &mc, &mcvl); - - Event e(Controller); - - if(_cnum == CTRL_VELOCITY && e.type() == Note) - { - items.add(new CEvent(e, part, e.velo())); - - } - - } - } - */ - - /* - MidiTrackList* mtl = song->midis(); - for(ciMidiTrack imt = mtl->begin(); imt != mtl->end(); ++imt) - { - //MidiTrack* mt = *imt; - PartList* pl = (*imt)->parts(); - for(ciPart p = pl->begin(); p != pl->end(); ++p) - { - MidiPart* part = (MidiPart*)(p->second); - - bool edpart = false; - if(editor->parts()->index(part) != -1) - edpart = true; - - EventList* el = part->events(); - MidiController* mc; - MidiCtrlValList* mcvl; - partControllers(part, _cnum, 0, 0, &mc, &mcvl); - - for(iEvent i = el->begin(); i != el->end(); ++i) - { - Event e = i->second; - if(_cnum == CTRL_VELOCITY && e.type() == Note) - { - if(curDrumInstrument == -1) - { - items.add(new CEvent(e, part, e.velo())); - } - else if (e.dataA() == curDrumInstrument) //same note - items.add(new CEvent(e, part, e.velo())); - } - else if (e.type() == Controller && e.dataA() == _didx) - { - if(mcvl && last.empty()) - { - Event le(Controller); - //le.setType(Controller); - le.setA(_didx); - //le.setB(e.dataB()); - le.setB(CTRL_VAL_UNKNOWN); - //lastce = new CEvent(Event(), part, mcvl->value(part->tick(), part)); - //lastce = new CEvent(le, part, mcvl->value(part->tick(), part)); - lastce = new CEvent(le, part, mcvl->value(part->tick())); - items.add(lastce); - } - if (lastce) - lastce->setEX(e.tick()); - lastce = new CEvent(e, part, e.dataB()); - items.add(lastce); - last = e; - } - } - } - } - */ - - - - if(!editor->parts()->empty()) { - //Event last; - //CEvent* lastce = 0; CEvent *newev = 0; for (iPart p = editor->parts()->begin(); p != editor->parts()->end(); ++p) @@ -790,7 +693,6 @@ void CtrlCanvas::viewMousePressEvent(QMouseEvent* event) } if(do_redraw) redraw(); // Let songChanged handle the redraw upon SC_SELECTION. - //song->update(SC_SELECTION); // } @@ -947,11 +849,8 @@ void CtrlCanvas::viewMouseReleaseEvent(QMouseEvent* event) } } drag = DRAG_OFF; - //if(do_redraw) - // redraw(); // Let songChanged handle the redraw upon SC_SELECTION. + // Let songChanged handle the redraw upon SC_SELECTION. song->update(SC_SELECTION); // - //else - // redraw(); } break; @@ -995,7 +894,7 @@ void CtrlCanvas::newValRamp(int x1, int y1, int x2, int y2) useRaster = true; } - song->startUndo(); + Undo operations; // delete existing events @@ -1003,44 +902,29 @@ void CtrlCanvas::newValRamp(int x1, int y1, int x2, int y2) int lastpv = CTRL_VAL_UNKNOWN; for (ciCEvent i = items.begin(); i != items.end(); ++i) { CEvent* ev = *i; - if(ev->part() != curPart) + if (ev->part() != curPart) continue; Event event = ev->event(); if (event.empty()) continue; int x = event.tick() + curPartTick; - //printf("CtrlCanvas::newValRamp x:%d xx1:%d xx2:%d len:%d\n", x, xx1, xx2, curPart->lenTick()); if (x < xx1) - { - // if(event.dataB() != CTRL_VAL_UNKNOWN) - // lastpv = event.dataB(); continue; - } - //if (x <= xx1) - //{ - // if(type == CTRL_PROGRAM && event.dataB() != CTRL_VAL_UNKNOWN && ((event.dataB() & 0xffffff) != 0xffffff)) - // lastpv = event.dataB(); - // if (x < xx1) - // continue; - //} + if (x >= xx2) break; - // Indicate no undo, and do port controller values and clone parts. - audio->msgDeleteEvent(event, curPart, false, true, true); + // Do port controller values and clone parts. + operations.push_back(UndoOp(UndoOp::DeleteEvent, event, curPart, true, true)); } - //if(type == CTRL_PROGRAM && lastpv == CTRL_VAL_UNKNOWN) - if(ctrl) + if (ctrl) lastpv = ctrl->hwVal(); unsigned curPartLen = curPart->lenTick(); // insert new events - //for (int x = xx1; x < xx2; x += raster) { - // int y = (x2==x1) ? y1 : (((y2-y1)*(x-x1))/(x2-x1))+y1; - // int nval = computeVal(_controller, y, height()); for (int x = xx1, step; x < xx2 ; x += step ) { step = useRaster ? raster : editor->rasterVal2(x + 1) - x; @@ -1048,21 +932,18 @@ void CtrlCanvas::newValRamp(int x1, int y1, int x2, int y2) int y = x + step >= xx2 || x2 == x1 ? y2 : (x == xx1 ? y1 : (((y2 - y1) * (x + step/2 - x1)) / (x2 - x1)) + y1); int nval = computeVal(_controller, y, height()); - //int tick = x - curPartTick; unsigned tick = x - curPartTick; - //printf("CtrlCanvas::newValRamp x:%d xx1:%d xx2:%d step:%d newtick:%d\n", x, xx1, xx2, step, tick); // Do not add events which are past the end of the part. - //if((unsigned)tick >= curPartLen) - if(tick >= curPartLen) + if (tick >= curPartLen) break; Event event(Controller); event.setTick(tick); event.setA(_didx); - if(type == CTRL_PROGRAM) + if (type == CTRL_PROGRAM) { - if(lastpv == CTRL_VAL_UNKNOWN) + if (lastpv == CTRL_VAL_UNKNOWN) { - if(song->mtype() == MT_GM) + if (song->mtype() == MT_GM) event.setB(0xffff00 | (nval - 1)); else event.setB(nval - 1); @@ -1073,13 +954,11 @@ void CtrlCanvas::newValRamp(int x1, int y1, int x2, int y2) else event.setB(nval); - // Indicate no undo, and do port controller values and clone parts. - audio->msgAddEvent(event, curPart, false, true, true); + // Do port controller values and clone parts. + operations.push_back(UndoOp(UndoOp::AddEvent, event, curPart, true, true)); } - ///song->update(0); - ///redraw(); - song->endUndo(SC_EVENT_MODIFIED | SC_EVENT_INSERTED | SC_EVENT_REMOVED); + song->applyOperationGroup(operations); } //--------------------------------------------------------- @@ -1091,27 +970,24 @@ void CtrlCanvas::changeValRamp(int x1, int y1, int x2, int y2) int h = height(); bool changed = false; int type = _controller->num(); - //int xx1 = editor->rasterVal1(x1); - song->startUndo(); + Undo operations; for (ciCEvent i = items.begin(); i != items.end(); ++i) { if ((*i)->contains(x1, x2)) { - //if ((*i)->contains(xx1, x2)) { CEvent* ev = *i; - if(ev->part() != curPart) + if (ev->part() != curPart) continue; + Event event = ev->event(); if (event.empty()) continue; - //MidiPart* part = ev->part(); - //int x = event.tick() + ev->part()->tick(); int x = event.tick() + curPart->tick(); int y = (x2==x1) ? y1 : (((y2-y1)*(x-x1))/(x2-x1))+y1; int nval = computeVal(_controller, y, h); - if(type == CTRL_PROGRAM) + if (type == CTRL_PROGRAM) { - if(event.dataB() == CTRL_VAL_UNKNOWN) + if (event.dataB() == CTRL_VAL_UNKNOWN) { --nval; if(song->mtype() == MT_GM) @@ -1123,16 +999,13 @@ void CtrlCanvas::changeValRamp(int x1, int y1, int x2, int y2) ev->setVal(nval); - //MidiController::ControllerType type = midiControllerType(_controller->num()); - //if (type == MidiController::Velo) { if (type == CTRL_VELOCITY) { if ((event.velo() != nval)) { Event newEvent = event.clone(); newEvent.setVelo(nval); ev->setEvent(newEvent); - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgChangeEvent(event, newEvent, curPart, false, false, false); - ///ev->setEvent(newEvent); + // Do not do port controller values and clone parts. + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, event, curPart, false, false)); changed = true; } } @@ -1142,34 +1015,16 @@ void CtrlCanvas::changeValRamp(int x1, int y1, int x2, int y2) Event newEvent = event.clone(); newEvent.setB(nval); ev->setEvent(newEvent); - // Indicate no undo, and do port controller values and clone parts. - audio->msgChangeEvent(event, newEvent, curPart, false, true, true); - ///ev->setEvent(newEvent); + // Do port controller values and clone parts. + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, event, curPart, true, true)); changed = true; } } - else { - //if(!ctrl) - //{ - // ctrl = - //} - - // Removed by T356. Never gets here? A good thing, don't wan't auto-create values. - //int oval = ctrl->value(0); - //if (oval != nval) { - // Changed by T356. - //ctrl->add(0, nval); - // ctrl->add(0, nval, part); - // changed = true; - // } - - } } } } - ///if (changed) - /// redraw(); - song->endUndo(SC_EVENT_MODIFIED); + + song->applyOperationGroup(operations); } //--------------------------------------------------------- @@ -1181,7 +1036,6 @@ void CtrlCanvas::changeVal(int x1, int x2, int y) bool changed = false; int newval = computeVal(_controller, y, height()); int type = _controller->num(); - //int xx1 = editor->rasterVal1(x1); for (ciCEvent i = items.begin(); i != items.end(); ++i) { if (!(*i)->contains(x1, x2)) @@ -1191,26 +1045,7 @@ void CtrlCanvas::changeVal(int x1, int x2, int y) if(ev->part() != curPart) continue; Event event = ev->event(); - //if(event.tick() >= curPart->lenTick()) - // break; - - //MidiPart* part = ev->part(); - //int nval = newval; - //if(type == CTRL_PROGRAM) - //{ - // if(event.dataB() == CTRL_VAL_UNKNOWN) - // { - // --nval; - // if(song->mtype() == MT_GM) - // nval |= 0xffff00; - // } - // else - // nval = (event.dataB() & 0xffff00) | (nval - 1); - //} - //ev->setVal(nval); - - //MidiController::ControllerType type = midiControllerType(_controller->num()); - //if (type == MidiController::Velo) { + if (type == CTRL_VELOCITY) { if ((event.velo() != newval)) { ev->setVal(newval); @@ -1249,160 +1084,12 @@ void CtrlCanvas::changeVal(int x1, int x2, int y) changed = true; } } - else { - //if(!ctrl) - //{ - // ctrl = - //} - - // Removed by T356. Never gets here? A good thing, don't wan't auto-create values. - //int oval = ctrl->value(0); - //if (oval != nval) { - // Changed by T356. - //ctrl->add(0, nval); - // ctrl->add(0, nval, part); - // changed = true; - // } - } } } if (changed) redraw(); } -/* -//--------------------------------------------------------- -// newVal -//--------------------------------------------------------- - -void CtrlCanvas::newVal(int x1, int x2, int y) - { - int xx1 = editor->rasterVal1(x1); - int xx2 = editor->rasterVal2(x2); - int newval = computeVal(_controller, y, height()); - int type = _controller->num(); - - bool found = false; - bool song_changed = false; - - int lastpv = CTRL_VAL_UNKNOWN; - if(ctrl) - lastpv = ctrl->hwVal(); - - for (ciCEvent i = items.begin(); i != items.end(); ++i) { - CEvent* ev = *i; - if(ev->part() != curPart) - continue; - //int partTick = ev->part()->tick(); - int partTick = curPart->tick(); - Event event = ev->event(); - if (event.empty()) - continue; - int ax = event.tick() + partTick; - //printf("CtrlCanvas::newVal ax:%d xx1:%d xx2:%d len:%d\n", ax, xx1, xx2, curPart->lenTick()); - - if (ax < xx1) - continue; - //if(ax <= xx1) - //{ - // if(type == CTRL_PROGRAM && event.dataB() != CTRL_VAL_UNKNOWN && ((event.dataB() & 0xffffff) != 0xffffff)) - // lastpv = event.dataB(); - // if(ax < xx1) - // continue; - //} - if (ax >= xx2) - break; - - // Added by T356. Do not add events which are past the end of the part. - //if(event.tick() >= curPart->lenTick()) - // break; - - int nval = newval; - if(type == CTRL_PROGRAM) - { - if(event.dataB() == CTRL_VAL_UNKNOWN) - { - //if(lastpv == CTRL_VAL_UNKNOWN) - // lastpv = ctrl->hwVal(); - - if(lastpv == CTRL_VAL_UNKNOWN) - { - --nval; - if(song->mtype() == MT_GM) - nval |= 0xffff00; - } - else - nval = (lastpv & 0xffff00) | (nval - 1); - } - else - nval = (event.dataB() & 0xffff00) | (nval - 1); - } - - if (ax == xx1) { - // change event - found = true; - ev->setVal(nval); - if ((event.dataB() != nval)) { - Event newEvent = event.clone(); - newEvent.setB(nval); - // Indicate no undo, and do port controller values and clone parts. - audio->msgChangeEvent(event, newEvent, curPart, false, true, true); - ev->setEvent(newEvent); - song_changed = true; - } - } - else if (ax < xx2) { - // delete event - - //printf("CtrlCanvas::newVal delete xx1:%d xx2:%d len:%d\n", xx1, xx2, curPart->lenTick()); - - // Indicate no undo, and do port controller values and clone parts. - audio->msgDeleteEvent(event, curPart, false, true, true); - - song_changed = true; - } - } - if (!found) { - // new event - int tick = xx1 - curPart->tick(); - // Do not add events which are past the end of the part. - if((unsigned)tick < curPart->lenTick()) - { - Event event(Controller); - event.setTick(tick); - event.setA(_didx); - if(type == CTRL_PROGRAM) - { - if(lastpv == CTRL_VAL_UNKNOWN) - { - if(song->mtype() == MT_GM) - event.setB(0xffff00 | (newval - 1)); - else - event.setB(newval - 1); - } - else - event.setB((lastpv & 0xffff00) | (newval - 1)); - } - else - event.setB(newval); - - //printf("CtrlCanvas::newVal add tick:%d A:%d B:%d\n", tick, event.dataA(), event.dataB()); - - // Indicate no undo, and do port controller values and clone parts. - audio->msgAddEvent(event, curPart, false, true, true); - - song_changed = true; - } - } - if (song_changed) - { - songChanged(0); - return; - } - redraw(); - } -*/ - //--------------------------------------------------------- // newVal //--------------------------------------------------------- @@ -1607,10 +1294,7 @@ void CtrlCanvas::newVal(int x1, int y) } } - //if(do_selchanged) - // song->update(SC_SELECTION); // Let songChanged handle the redraw upon SC_SELECTION. - //else - if(do_redraw) // + if(do_redraw) // Let songChanged handle the redraw upon SC_SELECTION. redraw(); } @@ -1637,12 +1321,8 @@ void CtrlCanvas::newVal(int x1, int y1, int x2, int y2) // So I draw from the first x. (TODO The idea may work now since I wrote this - more work was done.) p4.0.18 Tim. int xx1 = editor->rasterVal1(x1); - // Grab the 'second' raster. Nudge by +1 and let rasterVal2 snap to the next raster. - //int xn1 = editor->rasterVal2(xx1 + 1); int xx2 = editor->rasterVal2(x2); - // Grab the 'second last' raster. Nudge by -1 and let rasterVal1 snap to the previous raster. - //int xn2 = editor->rasterVal1(xx2 - 1); // If x1 and x2 happen to lie directly on the same raster, xx1 will equal xx2, // which is not good - there should always be a spread. Nudge by +1 and recompute. @@ -1661,7 +1341,6 @@ void CtrlCanvas::newVal(int x1, int y1, int x2, int y2) } bool do_redraw = false; - //bool do_selchanged = false; // delete existing events @@ -1671,7 +1350,6 @@ void CtrlCanvas::newVal(int x1, int y1, int x2, int y2) bool curPartFound = false; int lastpv = CTRL_VAL_UNKNOWN; int partTick = curPart->tick(); - //for (ciCEvent i = items.begin(); i != items.end(); ++i) for (iCEvent i = items.begin(); i != items.end() ; ) { CEvent* ev = *i; @@ -1701,10 +1379,7 @@ void CtrlCanvas::newVal(int x1, int y1, int x2, int y2) //printf("CtrlCanvas::newVal x:%d xx1:%d xx2:%d len:%d\n", x, xx1, xx2, curPart->lenTick()); if (x < xx1) - //if (x < (xn1 >= xx2 ? xx1 : xn1)) { - // if(event.dataB() != CTRL_VAL_UNKNOWN) - // lastpv = event.dataB(); prev_ev = i; ++i; continue; @@ -1739,24 +1414,14 @@ void CtrlCanvas::newVal(int x1, int y1, int x2, int y2) } do_redraw = true; // Let songChanged handle the redraw upon SC_SELECTION. - //do_selchanged = true; // prev_ev = i; } - //if(type == CTRL_PROGRAM && lastpv == CTRL_VAL_UNKNOWN) if(ctrl) lastpv = ctrl->hwVal(); // insert new events - //for (int x = xx1; x < xx2; x += raster) { - // Nudge x by +1 and let rasterVal2 snap to the next raster. - //for (int x = xx1; x < xx2; x = useRaster ? x + raster : editor->rasterVal2(x + 1)) - //for (int x = xn1; x < xx2; x = useRaster ? x + raster : editor->rasterVal2(x + 1)) - //for (int x = xn1, step; x < xx2 ; x += (step = useRaster ? raster : editor->rasterVal2(x + 1) - x) ) - // Start from the 'second' raster - the first raster is already set in mouseDown! - //for (int x = xn1, step; x < xx2 ; x += step ) - //for (int x = xn1 >= xx2 ? xx1 : xn1, step; x < xx2 ; x += step ) for (int x = xx1, step; x < xx2 ; x += step ) { step = useRaster ? raster : editor->rasterVal2(x + 1) - x; @@ -1808,9 +1473,6 @@ void CtrlCanvas::newVal(int x1, int y1, int x2, int y2) do_redraw = true; } - //if(do_selchanged) - // song->update(SC_SELECTION); // Let songChanged handle the redraw upon SC_SELECTION. - //else if(do_redraw) // redraw(); } @@ -1841,10 +1503,8 @@ void CtrlCanvas::deleteVal(int x1, int x2, int) iCEvent prev_ev = items.end(); bool curPartFound = false; - //bool song_changed = false; bool do_redraw = false; - //for (ciCEvent i = items.begin(); i != items.end(); ++i) for (iCEvent i = items.begin(); i != items.end() ;) { CEvent* ev = *i; @@ -1895,13 +1555,8 @@ void CtrlCanvas::deleteVal(int x1, int x2, int) prev_ev = i; } - //if (song_changed) { - // songChanged(0); - // return; - // } if(do_redraw) redraw(); // Let songChanged handle the redraw upon SC_SELECTION. - //song->update(SC_SELECTION); // } //--------------------------------------------------------- diff --git a/muse2/muse/midiedit/dcanvas.cpp b/muse2/muse/midiedit/dcanvas.cpp index a61b5001..61e98aea 100644 --- a/muse2/muse/midiedit/dcanvas.cpp +++ b/muse2/muse/midiedit/dcanvas.cpp @@ -95,7 +95,7 @@ DrumCanvas::DrumCanvas(MidiEditor* pr, QWidget* parent, int sx, // moveCanvasItems //--------------------------------------------------------- -Undo DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype, int* pflags) +Undo DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype) { if(editor->parts()->empty()) return Undo(); //return empty list @@ -103,7 +103,6 @@ Undo DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp PartsToChangeMap parts2change; Undo operations; - int modified = 0; for(iPart ip = editor->parts()->begin(); ip != editor->parts()->end(); ++ip) { Part* part = ip->second; @@ -159,8 +158,6 @@ Undo DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp newPart->setLenTick(newPart->lenTick() + diff); - modified = SC_PART_MODIFIED; - // BUG FIX: #1650953 // Added by T356. // Fixes posted "select and drag past end of part - crashing" bug @@ -229,9 +226,6 @@ Undo DrumCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp selectItem(ci, false); } - if(pflags) - *pflags = modified; - return operations; } @@ -818,13 +812,6 @@ void DrumCanvas::keyReleased(int index, bool) void DrumCanvas::mapChanged(int spitch, int dpitch) { - //TODO: Circumvent undo behaviour, since this isn't really a true change of the events, - // but merely a change in pitch because the pitch relates to the order of the dlist. - // Right now the sequencer spits out internalError: undoOp without startUndo() if start/stopundo is there, which is misleading - // If start/stopundo is there, undo misbehaves since it doesn't undo but messes things up - // Other solution: implement a specific undo-event for this (SC_DRUMMAP_MODIFIED or something) which undoes movement of - // dlist-items (ml) - Undo operations; std::vector< std::pair > delete_events; std::vector< std::pair > add_events; @@ -900,8 +887,8 @@ void DrumCanvas::mapChanged(int spitch, int dpitch) operations.push_back(UndoOp(UndoOp::AddEvent, theEvent, thePart, true, false)); } - song->applyOperationGroup(operations); - song->update(SC_DRUMMAP); + song->applyOperationGroup(operations, false); // do not indicate undo + song->update(SC_DRUMMAP); //this update is neccessary, as it's not handled by applyOperationGroup() } //--------------------------------------------------------- diff --git a/muse2/muse/midiedit/dcanvas.h b/muse2/muse/midiedit/dcanvas.h index 748dd74f..cc3b8fff 100644 --- a/muse2/muse/midiedit/dcanvas.h +++ b/muse2/muse/midiedit/dcanvas.h @@ -50,7 +50,7 @@ class DrumCanvas : public EventCanvas { virtual void drawItem(QPainter&, const CItem*, const QRect&); void drawTopItem(QPainter& p, const QRect& rect); virtual void drawMoving(QPainter&, const CItem*, const QRect&); - virtual Undo moveCanvasItems(CItemList&, int, int, DragType, int*); + virtual Undo moveCanvasItems(CItemList&, int, int, DragType); virtual UndoOp moveItem(CItem*, const QPoint&, DragType); virtual CItem* newItem(const QPoint&, int); virtual void resizeItem(CItem*, bool); diff --git a/muse2/muse/midiedit/ecanvas.cpp b/muse2/muse/midiedit/ecanvas.cpp index e084c212..9ce84147 100644 --- a/muse2/muse/midiedit/ecanvas.cpp +++ b/muse2/muse/midiedit/ecanvas.cpp @@ -100,16 +100,6 @@ QPoint EventCanvas::raster(const QPoint& p) const return QPoint(x, y); } -//--------------------------------------------------------- -// update -//--------------------------------------------------------- - -void EventCanvas::updateSong(DragType dtype, int flags) - { - song->update(flags | ((dtype == MOVE_COPY || dtype == MOVE_CLONE) - ? SC_EVENT_INSERTED : SC_EVENT_MODIFIED)); - } - //--------------------------------------------------------- // mouseMove //--------------------------------------------------------- @@ -465,7 +455,7 @@ void EventCanvas::pasteAt(const QString& pt, int pos) return; case Xml::TagStart: if (tag == "eventlist") { - song->startUndo(); + Undo operations; EventList* el = new EventList(); el->read(xml, "eventlist", true); int modified = SC_EVENT_INSERTED; @@ -474,7 +464,6 @@ void EventCanvas::pasteAt(const QString& pt, int pos) int tick = e.tick() + pos - curPart->tick(); if (tick<0) { printf("ERROR: trying to add event before current part!\n"); - song->endUndo(SC_EVENT_INSERTED); delete el; return; } @@ -484,15 +473,15 @@ void EventCanvas::pasteAt(const QString& pt, int pos) if (diff > 0) {// too short part? extend it Part* newPart = curPart->clone(); newPart->setLenTick(newPart->lenTick()+diff); - // Indicate no undo, and do port controller values but not clone parts. - audio->msgChangePart(curPart, newPart, false, true, false); + // Do port controller values but not clone parts. + operations.push_back(UndoOp(UndoOp::ModifyPart, curPart, newPart, true, false)); modified=modified|SC_PART_MODIFIED; curPart = newPart; // reassign } - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgAddEvent(e, curPart, false, false, false); + // Do not do port controller values and clone parts. + operations.push_back(UndoOp(UndoOp::AddEvent, e, curPart, false, false)); } - song->endUndo(modified); + song->applyOperationGroup(operations); delete el; return; } @@ -556,11 +545,8 @@ void EventCanvas::endMoveItems(const QPoint& pos, DragType dragtype, int dir) - int modified = 0; - - Undo operations = moveCanvasItems(moving, dp, dx, dragtype, &modified); + Undo operations = moveCanvasItems(moving, dp, dx, dragtype); song->applyOperationGroup(operations); - updateSong(dragtype, modified); moving.clear(); updateSelection(); diff --git a/muse2/muse/midiedit/ecanvas.h b/muse2/muse/midiedit/ecanvas.h index 23875598..b3275607 100644 --- a/muse2/muse/midiedit/ecanvas.h +++ b/muse2/muse/midiedit/ecanvas.h @@ -53,10 +53,9 @@ class EventCanvas : public Canvas { virtual void addItem(Part*, Event&) = 0; // Added by T356. virtual QPoint raster(const QPoint&) const; - virtual Undo moveCanvasItems(CItemList&, int, int, DragType, int*) = 0; + virtual Undo moveCanvasItems(CItemList&, int, int, DragType) = 0; virtual UndoOp moveItem(CItem*, const QPoint&, DragType) = 0; virtual void endMoveItems(const QPoint&, DragType, int dir); - virtual void updateSong(DragType, int flags = 0); public slots: void redrawGrid() { redraw(); } diff --git a/muse2/muse/midiedit/prcanvas.cpp b/muse2/muse/midiedit/prcanvas.cpp index 6845bd12..05fe8252 100644 --- a/muse2/muse/midiedit/prcanvas.cpp +++ b/muse2/muse/midiedit/prcanvas.cpp @@ -258,7 +258,7 @@ void PianoCanvas::viewMouseDoubleClickEvent(QMouseEvent* event) // moveCanvasItems //--------------------------------------------------------- -Undo PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype, int* pflags) +Undo PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype) { if(editor->parts()->empty()) return Undo(); //return empty list @@ -266,7 +266,6 @@ Undo PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dty Undo operations; PartsToChangeMap parts2change; - int modified = 0; for(iPart ip = editor->parts()->begin(); ip != editor->parts()->end(); ++ip) { Part* part = ip->second; @@ -322,8 +321,6 @@ Undo PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dty newPart->setLenTick(newPart->lenTick() + diff); - modified = SC_PART_MODIFIED; - // BUG FIX: #1650953 // Added by T356. // Fixes posted "select and drag past end of part - crashing" bug @@ -392,9 +389,6 @@ Undo PianoCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dty selectItem(ci, false); } - if(pflags) - *pflags = modified; - return operations; } diff --git a/muse2/muse/midiedit/prcanvas.h b/muse2/muse/midiedit/prcanvas.h index 94827354..7c77b229 100644 --- a/muse2/muse/midiedit/prcanvas.h +++ b/muse2/muse/midiedit/prcanvas.h @@ -49,7 +49,7 @@ class PianoCanvas : public EventCanvas { virtual void drawItem(QPainter&, const CItem*, const QRect&); void drawTopItem(QPainter &p, const QRect &rect); virtual void drawMoving(QPainter&, const CItem*, const QRect&); - virtual Undo moveCanvasItems(CItemList&, int, int, DragType, int*); + virtual Undo moveCanvasItems(CItemList&, int, int, DragType); virtual UndoOp moveItem(CItem*, const QPoint&, DragType); virtual CItem* newItem(const QPoint&, int); virtual void resizeItem(CItem*, bool noSnap); diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp index b60b6dbd..7f7382f4 100644 --- a/muse2/muse/midiedit/scoreedit.cpp +++ b/muse2/muse/midiedit/scoreedit.cpp @@ -4221,12 +4221,6 @@ void staff_t::apply_lasso(QRect rect, set& already_processed) * o rename stuff: UndoOp -> Operation, Undo -> OpList, * UndoType -> OpType, iUndoOp, riUndoOp -> iOperation, * undo.cpp/.h -> operations.cpp/.h - * o resizing a part is slow, because events get erased - * o drag'n'drop in canvases is slow - * o drawing controller lines is slow - * o cut,copy'n'paste is slow - * o reordering drum list is dead slow - * o reordering drum list creates unneccessary, actually wrong undo entry * * * o drum list: scroll while dragging @@ -4241,8 +4235,6 @@ void staff_t::apply_lasso(QRect rect, set& already_processed) * o legato: extend length to next note * o delete: add velo and len threshold * o thin out: remove unneeded ctrl messages - * o in drum roll: changing the list causes undo to be triggered, WTF? - * o changing list is dead slow * * less important stuff * o controller view in score editor diff --git a/muse2/muse/part.cpp b/muse2/muse/part.cpp index c9459c1f..231b947b 100644 --- a/muse2/muse/part.cpp +++ b/muse2/muse/part.cpp @@ -833,7 +833,7 @@ void Song::cmdResizePart(Track* track, Part* oPart, unsigned int len) // - 0 or more events are beginning after the new final position. Those are removed from the part // - The last event begins before new final position and ends after it. If so, it will be resized to end at new part length if (new_partlength < oPart->lenFrame()) { - startUndo(); + Undo operations; for (iEvent i = el->begin(); i != el->end(); i++) { Event e = i->second; @@ -843,31 +843,30 @@ void Song::cmdResizePart(Track* track, Part* oPart, unsigned int len) if (event_endframe < new_partlength) continue; if (event_startframe > new_partlength) { // If event start was after the new length, remove it from part - // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgDeleteEvent(e, nPart, false); - audio->msgDeleteEvent(e, nPart, false, false, false); + // Do not do port controller values and clone parts. + operations.push_back(UndoOp(UndoOp::DeleteEvent, e, nPart, false, false)); continue; } if (event_endframe > new_partlength) { // If this event starts before new length and ends after, shrink it Event newEvent = e.clone(); newEvent.setLenFrame(new_partlength - event_startframe); - // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgChangeEvent(e, newEvent, nPart, false); + // Do not do port controller values and clone parts. audio->msgChangeEvent(e, newEvent, nPart, false, false, false); + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, e, nPart, false,false)); } } nPart->setLenFrame(new_partlength); - // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgChangePart(oPart, nPart, false); - audio->msgChangePart(oPart, nPart, false, false, false); + // Do not do port controller values and clone parts. + operations.push_back(UndoOp(UndoOp::ModifyPart, oPart, nPart, false, false)); - endUndo(SC_PART_MODIFIED); + song->applyOperationGroup(operations); } // If the part is expanded there can be no additional events beginning after the previous final position // since those are removed if the part has been shrunk at some time (see above) // The only thing we need to check is the final event: If it has data after the previous final position, // we'll expand that event else { + Undo operations; if(!el->empty()) { iEvent i = el->end(); @@ -887,33 +886,27 @@ void Song::cmdResizePart(Track* track, Part* oPart, unsigned int len) new_eventlength = clipframes; newEvent.setLenFrame(new_eventlength); - startUndo(); - // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgChangeEvent(last, newEvent, nPart, false); - audio->msgChangeEvent(last, newEvent, nPart, false, false, false); - } - else - { - startUndo(); + // Do not do port controller values and clone parts. + operations.push_back(UndoOp(UndoOp::ModifyEvent, newEvent, last, nPart, false, false)); } nPart->setLenFrame(new_partlength); - // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgChangePart(oPart, nPart, false); + // Do not do port controller values and clone parts. audio->msgChangePart(oPart, nPart, false, false, false); - endUndo(SC_PART_MODIFIED); + operations.push_back(UndoOp(UndoOp::ModifyPart, oPart, nPart, false, false)); + song->applyOperationGroup(operations); } } break; case Track::MIDI: case Track::DRUM: { - startUndo(); + Undo operations; MidiPart* nPart = new MidiPart(*(MidiPart*)oPart); nPart->setLenTick(len); - // Indicate no undo, and do port controller values but not clone parts. - audio->msgChangePart(oPart, nPart, false, true, false); + // Do port controller values but not clone parts. + operations.push_back(UndoOp(UndoOp::ModifyPart, oPart, nPart, true, false)); // cut Events in nPart // Changed by T356. Don't delete events if this is a clone part. @@ -926,14 +919,13 @@ void Song::cmdResizePart(Track* track, Part* oPart, unsigned int len) for (; ie != el->end();) { iEvent i = ie; ++ie; - // Indicate no undo, and do port controller values and clone parts. - audio->msgDeleteEvent(i->second, nPart, false, true, true); //FINDMICH + // Do port controller values and clone parts. + operations.push_back(UndoOp(UndoOp::DeleteEvent, i->second, nPart, true, true)); } } } - - endUndo(SC_PART_MODIFIED); + song->applyOperationGroup(operations); break; } default: diff --git a/muse2/muse/song.h b/muse2/muse/song.h index cb9d0f9d..17d70833 100644 --- a/muse2/muse/song.h +++ b/muse2/muse/song.h @@ -147,7 +147,7 @@ class Song : public QObject { Song(const char* name = 0); ~Song(); - void applyOperationGroup(Undo& group); + void applyOperationGroup(Undo& group, bool doUndo=true); void putEvent(int pv); void endMsgCmd(); diff --git a/muse2/muse/undo.cpp b/muse2/muse/undo.cpp index 2b90e26f..2a11c3dc 100644 --- a/muse2/muse/undo.cpp +++ b/muse2/muse/undo.cpp @@ -14,6 +14,8 @@ #include "song.h" #include "globals.h" +#include + // iundo points to last Undo() in Undo-list static bool undoMode = false; // for debugging @@ -201,12 +203,21 @@ void Song::endUndo(int flags) } -void Song::applyOperationGroup(Undo& group) +void Song::applyOperationGroup(Undo& group, bool doUndo) +{ + if (!group.empty()) { - //this is a HACK! but it works :) (added by flo93) - redoList->push_back(group); - redo(); + //this is a HACK! but it works :) (added by flo93) + redoList->push_back(group); + redo(); + + if (!doUndo) + { + undoList->pop_back(); + undoAction->setEnabled(!undoList->empty()); + } } +} diff --git a/muse2/muse/widgets/canvas.h b/muse2/muse/widgets/canvas.h index 5037bf37..2eae3d03 100644 --- a/muse2/muse/widgets/canvas.h +++ b/muse2/muse/widgets/canvas.h @@ -105,7 +105,6 @@ class Canvas : public View { virtual void resizeItem(CItem*, bool noSnap=false) = 0; virtual void newItem(CItem*, bool noSnap=false) = 0; virtual bool deleteItem(CItem*) = 0; - virtual void updateSong(DragType, int flags) = 0; int getCurrentDrag(); /*! -- cgit v1.2.3 From 6786200a6243758c0ab6ba5d76ac1f34912788fb Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sat, 4 Jun 2011 16:25:03 +0000 Subject: changed behaviour of middle click in all canvases to "delete" --- muse2/ChangeLog | 4 ++++ muse2/muse/arranger/pcanvas.cpp | 7 ------- muse2/muse/midiedit/scoreedit.cpp | 10 +++++----- muse2/muse/widgets/canvas.cpp | 9 +++------ 4 files changed, 12 insertions(+), 18 deletions(-) (limited to 'muse2') diff --git a/muse2/ChangeLog b/muse2/ChangeLog index 1af47f28..3092040e 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,9 +1,13 @@ +04.06.2011: + - changed behaviour of middle click in all canvases to "delete" (flo93) 02.06.2011: - the score editor now allows batch-movements, that is, you can transpose or move the whole selection and not only single notes (flo93) - the functions now return as boolean, if they have triggered undo (flo93) + - applied another patch from WillyFoobar: moved Q_OBJECT + to the top of each class definition, where it belongs (flo93) 30.05.2011: - implemented cut,copy'n'paste and the "select foo" entries in the score editor (flo93) - added select_foo() functions to functions.cpp (flo93) diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index d65b8957..7b63d9e9 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -214,9 +214,7 @@ void PartCanvas::returnPressed() newPart->setName(lineEditor->text()); // Indicate do undo, and do port controller values but not clone parts. - //audio->msgChangePart(oldPart, newPart); audio->msgChangePart(oldPart, newPart, true, true, false); - //printf("PartCanvas::returnPressed after msgChangePart oldPart refs:%d Arefs:%d newPart refs:%d Arefs:%d\n", oldPart->events()->refCount(), oldPart->events()->arefCount(), newPart->events()->refCount(), newPart->events()->arefCount()); editMode = false; } @@ -429,12 +427,10 @@ bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) if (dtrack->type() == Track::WAVE) { // Indicate no undo, and do not do port controller values and clone parts. - //audio->msgChangePart((WavePart*)spart, (WavePart*)dpart,false); audio->msgChangePart((WavePart*)spart, (WavePart*)dpart, false, false, false); } else { // Indicate no undo, and do port controller values but not clone parts. - //audio->msgChangePart(spart, dpart, false); audio->msgChangePart(spart, dpart, false, true, false); } spart->setSelected(false); @@ -794,10 +790,7 @@ void PartCanvas::itemPopup(CItem* item, int n, const QPoint& pt) } song->startUndo(); // Indicate no undo, and do port controller values but not clone parts. - //audio->msgChangePart(spart, dpart, false); audio->msgChangePart(spart, dpart, false, true, false); - //printf("PartCanvas::itemPopup: #2 spart %s %p next:%s %p prev:%s %p\n", spart->name().toLatin1().constData(), spart, spart->nextClone()->name().toLatin1().constData(), spart->nextClone(), spart->prevClone()->name().toLatin1().constData(), spart->prevClone()); - //printf("PartCanvas::itemPopup: #2 dpart %s %p next:%s %p prev:%s %p\n", dpart->name().toLatin1().constData(), dpart, dpart->nextClone()->name().toLatin1().constData(), dpart->nextClone(), dpart->prevClone()->name().toLatin1().constData(), dpart->prevClone()); song->endUndo(SC_PART_MODIFIED); break; // Has to be break here, right? diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp index 0eb61554..e2b17dd3 100644 --- a/muse2/muse/midiedit/scoreedit.cpp +++ b/muse2/muse/midiedit/scoreedit.cpp @@ -4451,9 +4451,7 @@ void staff_t::update_part_indices() /* BUGS and potential bugs - * o quantize always quantizes length. make this selectable! * o when the keymap is not used, this will probably lead to a bug - * same when mastertrack is disabled * o tied notes don't work properly when there's a key-change in * between, for example, when a cis is tied to a des * @@ -4466,12 +4464,14 @@ void staff_t::update_part_indices() * o controller view in score editor * o deal with expanding parts * o fix sigedit boxes - * o mid-click in pianoroll: change to "delete", or initiate drag and drop between windows? - * - * * o drum list: scroll while dragging + * o remove functions for disabling key/sigmap + * o mastertrack editor: key-combobox is buggy + * o drum editor: channel-stuff * * IMPORTANT TODO + * o solo button + * o grand staff brace * o do partial recalculating; recalculating can take pretty long * (0,5 sec) when displaying a whole song in scores * o transpose etc. must also transpose key-pressure events diff --git a/muse2/muse/widgets/canvas.cpp b/muse2/muse/widgets/canvas.cpp index fc0b1b6f..3e9cb46e 100644 --- a/muse2/muse/widgets/canvas.cpp +++ b/muse2/muse/widgets/canvas.cpp @@ -569,12 +569,9 @@ void Canvas::viewMousePressEvent(QMouseEvent* event) } if (curItem && (event->button() == Qt::MidButton)) { - if (!curItem->isSelected()) { - selectItem(curItem, true); - updateSelection(); - redraw(); - } - startDrag(curItem, ctrl); + deleteItem(start); // changed from "start drag" to "delete" by flo93 + drag = DRAG_DELETE; + setCursor(); } else if (event->button() == Qt::RightButton) { if (curItem) { -- cgit v1.2.3 From e7fa4482decd01231531eae9da73ecbad2b12094 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 5 Jun 2011 09:54:56 +0000 Subject: only cleaned up code (removed commented out and unused code) --- muse2/muse/arranger/pcanvas.cpp | 559 +------------------------------------- muse2/muse/arranger/pcanvas.h | 4 - muse2/muse/midiedit/scoreedit.cpp | 5 +- 3 files changed, 7 insertions(+), 561 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index 7b63d9e9..54f431cc 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -21,7 +21,6 @@ #include #include #include -//#include #include "fastlog.h" #include "widgets/tools.h" @@ -44,55 +43,6 @@ #include "midictrl.h" #include "utils.h" -// Moved into global config by Tim. -/* -const char* partColorNames[] = { - "Default", - "Refrain", - "Bridge", - "Intro", - "Coda", - "Chorus", - "Solo", - "Brass", - "Percussion", - "Drums", - "Guitar", - "Bass", - "Flute", - "Strings", - "Keyboard", - "Piano", - "Saxophon", - }; -*/ - -/* -//--------------------------------------------------------- -// ColorListItem -//--------------------------------------------------------- - -class ColorListItem { //: public QCustomMenuItem { ddskrjo - QColor color; - int h; - int fontheight; - QString label; - virtual QSize sizeHint() { return QSize(80, h); } - virtual void paint(QPainter* p, const QColorGroup&, bool act, bool enabled, int x, int y, int w, int h) - { - p->fillRect(x+5, y+2, h-4, h-4, QBrush(color)); - p->drawText(x+5 + h - 4 + 3, y+(fontheight * 3) / 4, label); - } - - public: - ColorListItem(const QColor& c, int _h, int _fh, const char* txt) - : color(c), h(_h), fontheight(_fh), label(txt) { - } - QString text() const { return QString("PartColor"); } - }; -*/ -// ORCAN : colorRect does the same job as the above class. -// Shall we get rid of the class? //--------------------------------------------------------- // colorRect @@ -119,7 +69,6 @@ NPart::NPart(Part* e) : CItem(Event(), e) { int th = track()->height(); int y = track()->y(); - //printf("NPart::NPart track name:%s, y:%d h:%d\n", track()->name().toLatin1().constData(), y, th); ///setPos(QPoint(e->tick(), y + 1)); setPos(QPoint(e->tick(), y)); @@ -378,8 +327,6 @@ bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) } Part* dpart; - //bool clone = (t == MOVE_CLONE) || (spart->events()->arefCount() > 1); - //bool clone = (t == MOVE_CLONE); bool clone = (t == MOVE_CLONE || (t == MOVE_COPY && spart->events()->arefCount() > 1)); if(t == MOVE_MOVE) @@ -397,11 +344,8 @@ bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) dpart->setTick(dtick); - //printf("PartCanvas::moveItem before add/changePart clone:%d spart:%p events:%p refs:%d Arefs:%d sn:%d dpart:%p events:%p refs:%d Arefs:%d sn:%d\n", clone, spart, spart->events(), spart->events()->refCount(), spart->events()->arefCount(), spart->sn(), dpart, dpart->events(), dpart->events()->refCount(), dpart->events()->arefCount(), dpart->sn()); - if(t == MOVE_MOVE) item->setPart(dpart); - //if (!clone) { if (t == MOVE_COPY && !clone) { // // Copy Events @@ -436,11 +380,10 @@ bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) spart->setSelected(false); } - //printf("PartCanvas::moveItem after add/changePart spart:%p events:%p refs:%d Arefs:%d dpart:%p events:%p refs:%d Arefs:%d\n", spart, spart->events(), spart->events()->refCount(), spart->events()->arefCount(), dpart, dpart->events(), dpart->events()->refCount(), dpart->events()->arefCount()); if (song->len() < (dpart->lenTick() + dpart->tick())) song->setLen(dpart->lenTick() + dpart->tick()); - //endUndo(t); + return true; //FINDMICH //TODO FINDMICH returns nothing... should be fixed (flo93) } @@ -654,11 +597,7 @@ QMenu* PartCanvas::genItemPopup(CItem* item) QMenu* colorPopup = partPopup->addMenu(tr("color")); // part color selection - //const QFontMetrics& fm = colorPopup->fontMetrics(); - //int h = fm.lineSpacing(); - for (int i = 0; i < NUM_PARTCOLORS; ++i) { - //ColorListItem* item = new ColorListItem(config.partColors[i], h, fontMetrics().height(), partColorNames[i]); //ddskrjo QAction *act_color = colorPopup->addAction(colorRect(config.partColors[i], 80, 80), config.partColorNames[i]); act_color->setData(20+i); } @@ -758,28 +697,13 @@ void PartCanvas::itemPopup(CItem* item, int n, const QPoint& pt) break; case 14: // wave edit - { - // Changed to allow multiple selected parts to be shown. By T356 - // Slightly inefficient to add (above), then clear here. - // Should really only add npart->part() to pl only if NOT here. - // Removed. Added wave editor menu item instead. - //pl->clear(); - //PartList* ptl = npart->track()->parts(); - //for(ciPart pi = ptl->begin(); pi != ptl->end(); pi++) - //{ - // if(pi->second->selected()) - // pl->add(pi->second); - //} emit startEditor(pl, 4); - } return; case 15: // declone { Part* spart = npart->part(); Track* track = npart->track(); Part* dpart = track->newPart(spart, false); - //printf("PartCanvas::itemPopup: #1 spart %s %p next:%s %p prev:%s %p\n", spart->name().toLatin1().constData(), spart, spart->nextClone()->name().toLatin1().constData(), spart->nextClone(), spart->prevClone()->name().toLatin1().constData(), spart->prevClone()); - //printf("PartCanvas::itemPopup: #1 dpart %s %p next:%s %p prev:%s %p\n", dpart->name().toLatin1().constData(), dpart, dpart->nextClone()->name().toLatin1().constData(), dpart->nextClone(), dpart->prevClone()->name().toLatin1().constData(), dpart->prevClone()); EventList* se = spart->events(); EventList* de = dpart->events(); @@ -799,13 +723,11 @@ void PartCanvas::itemPopup(CItem* item, int n, const QPoint& pt) { const Part* part = item->part(); bool popenFlag = false; - //QString fn = getSaveFileName(QString(""), part_file_pattern, this, tr("MusE: save part")); QString fn = getSaveFileName(QString(""), part_file_save_pattern, this, tr("MusE: save part")); if (!fn.isEmpty()) { FILE* fp = fileOpen(this, fn, ".mpt", "w", popenFlag, false, false); if (fp) { Xml tmpXml = Xml(fp); - //part->write(0, tmpXml); // Write the part. Indicate that it's a copy operation - to add special markers, // and force full wave paths. part->write(0, tmpXml, true, true); @@ -826,7 +748,6 @@ void PartCanvas::itemPopup(CItem* item, int n, const QPoint& pt) SndFileR f = event.sndFile(); if (f.isNull()) continue; - //str.append("\n" + f.path()); str.append(QString("\n@") + QString().setNum(event.tick()) + QString(" len:") + QString().setNum(event.lenTick()) + QString(" ") + f.path()); } @@ -845,14 +766,11 @@ void PartCanvas::itemPopup(CItem* item, int n, const QPoint& pt) { for(int i = 0; i < j; ++i) { - //printf("PartCanvas::itemPopup i:%d %s %p events %p refs:%d arefs:%d\n", i, p->name().toLatin1().constData(), p, part->cevents(), part->cevents()->refCount(), j); - p->setSelected(true); p = p->nextClone(); if(p == part) break; } - //song->update(); song->update(SC_SELECTION); } @@ -1380,13 +1298,6 @@ void PartCanvas::drawItem(QPainter& p, const CItem* item, const QRect& rect) QRect r = item->bbox(); - //printf("PartCanvas::drawItem %s evRefs:%d pTick:%d pLen:%d\nbb.x:%d bb.y:%d bb.w:%d bb.h:%d\n" - // "rect.x:%d rect.y:%d rect.w:%d rect.h:%d\nr.x:%d r.y:%d r.w:%d r.h:%d\n", - // part->name().toLatin1().constData(), part->events()->arefCount(), pTick, part->lenTick(), - // bb.x(), bb.y(), bb.width(), bb.height(), - // rect.x(), rect.y(), rect.width(), rect.height(), - // r.x(), r.y(), r.width(), r.height()); - int i = part->colorIndex(); p.setPen(Qt::black); if (part->mute()) { @@ -1400,7 +1311,6 @@ void PartCanvas::drawItem(QPainter& p, const CItem* item, const QRect& rect) // NOTE: For one-pixel border use first line For two-pixel border use second. p.drawRect(QRect(r.x(), r.y()-1, r.width(), r.height())); - //p.drawRect(r); return; } @@ -1415,11 +1325,7 @@ void PartCanvas::drawItem(QPainter& p, const CItem* item, const QRect& rect) // NOTE: For one-pixel border use first line. For two-pixel border use second. p.drawRect(QRect(r.x(), r.y()-1, r.width(), r.height())); - //p.drawRect(r); - } - //else if (part->mute()) - // return; else if (part->selected()) { bool clone = part->events()->arefCount() > 1; @@ -1528,8 +1434,6 @@ void PartCanvas::drawItem(QPainter& p, const CItem* item, const QRect& rect) void PartCanvas::drawMoving(QPainter& p, const CItem* item, const QRect&) { - //if(!item->isMoving()) - // return; p.setPen( Qt::black); //p.setBrush( Qt::NoBrush); @@ -1556,7 +1460,6 @@ void PartCanvas::drawMoving(QPainter& p, const CItem* item, const QRect&) void PartCanvas::drawMidiPart(QPainter& p, const QRect&, EventList* events, MidiTrack *mt, MidiPart *pt, const QRect& r, int pTick, int from, int to) { - //printf("x=%d y=%d h=%d w=%d\n",r.x(),r.y(),r.height(),r.width()); int color_brightness; if(pt) @@ -1781,9 +1684,6 @@ void PartCanvas::drawMidiPart(QPainter& p, const QRect&, EventList* events, Midi void PartCanvas::drawWavePart(QPainter& p, const QRect& bb, WavePart* wp, const QRect& _pr) { - //printf("PartCanvas::drawWavePart bb.x:%d bb.y:%d bb.w:%d bb.h:%d pr.x:%d pr.y:%d pr.w:%d pr.h:%d\n", - // bb.x(), bb.y(), bb.width(), bb.height(), _pr.x(), _pr.y(), _pr.width(), _pr.height()); - QRect rr = p.worldMatrix().mapRect(bb); QRect pr = p.worldMatrix().mapRect(_pr); @@ -1962,11 +1862,8 @@ void PartCanvas::cmd(int cmd) void PartCanvas::copy(PartList* pl) { - //printf("void PartCanvas::copy(PartList* pl)\n"); if (pl->empty()) return; - // Changed by T356. Support mixed .mpt files. - //bool isWave = pl->begin()->second->track()->type() == Track::WAVE; bool wave = false; bool midi = false; for(ciPart p = pl->begin(); p != pl->end(); ++p) @@ -1996,13 +1893,11 @@ void PartCanvas::copy(PartList* pl) // Clear the copy clone list. cloneList.clear(); - //copyCloneList.clear(); int level = 0; int tick = 0; for (ciPart p = pl->begin(); p != pl->end(); ++p) { // Indicate this is a copy operation. Also force full wave paths. - //p->second->write(level, xml); p->second->write(level, xml, true, true); int endTick = p->second->endTick(); @@ -2054,13 +1949,11 @@ void PartCanvas::copy(PartList* pl) int PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool clone, bool toTrack) { - //printf("int PartCanvas::pasteAt(const QString& pt, Track* track, int pos)\n"); QByteArray ba = pt.toLatin1(); const char* ptxt = ba.constData(); Xml xml(ptxt); bool firstPart=true; int posOffset=0; - //int finalPos=0; unsigned int finalPos = pos; int notDone = 0; int done = 0; @@ -2076,26 +1969,7 @@ int PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool end = true; break; case Xml::TagStart: - if (tag == "part") { - /* - Part* p = 0; - if(clone) - { - if(!(p = readClone(xml, track, toTrack))) - break; - } - else - { - if (track->type() == Track::MIDI || track->type() == Track::DRUM) - p = new MidiPart((MidiTrack*)track); - else if (track->type() == Track::WAVE) - p = new WavePart((WaveTrack*)track); - else - break; - p->read(xml, 0, toTrack); - } - */ - + if (tag == "part") { // Read the part. Part* p = 0; p = readXmlPart(xml, track, clone, toTrack); @@ -2149,403 +2023,12 @@ int PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool return finalPos; } -/* -//--------------------------------------------------------- -// PartCanvas::readPart -//--------------------------------------------------------- - -Part* PartCanvas::readPart(Xml& xml, Track* track, bool doClone, bool toTrack) - { - int id = -1; - Part* npart = 0; - uuid_t uuid; - uuid_clear(uuid); - bool uuidvalid = false; - bool clone = true; - - for (;;) { - Xml::Token token = xml.parse(); - const QString& tag = xml.s1(); - switch (token) { - case Xml::Error: - case Xml::End: - return npart; - case Xml::TagStart: - // If the part has not been created yet... - if(!npart) - { - // Attribute section did not create a clone from any matching part. Create a non-clone part now. - if(!track) - { - xml.skip("part"); - return 0; - } - if (track->type() == Track::MIDI || track->type() == Track::DRUM) - npart = new MidiPart((MidiTrack*)track); - else if (track->type() == Track::WAVE) - npart = new WavePart((WaveTrack*)track); - else - { - xml.skip("part"); - return 0; - } - - // Signify a new non-clone part was created. - // Even if the original part was itself a clone, clear this because the - // attribute section did not create a clone from any matching part. - clone = false; - - // If an id or uuid was found, add the part to the clone list - // so that subsequent parts can look it up and clone from it... - if(id != -1) - { - ClonePart ncp(npart, id); - cloneList.push_back(ncp); - } - else - if(uuidvalid) - { - ClonePart ncp(npart); - // New ClonePart creates its own uuid, but we need to replace it. - uuid_copy(ncp.uuid, uuid); - cloneList.push_back(ncp); - } - } - - if (tag == "name") - npart->setName(xml.parse1()); - else if (tag == "poslen") { - ((PosLen*)npart)->read(xml, "poslen"); - } - else if (tag == "pos") { - Pos pos; - pos.read(xml, "pos"); // obsolete - npart->setTick(pos.tick()); - } - else if (tag == "len") { - Pos len; - len.read(xml, "len"); // obsolete - npart->setLenTick(len.tick()); - } - else if (tag == "selected") - npart->setSelected(xml.parseInt()); - else if (tag == "color") - npart->setColorIndex(xml.parseInt()); - else if (tag == "mute") - npart->setMute(xml.parseInt()); - else if (tag == "event") - { - // If a new non-clone part was created, accept the events... - if(!clone) - { - EventType type = Wave; - if(track->isMidiTrack()) - type = Note; - Event e(type); - e.read(xml); - // stored tickpos for event has absolute value. However internally - // tickpos is relative to start of part, we substract tick(). - // TODO: better handling for wave event - e.move( -npart->tick() ); - int tick = e.tick(); - - // Do not discard events belonging to clone parts, - // at least not yet. A later clone might have a longer, - // fully accommodating part length! - //if ((tick < 0) || (tick >= (int) lenTick())) { - //if ((tick < 0) || ( id == -1 && !clone && (tick >= (int)lenTick()) )) - // No way to tell at the moment whether there will be clones referencing this... - // No choice but to accept all events past 0. - if(tick < 0) - { - //printf("readClone: warning: event not in part: %d - %d -%d, discarded\n", - printf("readClone: warning: event at tick:%d not in part:%s, discarded\n", - tick, npart->name().toLatin1().constData()); - } - else - { - npart->events()->add(e); - } - } - else - // ...Otherwise a clone was created, so we don't need the events. - xml.skip(tag); - } - else - xml.unknown("PartCanvas::readClone"); - break; - case Xml::Attribut: - if (tag == "cloneId") - { - id = xml.s2().toInt(); - if(id != -1) - { - for(iClone i = cloneList.begin(); i != cloneList.end(); ++i) - { - // Is a matching part found in the clone list? - if(i->id == id) - { - // If it's a regular paste (not paste clone), and the original part is - // not a clone, defer so that a new copy is created in TagStart above. - if(!doClone && i->cp->cevents()->arefCount() <= 1) - break; - - // This makes a clone, chains the part, and increases ref counts. - npart = track->newPart((Part*)i->cp, true); - break; - } - } - } - } - else if (tag == "uuid") - { - uuid_parse(xml.s2().toLatin1().constData(), uuid); - if(!uuid_is_null(uuid)) - { - uuidvalid = true; - for(iClone i = cloneList.begin(); i != cloneList.end(); ++i) - { - // Is a matching part found in the clone list? - if(uuid_compare(uuid, i->uuid) == 0) - { - Track* cpt = i->cp->track(); - // If we want to paste to the given track... - if(toTrack) - { - // If the given track type is not the same as the part's - // original track type, we can't continue. Just return. - if(!track || cpt->type() != track->type()) - { - xml.skip("part"); - return 0; - } - } - else - // ...else we want to paste to the part's original track. - { - // Make sure the track exists (has not been deleted). - if((cpt->isMidiTrack() && song->midis()->find(cpt) != song->midis()->end()) || - (cpt->type() == Track::WAVE && song->waves()->find(cpt) != song->waves()->end())) - track = cpt; - else - // Track was not found. Try pasting to the given track, as above... - { - if(!track || cpt->type() != track->type()) - { - // No luck. Just return. - xml.skip("part"); - return 0; - } - } - } - - // If it's a regular paste (not paste clone), and the original part is - // not a clone, defer so that a new copy is created in TagStart above. - if(!doClone && i->cp->cevents()->arefCount() <= 1) - break; - - // This makes a clone, chains the part, and increases ref counts. - npart = track->newPart((Part*)i->cp, true); - break; - } - } - } - } - //else if(tag == "isclone") // Ignore - // clone = xml.s2().toInt(); - break; - case Xml::TagEnd: - if (tag == "part") - return npart; - default: - break; - } - } - return npart; -} -*/ - -/* -//--------------------------------------------------------- -// PartCanvas::readClone -//--------------------------------------------------------- - -Part* PartCanvas::readClone(Xml& xml, Track* track, bool toTrack) - { - int id = -1; - Part* npart = 0; - uuid_t uuid; - uuid_clear(uuid); - bool uuidvalid = false; - bool clone = true; - - for (;;) { - Xml::Token token = xml.parse(); - const QString& tag = xml.s1(); - switch (token) { - case Xml::Error: - case Xml::End: - return npart; - case Xml::TagStart: - // If the part has not been created yet... - if(!npart) - { - // Attribute section did not create a clone from any matching part. Create a non-clone part now. - if (track->type() == Track::MIDI || track->type() == Track::DRUM) - npart = new MidiPart((MidiTrack*)track); - else if (track->type() == Track::WAVE) - npart = new WavePart((WaveTrack*)track); - else - return 0; - - // Signify a new non-clone part was created. - // Even if the original part was itself a clone, clear this because the - // attribute section did not create a clone from any matching part. - clone = false; - - // If an id or uuid was found, add the part to the clone list - // so that subsequent parts can look it up and clone from it... - if(id != -1) - { - ClonePart ncp(npart, id); - cloneList.push_back(ncp); - } - else - if(uuidvalid) - { - ClonePart ncp(npart); - // New ClonePart creates its own uuid, but we need to replace it. - uuid_copy(ncp.uuid, uuid); - cloneList.push_back(ncp); - } - } - - if (tag == "name") - npart->setName(xml.parse1()); - else if (tag == "poslen") { - ((PosLen*)npart)->read(xml, "poslen"); - } - else if (tag == "pos") { - Pos pos; - pos.read(xml, "pos"); // obsolete - npart->setTick(pos.tick()); - } - else if (tag == "len") { - Pos len; - len.read(xml, "len"); // obsolete - npart->setLenTick(len.tick()); - } - else if (tag == "selected") - npart->setSelected(xml.parseInt()); - else if (tag == "color") - npart->setColorIndex(xml.parseInt()); - else if (tag == "mute") - npart->setMute(xml.parseInt()); - else if (tag == "event") - { - // If a new non-clone part was created, accept the events... - if(!clone) - { - EventType type = Wave; - if(track->isMidiTrack()) - type = Note; - Event e(type); - e.read(xml); - // stored tickpos for event has absolute value. However internally - // tickpos is relative to start of part, we substract tick(). - // TODO: better handling for wave event - e.move( -npart->tick() ); - int tick = e.tick(); - - // Do not discard events belonging to clone parts, - // at least not yet. A later clone might have a longer, - // fully accommodating part length! - //if ((tick < 0) || (tick >= (int) lenTick())) { - //if ((tick < 0) || ( id == -1 && !clone && (tick >= (int)lenTick()) )) - // No way to tell at the moment whether there will be clones referencing this... - // No choice but to accept all events past 0. - if(tick < 0) - { - //printf("readClone: warning: event not in part: %d - %d -%d, discarded\n", - printf("readClone: warning: event at tick:%d not in part:%s, discarded\n", - tick, npart->name().toLatin1().constData()); - } - else - { - npart->events()->add(e); - } - } - else - // ...Otherwise a clone was created, so we don't need the events. - xml.skip(tag); - } - else - xml.unknown("PartCanvas::readClone"); - break; - case Xml::Attribut: - if (tag == "cloneId") - { - id = xml.s2().toInt(); - if(id != -1) - { - for(iClone i = cloneList.begin(); i != cloneList.end(); ++i) - { - // Is a matching part found in the clone list? - if(i->id == id) - { - // This makes a clone, chains the part, and increases ref counts. - npart = track->newPart((Part*)i->cp, true); - break; - } - } - } - } - else if (tag == "uuid") - { - uuid_parse(xml.s2().toLatin1().constData(), uuid); - if(!uuid_is_null(uuid)) - { - uuidvalid = true; - for(iClone i = cloneList.begin(); i != cloneList.end(); ++i) - { - // Is a matching part found in the clone list? - if(uuid_compare(uuid, i->uuid) == 0) - { - // If we want to paste to the part's original track... - if(!toTrack) - { - // Make sure the track exists (has not been deleted). - if((i->cp->track()->isMidiTrack() && song->midis()->find(i->cp->track()) != song->midis()->end()) || - (i->cp->track()->type() == Track::WAVE && song->waves()->find(i->cp->track()) != song->waves()->end())) - track = i->cp->track(); - } - // This makes a clone, chains the part, and increases ref counts. - npart = track->newPart((Part*)i->cp, true); - break; - } - } - } - } - //else if(tag == "isclone") // Ignore - // clone = xml.s2().toInt(); - break; - case Xml::TagEnd: - if (tag == "part") - return npart; - default: - break; - } - } - return npart; -} -*/ //--------------------------------------------------------- // paste // paste part to current selected track at cpos //--------------------------------------------------------- -//void PartCanvas::paste() void PartCanvas::paste(bool clone, bool toTrack, bool doInsert) { Track* track = 0; @@ -2656,7 +2139,6 @@ void PartCanvas::movePartsTotheRight(unsigned int startTicks, int length) if (!i->second->isSelected()) { Part* part = i->second->part(); if (part->tick() >= startTicks) { - //void Audio::msgChangePart(Part* oldPart, Part* newPart, bool doUndoFlag, bool doCtrls, bool doClones) Part *newPart = part->clone(); newPart->setTick(newPart->tick()+length); if (part->track()->type() == Track::WAVE) { @@ -2687,7 +2169,6 @@ void PartCanvas::movePartsTotheRight(unsigned int startTicks, int length) void PartCanvas::startDrag(CItem* item, DragType t) { - //printf("PartCanvas::startDrag(CItem* item, DragType t)\n"); NPart* p = (NPart*)(item); Part* part = p->part(); @@ -2748,7 +2229,6 @@ void PartCanvas::startDrag(CItem* item, DragType t) void PartCanvas::dragEnterEvent(QDragEnterEvent* event) { - ///event->accept(Q3TextDrag::canDecode(event)); event->acceptProposedAction(); // TODO CHECK Tim. } @@ -2756,22 +2236,6 @@ void PartCanvas::dragEnterEvent(QDragEnterEvent* event) // dragvent //--------------------------------------------------------- -void PartCanvas::dragMoveEvent(QDragMoveEvent*) - { -// printf("drag move %x\n", this); - //event->acceptProposedAction(); - } - -//--------------------------------------------------------- -// dragLeaveEvent -//--------------------------------------------------------- - -void PartCanvas::dragLeaveEvent(QDragLeaveEvent*) - { -// printf("drag leave\n"); - //event->acceptProposedAction(); - } - //--------------------------------------------------------- // dropEvent //--------------------------------------------------------- @@ -2791,7 +2255,6 @@ void PartCanvas::viewDropEvent(QDropEvent* event) if(event->mimeData()->hasFormat("text/partlist")) type = 1; else - //if(event->mimeData()->hasFormat("text/uri-list")) if(event->mimeData()->hasUrls()) type = 2; else @@ -2833,7 +2296,7 @@ void PartCanvas::viewDropEvent(QDropEvent* event) Track* track = 0; if (trackNo < tracks->size()) track = tracks->index(trackNo); - //printf("trackNo=%d\n, trackNo track=%d\n", trackNo, track); + int x = AL::sigmap.raster(event->pos().x(), *_raster); if (x < 0) x = 0; @@ -2911,7 +2374,6 @@ void PartCanvas::drawCanvas(QPainter& p, const QRect& rect) //-------------------------------- // vertical lines //------------------------------- - //printf("raster=%d\n", *_raster); if (config.canvasShowGrid) { int bar, beat; unsigned tick; @@ -2970,12 +2432,9 @@ void PartCanvas::drawCanvas(QPainter& p, const QRect& rect) th = track->height(); if (!th) continue; - ///if (/*config.canvasShowGrid ||*/ !track->isMidiTrack()) { if (config.canvasShowGrid && (track->isMidiTrack() || track->type() == Track::WAVE)) // Tim. { - //printf("PartCanvas::drawCanvas track name:%s, y:%d h:%d\n", track->name().toLatin1().constData(), yy, th); p.setPen(baseColor.dark(130)); - ///p.drawLine(x, yy, x + w, yy); p.drawLine(x, yy + th, x + w, yy + th); // Tim. p.setPen(baseColor); } @@ -3082,7 +2541,6 @@ void PartCanvas::drawTopItem(QPainter& p, const QRect& rect) MPEventList *el = mt->mpevents(); if (el->size()) { - //printf("num events %d\n", mt->mpevents()->size()); for (iMPEvent i = el->begin(); i != el->end(); ++i) { MidiPlayEvent pe = *i; @@ -3100,7 +2558,6 @@ void PartCanvas::drawTopItem(QPainter& p, const QRect& rect) if (e.pitch() == pe.dataA() && e.dataC() == 1) { e.setLenTick(pe.time() - e.tick()- startPos); e.setC(0); // reset the variable we borrowed for state handling - //printf("editing event tick=%d startPos=%d\n",e.tick(), startPos); continue; } } @@ -3182,7 +2639,6 @@ void PartCanvas::drawAutomation(QPainter& p, const QRect& r, AudioTrack *t) // prepare prevVal if (cl->valueType() == VAL_LOG ) { // use db scale for volume - //printf("volume cvval=%f\n", cvFirst.val); prevVal = dbToVal(cvFirst.val); // represent volume between 0 and 1 if (prevVal < 0) prevVal = 0.0; } @@ -3221,13 +2677,11 @@ void PartCanvas::drawAutomation(QPainter& p, const QRect& r, AudioTrack *t) (rr.bottom()-2)-prevVal*height, currentPixel, (rr.bottom()-2)-nextVal*height); - ///(rr.bottom()-2)- (discrete?prevVal:nextVal)*height); // Tim ///if(discrete) /// p.drawLine( currentPixel, (rr.bottom()-2)-prevVal*height, currentPixel, (rr.bottom()-2)-nextVal*height ); // Tim firstRun=false; - //printf("draw line: %d %f %d %f\n",tempomap.frame2tick(lastPos),rr.bottom()-lastVal*height,tempomap.frame2tick(cv.frame),rr.bottom()-curVal*height); prevPosFrame=cv.frame; prevVal=nextVal; if (currentPixel > rr.x()+ rr.width()) @@ -3237,12 +2691,10 @@ void PartCanvas::drawAutomation(QPainter& p, const QRect& r, AudioTrack *t) p.drawRect(mapx(tempomap.frame2tick(prevPosFrame))-2, (rr.bottom()-2)-prevVal*height-2, 5, 5); p.drawRect(mapx(tempomap.frame2tick(prevPosFrame))-1, (rr.bottom()-1)-prevVal*height-2, 3, 3); } - //printf("outer draw %f\n", cvFirst.val ); p.drawLine(mapx(tempomap.frame2tick(prevPosFrame)), (rr.bottom()-2)-prevVal*height, rr.x()+rr.width(), (rr.bottom()-2)-prevVal*height); - //printf("draw last line: %d %f %d %f\n",tempomap.frame2tick(prevPosFrame),(rr.bottom()-2)-prevVal*height,tempomap.frame2tick(prevPosFrame)+rr.width(),(rr.bottom()-2)-prevVal*height); } } quitDrawing: @@ -3335,7 +2787,6 @@ void PartCanvas::checkAutomation(Track * t, const QPoint &pointer, bool addNewCt continue; // not the right region } - //printf("firstX=%f lastX=%f firstY=%f lastY=%f proportion=%f currX=%d\n", firstX,lastX,firstY,lastY,proportion, currX); // 10 X(15) 20 // proportion = 0.5 @@ -3360,7 +2811,6 @@ void PartCanvas::checkAutomation(Track * t, const QPoint &pointer, bool addNewCt } } - //printf("point at x=%d xdiff=%d y=%d ydiff=%d\n", mapx(tempomap.frame2tick(cv.frame)), x1, mapx(ypixel), y1); oldX = xpixel; oldY = ypixel; @@ -3414,7 +2864,6 @@ void PartCanvas::controllerChanged(Track* /* t */) void PartCanvas::processAutomationMovements(QPoint pos, bool addPoint) { - //printf("processAutomationMovements %d %d %d %d %d %d\n", pos.x(), pos.y(),mapx(pos.x()), mapy(pos.y()), xpos, ypos); if (_tool == AutomationTool) { if (!automation.moveController) { // currently nothing going lets's check for some action. @@ -3493,9 +2942,7 @@ void PartCanvas::processAutomationMovements(QPoint pos, bool addPoint) if (cvval< min) cvval=min; if (cvval>max) cvval=max; automation.currentCtrl->val = cvval; - //printf("calc cvval=%f yfraction=%f ", cvval, yfraction); } - //printf("mouseY=%d\n", mouseY); controllerChanged(automation.currentTrack); } diff --git a/muse2/muse/arranger/pcanvas.h b/muse2/muse/arranger/pcanvas.h index 18e47426..daa244b2 100644 --- a/muse2/muse/arranger/pcanvas.h +++ b/muse2/muse/arranger/pcanvas.h @@ -12,9 +12,7 @@ #include "canvas.h" #include "trackautomationview.h" -class QDragMoveEvent; class QDropEvent; -class QDragLeaveEvent; class QMouseEvent; class QKeyEvent; class QEvent; @@ -94,8 +92,6 @@ class PartCanvas : public Canvas { virtual void updateSong(DragType, int); virtual void startDrag(CItem*, DragType); virtual void dragEnterEvent(QDragEnterEvent*); - virtual void dragMoveEvent(QDragMoveEvent*); - virtual void dragLeaveEvent(QDragLeaveEvent*); virtual void viewDropEvent(QDropEvent*); virtual QMenu* genItemPopup(CItem*); diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp index e2b17dd3..0ec300cf 100644 --- a/muse2/muse/midiedit/scoreedit.cpp +++ b/muse2/muse/midiedit/scoreedit.cpp @@ -4456,6 +4456,9 @@ void staff_t::update_part_indices() * between, for example, when a cis is tied to a des * * CURRENT TODO + * o speed up list editor + * o speed up arranger + * * o rename stuff: UndoOp -> Operation, Undo -> OpList, * UndoType -> OpType, iUndoOp, riUndoOp -> iOperation, * undo.cpp/.h -> operations.cpp/.h @@ -4464,7 +4467,6 @@ void staff_t::update_part_indices() * o controller view in score editor * o deal with expanding parts * o fix sigedit boxes - * o drum list: scroll while dragging * o remove functions for disabling key/sigmap * o mastertrack editor: key-combobox is buggy * o drum editor: channel-stuff @@ -4492,6 +4494,7 @@ void staff_t::update_part_indices() * keeping its own pos_add variable (which is only an optimisation) * o support edge-scrolling when opening a lasso * o save more configuration stuff (quant, color) + * o drum list: scroll while dragging (not important due to "reorder list") * * really unimportant nice-to-haves * o support in-song clef-changes -- cgit v1.2.3 From e2e536eab73dc7d1e2294078628eea80ecf6d120 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 5 Jun 2011 22:05:16 +0000 Subject: speeded up the arranger's part canvas --- muse2/muse/app.cpp | 15 ++-- muse2/muse/arranger/pcanvas.cpp | 180 +++++++++++++++++--------------------- muse2/muse/arranger/pcanvas.h | 8 +- muse2/muse/audio.h | 6 -- muse2/muse/functions.cpp | 2 +- muse2/muse/midiedit/scoreedit.cpp | 3 +- muse2/muse/seqmsg.cpp | 20 ++--- muse2/muse/undo.cpp | 7 ++ muse2/muse/undo.h | 4 +- 9 files changed, 110 insertions(+), 135 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/app.cpp b/muse2/muse/app.cpp index 72cdad6a..04c55b01 100644 --- a/muse2/muse/app.cpp +++ b/muse2/muse/app.cpp @@ -2971,14 +2971,13 @@ void MusE::cmd(int cmd) arranger->cmd(Arranger::CMD_INSERT_EMPTYMEAS); break; case CMD_DELETE: - song->startUndo(); - if (song->msgRemoveParts()) { - song->endUndo(SC_PART_REMOVED); - break; - } - else - audio->msgRemoveTracks(); - song->endUndo(SC_TRACK_REMOVED); + if (!song->msgRemoveParts()) //automatically does undo if neccessary and returns true then + { + //msgRemoveParts() returned false -> no parts to remove? + song->startUndo(); + audio->msgRemoveTracks(); //TODO FINDME this could still be speeded up! + song->endUndo(SC_TRACK_REMOVED); + } break; case CMD_DELETE_TRACK: song->startUndo(); diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index 54f431cc..e17d08e1 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -259,8 +259,10 @@ void PartCanvas::updateSong(DragType t, int flags) // moveCanvasItems //--------------------------------------------------------- -void PartCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype, int*) +void PartCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtype) { + Undo operations; + for(iCItem ici = items.begin(); ici != items.end(); ++ici) { CItem* ci = ici->second; @@ -278,15 +280,21 @@ void PartCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp QPoint newpos = raster(QPoint(nx, ny)); selectItem(ci, true); - if (moveItem(ci, newpos, dtype)) + UndoOp operation=moveItem(ci, newpos, dtype); + if (operation.type != UndoOp::DoNothing) + { ci->move(newpos); + operations.push_back(operation); + } if(moving.size() == 1) { itemReleased(curItem, newpos); } if(dtype == MOVE_COPY || dtype == MOVE_CLONE) selectItem(ci, false); - } + } + + song->applyOperationGroup(operations); } //--------------------------------------------------------- @@ -295,7 +303,7 @@ void PartCanvas::moveCanvasItems(CItemList& items, int dp, int dx, DragType dtyp //--------------------------------------------------------- // Changed by T356. -bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) +UndoOp PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) { UndoOp result; NPart* npart = (NPart*) item; @@ -305,7 +313,7 @@ bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) unsigned ntrack = y2pitch(item->mp().y()); Track::TrackType type = track->type(); if (tracks->index(track) == ntrack && (dtick == spart->tick())) { - return false; //FINDMICH + return UndoOp(UndoOp::DoNothing); } if (ntrack >= tracks->size()) { ntrack = tracks->size(); @@ -323,7 +331,7 @@ bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) if (dtrack->type() != type) { QMessageBox::critical(this, QString("MusE"), tr("Cannot copy/move/clone to different Track-Type")); - return false; //FINDMICH + return UndoOp(UndoOp::DoNothing); } Part* dpart; @@ -341,6 +349,8 @@ bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) // This increments aref count if cloned, and chains clones. // It also gives the new part a new serial number. dpart = dtrack->newPart(spart, clone); + dpart->events()->incARef(-1); // the later song->applyOperationGroup() will increment it + // so we must decrement it first :/ dpart->setTick(dtick); @@ -359,33 +369,24 @@ bool PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) } } if (t == MOVE_COPY || t == MOVE_CLONE) { - // These will not increment ref count, and will not chain clones... - if (dtrack->type() == Track::WAVE) - audio->msgAddPart((WavePart*)dpart,false); - else - audio->msgAddPart(dpart,false); + // These will not increment ref count, and will not chain clones... + // TODO: is this still correct (by flo93)? + result=UndoOp(UndoOp::AddPart,dpart); } else if (t == MOVE_MOVE) { dpart->setSelected(spart->selected()); // These will increment ref count if not a clone, and will chain clones... - - if (dtrack->type() == Track::WAVE) { - // Indicate no undo, and do not do port controller values and clone parts. - audio->msgChangePart((WavePart*)spart, (WavePart*)dpart, false, false, false); - } - else { - // Indicate no undo, and do port controller values but not clone parts. - audio->msgChangePart(spart, dpart, false, true, false); - } + // TODO: is this still correct (by flo93)? + result=UndoOp(UndoOp::ModifyPart,spart, dpart, true, false); + spart->setSelected(false); - } + // else // will never happen -> result will always be defined if (song->len() < (dpart->lenTick() + dpart->tick())) song->setLen(dpart->lenTick() + dpart->tick()); - return true; //FINDMICH - //TODO FINDMICH returns nothing... should be fixed (flo93) + return result; } //--------------------------------------------------------- @@ -521,7 +522,7 @@ void PartCanvas::newItem(CItem* i, bool noSnap) len = AL::sigmap.rasterStep(p->tick(), *_raster); p->setLenTick(len); p->setSelected(true); - audio->msgAddPart(p); + audio->msgAddPart(p, true); //indicate undo } //--------------------------------------------------------- @@ -531,7 +532,7 @@ void PartCanvas::newItem(CItem* i, bool noSnap) bool PartCanvas::deleteItem(CItem* i) { Part* p = ((NPart*)(i))->part(); - audio->msgRemovePart(p); //Invokes songChanged which calls partsChanged which makes it difficult to delete them there + audio->msgRemovePart(p, true); //Invokes songChanged which calls partsChanged which makes it difficult to delete them there return true; } @@ -712,11 +713,9 @@ void PartCanvas::itemPopup(CItem* item, int n, const QPoint& pt) Event ev = oldEvent.clone(); de->add(ev); } - song->startUndo(); - // Indicate no undo, and do port controller values but not clone parts. - audio->msgChangePart(spart, dpart, false, true, false); - - song->endUndo(SC_PART_MODIFIED); + // Indicate undo, and do port controller values but not clone parts. + // changed by flo93: removed start and endUndo, instead changed first bool to true + audio->msgChangePart(spart, dpart, true, true, false); break; // Has to be break here, right? } case 16: // Export to file @@ -929,14 +928,10 @@ void PartCanvas::keyPress(QKeyEvent* event) key += Qt::CTRL; if (key == shortcuts[SHRT_DELETE].key) { - if (getCurrentDrag()) { - //printf("dragging!!\n"); + if (getCurrentDrag()) return; - } - song->startUndo(); song->msgRemoveParts(); - song->endUndo(SC_PART_REMOVED); return; } else if (key == shortcuts[SHRT_POS_DEC].key) { @@ -1807,26 +1802,23 @@ void PartCanvas::cmd(int cmd) } switch (cmd) { case CMD_CUT_PART: + { copy(&pl); - song->startUndo(); - bool loop; - do - { - loop = false; - for (iCItem i = items.begin(); i != items.end(); ++i) { - if (!i->second->isSelected()) - continue; - NPart* p = (NPart*)(i->second); - Part* part = p->part(); - audio->msgRemovePart(part); - - loop = true; - break; - } - } while (loop); - song->endUndo(SC_PART_REMOVED); + Undo operations; + + for (iCItem i = items.begin(); i != items.end(); ++i) { + if (i->second->isSelected()) { + NPart* p = (NPart*)(i->second); + Part* part = p->part(); + operations.push_back(UndoOp(UndoOp::DeletePart, part)); + } + } + + song->applyOperationGroup(operations); + break; + } case CMD_COPY_PART: copy(&pl); break; @@ -1846,11 +1838,10 @@ void PartCanvas::cmd(int cmd) paste(false, false, true); break; case CMD_INSERT_EMPTYMEAS: - song->startUndo(); int startPos=song->vcpos(); int oneMeas=AL::sigmap.ticksMeasure(startPos); - movePartsTotheRight(startPos,oneMeas); - song->endUndo(SC_PART_INSERTED); + Undo temp=movePartsTotheRight(startPos,oneMeas); + song->applyOperationGroup(temp); break; } } @@ -1947,8 +1938,10 @@ void PartCanvas::copy(PartList* pl) // pasteAt //--------------------------------------------------------- -int PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool clone, bool toTrack) +Undo PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool clone, bool toTrack, int* finalPosPtr) { + Undo operations; + QByteArray ba = pt.toLatin1(); const char* ptxt = ba.constData(); Xml xml(ptxt); @@ -1959,7 +1952,6 @@ int PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool int done = 0; bool end = false; - //song->startUndo(); for (;;) { Xml::Token token = xml.parse(); const QString& tag = xml.s1(); @@ -1973,6 +1965,7 @@ int PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool // Read the part. Part* p = 0; p = readXmlPart(xml, track, clone, toTrack); + // If it could not be created... if(!p) { @@ -1980,6 +1973,9 @@ int PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool ++notDone; break; } + + p->events()->incARef(-1); // the later song->applyOperationGroup() will increment it + // so we must decrement it first :/ // Increment the number of parts done. ++done; @@ -1992,8 +1988,7 @@ int PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool if (p->tick()+p->lenTick()>finalPos) { finalPos=p->tick()+p->lenTick(); } - //pos += p->lenTick(); - audio->msgAddPart(p,false); + operations.push_back(UndoOp(UndoOp::AddPart,p)); } else xml.unknown("PartCanvas::pasteAt"); @@ -2008,8 +2003,6 @@ int PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool break; } - //song->endUndo(SC_PART_INSERTED); - //return pos; if(notDone) { @@ -2020,7 +2013,8 @@ int PartCanvas::pasteAt(const QString& pt, Track* track, unsigned int pos, bool tr(" could not be pasted.\nLikely the selected track is the wrong type.")); } - return finalPos; + if (finalPosPtr) *finalPosPtr=finalPos; + return operations; } @@ -2110,30 +2104,30 @@ void PartCanvas::paste(bool clone, bool toTrack, bool doInsert) return; } - int endPos=0; - unsigned int startPos=song->vcpos(); if (!txt.isEmpty()) { - song->startUndo(); - endPos=pasteAt(txt, track, startPos, clone, toTrack); + int endPos=0; + unsigned int startPos=song->vcpos(); + Undo operations=pasteAt(txt, track, startPos, clone, toTrack, &endPos); Pos p(endPos, true); song->setPos(0, p); - if (!doInsert) - song->endUndo(SC_PART_INSERTED); + if (doInsert) { + int offset = endPos-startPos; + Undo temp=movePartsTotheRight(startPos, offset); + operations.insert(operations.end(), temp.begin(), temp.end()); + } + song->applyOperationGroup(operations); } - if (doInsert) { - int offset = endPos-startPos; - movePartsTotheRight(startPos, offset); - song->endUndo(SC_PART_INSERTED); - } } //--------------------------------------------------------- // movePartsToTheRight //--------------------------------------------------------- -void PartCanvas::movePartsTotheRight(unsigned int startTicks, int length) +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()) { @@ -2141,12 +2135,8 @@ void PartCanvas::movePartsTotheRight(unsigned int startTicks, int length) if (part->tick() >= startTicks) { Part *newPart = part->clone(); newPart->setTick(newPart->tick()+length); - if (part->track()->type() == Track::WAVE) { - audio->msgChangePart((WavePart*)part,(WavePart*)newPart,false,false,false); - } else { - audio->msgChangePart(part,newPart,false,false,false); - } - + + operations.push_back(UndoOp(UndoOp::ModifyPart,part,newPart,false,false)); } } } @@ -2159,9 +2149,11 @@ void PartCanvas::movePartsTotheRight(unsigned int startTicks, int length) Marker *oldMarker = new Marker(); *oldMarker = *m; m->setTick(m->tick()+length); - song->addUndo(UndoOp(UndoOp::ModifyMarker,oldMarker, m)); + operations.push_back(UndoOp(UndoOp::ModifyMarker,oldMarker, m)); } } + + return operations; } //--------------------------------------------------------- // startDrag @@ -2284,11 +2276,11 @@ void PartCanvas::viewDropEvent(QDropEvent* event) Track* track = 0; if (trackNo < tracks->size()) track = tracks->index(trackNo); - if (track) { - song->startUndo(); - pasteAt(text, track, x); - song->endUndo(SC_PART_INSERTED); - } + if (track) + { + Undo temp=pasteAt(text, track, x); + song->applyOperationGroup(temp); + } } else if (type == 2) { @@ -2967,8 +2959,6 @@ double PartCanvas::valToDb(double inV) void PartCanvas::endMoveItems(const QPoint& pos, DragType dragtype, int dir) { - song->startUndo(); - int dp = y2pitch(pos.y()) - y2pitch(start.y()); int dx = pos.x() - start.x(); @@ -2976,19 +2966,9 @@ void PartCanvas::endMoveItems(const QPoint& pos, DragType dragtype, int dir) dp = 0; else if (dir == 2) dx = 0; + + moveCanvasItems(moving, dp, dx, dragtype); - - - int modified = 0; - - moveCanvasItems(moving, dp, dx, dragtype, &modified); - - if (dragtype == MOVE_COPY || dragtype == MOVE_CLONE) - modified|=SC_PART_INSERTED; - else - modified|=SC_PART_MODIFIED; - - song->endUndo(modified); moving.clear(); updateSelection(); redraw(); diff --git a/muse2/muse/arranger/pcanvas.h b/muse2/muse/arranger/pcanvas.h index daa244b2..acfe565e 100644 --- a/muse2/muse/arranger/pcanvas.h +++ b/muse2/muse/arranger/pcanvas.h @@ -86,8 +86,8 @@ class PartCanvas : public Canvas { virtual void resizeItem(CItem*,bool); virtual void newItem(CItem*,bool); virtual bool deleteItem(CItem*); - virtual void moveCanvasItems(CItemList&, int, int, DragType, int*); - virtual bool moveItem(CItem*, const QPoint&, DragType); + virtual void moveCanvasItems(CItemList&, int, int, DragType); + virtual UndoOp moveItem(CItem*, const QPoint&, DragType); virtual void updateSong(DragType, int); virtual void startDrag(CItem*, DragType); @@ -102,8 +102,8 @@ class PartCanvas : public Canvas { void copy(PartList*); void paste(bool clone = false, bool toTrack = true, bool doInsert=false); - int pasteAt(const QString&, Track*, unsigned int, bool clone = false, bool toTrack = true); - void movePartsTotheRight(unsigned int startTick, int length); + Undo pasteAt(const QString&, Track*, unsigned int, bool clone = false, bool toTrack = true, int* finalPosPtr = NULL); + Undo movePartsTotheRight(unsigned int startTick, int length); //Part* readClone(Xml&, Track*, bool toTrack = true); void drawWavePart(QPainter&, const QRect&, WavePart*, const QRect&); //void drawMidiPart(QPainter&, const QRect& rect, EventList* events, MidiTrack*mt, const QRect& r, int pTick, int from, int to); diff --git a/muse2/muse/audio.h b/muse2/muse/audio.h index 940dd2a5..e332f516 100644 --- a/muse2/muse/audio.h +++ b/muse2/muse/audio.h @@ -124,7 +124,6 @@ class Audio { bool idle; // do nothing in idle mode bool _freewheel; bool _bounce; - //bool loopPassed; unsigned _loopFrame; // Startframe of loop if in LOOP mode. Not quite the same as left marker ! int _loopCount; // Number of times we have looped so far @@ -202,13 +201,9 @@ class Audio { void msgMoveTrack(int idx1, int dx2, bool u = true); void msgAddPart(Part*, bool u = true); void msgRemovePart(Part*, bool u = true); - //void msgChangePart(Part* oldPart, Part* newPart, bool u = true); void msgChangePart(Part* oldPart, Part* newPart, bool u = true, bool doCtrls = true, bool doClones = false); - //void msgAddEvent(Event&, Part*, bool u = true); void msgAddEvent(Event&, Part*, bool u = true, bool doCtrls = true, bool doClones = false); - //void msgDeleteEvent(Event&, Part*, bool u = true); void msgDeleteEvent(Event&, Part*, bool u = true, bool doCtrls = true, bool doClones = false); - //void msgChangeEvent(Event&, Event&, Part*, bool u = true); void msgChangeEvent(Event&, Event&, Part*, bool u = true, bool doCtrls = true, bool doClones = false); void msgScanAlsaMidiPorts(); void msgAddTempo(int tick, int tempo, bool doUndoFlag = true); @@ -250,7 +245,6 @@ class Audio { void msgResetMidiDevices(); void msgIdle(bool); void msgBounce(); - //void msgSetPluginCtrlVal(PluginI* /*plugin*/, int /*param*/, double /*val*/); void msgSetPluginCtrlVal(AudioTrack*, int /*param*/, double /*val*/); void msgSwapControllerIDX(AudioTrack*, int, int); void msgClearControllerEvents(AudioTrack*, int); diff --git a/muse2/muse/functions.cpp b/muse2/muse/functions.cpp index 4a65d19c..a6c9c95a 100644 --- a/muse2/muse/functions.cpp +++ b/muse2/muse/functions.cpp @@ -759,7 +759,7 @@ void paste_at(Part* dest_part, const QString& pt, int pos) goto end_of_paste_at; } else - xml.unknown("pasteAt"); + xml.unknown("paste_at"); break; case Xml::Attribut: diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp index 0ec300cf..ca88d36a 100644 --- a/muse2/muse/midiedit/scoreedit.cpp +++ b/muse2/muse/midiedit/scoreedit.cpp @@ -4457,7 +4457,8 @@ void staff_t::update_part_indices() * * CURRENT TODO * o speed up list editor - * o speed up arranger + * o insert empty measure should also work inside parts + * o canvas editor: create clone via "alt+drag" moves window instead * * o rename stuff: UndoOp -> Operation, Undo -> OpList, * UndoType -> OpType, iUndoOp, riUndoOp -> iOperation, diff --git a/muse2/muse/seqmsg.cpp b/muse2/muse/seqmsg.cpp index 0aa74aaa..57aadc18 100644 --- a/muse2/muse/seqmsg.cpp +++ b/muse2/muse/seqmsg.cpp @@ -893,31 +893,23 @@ void Audio::msgRemovePart(Part* part, bool doUndoFlag) bool Song::msgRemoveParts() { - bool loop; + Undo operations; bool partSelected = false; - do { - loop = false; + TrackList* tl = song->tracks(); for (iTrack it = tl->begin(); it != tl->end(); ++it) { PartList* pl = (*it)->parts(); for (iPart ip = pl->begin(); ip != pl->end(); ++ip) { if (ip->second->selected()) { - if ((*it)->type() == Track::WAVE) { - audio->msgRemovePart((WavePart*)(ip->second)); - } - else { - audio->msgRemovePart(ip->second, false); - } - loop = true; + operations.push_back(UndoOp(UndoOp::DeletePart,ip->second)); partSelected = true; - break; } } - if (loop) - break; } - } while (loop); + + song->applyOperationGroup(operations); + return partSelected; } diff --git a/muse2/muse/undo.cpp b/muse2/muse/undo.cpp index c57bb5c1..c5b211b2 100644 --- a/muse2/muse/undo.cpp +++ b/muse2/muse/undo.cpp @@ -480,6 +480,7 @@ void Song::doUndo2() break; case UndoOp::ModifyClip: case UndoOp::ModifyMarker: + case UndoOp::DoNothing: break; } } @@ -716,6 +717,7 @@ void Song::doRedo2() break; case UndoOp::ModifyClip: case UndoOp::ModifyMarker: + case UndoOp::DoNothing: break; } } @@ -725,6 +727,11 @@ UndoOp::UndoOp() { } +UndoOp::UndoOp(UndoType type_) +{ + type = type_; +} + UndoOp::UndoOp(UndoType type_, int a_, int b_, int c_) { type = type_; diff --git a/muse2/muse/undo.h b/muse2/muse/undo.h index 88810b80..b8f69d9f 100644 --- a/muse2/muse/undo.h +++ b/muse2/muse/undo.h @@ -36,7 +36,8 @@ struct UndoOp { AddKey, DeleteKey, SwapTrack, ModifyClip, - ModifyMarker + ModifyMarker, + DoNothing }; UndoType type; @@ -99,6 +100,7 @@ struct UndoOp { UndoOp(UndoType type, SigEvent* oevent, SigEvent* nevent); UndoOp(UndoType type, const char* changedFile, const char* changeData, int startframe, int endframe); UndoOp(UndoType type, Marker* copyMarker, Marker* realMarker); + UndoOp(UndoType type); }; class Undo : public std::list { -- cgit v1.2.3 From 5e9533d5620f312b3727122c1680d97cf6ca2ff1 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Mon, 6 Jun 2011 12:31:55 +0000 Subject: speeded up list editor --- muse2/muse/liste/listedit.cpp | 14 +++++++------- muse2/muse/midiedit/scoreedit.cpp | 22 +++++++++------------- muse2/muse/undo.cpp | 1 + 3 files changed, 17 insertions(+), 20 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/liste/listedit.cpp b/muse2/muse/liste/listedit.cpp index 080ee01c..5f73a3ba 100644 --- a/muse2/muse/liste/listedit.cpp +++ b/muse2/muse/liste/listedit.cpp @@ -852,7 +852,7 @@ void ListEdit::cmd(int cmd) bool found = false; for (int row = 0; row < liste->topLevelItemCount(); ++row) { - QTreeWidgetItem* i = liste->topLevelItem(row); + QTreeWidgetItem* i = liste->topLevelItem(row); EventListItem *item = (EventListItem *) i; if (i->isSelected() || item->event.selected()) { @@ -862,7 +862,8 @@ void ListEdit::cmd(int cmd) } if(!found) break; - song->startUndo(); + + Undo operations; EventListItem *deletedEvent=NULL; for (int row = 0; row < liste->topLevelItemCount(); ++row) { @@ -871,8 +872,8 @@ void ListEdit::cmd(int cmd) if (i->isSelected() || item->event.selected()) { deletedEvent=item; - // Indicate no undo, and do port controller values and clone parts. - audio->msgDeleteEvent(item->event, item->part, false, true, true); + // Port controller values and clone parts. + operations.push_back(UndoOp(UndoOp::DeleteEvent,item->event, item->part, true, true)); } } @@ -895,9 +896,8 @@ void ListEdit::cmd(int cmd) } } selectedTick=nextTick; - song->endUndo(SC_EVENT_MODIFIED); - //printf("selected tick = %d\n", selectedTick); - //emit selectionChanged(); + + song->applyOperationGroup(operations); break; } } diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp index ca88d36a..309342ae 100644 --- a/muse2/muse/midiedit/scoreedit.cpp +++ b/muse2/muse/midiedit/scoreedit.cpp @@ -4443,7 +4443,7 @@ void staff_t::update_part_indices() -//hint: recalculating event- and itemlists "from zero" +//note: recalculating event- and itemlists "from zero" // could happen in realtime, as it is pretty fast. // however, this adds unneccessary cpu usage. // it is NO problem to recalc the stuff "from zero" @@ -4456,25 +4456,21 @@ void staff_t::update_part_indices() * between, for example, when a cis is tied to a des * * CURRENT TODO - * o speed up list editor - * o insert empty measure should also work inside parts - * o canvas editor: create clone via "alt+drag" moves window instead - * - * o rename stuff: UndoOp -> Operation, Undo -> OpList, - * UndoType -> OpType, iUndoOp, riUndoOp -> iOperation, - * undo.cpp/.h -> operations.cpp/.h + * o remove functions for disabling key/sigmap * o either remove these "hidden notes", or deal with them in the score editor + * o insert empty measure should also work inside parts, that is, + * move notes _within_ parts + * + * IMPORTANT TODO + * o canvas editor: create clone via "alt+drag" moves window instead * o investigate with valgrind * o controller view in score editor * o deal with expanding parts * o fix sigedit boxes - * o remove functions for disabling key/sigmap - * o mastertrack editor: key-combobox is buggy - * o drum editor: channel-stuff - * - * IMPORTANT TODO * o solo button * o grand staff brace + * o mastertrack editor: key-combobox is buggy + * o drum editor: channel-stuff * o do partial recalculating; recalculating can take pretty long * (0,5 sec) when displaying a whole song in scores * o transpose etc. must also transpose key-pressure events diff --git a/muse2/muse/undo.cpp b/muse2/muse/undo.cpp index c5b211b2..0c05ef08 100644 --- a/muse2/muse/undo.cpp +++ b/muse2/muse/undo.cpp @@ -77,6 +77,7 @@ void UndoOp::dump() case ModifyMarker: case AddKey: case DeleteKey: + case DoNothing: break; } } -- cgit v1.2.3 From 6c8a1eb61743e3fa83925d40c14d3a6754c8359f Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Mon, 6 Jun 2011 16:49:02 +0000 Subject: implemented functions for shrinking, expanding and cleaning parts --- muse2/muse/app.cpp | 47 ++++++++--------- muse2/muse/app.h | 3 +- muse2/muse/functions.cpp | 104 +++++++++++++++++++++++++++++++++++++- muse2/muse/functions.h | 5 ++ muse2/muse/midiedit/scoreedit.cpp | 2 + 5 files changed, 133 insertions(+), 28 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/app.cpp b/muse2/muse/app.cpp index 9e2f6c9a..6b9f2b5b 100644 --- a/muse2/muse/app.cpp +++ b/muse2/muse/app.cpp @@ -54,6 +54,7 @@ #include "tools.h" #include "visibletracks.h" #include "widgets/unusedwavefiles.h" +#include "functions.h" #ifdef DSSI_SUPPORT #include "dssihost.h" @@ -977,6 +978,10 @@ MusE::MusE(int argc, char** argv) : QMainWindow() editPaste2TrackAction = new QAction(QIcon(*editpaste2TrackIconSet), tr("Paste to &track"), this); editPasteC2TAction = new QAction(QIcon(*editpasteClone2TrackIconSet), tr("Paste clone to trac&k"), this); editDeleteSelectedAction = new QAction(QIcon(*edit_track_delIcon), tr("Delete Selected Tracks"), this); + + editShrinkPartsAction = new QAction(tr("Shrink selected parts"), this); //FINDMICH TODO tooltips! + editExpandPartsAction = new QAction(tr("Expand selected parts"), this); + editCleanPartsAction = new QAction(tr("Clean selected parts"), this); addTrack = new QMenu(tr("Add Track"), this); @@ -1127,6 +1132,10 @@ MusE::MusE(int argc, char** argv) : QMainWindow() connect(editPasteC2TAction, SIGNAL(triggered()), editSignalMapper, SLOT(map())); connect(editDeleteSelectedAction, SIGNAL(triggered()), editSignalMapper, SLOT(map())); + connect(editShrinkPartsAction, SIGNAL(triggered()), editSignalMapper, SLOT(map())); + connect(editExpandPartsAction, SIGNAL(triggered()), editSignalMapper, SLOT(map())); + connect(editCleanPartsAction, SIGNAL(triggered()), editSignalMapper, SLOT(map())); + connect(editSelectAllAction, SIGNAL(triggered()), editSignalMapper, SLOT(map())); connect(editDeselectAllAction, SIGNAL(triggered()), editSignalMapper, SLOT(map())); connect(editInvertSelectionAction, SIGNAL(triggered()), editSignalMapper, SLOT(map())); @@ -1143,6 +1152,9 @@ MusE::MusE(int argc, char** argv) : QMainWindow() editSignalMapper->setMapping(editPasteC2TAction, CMD_PASTE_CLONE_TO_TRACK); editSignalMapper->setMapping(editInsertEMAction, CMD_INSERTMEAS); editSignalMapper->setMapping(editDeleteSelectedAction, CMD_DELETE_TRACK); + editSignalMapper->setMapping(editShrinkPartsAction, CMD_SHRINK_PART); + editSignalMapper->setMapping(editExpandPartsAction, CMD_EXPAND_PART); + editSignalMapper->setMapping(editCleanPartsAction, CMD_CLEAN_PART); editSignalMapper->setMapping(editSelectAllAction, CMD_SELECT_ALL); editSignalMapper->setMapping(editDeselectAllAction, CMD_SELECT_NONE); editSignalMapper->setMapping(editInvertSelectionAction, CMD_SELECT_INVERT); @@ -1361,6 +1373,10 @@ MusE::MusE(int argc, char** argv) : QMainWindow() menuEdit->addAction(editPaste2TrackAction); menuEdit->addAction(editPasteC2TAction); menuEdit->addSeparator(); + menuEdit->addAction(editShrinkPartsAction); + menuEdit->addAction(editExpandPartsAction); + menuEdit->addAction(editCleanPartsAction); + menuEdit->addSeparator(); menuEdit->addAction(editDeleteSelectedAction); // Moved below. Have to wait until synths are available... @@ -1389,7 +1405,7 @@ MusE::MusE(int argc, char** argv) : QMainWindow() menuEdit->addMenu(midiEdit); -#if 0 // TODO +#if 0 // TODO FINDMICH delete! midiEdit->insertItem(tr("Modify Gate Time"), this, SLOT(modifyGateTime())); midiEdit->insertItem(tr("Modify Velocity"), this, SLOT(modifyVelocity())); midiEdit->insertItem(tr("Crescendo"), this, SLOT(crescendo())); @@ -3046,6 +3062,10 @@ void MusE::cmd(int cmd) song->setFollow(Song::CONTINUOUS); setFollow(); break; + + case CMD_SHRINK_PART: shrink_parts(); break; + case CMD_EXPAND_PART: expand_parts(); break; + case CMD_CLEAN_PART: clean_parts(); break; } } @@ -3055,37 +3075,12 @@ void MusE::cmd(int cmd) void MusE::clipboardChanged() { -/* - //Q3CString subtype("partlist"); - //QString subtype("partlist"); - QMimeSource* ms = QApplication::clipboard()->data(QClipboard::Clipboard); - if (ms == 0) - return; - bool flag = false; - for (int i = 0; ms->format(i); ++i) { -// printf("Format <%s\n", ms->format(i)); - if ((strncmp(ms->format(i), "text/midipartlist", 17) == 0) - || (strncmp(ms->format(i), "text/wavepartlist", 17) == 0) - // Added by T356. Support mixed .mpt files. - || (strncmp(ms->format(i), "text/mixedpartlist", 18) == 0)) { - flag = true; - break; - } - } -*/ - bool flag = false; if(QApplication::clipboard()->mimeData()->hasFormat(QString("text/x-muse-midipartlist")) || QApplication::clipboard()->mimeData()->hasFormat(QString("text/x-muse-wavepartlist")) || QApplication::clipboard()->mimeData()->hasFormat(QString("text/x-muse-mixedpartlist"))) flag = true; - //bool flag = false; - //if(!QApplication::clipboard()->text(QString("x-muse-midipartlist"), QClipboard::Clipboard).isEmpty() || - // !QApplication::clipboard()->text(QString("x-muse-wavepartlist"), QClipboard::Clipboard).isEmpty() || - // !QApplication::clipboard()->text(QString("x-muse-mixedpartlist"), QClipboard::Clipboard).isEmpty()) - // flag = true; - editPasteAction->setEnabled(flag); editInsertAction->setEnabled(flag); editPasteCloneAction->setEnabled(flag); diff --git a/muse2/muse/app.h b/muse2/muse/app.h index 256154e2..3f539196 100644 --- a/muse2/muse/app.h +++ b/muse2/muse/app.h @@ -80,7 +80,7 @@ class MusE : public QMainWindow CMD_SELECT_ALL, CMD_SELECT_NONE, CMD_SELECT_INVERT, CMD_SELECT_ILOOP, CMD_SELECT_OLOOP, CMD_SELECT_PARTS, CMD_FOLLOW_NO, CMD_FOLLOW_JUMP, CMD_FOLLOW_CONTINUOUS , - CMD_DELETE_TRACK + CMD_DELETE_TRACK, CMD_EXPAND_PART, CMD_SHRINK_PART, CMD_CLEAN_PART }; //File menu items: @@ -113,6 +113,7 @@ class MusE : public QMainWindow QAction *masterGraphicAction, *masterListAction; QAction *midiTransformerAction; QAction *editSongInfoAction; + QAction *editCleanPartsAction, *editShrinkPartsAction, *editExpandPartsAction; public: QAction *startScoreEditAction, *startPianoEditAction, *startDrumEditAction, *startListEditAction, *startWaveEditAction; QMenu *scoreSubmenu, *scoreOneStaffPerTrackSubsubmenu, *scoreAllInOneSubsubmenu; diff --git a/muse2/muse/functions.cpp b/muse2/muse/functions.cpp index a6c9c95a..3d10a878 100644 --- a/muse2/muse/functions.cpp +++ b/muse2/muse/functions.cpp @@ -749,7 +749,7 @@ void paste_at(Part* dest_part, const QString& pt, int pos) Part* newPart = dest_part->clone(); newPart->setLenTick(newPart->lenTick()+diff); // Indicate no undo, and do port controller values but not clone parts. - operations.push_back(UndoOp(UndoOp::ModifyPart,dest_part, newPart, true, false)); //FINDMICHJETZT oder andersrum? + operations.push_back(UndoOp(UndoOp::ModifyPart,dest_part, newPart, true, false)); dest_part = newPart; // reassign TODO FINDME does this work, or has dest_part to be a nonconst reference? } // Indicate no undo, and do not do port controller values and clone parts. @@ -831,6 +831,108 @@ void select_not_in_loop(const std::set& parts) } +void shrink_parts() +{ + Undo operations; + + TrackList* tracks = song->tracks(); + for (iTrack track = tracks->begin(); track != tracks->end(); track++) + for (iPart part = (*track)->parts()->begin(); part != (*track)->parts()->end(); part++) + if (part->second->selected()) + { + EventList* events=part->second->events(); + unsigned len=0; + + for (iEvent ev=events->begin(); ev!=events->end(); ev++) + if (ev->second.endTick() > len) + len=ev->second.endTick(); + + if (len > part->second->lenTick()) + len = part->second->lenTick(); + + if (len != part->second->lenTick()) + { + MidiPart* new_part = new MidiPart(*(MidiPart*)part->second); + new_part->setLenTick(len); + operations.push_back(UndoOp(UndoOp::ModifyPart, part->second, new_part, true, false)); + } + } + + song->applyOperationGroup(operations); +} + +void expand_parts() +{ + Undo operations; + + TrackList* tracks = song->tracks(); + for (iTrack track = tracks->begin(); track != tracks->end(); track++) + for (iPart part = (*track)->parts()->begin(); part != (*track)->parts()->end(); part++) + if (part->second->selected()) + { + EventList* events=part->second->events(); + unsigned len=part->second->lenTick(); + + for (iEvent ev=events->begin(); ev!=events->end(); ev++) + if (ev->second.endTick() > len) + len=ev->second.endTick(); + + if (len != part->second->lenTick()) + { + MidiPart* new_part = new MidiPart(*(MidiPart*)part->second); + new_part->setLenTick(len); + operations.push_back(UndoOp(UndoOp::ModifyPart, part->second, new_part, true, false)); + } + } + + song->applyOperationGroup(operations); +} + +void clean_parts() +{ + Undo operations; + set already_processed; + + TrackList* tracks = song->tracks(); + for (iTrack track = tracks->begin(); track != tracks->end(); track++) + for (iPart part = (*track)->parts()->begin(); part != (*track)->parts()->end(); part++) + if ((part->second->selected()) && (already_processed.find(part->second)==already_processed.end())) + { + // find out the length of the longest clone of this part; + // avoid processing eventlist multiple times (because of + // multiple clones) + unsigned len=0; + + Part* part_it=part->second; + do + { + if (part_it->lenTick() > len) + len=part_it->lenTick(); + + already_processed.insert(part_it); + part_it=part_it->nextClone(); + } while ((part_it!=part->second) && (part_it!=NULL)); + + + // erase all events exceeding the longest clone of this part + // (i.e., erase all hidden events) or shorten them + EventList* el = part->second->events(); + for (iEvent ev=el->begin(); ev!=el->end(); ev++) + if (ev->second.tick() >= len) + operations.push_back(UndoOp(UndoOp::DeleteEvent, ev->second, part->second, true, true)); + else if (ev->second.endTick() > len) + { + Event new_event = ev->second.clone(); + new_event.setLenTick(len - ev->second.tick()); + + operations.push_back(UndoOp(UndoOp::ModifyEvent, new_event, ev->second, part->second, true, true)); + } + } + + song->applyOperationGroup(operations); +} + + void read_function_dialog_config(Xml& xml) { if (erase_dialog==NULL) diff --git a/muse2/muse/functions.h b/muse2/muse/functions.h index bc2bb8f4..8a1eb3ed 100644 --- a/muse2/muse/functions.h +++ b/muse2/muse/functions.h @@ -84,6 +84,11 @@ void select_invert(const std::set& parts); void select_in_loop(const std::set& parts); void select_not_in_loop(const std::set& parts); +//functions for parts +void shrink_parts(); +void expand_parts(); +void clean_parts(); + //functions for reading and writing default values class Xml; void read_function_dialog_config(Xml& xml); diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp index f1c305d6..450d6f98 100644 --- a/muse2/muse/midiedit/scoreedit.cpp +++ b/muse2/muse/midiedit/scoreedit.cpp @@ -4452,6 +4452,8 @@ void staff_t::update_part_indices() /* BUGS and potential bugs + * o clones aren't marked as clones any more :( + * * o when the keymap is not used, this will probably lead to a bug * o tied notes don't work properly when there's a key-change in * between, for example, when a cis is tied to a des -- cgit v1.2.3 From 2359a1c010c298eb66b5b03e0e23f55b4fd9ff4b Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Mon, 6 Jun 2011 17:46:25 +0000 Subject: only cleaned up code --- muse2/muse/app.cpp | 455 +-------------------------------------------------- muse2/muse/app.h | 20 +-- muse2/muse/event.cpp | 71 -------- muse2/muse/event.h | 14 -- muse2/muse/part.cpp | 4 - muse2/muse/part.h | 15 -- 6 files changed, 7 insertions(+), 572 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/app.cpp b/muse2/muse/app.cpp index 6b9f2b5b..fb07955f 100644 --- a/muse2/muse/app.cpp +++ b/muse2/muse/app.cpp @@ -106,13 +106,6 @@ int watchAudio, watchAudioPrefetch, watchMidi; pthread_t splashThread; -//PyScript *pyscript; -// void MusE::runPythonScript() -// { -// QString script("test.py"); -// // pyscript->runPythonScript(script); -// } - void MusE::clearScoreMenuMappers() { @@ -138,127 +131,12 @@ void microSleep(long msleep) sleepOk=usleep(msleep); } -// Removed p3.3.17 -/* -//--------------------------------------------------------- -// watchdog thread -//--------------------------------------------------------- - -static void* watchdog(void*) - { - doSetuid(); - - struct sched_param rt_param; - memset(&rt_param, 0, sizeof(rt_param)); - rt_param.sched_priority = sched_get_priority_max(SCHED_FIFO); - int rv = pthread_setschedparam(pthread_self(), SCHED_FIFO, &rt_param); - if (rv != 0) - perror("Set realtime scheduler"); - - int policy; - if (pthread_getschedparam(pthread_self(), &policy, &rt_param)!= 0) { - printf("Cannot get current client scheduler: %s\n", strerror(errno)); - } - if (policy != SCHED_FIFO) - printf("watchdog process %d _NOT_ running SCHED_FIFO\n", getpid()); - else if (debugMsg) - printf("watchdog set to SCHED_FIFO priority %d\n", - sched_get_priority_max(SCHED_FIFO)); - - undoSetuid(); - int fatal = 0; - for (;;) { - watchAudio = 0; - watchMidi = 0; - static const int WD_TIMEOUT = 3; - - // sleep can be interrpted by signals: - int to = WD_TIMEOUT; - while (to > 0) - to = sleep(to); - - bool timeout = false; - if (midiSeqRunning && watchMidi == 0) - { - printf("midiSeqRunning = %i watchMidi %i\n", midiSeqRunning, watchMidi); - timeout = true; - } - if (watchAudio == 0) - timeout = true; - if (watchAudio > 500000) - timeout = true; - if (timeout) - ++fatal; - else - fatal = 0; - if (fatal >= 3) { - printf("WatchDog: fatal error, realtime task timeout\n"); - printf(" (%d,%d-%d) - stopping all services\n", - watchMidi, watchAudio, fatal); - break; - } -// printf("wd %d %d %d\n", watchMidi, watchAudio, fatal); - } - audio->stop(true); - audioPrefetch->stop(true); - printf("watchdog exit\n"); - exit(-1); - } -*/ - //--------------------------------------------------------- // seqStart //--------------------------------------------------------- bool MusE::seqStart() { - // Changed by Tim. p3.3.17 - - /* - if (audio->isRunning()) { - printf("seqStart(): already running\n"); - return true; - } - - if (realTimeScheduling) { - // - // create watchdog thread with max priority - // - doSetuid(); - struct sched_param rt_param; - memset(&rt_param, 0, sizeof(rt_param)); - rt_param.sched_priority = realTimePriority +1;//sched_get_priority_max(SCHED_FIFO); - - pthread_attr_t* attributes = (pthread_attr_t*) malloc(sizeof(pthread_attr_t)); - pthread_attr_init(attributes); - -// if (pthread_attr_setschedpolicy(attributes, SCHED_FIFO)) { -// printf("MusE: cannot set FIFO scheduling class for RT thread\n"); -// } -// if (pthread_attr_setschedparam (attributes, &rt_param)) { -// // printf("Cannot set scheduling priority for RT thread (%s)\n", strerror(errno)); -// } -// if (pthread_attr_setscope (attributes, PTHREAD_SCOPE_SYSTEM)) { -// printf("MusE: Cannot set scheduling scope for RT thread\n"); -// } - if (pthread_create(&watchdogThread, attributes, ::watchdog, 0)) - perror("MusE: creating watchdog thread failed:"); - pthread_attr_destroy(attributes); - undoSetuid(); - } - audioPrefetch->start(); - audioPrefetch->msgSeek(0, true); // force - midiSeqRunning = !midiSeq->start(); - - if (!audio->start()) { - QMessageBox::critical( muse, tr(QString("Failed to start audio!")), - tr(QString("Was not able to start audio, check if jack is running.\n"))); - return false; - } - - return true; - */ - if (audio->isRunning()) { printf("seqStart(): already running\n"); return true; @@ -275,12 +153,10 @@ bool MusE::seqStart() // for(int i = 0; i < 60; ++i) { - //if (audioState == AUDIO_START2) if(audio->isRunning()) break; sleep(1); } - //if (audioState != AUDIO_START2) { if(!audio->isRunning()) { QMessageBox::critical( muse, tr("Failed to start audio!"), @@ -294,66 +170,6 @@ bool MusE::seqStart() if(debugMsg) printf("MusE::seqStart: getting audio driver realTimePriority:%d\n", realTimePriority); - // Disabled by Tim. p3.3.22 - /* - if(realTimeScheduling) - { - // - // create watchdog thread with max priority - // - doSetuid(); - struct sched_param rt_param; - memset(&rt_param, 0, sizeof(rt_param)); - rt_param.sched_priority = realTimePriority + 1;//sched_get_priority_max(SCHED_FIFO); - - pthread_attr_t* attributes = (pthread_attr_t*) malloc(sizeof(pthread_attr_t)); - pthread_attr_init(attributes); - -// if (pthread_attr_setschedpolicy(attributes, SCHED_FIFO)) { -// printf("MusE: cannot set FIFO scheduling class for RT thread\n"); -// } -// if (pthread_attr_setschedparam (attributes, &rt_param)) { -// // printf("Cannot set scheduling priority for RT thread (%s)\n", strerror(errno)); -// } -// if (pthread_attr_setscope (attributes, PTHREAD_SCOPE_SYSTEM)) { -// printf("MusE: Cannot set scheduling scope for RT thread\n"); -// } - if (pthread_create(&watchdogThread, attributes, ::watchdog, 0)) - perror("MusE: creating watchdog thread failed"); - pthread_attr_destroy(attributes); - undoSetuid(); - } - */ - - //int policy; - //if ((policy = sched_getscheduler (0)) < 0) { - // printf("Cannot get current client scheduler: %s\n", strerror(errno)); - // } - //if (policy != SCHED_FIFO) - // printf("midi thread %d _NOT_ running SCHED_FIFO\n", getpid()); - - - //audioState = AUDIO_RUNNING; - // Changed by Tim. p3.3.22 - /* - //if(realTimePriority) - if(realTimeScheduling) - { - int pr = realTimePriority; - if(pr > 5) - pr -= 5; - else - pr = 0; - audioPrefetch->start(pr); - //audioWriteback->start(realTimePriority - 5); - } - else - { - audioPrefetch->start(0); - //audioWriteback->start(0); - } - */ - int pfprio = 0; int midiprio = 0; @@ -363,52 +179,6 @@ bool MusE::seqStart() // in JackAudioDevice::realtimePriority() which is a bit flawed - it reports there's no RT... if(realTimeScheduling) { - //if(realTimePriority < 5) - // printf("MusE: WARNING: Recommend setting audio realtime priority to a higher value!\n"); - /* - if(realTimePriority == 0) - { - pfprio = 1; - midiprio = 2; - } - else - if(realTimePriority == 1) - { - pfprio = 2; - midiprio = 3; - } - else - if(realTimePriority == 2) - { - pfprio = 1; - midiprio = 3; - } - else - if(realTimePriority == 3) - { - pfprio = 1; - //midiprio = 2; - // p3.3.37 - midiprio = 4; - } - else - if(realTimePriority == 4) - { - pfprio = 1; - //midiprio = 3; - // p3.3.37 - midiprio = 5; - } - else - if(realTimePriority == 5) - { - pfprio = 1; - //midiprio = 3; - // p3.3.37 - midiprio = 6; - } - else - */ { //pfprio = realTimePriority - 5; // p3.3.40 @@ -537,16 +307,6 @@ void addProject(const QString& name) // populateAddSynth //--------------------------------------------------------- -/* -struct addSynth_cmp_str -{ - bool operator()(std::string a, std::string b) - { - return (a < b); - } -}; -*/ - // ORCAN - CHECK QMenu* populateAddSynth(QWidget* parent) { @@ -1326,12 +1086,6 @@ MusE::MusE(int argc, char** argv) : QMainWindow() // Popups //--------------------------------------------------- -// QPopupMenu *foo = new QPopupMenu(this); -// testAction = new QAction(foo,"testPython"); -// testAction->addTo(foo); -// menuBar()->insertItem(tr("&testpython"), foo); -// connect(testAction, SIGNAL(activated()), this, SLOT(runPythonScript())); - //------------------------------------------------------------- // popup File @@ -1405,20 +1159,14 @@ MusE::MusE(int argc, char** argv) : QMainWindow() menuEdit->addMenu(midiEdit); -#if 0 // TODO FINDMICH delete! - midiEdit->insertItem(tr("Modify Gate Time"), this, SLOT(modifyGateTime())); - midiEdit->insertItem(tr("Modify Velocity"), this, SLOT(modifyVelocity())); - midiEdit->insertItem(tr("Crescendo"), this, SLOT(crescendo())); - midiEdit->insertItem(tr("Thin Out"), this, SLOT(thinOut())); - midiEdit->insertItem(tr("Erase Event"), this, SLOT(eraseEvent())); - midiEdit->insertItem(tr("Note Shift"), this, SLOT(noteShift())); - midiEdit->insertItem(tr("Move Clock"), this, SLOT(moveClock())); - midiEdit->insertItem(tr("Copy Measure"), this, SLOT(copyMeasure())); +/* commented out by flo: these are not implemented, + but maybe will be in future (state: revision 988) + midiEdit->insertItem(tr("Copy Measure"), this, SLOT(copyMeasure())); midiEdit->insertItem(tr("Erase Measure"), this, SLOT(eraseMeasure())); midiEdit->insertItem(tr("Delete Measure"), this, SLOT(deleteMeasure())); midiEdit->insertItem(tr("Create Measure"), this, SLOT(createMeasure())); midiEdit->insertItem(tr("Mix Track"), this, SLOT(mixTrack())); -#endif +*/ midiEdit->addAction(midiTransformerAction); menuEdit->addAction(editSongInfoAction); @@ -1638,9 +1386,6 @@ MusE::MusE(int argc, char** argv) : QMainWindow() MusE::~MusE() { - //printf("MusE::~MusE\n"); - //if(transport) - // delete transport; } //--------------------------------------------------------- @@ -1964,37 +1709,6 @@ void MusE::setUntitledProject() void MusE::setConfigDefaults() { readConfiguration(); // used for reading midi files -#if 0 - if (readConfiguration()) { - // - // failed to load config file - // set buildin defaults - // - configTransportVisible = false; - configBigTimeVisible = false; - - for (int channel = 0; channel < 2; ++channel) - song->addTrack(Track::AUDIO_GROUP); - AudioTrack* out = (AudioTrack*)song->addTrack(Track::AUDIO_OUTPUT); - AudioTrack* in = (AudioTrack*)song->addTrack(Track::AUDIO_INPUT); - - // set some default routes - std::list il = audioDevice->inputPorts(); - int channel = 0; - for (std::list::iterator i = il.begin(); i != il.end(); ++i, ++channel) { - if (channel == 2) - break; - audio->msgAddRoute(Route(out,channel), Route(*i,channel)); - } - channel = 0; - std::list ol = audioDevice->outputPorts(); - for (std::list::iterator i = ol.begin(); i != ol.end(); ++i, ++channel) { - if (channel == 2) - break; - audio->msgAddRoute(Route(*i, channel), Route(in,channel)); - } - } -#endif song->dirty = false; } @@ -3101,113 +2815,6 @@ void MusE::selectionChanged() } -//--------------------------------------------------------- -// modifyGateTime -//--------------------------------------------------------- - -void MusE::modifyGateTime() - { - printf("not implemented\n"); - } - -//--------------------------------------------------------- -// modifyVelocity -//--------------------------------------------------------- - -void MusE::modifyVelocity() - { - printf("not implemented\n"); - } - -//--------------------------------------------------------- -// crescendo -//--------------------------------------------------------- - -void MusE::crescendo() - { - printf("not implemented\n"); - } - -//--------------------------------------------------------- -// thinOut -//--------------------------------------------------------- - -void MusE::thinOut() - { - printf("not implemented\n"); - } - -//--------------------------------------------------------- -// eraseEvent -//--------------------------------------------------------- - -void MusE::eraseEvent() - { - printf("not implemented\n"); - } - -//--------------------------------------------------------- -// noteShift -//--------------------------------------------------------- - -void MusE::noteShift() - { - printf("not implemented\n"); - } - -//--------------------------------------------------------- -// moveClock -//--------------------------------------------------------- - -void MusE::moveClock() - { - printf("not implemented\n"); - } - -//--------------------------------------------------------- -// copyMeasure -//--------------------------------------------------------- - -void MusE::copyMeasure() - { - printf("not implemented\n"); - } - -//--------------------------------------------------------- -// eraseMeasure -//--------------------------------------------------------- - -void MusE::eraseMeasure() - { - printf("not implemented\n"); - } - -//--------------------------------------------------------- -// deleteMeasure -//--------------------------------------------------------- - -void MusE::deleteMeasure() - { - printf("not implemented\n"); - } - -//--------------------------------------------------------- -// createMeasure -//--------------------------------------------------------- - -void MusE::createMeasure() - { - printf("not implemented\n"); - } - -//--------------------------------------------------------- -// mixTrack -//--------------------------------------------------------- - -void MusE::mixTrack() - { - printf("not implemented\n"); - } //--------------------------------------------------------- // configAppearance @@ -3807,19 +3414,6 @@ void MusE::updateConfiguration() //menuSettings->setAccel(shortcuts[SHRT_CONFIG_AUDIO_PORTS].key, menu_ids[CMD_CONFIG_AUDIO_PORTS]); //menu_help->setAccel(menu_ids[CMD_START_WHATSTHIS], shortcuts[SHRT_START_WHATSTHIS].key); - // Just in case, but no, app kb handler takes care of these. - /* - loopAction->setShortcut(shortcuts[].key); - punchinAction->setShortcut(shortcuts[].key); - punchoutAction->setShortcut(shortcuts[].key); - startAction->setShortcut(shortcuts[].key); - rewindAction->setShortcut(shortcuts[].key); - forwardAction->setShortcut(shortcuts[].key); - stopAction->setShortcut(shortcuts[].key); - playAction->setShortcut(shortcuts[].key); - recordAction->setShortcut(shortcuts[].key); - panicAction->setShortcut(shortcuts[].key); - */ } //--------------------------------------------------------- @@ -3860,24 +3454,6 @@ void MusE::bigtimeClosed() viewBigtimeAction->setChecked(false); } -//--------------------------------------------------------- -// showMixer -//--------------------------------------------------------- - -/* -void MusE::showMixer(bool on) - { - if (on && audioMixer == 0) { - audioMixer = new AudioMixerApp(this); - connect(audioMixer, SIGNAL(closed()), SLOT(mixerClosed())); - audioMixer->resize(config.geometryMixer.size()); - audioMixer->move(config.geometryMixer.topLeft()); - } - if (audioMixer) - audioMixer->setVisible(on); - menuView->setItemChecked(aid1, on); - } -*/ //--------------------------------------------------------- // showMixer1 @@ -3913,17 +3489,6 @@ void MusE::showMixer2(bool on) viewMixerBAction->setChecked(on); } -//--------------------------------------------------------- -// toggleMixer -//--------------------------------------------------------- - -/* -void MusE::toggleMixer() - { - showMixer(!menuView->isItemChecked(aid1)); - } -*/ - //--------------------------------------------------------- // toggleMixer1 //--------------------------------------------------------- @@ -3942,17 +3507,6 @@ void MusE::toggleMixer2(bool checked) showMixer2(checked); } -//--------------------------------------------------------- -// mixerClosed -//--------------------------------------------------------- - -/* -void MusE::mixerClosed() - { - menuView->setItemChecked(aid1, false); - } -*/ - //--------------------------------------------------------- // mixer1Closed //--------------------------------------------------------- @@ -3972,7 +3526,6 @@ void MusE::mixer2Closed() } -//QWidget* MusE::mixerWindow() { return audioMixer; } QWidget* MusE::mixer1Window() { return mixer1; } QWidget* MusE::mixer2Window() { return mixer2; } diff --git a/muse2/muse/app.h b/muse2/muse/app.h index 3f539196..3fd93fc8 100644 --- a/muse2/muse/app.h +++ b/muse2/muse/app.h @@ -11,7 +11,6 @@ #include "config.h" #include "cobject.h" -//#include "tools.h" #include @@ -97,8 +96,6 @@ class MusE : public QMainWindow CMD_AUDIO_BOUNCE_TO_FILE, CMD_AUDIO_BOUNCE_TO_TRACK, CMD_AUDIO_RESTART, CMD_LAST }; - //int menu_ids[CMD_LAST]; - // File menu actions QAction *fileSaveAction, *fileOpenAction, *fileNewAction, *testAction; QAction *fileSaveAsAction, *fileImportMidiAction, *fileExportMidiAction; @@ -228,7 +225,6 @@ class MusE : public QMainWindow void configChanged(); private slots: - //void runPythonScript(); void loadProject(); bool save(); void configGlobalSettings(); @@ -248,7 +244,6 @@ class MusE : public QMainWindow void toggleTransport(bool); void toggleMarker(bool); void toggleBigTime(bool); - //void toggleMixer(); void toggleMixer1(bool); void toggleMixer2(bool); @@ -290,18 +285,12 @@ class MusE : public QMainWindow void cmd(int); void clipboardChanged(); void selectionChanged(); - void modifyGateTime(); - void modifyVelocity(); - void crescendo(); - void thinOut(); - void eraseEvent(); - void noteShift(); - void moveClock(); - void copyMeasure(); - void eraseMeasure(); +/* void copyMeasure(); // commented out by flo: these are not implemented, + void eraseMeasure(); // but maybe will be in future (state: revision 988) void deleteMeasure(); void createMeasure(); void mixTrack(); +*/ void startMidiInputPlugin(int); void hideMitPluginTranspose(); void hideMidiInputTransform(); @@ -323,7 +312,6 @@ class MusE : public QMainWindow void takeAutomationSnapshot(); void clearAutomation(); void bigtimeClosed(); - //void mixerClosed(); void mixer1Closed(); void mixer2Closed(); void markerClosed(); @@ -345,7 +333,6 @@ class MusE : public QMainWindow bool seqRestart(); void loadTemplate(); void showBigtime(bool); - //void showMixer(bool); void showMixer1(bool); void showMixer2(bool); void showMarker(bool); @@ -369,7 +356,6 @@ class MusE : public QMainWindow void setHeartBeat(); void importController(int, MidiPort*, int); QString projectName() { return project.fileName(); } - //QWidget* mixerWindow(); QWidget* mixer1Window(); QWidget* mixer2Window(); QWidget* transportWindow(); diff --git a/muse2/muse/event.cpp b/muse2/muse/event.cpp index 5d16fde9..77b66359 100644 --- a/muse2/muse/event.cpp +++ b/muse2/muse/event.cpp @@ -7,16 +7,10 @@ //========================================================= #include -// #include -//#include "audioconvert.h" #include "event.h" #include "eventbase.h" #include "waveevent.h" #include "midievent.h" -//#include "globals.h" - -// Added by Tim. p3.3.20 -//#define USE_SAMPLERATE //--------------------------------------------------------- // Event @@ -65,11 +59,6 @@ void EventBase::dump(int n) const Event Event::clone() { - // p3.3.31 - //printf("Event::clone() this:%p\n", this); - - // p3.3.31 - //return Event(ev->clone()); #ifdef USE_SAMPLERATE return Event(ev->clone(), _audConv); #else @@ -80,14 +69,9 @@ Event Event::clone() Event::Event() { ev = 0; - //_sfCurFrame = 0; - //_audConv = 0; } Event::Event(EventType t) { - //_sfCurFrame = 0; - //_audConv = 0; - if (t == Wave) ev = new WaveEventBase(t); else @@ -95,30 +79,21 @@ Event::Event(EventType t) { ++(ev->refCount); } Event::Event(const Event& e) { - //_sfCurFrame = 0; - //_audConv = 0; - ev = e.ev; if(ev) ++(ev->refCount); #ifdef USE_SAMPLERATE - //_audConv = AudioConverter::getAudioConverter(e._audConv); if(e._audConv) _audConv = e._audConv->reference(); #endif } Event::Event(EventBase* eb) { - //_sfCurFrame = 0; - //_audConv = 0; - ev = eb; ++(ev->refCount); #ifdef USE_SAMPLERATE if(!ev->sndFile().isNull()) - //_audConv = AudioConverter::getAudioConverter(eb, SRC_SINC_MEDIUM_QUALITY); - //_audConv = new AudioConverter(ev->sndFile().channels(), SRC_SINC_MEDIUM_QUALITY); _audConv = new SRCAudioConverter(ev->sndFile().channels(), SRC_SINC_MEDIUM_QUALITY); #endif } @@ -162,19 +137,6 @@ void Event::setType(EventType t) { } Event& Event::operator=(const Event& e) { - /* - if (ev == e.ev) - return *this; - if (ev && --(ev->refCount) == 0) { - delete ev; - ev = 0; - } - ev = e.ev; - if (ev) - ++(ev->refCount); - return *this; - */ - if (ev != e.ev) { if (ev && --(ev->refCount) == 0) { @@ -191,7 +153,6 @@ Event& Event::operator=(const Event& e) { { if(_audConv) AudioConverter::release(_audConv); - //_audConv = AudioConverter::getAudioConverter(e._audConv); _audConv = e._audConv->reference(); } #endif @@ -207,7 +168,6 @@ bool Event::selected() const { return ev->_selected; } void Event::setSelected(bool val) { ev->_selected = val; } void Event::move(int offset) { ev->move(offset); } -//void Event::read(Xml& xml) { ev->read(xml); } void Event::read(Xml& xml) { ev->read(xml); @@ -216,27 +176,14 @@ void Event::read(Xml& xml) if(!ev->sndFile().isNull()) { if(_audConv) - { _audConv->setChannels(ev->sndFile().channels()); - } else - { - //int srcerr; - //if(debugMsg) - // printf("Event::read Creating samplerate converter with %d channels\n", ev->sndFile().channels()); - //_src_state = src_new(SRC_SINC_MEDIUM_QUALITY, ev->sndFile().channels(), &srcerr); -// _audConv = new AudioConverter(ev->sndFile().channels(), SRC_SINC_MEDIUM_QUALITY); _audConv = new SRCAudioConverter(ev->sndFile().channels(), SRC_SINC_MEDIUM_QUALITY); - //if(!_src_state) - //if(!_audConv) - // printf("Event::read Creation of samplerate converter with %d channels failed:%s\n", ev->sndFile().channels(), src_strerror(srcerr)); - } } #endif } -//void Event::write(int a, Xml& xml, const Pos& o) const { ev->write(a, xml, o); } void Event::write(int a, Xml& xml, const Pos& o, bool forceWavePaths) const { ev->write(a, xml, o, forceWavePaths); } void Event::dump(int n) const { ev->dump(n); } Event Event::mid(unsigned a, unsigned b) { return Event(ev->mid(a, b)); } @@ -268,22 +215,11 @@ int Event::spos() const { return ev->spos(); } void Event::setSpos(int s) { ev->setSpos(s); } SndFileR Event::sndFile() const { return ev->sndFile(); } -//void Event::setSndFile(SndFileR& sf) { ev->setSndFile(sf); } void Event::setSndFile(SndFileR& sf) { ev->setSndFile(sf); #ifdef USE_SAMPLERATE - //if(_audConv) -// if(_audConv && !sf.isNull()) -// { - //_audConv->setSndFile(sf); - //if(sf.isNull()) - // AudioConverter::release(_audConv); - //else -// _audConv->setChannels(sf.channels()); -// } - if(_audConv) { // Do we release? Or keep the converter around, while gaining speed since no rapid creation/destruction. @@ -302,15 +238,8 @@ void Event::setSndFile(SndFileR& sf) #endif } -//void Event::read(unsigned offset, float** bpp, int channels, int nn, bool overwrite) -//void Event::readAudio(unsigned offset, float** bpp, int channels, int nn, bool doSeek, bool overwrite) -// p3.3.33 void Event::readAudio(WavePart* part, unsigned offset, float** bpp, int channels, int nn, bool doSeek, bool overwrite) { - //ev->read(offset, bpp, channels, nn, overwrite); - //ev->readAudio(offset, bpp, channels, nn, doSeek, overwrite); - //_sfCurFrame = ev->readAudio(_src_state, _sfCurFrame, offset, bpp, channels, nn, doSeek, overwrite); - // p3.3.33 ev->readAudio(part, offset, bpp, channels, nn, doSeek, overwrite); } void Event::setTick(unsigned val) { ev->setTick(val); } diff --git a/muse2/muse/event.h b/muse2/muse/event.h index 5a8a74f8..b450d1fd 100644 --- a/muse2/muse/event.h +++ b/muse2/muse/event.h @@ -10,7 +10,6 @@ #define __EVENT_H__ #include -//#include #include #include "wave.h" // wg. SndFile @@ -23,7 +22,6 @@ class QString; class Xml; class EventBase; -//class AudioConverter; class WavePart; //--------------------------------------------------------- @@ -33,20 +31,12 @@ class WavePart; class Event { EventBase* ev; - //off_t _sfCurFrame; - //AudioConverter* _audConv; - public: - //Event() { ev = 0; } Event(); Event(EventType t); Event(const Event& e); Event(EventBase* eb); - //#ifdef USE_SAMPLERATE - //Event(EventBase* eb, AudioConverter* cv); - //#endif - virtual ~Event(); bool empty() const; @@ -62,7 +52,6 @@ class Event { void move(int offset); void read(Xml& xml); - //void write(int a, Xml& xml, const Pos& offset) const; void write(int a, Xml& xml, const Pos& offset, bool ForceWavePaths = false) const; void dump(int n = 0) const; Event clone(); @@ -93,12 +82,9 @@ class Event { void setName(const QString& s); int spos() const; void setSpos(int s); - //AudioConverter* audioConverter() { return _audConv;} SndFileR sndFile() const; virtual void setSndFile(SndFileR& sf); - //virtual void read(unsigned offset, float** bpp, int channels, int nn, bool overwrite = true); - //virtual void readAudio(unsigned /*offset*/, float** /*bpp*/, int /*channels*/, int /*nn*/, bool /*doSeek*/, bool /*overwrite*/); virtual void readAudio(WavePart* /*part*/, unsigned /*offset*/, float** /*bpp*/, int /*channels*/, int /*nn*/, bool /*doSeek*/, bool /*overwrite*/); void setTick(unsigned val); diff --git a/muse2/muse/part.cpp b/muse2/muse/part.cpp index 231b947b..398720af 100644 --- a/muse2/muse/part.cpp +++ b/muse2/muse/part.cpp @@ -827,7 +827,6 @@ void Song::cmdResizePart(Track* track, Part* oPart, unsigned int len) WavePart* nPart = new WavePart(*(WavePart*)oPart); EventList* el = nPart->events(); unsigned new_partlength = tempomap.deltaTick2frame(oPart->tick(), oPart->tick() + len); - //printf("new partlength in frames: %d\n", new_partlength); // If new nr of frames is less than previous what can happen is: // - 0 or more events are beginning after the new final position. Those are removed from the part @@ -839,7 +838,6 @@ void Song::cmdResizePart(Track* track, Part* oPart, unsigned int len) Event e = i->second; unsigned event_startframe = e.frame(); unsigned event_endframe = event_startframe + e.lenFrame(); - //printf("Event frame=%d, length=%d\n", event_startframe, event_length); if (event_endframe < new_partlength) continue; if (event_startframe > new_partlength) { // If event start was after the new length, remove it from part @@ -879,7 +877,6 @@ void Song::cmdResizePart(Track* track, Part* oPart, unsigned int len) unsigned clipframes = (file.samples() - last.spos());// / file.channels(); Event newEvent = last.clone(); - //printf("SndFileR samples=%d channels=%d event samplepos=%d clipframes=%d\n", file.samples(), file.channels(), last.spos(), clipframes); unsigned new_eventlength = new_partlength - last_start; if (new_eventlength > clipframes) // Shrink event length if new partlength exceeds last clip @@ -967,7 +964,6 @@ void Track::splitPart(Part* part, int tickpos, Part*& p1, Part*& p2) p2 = newPart(part); // new right part // Added by Tim. p3.3.6 - //printf("Track::splitPart part ev %p sz:%d ref:%d p1 %p sz:%d ref:%d p2 %p sz:%d ref:%d\n", part->events(), part->events()->size(), part->events()->arefCount(), p1->events(), p1->events()->size(), p1->events()->arefCount(), p2->events(), p2->events()->size(), p2->events()->arefCount()); switch (type()) { case WAVE: diff --git a/muse2/muse/part.h b/muse2/muse/part.h index f7a864e5..9b037edd 100644 --- a/muse2/muse/part.h +++ b/muse2/muse/part.h @@ -24,17 +24,11 @@ class MidiTrack; class WaveTrack; class Xml; class Part; -//class AudioConvertMap; - -// typedef std::multimap >::iterator iEvent; struct ClonePart { - //const EventList* el; const Part* cp; int id; uuid_t uuid; - //ClonePart(const EventList* e, int i) : el(e), id(i) {} - //ClonePart(const Part* p, int i) : cp(p), id(i) {} ClonePart(const Part*, int i = -1); }; @@ -90,12 +84,8 @@ class Part : public PosLen { iEvent addEvent(Event& p); - //virtual void read(Xml&, int newPartOffset=0, bool toTrack = true); - //virtual void write(int, Xml&) const; - //virtual void write(int, Xml&, bool isCopy = false) const; virtual void write(int, Xml&, bool isCopy = false, bool forceWavePaths = false) const; -// virtual Event* newEvent() const = 0; virtual void dump(int n = 0) const; }; @@ -113,7 +103,6 @@ class MidiPart : public Part { virtual MidiPart* clone() const; MidiTrack* track() const { return (MidiTrack*)Part::track(); } -// virtual Event* newEvent() const; virtual void dump(int n = 0) const; }; @@ -134,7 +123,6 @@ class WavePart : public Part { virtual WavePart* clone() const; WaveTrack* track() const { return (WaveTrack*)Part::track(); } -// virtual Event* newEvent() const; virtual void dump(int n = 0) const; }; @@ -167,9 +155,6 @@ extern void addPortCtrlEvents(Event& event, Part* part, bool doClones); extern void removePortCtrlEvents(Part* part, bool doClones); extern void removePortCtrlEvents(Event& event, Part* part, bool doClones); extern CloneList cloneList; -//extern CloneList copyCloneList; -//extern void updateCloneList(Part* oPart, Part* nPart); -//extern void clearClipboardAndCloneList(); extern Part* readXmlPart(Xml&, Track*, bool doClone = false, bool toTrack = true); #endif -- cgit v1.2.3 From 637498c87bf1ac780d8527d0596936fcdd2c6dfc Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Mon, 6 Jun 2011 18:01:05 +0000 Subject: hopefully fixed the "clones aren't treated as clones" bug fixed stupid behaviour of shrink and expand part --- muse2/muse/arranger/pcanvas.cpp | 7 +++++-- muse2/muse/functions.cpp | 26 +++++++++++++++++++------- muse2/muse/functions.h | 4 ++-- muse2/muse/midiedit/scoreedit.cpp | 4 +--- 4 files changed, 27 insertions(+), 14 deletions(-) (limited to 'muse2') diff --git a/muse2/muse/arranger/pcanvas.cpp b/muse2/muse/arranger/pcanvas.cpp index e17d08e1..f7a2abde 100644 --- a/muse2/muse/arranger/pcanvas.cpp +++ b/muse2/muse/arranger/pcanvas.cpp @@ -349,14 +349,15 @@ UndoOp PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) // This increments aref count if cloned, and chains clones. // It also gives the new part a new serial number. dpart = dtrack->newPart(spart, clone); - dpart->events()->incARef(-1); // the later song->applyOperationGroup() will increment it - // so we must decrement it first :/ dpart->setTick(dtick); if(t == MOVE_MOVE) item->setPart(dpart); if (t == MOVE_COPY && !clone) { + dpart->events()->incARef(-1); // the later song->applyOperationGroup() will increment it + // so we must decrement it first :/ + // // Copy Events // @@ -368,6 +369,8 @@ UndoOp PartCanvas::moveItem(CItem* item, const QPoint& newpos, DragType t) de->add(ev); } } + + if (t == MOVE_COPY || t == MOVE_CLONE) { // These will not increment ref count, and will not chain clones... // TODO: is this still correct (by flo93)? diff --git a/muse2/muse/functions.cpp b/muse2/muse/functions.cpp index 3d10a878..b47874fd 100644 --- a/muse2/muse/functions.cpp +++ b/muse2/muse/functions.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -831,10 +832,14 @@ void select_not_in_loop(const std::set& parts) } -void shrink_parts() +void shrink_parts(int raster) { Undo operations; + unsigned min_len; + if (raster<0) raster=config.division; + if (raster>=0) min_len=raster; else min_len=config.division; + TrackList* tracks = song->tracks(); for (iTrack track = tracks->begin(); track != tracks->end(); track++) for (iPart part = (*track)->parts()->begin(); part != (*track)->parts()->end(); part++) @@ -847,10 +852,10 @@ void shrink_parts() if (ev->second.endTick() > len) len=ev->second.endTick(); - if (len > part->second->lenTick()) - len = part->second->lenTick(); + if (raster) len=ceil((float)len/raster)*raster; + if (lensecond->lenTick()) + if (len < part->second->lenTick()) { MidiPart* new_part = new MidiPart(*(MidiPart*)part->second); new_part->setLenTick(len); @@ -861,10 +866,14 @@ void shrink_parts() song->applyOperationGroup(operations); } -void expand_parts() +void expand_parts(int raster) { Undo operations; + unsigned min_len; + if (raster<0) raster=config.division; + if (raster>=0) min_len=raster; else min_len=config.division; + TrackList* tracks = song->tracks(); for (iTrack track = tracks->begin(); track != tracks->end(); track++) for (iPart part = (*track)->parts()->begin(); part != (*track)->parts()->end(); part++) @@ -876,8 +885,11 @@ void expand_parts() for (iEvent ev=events->begin(); ev!=events->end(); ev++) if (ev->second.endTick() > len) len=ev->second.endTick(); - - if (len != part->second->lenTick()) + + if (raster) len=ceil((float)len/raster)*raster; + if (len part->second->lenTick()) { MidiPart* new_part = new MidiPart(*(MidiPart*)part->second); new_part->setLenTick(len); diff --git a/muse2/muse/functions.h b/muse2/muse/functions.h index 8a1eb3ed..633457a9 100644 --- a/muse2/muse/functions.h +++ b/muse2/muse/functions.h @@ -85,8 +85,8 @@ void select_in_loop(const std::set& parts); void select_not_in_loop(const std::set& parts); //functions for parts -void shrink_parts(); -void expand_parts(); +void shrink_parts(int raster=-1); //negative values mean "config.division" +void expand_parts(int raster=-1); void clean_parts(); //functions for reading and writing default values diff --git a/muse2/muse/midiedit/scoreedit.cpp b/muse2/muse/midiedit/scoreedit.cpp index 450d6f98..1a885d99 100644 --- a/muse2/muse/midiedit/scoreedit.cpp +++ b/muse2/muse/midiedit/scoreedit.cpp @@ -4452,14 +4452,12 @@ void staff_t::update_part_indices() /* BUGS and potential bugs - * o clones aren't marked as clones any more :( - * * o when the keymap is not used, this will probably lead to a bug * o tied notes don't work properly when there's a key-change in * between, for example, when a cis is tied to a des * * CURRENT TODO - * o either remove these "hidden notes", or deal with them in the score editor + * o clones should have same size * o insert empty measure should also work inside parts, that is, * move notes _within_ parts * -- cgit v1.2.3