diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2010-05-31 19:47:15 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2010-05-31 19:47:15 +0000 |
commit | db6706429643d80e68a050daa015d17f36d5321b (patch) | |
tree | 1cc41a1d46050029082825043ed07663b0b6d72f | |
parent | c51d6a15829439242c8520a78b8d89ed06cc697b (diff) |
switch Evoral::Sequence debugging to use DEBUG_TRACE(); Sequence uses multiset<...,EarlierNoteComparator> for _write_notes, does FIFO note resolution for overlapping notes in SMF file; implement Sequence::overlaps() ... current use is uncertain; ARDOUR::coverage() uses 64bit framepos_t
git-svn-id: svn://localhost/ardour2/branches/3.0@7199 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | libs/ardour/ardour/types.h | 6 | ||||
-rw-r--r-- | libs/ardour/audiofilesource.cc | 2 | ||||
-rw-r--r-- | libs/ardour/globals.cc | 9 | ||||
-rw-r--r-- | libs/evoral/evoral/Note.hpp | 3 | ||||
-rw-r--r-- | libs/evoral/evoral/Sequence.hpp | 9 | ||||
-rw-r--r-- | libs/evoral/evoral/types.hpp | 9 | ||||
-rw-r--r-- | libs/evoral/src/Sequence.cpp | 164 | ||||
-rw-r--r-- | libs/evoral/wscript | 1 |
8 files changed, 130 insertions, 73 deletions
diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index 2bbb140bb2..e55840cb20 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -82,9 +82,9 @@ namespace ARDOUR { OverlapEnd, // overlap begins within and covers end OverlapExternal // overlap extends to (at least) begin+end }; - - OverlapType coverage (nframes_t start_a, nframes_t end_a, - nframes_t start_b, nframes_t end_b); + + ARDOUR::OverlapType coverage (framepos_t sa, framepos_t ea, + framepos_t sb, framepos_t eb); /** See parameter.h * XXX: I don't think/hope these hex values matter anymore. diff --git a/libs/ardour/audiofilesource.cc b/libs/ardour/audiofilesource.cc index 1973678359..c783b47b9b 100644 --- a/libs/ardour/audiofilesource.cc +++ b/libs/ardour/audiofilesource.cc @@ -222,7 +222,7 @@ AudioFileSource::old_peak_path (ustring audio_path) #ifdef __APPLE__ snprintf (buf, sizeof (buf), "%u-%u-%d.peak", stat_mount.st_ino, stat_file.st_ino, _channel); #else - snprintf (buf, sizeof (buf), "%lld-%lld-%d.peak", stat_mount.st_ino, stat_file.st_ino, _channel); + snprintf (buf, sizeof (buf), "%" PRId64 "-%" PRId64 "-%d.peak", (int64_t) stat_mount.st_ino, (int64_t) stat_file.st_ino, _channel); #endif ustring res = peak_dir; diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc index b78edc11d2..c9641bfe43 100644 --- a/libs/ardour/globals.cc +++ b/libs/ardour/globals.cc @@ -535,8 +535,8 @@ ARDOUR::setup_fpu () } ARDOUR::OverlapType -ARDOUR::coverage (nframes_t sa, nframes_t ea, - nframes_t sb, nframes_t eb) +ARDOUR::coverage (framepos_t sa, framepos_t ea, + framepos_t sb, framepos_t eb) { /* OverlapType returned reflects how the second (B) range overlaps the first (A). @@ -563,11 +563,8 @@ ARDOUR::coverage (nframes_t sa, nframes_t ea, "B is internal to A" */ -#ifdef OLD_COVERAGE - if ((sb >= sa) && (eb <= ea)) { -#else + if ((sb > sa) && (eb <= ea)) { -#endif return OverlapInternal; } diff --git a/libs/evoral/evoral/Note.hpp b/libs/evoral/evoral/Note.hpp index 6110ad42fe..1c48634530 100644 --- a/libs/evoral/evoral/Note.hpp +++ b/libs/evoral/evoral/Note.hpp @@ -42,6 +42,7 @@ public: note() == other.note() && musical_time_equal (length(), other.length()) && velocity() == other.velocity() && + off_velocity() == other.off_velocity() && channel() == other.channel(); } @@ -49,6 +50,7 @@ public: inline Time end_time() const { return _off_event.time(); } inline uint8_t note() const { return _on_event.note(); } inline uint8_t velocity() const { return _on_event.velocity(); } + inline uint8_t off_velocity() const { return _off_event.velocity(); } inline Time length() const { return _off_event.time() - _on_event.time(); } inline uint8_t channel() const { assert(_on_event.channel() == _off_event.channel()); @@ -58,6 +60,7 @@ public: inline void set_time(Time t) { _off_event.time() = t + length(); _on_event.time() = t; } inline void set_note(uint8_t n) { _on_event.buffer()[1] = n; _off_event.buffer()[1] = n; } inline void set_velocity(uint8_t n) { _on_event.buffer()[2] = n; } + inline void set_off_velocity(uint8_t n) { _off_event.buffer()[2] = n; } inline void set_length(Time l) { _off_event.time() = _on_event.time() + l; } inline void set_channel(uint8_t c) { _on_event.set_channel(c); _off_event.set_channel(c); } diff --git a/libs/evoral/evoral/Sequence.hpp b/libs/evoral/evoral/Sequence.hpp index 36f4138abd..c76d126904 100644 --- a/libs/evoral/evoral/Sequence.hpp +++ b/libs/evoral/evoral/Sequence.hpp @@ -220,7 +220,9 @@ public: bool edited() const { return _edited; } void set_edited(bool yn) { _edited = yn; } + bool overlaps (const boost::shared_ptr< Note<Time> > ev) const; bool contains (const boost::shared_ptr< Note<Time> > ev) const; + bool add_note_unlocked(const boost::shared_ptr< Note<Time> > note); void remove_note_unlocked(const boost::shared_ptr< const Note<Time> > note); @@ -234,8 +236,11 @@ protected: private: friend class const_iterator; + bool overlaps_unlocked (const boost::shared_ptr< Note<Time> > ev) const; + bool contains_unlocked (const boost::shared_ptr< Note<Time> > ev) const; + void append_note_on_unlocked(uint8_t chan, Time time, uint8_t note, uint8_t velocity); - void append_note_off_unlocked(uint8_t chan, Time time, uint8_t note); + void append_note_off_unlocked(uint8_t chan, Time time, uint8_t note, uint8_t velocity); void append_control_unlocked(const Parameter& param, Time time, double value); void append_sysex_unlocked(const MIDIEvent<Time>& ev); @@ -244,7 +249,7 @@ private: Notes _notes; SysExes _sysexes; - typedef std::set<boost::shared_ptr< Note<Time> >, NoteNumberComparator> WriteNotes; + typedef std::multiset<boost::shared_ptr< Note<Time> >, EarlierNoteComparator> WriteNotes; WriteNotes _write_notes[16]; bool _writing; diff --git a/libs/evoral/evoral/types.hpp b/libs/evoral/evoral/types.hpp index a2cc814c69..5ae646c292 100644 --- a/libs/evoral/evoral/types.hpp +++ b/libs/evoral/evoral/types.hpp @@ -24,6 +24,8 @@ #include <cmath> #include <cfloat> +#include "pbd/debug.h" + namespace Evoral { /** Frame count (i.e. length of time in audio frames) */ @@ -53,4 +55,11 @@ struct RangeMove { } // namespace Evoral +namespace PBD { + namespace DEBUG { + extern uint64_t Sequence; + extern uint64_t Note; + } +} + #endif // EVORAL_TYPES_HPP diff --git a/libs/evoral/src/Sequence.cpp b/libs/evoral/src/Sequence.cpp index 2dadbeb64d..e3db285287 100644 --- a/libs/evoral/src/Sequence.cpp +++ b/libs/evoral/src/Sequence.cpp @@ -24,6 +24,9 @@ #include <stdexcept> #include <stdint.h> #include <cstdio> + +#include "pbd/compose.h" + #include "evoral/Control.hpp" #include "evoral/ControlList.hpp" #include "evoral/ControlSet.hpp" @@ -33,16 +36,8 @@ #include "evoral/TypeMap.hpp" #include "evoral/midi_util.h" -// #define DEBUG_SEQUENCE 1 -#ifdef DEBUG_SEQUENCE - #include <boost/format.hpp> - using boost::format; - #define DUMP(x) cerr << (x); -#else - #define DUMP(x) -#endif - using namespace std; +using namespace PBD; namespace Evoral { @@ -66,7 +61,7 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq, Time t , _sysex_iter(seq.sysexes().end()) , _control_iter(_control_iters.end()) { - DUMP(format("Created Iterator @ %1% (is end: %2%)\n)") % t % _is_end); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("Created Iterator @ %1 (is end: %2)\n)", t, _is_end)); if (!_is_end) { _lock = seq.read_lock(); @@ -95,12 +90,12 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq, Time t bool found = false; size_t earliest_control_index = 0; for (Controls::const_iterator i = seq._controls.begin(); i != seq._controls.end(); ++i) { - DUMP(format("Iterator: control: %1%\n") % seq._type_map.to_symbol(i->first)); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("Iterator: control: %1\n", seq._type_map.to_symbol(i->first))); double x, y; bool ret = i->second->list()->rt_safe_earliest_event_unlocked(t, DBL_MAX, x, y, true); if (!ret) { - DUMP(format("Iterator: CC %1% (size %2%) has no events past %3%\n") - % i->first.id() % i->second->list()->size() % t); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("Iterator: CC %1 (size %2) has no events past %3\n", + i->first.id(), i->second->list()->size(), t)); continue; } @@ -113,7 +108,7 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq, Time t continue; } - DUMP(format("Iterator: CC %1% added (%2%, %3%)\n") % i->first.id() % x % y); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("Iterator: CC %1 added (%2, %3)\n", i->first.id(), x, y)); const ControlIterator new_iter(i->second->list(), x, y); _control_iters.push_back(new_iter); @@ -156,18 +151,18 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq, Time t switch (_type) { case NOTE_ON: - DUMP(format("Starting at note on event @ %1%\n") % earliest_t); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("Starting at note on event @ %1\n", earliest_t)); _event = boost::shared_ptr< Event<Time> >( new Event<Time>((*_note_iter)->on_event(), true)); _active_notes.push(*_note_iter); break; case SYSEX: - DUMP(format("Starting at sysex event @ %1%\n") % earliest_t); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("Starting at sysex event @ %1\n", earliest_t)); _event = boost::shared_ptr< Event<Time> >( new Event<Time>(*(*_sysex_iter), true)); break; case CONTROL: - DUMP(format("Starting at control event @ %1%\n") % earliest_t); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("Starting at control event @ %1\n", earliest_t)); seq.control_to_midi_event(_event, earliest_control); break; default: @@ -175,14 +170,14 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq, Time t } if (_type == NIL || !_event || _event->size() == 0) { - DUMP(format("Starting at end @ %1%\n") % t); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("Starting at end @ %1\n", t)); _type = NIL; _is_end = true; } else { - DUMP(printf("New iterator = 0x%x : 0x%x @ %f\n", - (int)_event->event_type(), - (int)((MIDIEvent<Time>*)_event.get())->type(), - _event->time())); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("New iterator = 0x%x : 0x%x @ %f\n", + (int)_event->event_type(), + (int)((MIDIEvent<Time>*)_event.get())->type(), + _event->time())); assert(midi_event_is_valid(_event->buffer(), _event->size())); } } @@ -217,7 +212,7 @@ Sequence<Time>::const_iterator::operator++() throw std::logic_error("Attempt to iterate past end of Sequence"); } - DUMP("Sequence::const_iterator++\n"); + DEBUG_TRACE(DEBUG::Sequence, "Sequence::const_iterator++\n"); assert(_event && _event->buffer() && _event->size() > 0); const MIDIEvent<Time>& ev = *((MIDIEvent<Time>*)_event.get()); @@ -310,26 +305,26 @@ Sequence<Time>::const_iterator::operator++() // Set event to reflect new position switch (_type) { case NOTE_ON: - DUMP("iterator = note on\n"); + DEBUG_TRACE(DEBUG::Sequence, "iterator = note on\n"); *_event = (*_note_iter)->on_event(); _active_notes.push(*_note_iter); break; case NOTE_OFF: - DUMP("iterator = note off\n"); + DEBUG_TRACE(DEBUG::Sequence, "iterator = note off\n"); assert(!_active_notes.empty()); *_event = _active_notes.top()->off_event(); _active_notes.pop(); break; case CONTROL: - DUMP("iterator = control\n"); + DEBUG_TRACE(DEBUG::Sequence, "iterator = control\n"); _seq->control_to_midi_event(_event, *_control_iter); break; case SYSEX: - DUMP("iterator = sysex\n"); + DEBUG_TRACE(DEBUG::Sequence, "iterator = sysex\n"); *_event = *(*_sysex_iter); break; default: - DUMP("iterator = end\n"); + DEBUG_TRACE(DEBUG::Sequence, "iterator = end\n"); _is_end = true; } @@ -393,7 +388,7 @@ Sequence<Time>::Sequence(const TypeMap& type_map) , _lowest_note(127) , _highest_note(0) { - DUMP(format("Sequence constructed: %1%\n") % this); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("Sequence constructed: %1\n", this)); assert(_end_iter._is_end); assert( ! _end_iter._lock); } @@ -419,7 +414,7 @@ Sequence<Time>::Sequence(const Sequence<Time>& other) _sysexes.push_back (n); } - DUMP(format("Sequence copied: %1%\n") % this); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("Sequence copied: %1\n", this)); assert(_end_iter._is_end); assert(! _end_iter._lock); } @@ -523,7 +518,7 @@ template<typename Time> void Sequence<Time>::start_write() { - DUMP(format("%1% : start_write (percussive = %2%)\n") % this % _percussive); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 : start_write (percussive = %2)\n", this, _percussive)); WriteLock lock(write_lock()); _writing = true; for (int i = 0; i < 16; ++i) { @@ -548,7 +543,7 @@ Sequence<Time>::end_write(bool delete_stuck) return; } - DUMP(format("%1% : end_write (%2% notes)\n") % this % _notes.size()); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 : end_write (%2 notes)\n", this, _notes.size())); if (!_percussive && delete_stuck) { for (typename Notes::iterator n = _notes.begin(); n != _notes.end() ;) { @@ -603,7 +598,7 @@ Sequence<Time>::append(const Event<Time>& event) if (ev.is_note_on()) { append_note_on_unlocked(ev.channel(), ev.time(), ev.note(), ev.velocity()); } else if (ev.is_note_off()) { - append_note_off_unlocked(ev.channel(), ev.time(), ev.note()); + append_note_off_unlocked(ev.channel(), ev.time(), ev.note(), ev.velocity()); } else if (ev.is_sysex()) { append_sysex_unlocked(ev); } else if (!_type_map.type_is_midi(ev.event_type())) { @@ -638,15 +633,15 @@ template<typename Time> void Sequence<Time>::append_note_on_unlocked(uint8_t chan, Time time, uint8_t note_num, uint8_t velocity) { - DUMP(format("%1% c=%2% note %3% on @ %4% v=%5%\n") - % this % (int)chan % (int)note_num % time % (int)velocity); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 c=%2 note %3 on @ %4 v=%5\n", + this, (int)chan, (int)note_num, time, (int)velocity)); assert(note_num <= 127); assert(chan < 16); assert(_writing); _edited = true; if (velocity == 0) { - append_note_off_unlocked(chan, time, note_num); + append_note_off_unlocked(chan, time, note_num, velocity); return; } @@ -658,41 +653,46 @@ Sequence<Time>::append_note_on_unlocked(uint8_t chan, Time time, uint8_t note_nu boost::shared_ptr< Note<Time> > new_note(new Note<Time>(chan, time, 0, note_num, velocity)); _notes.insert(new_note); if (!_percussive) { - DUMP(format("Sustained: Appending active note on %1% channel %2%\n") - % (unsigned)(uint8_t)note_num % chan); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("Sustained: Appending active note on %1 channel %2\n", + (unsigned)(uint8_t)note_num, chan)); _write_notes[chan].insert(new_note); } else { - DUMP("Percussive: NOT appending active note on\n"); + DEBUG_TRACE(DEBUG::Sequence, "Percussive: NOT appending active note on\n"); } } template<typename Time> void -Sequence<Time>::append_note_off_unlocked(uint8_t chan, Time time, uint8_t note_num) +Sequence<Time>::append_note_off_unlocked(uint8_t chan, Time time, uint8_t note_num, uint8_t velocity) { - DUMP(format("%1% c=%2% note %3% off @ %4%\n") - % this % (int)chan % (int)note_num % time); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 c=%2 note %3 off @ %4\n", + this, (int)chan, (int)note_num, time)); assert(note_num <= 127); assert(chan < 16); assert(_writing); _edited = true; if (_percussive) { - DUMP("Sequence Ignoring note off (percussive mode)\n"); + DEBUG_TRACE(DEBUG::Sequence, "Sequence Ignoring note off (percussive mode)\n"); return; } - // TODO: support note off velocity - bool resolved = false; - for (typename WriteNotes::iterator n = _write_notes[chan].begin(); - n != _write_notes[chan].end(); ++n) { + + /* _write_notes is sorted earliest-latest, so this will find the first matching note (FIFO) that + matches this note (by pitch & channel). the MIDI specification doesn't provide any guidance + whether to use FIFO or LIFO for this matching process, so SMF is fundamentally a lossy + format. + */ + + for (typename WriteNotes::iterator n = _write_notes[chan].begin(); n != _write_notes[chan].end(); ++n) { boost::shared_ptr< Note<Time> > note = *n; - if (note->note() == note_num) { + if (note->note() == note_num && note->channel() == chan) { assert(time >= note->time()); - note->set_length(time - note->time()); + note->set_length (time - note->time()); + note->set_off_velocity (velocity); _write_notes[chan].erase(n); - DUMP(format("resolved note, length: %1%\n") % note->length()); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("resolved note, length: %1\n", note->length())); resolved = true; break; } @@ -708,8 +708,8 @@ template<typename Time> void Sequence<Time>::append_control_unlocked(const Parameter& param, Time time, double value) { - DUMP(format("%1% %2% @ %3%\t=\t%4% # controls: %5%\n") - % this % _type_map.to_symbol(param) % time % value % _controls.size()); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 %2 @ %3\t=\t%4 # controls: %5\n", + this, _type_map.to_symbol(param), time, value, _controls.size())); boost::shared_ptr<Control> c = control(param, true); c->list()->rt_add(time, value); } @@ -731,10 +731,15 @@ Sequence<Time>::append_sysex_unlocked(const MIDIEvent<Time>& ev) template<typename Time> bool -Sequence<Time>::contains(const boost::shared_ptr< Note<Time> > note) const +Sequence<Time>::contains (const boost::shared_ptr< Note<Time> > note) const { - ReadLock lock (read_lock()); + return contains_unlocked (note); +} +template<typename Time> +bool +Sequence<Time>::contains_unlocked (const boost::shared_ptr< Note<Time> > note) const +{ for (typename Sequence<Time>::Notes::const_iterator i = note_lower_bound(note->time()); i != _notes.end() && (*i)->time() == note->time(); ++i) { if (*i == note) { @@ -748,17 +753,54 @@ Sequence<Time>::contains(const boost::shared_ptr< Note<Time> > note) const template<typename Time> bool +Sequence<Time>::overlaps (const boost::shared_ptr< Note<Time> > note) const +{ + ReadLock lock (read_lock()); + return overlaps_unlocked (note); +} + +template<typename Time> +bool +Sequence<Time>::overlaps_unlocked (const boost::shared_ptr< Note<Time> > note) const +{ + Time sa = note->time(); + Time ea = note->end_time(); + + for (typename Sequence<Time>::Notes::const_iterator i = note_lower_bound (note->time()); i != _notes.end(); ++i) { + + if ((note->note() != (*i)->note()) || + (note->channel() != (*i)->channel())) { + continue; + } + + Time sb = (*i)->time(); + Time eb = (*i)->end_time(); + + if (((sb > sa) && (eb <= ea)) || + ((eb >= sa) && (eb <= ea)) || + ((sb > sa) && (sb <= ea)) || + ((sa >= sb) && (sa <= eb) && (ea <= eb))) { + return true; + } + } + + return false; +} + +template<typename Time> +bool Sequence<Time>::add_note_unlocked(const boost::shared_ptr< Note<Time> > note) { - DUMP(format("%1% add note %2% @ %3%\n") % this % (int)note->note() % note->time()); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 add note %2 @ %3\n", this, (int)note->note(), note->time())); - for (typename Sequence<Time>::Notes::iterator i = note_lower_bound(note->time()); - i != _notes.end() && (*i)->time() == note->time(); ++i) { - if (*i == note) { - return false; - } + if (contains_unlocked (note)) { + return false; } + if (overlaps_unlocked (note)) { + return false; + } + _edited = true; _notes.insert(note); return true; @@ -769,7 +811,7 @@ void Sequence<Time>::remove_note_unlocked(const boost::shared_ptr< const Note<Time> > note) { _edited = true; - DUMP(format("%1% remove note %2% @ %3%\n") % this % (int)note->note() % note->time()); + DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 remove note %2 @ %3\n", this, (int)note->note(), note->time())); for (typename Sequence<Time>::Notes::iterator i = note_lower_bound(note->time()); i != _notes.end() && (*i)->time() == note->time(); ++i) { if (*i == note) { diff --git a/libs/evoral/wscript b/libs/evoral/wscript index 4293fd88d1..77dfdac15d 100644 --- a/libs/evoral/wscript +++ b/libs/evoral/wscript @@ -81,6 +81,7 @@ def build(bld): src/Note.cpp src/SMF.cpp src/Sequence.cpp + src/debug.cpp ''' # Library |