diff options
author | Hans Baier <hansfbaier@googlemail.com> | 2012-10-11 03:22:17 +0000 |
---|---|---|
committer | Hans Baier <hansfbaier@googlemail.com> | 2012-10-11 03:22:17 +0000 |
commit | 97c23848d7d4126dc948caac47476317d6752e4d (patch) | |
tree | 1c5eaa7d4d1041bab6bf9b97d9b4ee552c5e12d8 /libs | |
parent | 9707a0e8271a54dd21e49d6ca9ae98378ac4f8a5 (diff) |
implement deleting of sysex events
git-svn-id: svn://localhost/ardour2/branches/3.0@13238 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/midi_model.h | 3 | ||||
-rw-r--r-- | libs/ardour/midi_model.cc | 14 | ||||
-rw-r--r-- | libs/evoral/evoral/Sequence.hpp | 15 | ||||
-rw-r--r-- | libs/evoral/src/Sequence.cpp | 44 |
4 files changed, 73 insertions, 3 deletions
diff --git a/libs/ardour/ardour/midi_model.h b/libs/ardour/ardour/midi_model.h index 38bd3ab982..0d11f940b9 100644 --- a/libs/ardour/ardour/midi_model.h +++ b/libs/ardour/ardour/midi_model.h @@ -152,6 +152,7 @@ public: int set_state (const XMLNode&, int version); XMLNode & get_state (); + void remove (SysExPtr sysex); void operator() (); void undo (); @@ -168,6 +169,8 @@ public: typedef std::list<Change> ChangeList; ChangeList _changes; + std::list<SysExPtr> _removed; + XMLNode & marshal_change (const Change &); Change unmarshal_change (XMLNode *); }; diff --git a/libs/ardour/midi_model.cc b/libs/ardour/midi_model.cc index e86b229c71..4c6f6633d5 100644 --- a/libs/ardour/midi_model.cc +++ b/libs/ardour/midi_model.cc @@ -786,6 +786,10 @@ MidiModel::SysExDiffCommand::operator() () { MidiModel::WriteLock lock (_model->edit_lock ()); + for (list<SysExPtr>::iterator i = _removed.begin(); i != _removed.end(); ++i) { + _model->remove_sysex_unlocked (*i); + } + for (ChangeList::iterator i = _changes.begin(); i != _changes.end(); ++i) { switch (i->property) { case Time: @@ -803,6 +807,10 @@ MidiModel::SysExDiffCommand::undo () { MidiModel::WriteLock lock (_model->edit_lock ()); + for (list<SysExPtr>::iterator i = _removed.begin(); i != _removed.end(); ++i) { + _model->add_sysex_unlocked (*i); + } + for (ChangeList::iterator i = _changes.begin(); i != _changes.end(); ++i) { switch (i->property) { case Time: @@ -816,6 +824,12 @@ MidiModel::SysExDiffCommand::undo () _model->ContentsChanged(); /* EMIT SIGNAL */ } +void +MidiModel::SysExDiffCommand::remove (SysExPtr sysex) +{ + _removed.push_back(sysex); +} + XMLNode& MidiModel::SysExDiffCommand::marshal_change (const Change& change) { diff --git a/libs/evoral/evoral/Sequence.hpp b/libs/evoral/evoral/Sequence.hpp index cb851cf2f6..815d02f980 100644 --- a/libs/evoral/evoral/Sequence.hpp +++ b/libs/evoral/evoral/Sequence.hpp @@ -181,7 +181,16 @@ public: void set_notes (const Sequence<Time>::Notes& n); - typedef std::vector< boost::shared_ptr< Event<Time> > > SysExes; + typedef boost::shared_ptr< Event<Time> > SysExPtr; + typedef boost::shared_ptr<const Event<Time> > constSysExPtr; + + struct EarlierSysExComparator { + inline bool operator() (constSysExPtr a, constSysExPtr b) const { + return a->time() < b->time(); + } + }; + + typedef std::multiset<SysExPtr, EarlierSysExComparator> SysExes; inline SysExes& sysexes() { return _sysexes; } inline const SysExes& sysexes() const { return _sysexes; } @@ -262,6 +271,7 @@ public: typename Notes::const_iterator note_lower_bound (Time t) const; typename PatchChanges::const_iterator patch_change_lower_bound (Time t) const; + typename SysExes::const_iterator sysex_lower_bound (Time t) const; bool control_to_midi_event(boost::shared_ptr< Event<Time> >& ev, const ControlIterator& iter) const; @@ -279,6 +289,9 @@ public: void add_patch_change_unlocked (const PatchChangePtr); void remove_patch_change_unlocked (const constPatchChangePtr); + void add_sysex_unlocked (const SysExPtr); + void remove_sysex_unlocked (const SysExPtr); + uint8_t lowest_note() const { return _lowest_note; } uint8_t highest_note() const { return _highest_note; } diff --git a/libs/evoral/src/Sequence.cpp b/libs/evoral/src/Sequence.cpp index 7a8a08cfdf..1b5683320c 100644 --- a/libs/evoral/src/Sequence.cpp +++ b/libs/evoral/src/Sequence.cpp @@ -494,7 +494,7 @@ Sequence<Time>::Sequence(const Sequence<Time>& other) for (typename SysExes::const_iterator i = other._sysexes.begin(); i != other._sysexes.end(); ++i) { boost::shared_ptr<Event<Time> > n (new Event<Time> (**i, true)); - _sysexes.push_back (n); + _sysexes.insert (n); } for (typename PatchChanges::const_iterator i = other._patch_changes.begin(); i != other._patch_changes.end(); ++i) { @@ -788,6 +788,24 @@ Sequence<Time>::remove_patch_change_unlocked (const constPatchChangePtr p) } } +template<typename Time> +void +Sequence<Time>::remove_sysex_unlocked (const SysExPtr sysex) +{ + typename Sequence<Time>::SysExes::iterator i = sysex_lower_bound (sysex->time ()); + while (i != _sysexes.end() && (*i)->time() == sysex->time()) { + + typename Sequence<Time>::SysExes::iterator tmp = i; + ++tmp; + + if (*i == sysex) { + _sysexes.erase (i); + } + + i = tmp; + } +} + /** Append \a ev to model. NOT realtime safe. * * The timestamp of event is expected to be relative to @@ -984,7 +1002,7 @@ Sequence<Time>::append_sysex_unlocked(const MIDIEvent<Time>& ev, event_id_t /* e boost::shared_ptr<MIDIEvent<Time> > event(new MIDIEvent<Time>(ev, true)); /* XXX sysex events should use IDs */ - _sysexes.push_back(event); + _sysexes.insert(event); } template<typename Time> @@ -1012,6 +1030,17 @@ Sequence<Time>::add_patch_change_unlocked (PatchChangePtr p) } template<typename Time> +void +Sequence<Time>::add_sysex_unlocked (SysExPtr s) +{ + if (s->id () < 0) { + s->set_id (Evoral::next_event_id ()); + } + + _sysexes.insert (s); +} + +template<typename Time> bool Sequence<Time>::contains (const NotePtr& note) const { @@ -1105,6 +1134,17 @@ Sequence<Time>::patch_change_lower_bound (Time t) const return i; } +/** Return the earliest sysex with time >= t */ +template<typename Time> +typename Sequence<Time>::SysExes::const_iterator +Sequence<Time>::sysex_lower_bound (Time t) const +{ + SysExPtr search (new Event<Time> (0, t)); + typename Sequence<Time>::SysExes::const_iterator i = _sysexes.lower_bound (search); + assert (i == _sysexes.end() || (*i)->time() >= t); + return i; +} + template<typename Time> void Sequence<Time>::get_notes (Notes& n, NoteOperator op, uint8_t val, int chan_mask) const |