struct NoteChange {
NoteDiffCommand::Property property;
NotePtr note;
+ uint32_t note_id;
+
union {
uint8_t old_value;
TimeType old_time;
private:
struct Change {
boost::shared_ptr<Evoral::Event<TimeType> > sysex;
+ gint sysex_id;
SysExDiffCommand::Property property;
TimeType old_time;
TimeType new_time;
struct Change {
PatchChangePtr patch;
Property property;
+ gint patch_id;
union {
TimeType old_time;
uint8_t old_channel;
void filter_channels (BufferSet& bufs, ChannelMode mode, uint32_t mask);
+/* if mode is ForceChannel, force mask to the lowest set channel or 1 if no
+ * channels are set.
+ */
+#define force_mask(mode,mask) (((mode) == ForceChannel) ? (((mask) ? (1<<(ffs((mask))-1)) : 1)) : mask)
+
void _set_playback_channel_mode(ChannelMode mode, uint16_t mask) {
+ mask = force_mask (mode, mask);
g_atomic_int_set(&_playback_channel_mask, (uint32_t(mode) << 16) | uint32_t(mask));
}
void _set_playback_channel_mask (uint16_t mask) {
+ mask = force_mask (get_playback_channel_mode(), mask);
g_atomic_int_set(&_playback_channel_mask, (uint32_t(get_playback_channel_mode()) << 16) | uint32_t(mask));
}
void _set_capture_channel_mode(ChannelMode mode, uint16_t mask) {
+ mask = force_mask (mode, mask);
g_atomic_int_set(&_capture_channel_mask, (uint32_t(mode) << 16) | uint32_t(mask));
}
void _set_capture_channel_mask (uint16_t mask) {
+ mask = force_mask (get_capture_channel_mode(), mask);
g_atomic_int_set(&_capture_channel_mask, (uint32_t(get_capture_channel_mode()) << 16) | uint32_t(mask));
}
+
+#undef force_mask
};
} /* namespace ARDOUR*/
for (ChangeList::iterator i = _changes.begin(); i != _changes.end(); ++i) {
Property prop = i->property;
+
+ if (!i->note) {
+ /* note found during deserialization, so try
+ again now that the model state is different.
+ */
+ i->note = _model->find_note (i->note_id);
+ assert (i->note);
+ }
+
switch (prop) {
case NoteNumber:
if (temporary_removals.find (i->note) == temporary_removals.end()) {
_removed_notes.push_back (*i);
}
}
-
+
if (!side_effect_removals.empty()) {
cerr << "SER: \n";
for (set<NotePtr>::iterator i = side_effect_removals.begin(); i != side_effect_removals.end(); ++i) {
/* notes we modify in a way that requires remove-then-add to maintain ordering */
set<NotePtr> temporary_removals;
+
+ /* lazily discover any affected notes that were not discovered when
+ * loading the history because of deletions, etc.
+ */
+
+ for (ChangeList::iterator i = _changes.begin(); i != _changes.end(); ++i) {
+ if (!i->note) {
+ i->note = _model->find_note (i->note_id);
+ assert (i->note);
+ }
+ }
+
for (ChangeList::iterator i = _changes.begin(); i != _changes.end(); ++i) {
Property prop = i->property;
- switch (prop) {
+ switch (prop) {
case NoteNumber:
- if (
- temporary_removals.find (i->note) == temporary_removals.end() &&
- find (_removed_notes.begin(), _removed_notes.end(), i->note) == _removed_notes.end()
- ) {
+ if (temporary_removals.find (i->note) == temporary_removals.end() &&
+ find (_removed_notes.begin(), _removed_notes.end(), i->note) == _removed_notes.end()) {
/* We only need to mark this note for re-add if (a) we haven't
already marked it and (b) it isn't on the _removed_notes
break;
case StartTime:
- if (
- temporary_removals.find (i->note) == temporary_removals.end() &&
- find (_removed_notes.begin(), _removed_notes.end(), i->note) == _removed_notes.end()
- ) {
+ if (temporary_removals.find (i->note) == temporary_removals.end() &&
+ find (_removed_notes.begin(), _removed_notes.end(), i->note) == _removed_notes.end()) {
/* See above ... */
break;
case Channel:
- if (
- temporary_removals.find (i->note) == temporary_removals.end() &&
- find (_removed_notes.begin(), _removed_notes.end(), i->note) == _removed_notes.end()
- ) {
+ if (temporary_removals.find (i->note) == temporary_removals.end() &&
+ find (_removed_notes.begin(), _removed_notes.end(), i->note) == _removed_notes.end()) {
/* See above ... */
_model->add_note_unlocked (*i);
}
}
-
+
_model->ContentsChanged(); /* EMIT SIGNAL */
}
}
/* we must point at the instance of the note that is actually in the model.
- so go look for it ...
+ so go look for it ... it may not be there (it could have been
+ deleted in a later operation, so store the note id so that we can
+ look it up again later).
*/
change.note = _model->find_note (note_id);
-
- if (!change.note) {
- warning << "MIDI note #" << note_id << " not found in model - programmers should investigate this" << endmsg;
- return change;
- }
+ change.note_id = note_id;
return change;
}
_model->remove_sysex_unlocked (*i);
}
+ /* find any sysex events that were missing when unmarshalling */
+
+ for (ChangeList::iterator i = _changes.begin(); i != _changes.end(); ++i) {
+ if (!i->sysex) {
+ i->sysex = _model->find_sysex (i->sysex_id);
+ assert (i->sysex);
+ }
+ }
+
for (ChangeList::iterator i = _changes.begin(); i != _changes.end(); ++i) {
switch (i->property) {
case Time:
_model->add_sysex_unlocked (*i);
}
+ /* find any sysex events that were missing when unmarshalling */
+
+ for (ChangeList::iterator i = _changes.begin(); i != _changes.end(); ++i) {
+ if (!i->sysex) {
+ i->sysex = _model->find_sysex (i->sysex_id);
+ assert (i->sysex);
+ }
+ }
+
for (ChangeList::iterator i = _changes.begin(); i != _changes.end(); ++i) {
switch (i->property) {
case Time:
*/
change.sysex = _model->find_sysex (sysex_id);
-
- if (!change.sysex) {
- warning << "Sys-ex #" << sysex_id << " not found in model - programmers should investigate this" << endmsg;
- return change;
- }
+ change.sysex_id = sysex_id;
return change;
}
_model->remove_patch_change_unlocked (*i);
}
+ /* find any patch change events that were missing when unmarshalling */
+
+ for (ChangeList::iterator i = _changes.begin(); i != _changes.end(); ++i) {
+ if (!i->patch) {
+ i->patch = _model->find_patch_change (i->patch_id);
+ assert (i->patch);
+ }
+ }
+
set<PatchChangePtr> temporary_removals;
for (ChangeList::iterator i = _changes.begin(); i != _changes.end(); ++i) {
_model->add_patch_change_unlocked (*i);
}
+ /* find any patch change events that were missing when unmarshalling */
+
+ for (ChangeList::iterator i = _changes.begin(); i != _changes.end(); ++i) {
+ if (!i->patch) {
+ i->patch = _model->find_patch_change (i->patch_id);
+ assert (i->patch);
+ }
+ }
+
set<PatchChangePtr> temporary_removals;
for (ChangeList::iterator i = _changes.begin(); i != _changes.end(); ++i) {
XMLProperty* prop;
Evoral::event_id_t id;
Evoral::MusicalTime time = 0;
- uint8_t channel = 0;
- uint8_t program = 0;
+ int channel = 0;
+ int program = 0;
int bank = 0;
-
+
if ((prop = n->property ("id")) != 0) {
istringstream s (prop->value());
s >> id;
{
XMLProperty* prop;
Change c;
+ int an_int;
prop = n->property ("property");
assert (prop);
assert (prop);
Evoral::event_id_t const id = atoi (prop->value().c_str());
+ /* we need to load via an int intermediate for all properties that are
+ actually uint8_t (char/byte).
+ */
+
prop = n->property ("old");
assert (prop);
{
if (c.property == Time) {
s >> c.old_time;
} else if (c.property == Channel) {
- s >> c.old_channel;
+ s >> an_int;
+ c.old_channel = an_int;
} else if (c.property == Program) {
- s >> c.old_program;
+ s >> an_int;
+ c.old_program = an_int;
} else if (c.property == Bank) {
- s >> c.old_bank;
+ s >> an_int;
+ c.old_bank = an_int;
}
}
assert (prop);
{
istringstream s (prop->value ());
+
if (c.property == Time) {
s >> c.new_time;
} else if (c.property == Channel) {
- s >> c.new_channel;
+ s >> an_int;
+ c.new_channel = an_int;
} else if (c.property == Program) {
- s >> c.new_program;
+ s >> an_int;
+ c.new_program = an_int;
} else if (c.property == Bank) {
- s >> c.new_bank;
+ s >> an_int;
+ c.new_bank = an_int;
}
}
c.patch = _model->find_patch_change (id);
- assert (c.patch);
+ c.patch_id = id;
return c;
}
assert (ms);
assert (!ms->mutex().trylock ());
- return WriteLock(new WriteLockImpl(NULL, _lock, _control_lock));
+ return WriteLock(new WriteLockImpl(0, _lock, _control_lock));
}
int
playback_channel_mode = ChannelMode (string_2_enum(prop->value(), playback_channel_mode));
}
if ((prop = node.property ("capture-channel-mode")) != 0) {
- playback_channel_mode = ChannelMode (string_2_enum(prop->value(), capture_channel_mode));
+ capture_channel_mode = ChannelMode (string_2_enum(prop->value(), capture_channel_mode));
}
if ((prop = node.property ("channel-mode")) != 0) {
/* 3.0 behaviour where capture and playback modes were not separated */
void what_has_data(std::set<Parameter>&) const;
- Glib::Threads::Mutex& control_lock() const { return _control_lock; }
+ Glib::Threads::Mutex& control_lock() const { return _control_lock; }
protected:
virtual void control_list_marked_dirty () {}
uint8_t channel () const { return _program_change.buffer()[0] & 0xf; }
inline bool operator< (const PatchChange<Time>& o) const {
- if (time() != o.time()) {
+ if (!musical_time_equal (time(), o.time())) {
return time() < o.time();
}
}
inline bool operator== (const PatchChange<Time>& o) const {
- return (time() == o.time() && program() == o.program() && bank() == o.bank());
+ return (musical_time_equal (time(), o.time()) && program() == o.program() && bank() == o.bank());
}
/** The PatchChange is made up of messages() MIDI messages; this method returns them by index.
}
+template<typename Time>
+std::ostream& operator<< (std::ostream& o, const Evoral::PatchChange<Time>& p) {
+ o << "Patch Change " << p.id() << " @ " << p.time() << " bank " << (int) p.bank() << " program " << (int) p.program();
+ return o;
+}
+
#endif
struct WriteLockImpl {
WriteLockImpl(Glib::Threads::RWLock& s, Glib::Threads::Mutex& c)
: sequence_lock(new Glib::Threads::RWLock::WriterLock(s))
- , control_lock(new Glib::Threads::Mutex::Lock(c))
- { }
+ , control_lock(new Glib::Threads::Mutex::Lock(c)) { }
~WriteLockImpl() {
delete sequence_lock;
delete control_lock;
typedef boost::shared_ptr<WriteLockImpl> WriteLock;
virtual ReadLock read_lock() const { return ReadLock(new Glib::Threads::RWLock::ReaderLock(_lock)); }
- virtual WriteLock write_lock() { return WriteLock(new WriteLockImpl(_lock, _control_lock)); }
+ virtual WriteLock write_lock() { return WriteLock(new WriteLockImpl(_lock, _control_lock)); }
void clear();
struct EarlierNoteComparator {
inline bool operator()(const boost::shared_ptr< const Note<Time> > a,
const boost::shared_ptr< const Note<Time> > b) const {
- return a->time() < b->time();
+ return musical_time_less_than (a->time(), b->time());
}
};
typedef const Note<Time>* value_type;
inline bool operator()(const boost::shared_ptr< const Note<Time> > a,
const boost::shared_ptr< const Note<Time> > b) const {
+ return musical_time_greater_than (a->time(), b->time());
return a->time() > b->time();
}
};
typedef const Note<Time>* value_type;
inline bool operator()(const boost::shared_ptr< const Note<Time> > a,
const boost::shared_ptr< const Note<Time> > b) const {
- return a->end_time() > b->end_time();
+ return musical_time_less_than (a->end_time(), b->end_time());
}
};
struct EarlierSysExComparator {
inline bool operator() (constSysExPtr a, constSysExPtr b) const {
- return a->time() < b->time();
+ return musical_time_less_than (a->time(), b->time());
}
};
struct EarlierPatchChangeComparator {
inline bool operator() (constPatchChangePtr a, constPatchChangePtr b) const {
- return a->time() < b->time();
+ return musical_time_less_than (a->time(), b->time());
}
};
return fabs (a - b) <= (1.0/1920.0);
}
+static inline bool musical_time_less_than (MusicalTime a, MusicalTime b) {
+ /* acceptable tolerance is 1 tick. Nice if there was no magic number here */
+ if (fabs (a - b) <= (1.0/1920.0)) {
+ return false; /* effectively identical */
+ } else {
+ return a < b;
+ }
+}
+
+static inline bool musical_time_greater_than (MusicalTime a, MusicalTime b) {
+ /* acceptable tolerance is 1 tick. Nice if there was no magic number here */
+ if (fabs (a - b) <= (1.0/1920.0)) {
+ return false; /* effectively identical */
+ } else {
+ return a > b;
+ }
+}
+
+static inline bool musical_time_greater_or_equal_to (MusicalTime a, MusicalTime b) {
+ /* acceptable tolerance is 1 tick. Nice if there was no magic number here */
+ if (fabs (a - b) <= (1.0/1920.0)) {
+ return true; /* effectively identical, note the "or_equal_to" */
+ } else {
+ return a >= b;
+ }
+}
+
/** Type of an event (opaque, mapped by application) */
typedef uint32_t EventType;
Sequence<Time>::remove_note_unlocked(const constNotePtr note)
{
bool erased = false;
+ bool id_matched = false;
- _edited = true;
-
- DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 remove note %2 @ %3\n", this, (int)note->note(), note->time()));
+ DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 remove note #%2 %3 @ %4\n", this, note->id(), (int)note->note(), note->time()));
- typename Sequence<Time>::Notes::iterator i = note_lower_bound(note->time());
- while (i != _notes.end() && (*i)->time() == note->time()) {
+ /* first try searching for the note using the time index, which is
+ * faster since the container is "indexed" by time. (technically, this
+ * means that lower_bound() can do a binary search rather than linear)
+ *
+ * this may not work, for reasons explained below.
+ */
- typename Sequence<Time>::Notes::iterator tmp = i;
- ++tmp;
+ typename Sequence<Time>::Notes::iterator i;
+
+ for (i = note_lower_bound(note->time()); i != _notes.end() && musical_time_equal ((*i)->time(), note->time()); ++i) {
if (*i == note) {
- NotePtr n = *i;
-
- DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1\terasing note %2 @ %3\n", this, (int)(*i)->note(), (*i)->time()));
+ DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1\terasing note #%2 %3 @ %4\n", this, (*i)->id(), (int)(*i)->note(), (*i)->time()));
_notes.erase (i);
- if (n->note() == _lowest_note || n->note() == _highest_note) {
+ if (note->note() == _lowest_note || note->note() == _highest_note) {
_lowest_note = 127;
_highest_note = 0;
}
erased = true;
+ break;
}
+ }
- i = tmp;
+ DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1\ttime-based lookup did not find note #%2 %3 @ %4\n", this, note->id(), (int)note->note(), note->time()));
+
+ if (!erased) {
+
+ /* if the note's time property was changed in tandem with some
+ * other property as the next operation after it was added to
+ * the sequence, then at the point where we call this to undo
+ * the add, the note we are targetting currently has a
+ * different time property than the one we we passed via
+ * the argument.
+ *
+ * in this scenario, we have no choice other than to linear
+ * search the list of notes and find the note by ID.
+ */
+
+ for (i = _notes.begin(); i != _notes.end(); ++i) {
+
+ if ((*i)->id() == note->id()) {
+
+ DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1\tID-based pass, erasing note #%2 %3 @ %4\n", this, (*i)->id(), (int)(*i)->note(), (*i)->time()));
+ _notes.erase (i);
+
+ if (note->note() == _lowest_note || note->note() == _highest_note) {
+
+ _lowest_note = 127;
+ _highest_note = 0;
+
+ for (typename Sequence<Time>::Notes::iterator ii = _notes.begin(); ii != _notes.end(); ++ii) {
+ if ((*ii)->note() < _lowest_note)
+ _lowest_note = (*ii)->note();
+ if ((*ii)->note() > _highest_note)
+ _highest_note = (*ii)->note();
+ }
+ }
+
+ erased = true;
+ id_matched = true;
+ break;
+ }
+ }
}
+
+ if (erased) {
- Pitches& p (pitches (note->channel()));
+ Pitches& p (pitches (note->channel()));
+
+ typename Pitches::iterator j;
- NotePtr search_note(new Note<Time>(0, 0, 0, note->note(), 0));
+ /* if we had to ID-match above, we can't expect to find it in
+ * pitches via note comparison either. so do another linear
+ * search to locate it. otherwise, we can use the note index
+ * to potentially speed things up.
+ */
- typename Pitches::iterator j = p.lower_bound (search_note);
- while (j != p.end() && (*j)->note() == note->note()) {
- typename Pitches::iterator tmp = j;
- ++tmp;
+ if (id_matched) {
+
+ for (j = p.begin(); j != p.end(); ++j) {
+ if ((*j)->id() == note->id()) {
+ p.erase (j);
+ break;
+ }
+ }
+
+ } else {
- if (*j == note) {
- DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1\terasing pitch %2 @ %3\n", this, (int)(*j)->note(), (*j)->time()));
- p.erase (j);
+ /* Now find the same note in the "pitches" list (which indexes
+ * notes by channel+time. We care only about its note number
+ * so the search_note has all other properties unset.
+ */
+
+ NotePtr search_note (new Note<Time>(0, 0, 0, note->note(), 0));
+
+ for (j = p.lower_bound (search_note); j != p.end() && (*j)->note() == note->note(); ++j) {
+
+ if ((*j) == note) {
+ DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1\terasing pitch %2 @ %3\n", this, (int)(*j)->note(), (*j)->time()));
+ p.erase (j);
+ break;
+ }
+ }
}
- j = tmp;
- }
+ if (j == p.end()) {
+ warning << string_compose ("erased note %1 not found in pitches for channel %2", *note, (int) note->channel()) << endmsg;
+ }
- if (!erased) {
- cerr << "Unable to find note to erase matching " << *note.get() << endl;
+ _edited = true;
+
+ } else {
+ cerr << "Unable to find note to erase matching " << *note.get() << endmsg;
}
}
Sequence<Time>::remove_patch_change_unlocked (const constPatchChangePtr p)
{
typename Sequence<Time>::PatchChanges::iterator i = patch_change_lower_bound (p->time ());
- while (i != _patch_changes.end() && (*i)->time() == p->time()) {
+
+ while (i != _patch_changes.end() && (musical_time_equal ((*i)->time(), p->time()))) {
typename Sequence<Time>::PatchChanges::iterator tmp = i;
++tmp;
- if (*i == p) {
+ if (**i == *p) {
_patch_changes.erase (i);
}
{
PatchChangePtr search (new PatchChange<Time> (t, 0, 0, 0));
typename Sequence<Time>::PatchChanges::const_iterator i = _patch_changes.lower_bound (search);
- assert (i == _patch_changes.end() || (*i)->time() >= t);
+ assert (i == _patch_changes.end() || musical_time_greater_or_equal_to ((*i)->time(), t));
return i;
}