diff options
author | Florian Jung <flo@windfisch.org> | 2013-08-22 18:50:19 +0200 |
---|---|---|
committer | Florian Jung <flo@windfisch.org> | 2013-08-24 18:54:40 +0200 |
commit | 3b165cb0e152d2514618c6e256bdb4f49ac7d867 (patch) | |
tree | 1b5e026ff0522bd8663f778700cb661e3aaaf32c | |
parent | 8c8b3ac35c12af3817ff8d8c3d169af166821198 (diff) |
implemented missing functions of Part
-rw-r--r-- | muse2/muse/event.h | 2 | ||||
-rw-r--r-- | muse2/muse/eventlist.cpp | 2 | ||||
-rw-r--r-- | muse2/muse/part.cpp | 97 | ||||
-rw-r--r-- | muse2/muse/part.h | 4 |
4 files changed, 78 insertions, 27 deletions
diff --git a/muse2/muse/event.h b/muse2/muse/event.h index ed1ddb87..e512e03d 100644 --- a/muse2/muse/event.h +++ b/muse2/muse/event.h @@ -137,7 +137,7 @@ class EventList : public EL { public: ciEvent find(const Event&) const; iEvent find(const Event&); - iEvent add(Event& event); + iEvent add(Event event); void move(Event& event, unsigned tick); void dump() const; void read(Xml& xml, const char* name, bool midi); diff --git a/muse2/muse/eventlist.cpp b/muse2/muse/eventlist.cpp index f499fd2d..ecc7f452 100644 --- a/muse2/muse/eventlist.cpp +++ b/muse2/muse/eventlist.cpp @@ -62,7 +62,7 @@ void EventList::read(Xml& xml, const char* name, bool midi) // add //--------------------------------------------------------- -iEvent EventList::add(Event& event) +iEvent EventList::add(Event event) { // Changed by Tim. An event list containing wave events should be sorted by // frames. WaveTrack::fetchData() relies on the sorting order, and diff --git a/muse2/muse/part.cpp b/muse2/muse/part.cpp index b6d1571a..9b869567 100644 --- a/muse2/muse/part.cpp +++ b/muse2/muse/part.cpp @@ -74,11 +74,8 @@ void Part::chainClone(Part* p) this->_nextClone->_prevClone = this; p->_nextClone = this; - // Synchronize this->_events to p->_events. Need to deep-copy, i.e. clone() the Events. - this->_events.clear(); - for (ciEvent it = p->_events.begin(); it!=p->_events.end(); it++) - this->_events.insert(std::pair<unsigned, Event>(it->first, it->second.clone())); - + // we only chain clones. we must trust in the GUI thread that the eventlist is consistent. + this->_clonemaster_sn = p->_sn; } @@ -90,6 +87,22 @@ void Part::rechainClone() _backupClone = NULL; } +bool Part::isCloneOf(const Part* other) const +{ + return this->_clonemaster_sn == other->_clonemaster_sn; +} + +int Part::nClones() const +{ + int n=1; + + for(const Part* it = this->_nextClone; it!=this; it=it->_nextClone) + n++; + + return n; +} + + // FIXME FINDMICHJETZT TODO: weg damit! //--------------------------------------------------------- @@ -414,30 +427,68 @@ Part::Part(Track* t) _colorIndex = 0; } - -/* FINDMICHJETZT FIXME! -Part* Part::duplicate() const +WavePart* WavePart::duplicateEmpty() const { - Part* dup = duplicateEmpty(); + WavePart* part = new WavePart((WaveTrack*)this->_track); + part->setName(name()); + part->setColorIndex(colorIndex()); + + *(PosLen*)part = *(PosLen*)this; + part->setMute(mute()); + + return part; +} - // copy the eventlist; duplicate each Event(Ptr!). - for (MusECore::ciEvent i = _events.begin(); i != _events.end(); ++i) - dup->_events.add(i->second.clone()) - - return dup; +WavePart* WavePart::duplicate() const +{ + return (WavePart*)Part::duplicate(); } -Part* Part::duplicateEmpty() const +WavePart* WavePart::createNewClone() const { - MidiPart* part = new MidiPart(this->_track); - part->setName(name()); - part->setColorIndex(colorIndex()); + return (WavePart*)Part::createNewClone(); +} - *(PosLen*)part = *(PosLen*)this; - part->setMute(mute()); - - return part; -} */ +MidiPart* MidiPart::duplicateEmpty() const +{ + MidiPart* part = new MidiPart((MidiTrack*)this->_track); + part->setName(name()); + part->setColorIndex(colorIndex()); + + *(PosLen*)part = *(PosLen*)this; + part->setMute(mute()); + + return part; +} + +MidiPart* MidiPart::duplicate() const +{ + return (MidiPart*)Part::duplicate(); +} + +MidiPart* MidiPart::createNewClone() const +{ + return (MidiPart*)Part::createNewClone(); +} + + +Part* Part::createNewClone() const +{ + Part* clone = duplicate(); + clone->_backupClone=const_cast<Part*>(this); + return clone; +} + +Part* Part::duplicate() const +{ + Part* dup = duplicateEmpty(); + + // copy the eventlist; duplicate each Event(Ptr!). + for (MusECore::ciEvent i = _events.begin(); i != _events.end(); ++i) + dup->_events.add(i->second.clone()); + + return dup; +} //--------------------------------------------------------- diff --git a/muse2/muse/part.h b/muse2/muse/part.h index 5523e71d..e579e64d 100644 --- a/muse2/muse/part.h +++ b/muse2/muse/part.h @@ -84,9 +84,9 @@ class Part : public PosLen { public: Part(Track*); virtual ~Part(); - virtual Part* duplicate() const = 0; + virtual Part* duplicate() const; virtual Part* duplicateEmpty() const = 0; - virtual Part* createNewClone() const = 0; + virtual Part* createNewClone() const; // this does NOT chain clones yet. Chain is updated only when the part is really added! virtual void splitPart(int tickpos, Part*& p1, Part*& p2) const; int clonemaster_sn() const { return _clonemaster_sn; } |