mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 15:25:01 +01:00
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
This commit is contained in:
parent
c51d6a1582
commit
db67064296
8 changed files with 130 additions and 73 deletions
|
|
@ -82,9 +82,9 @@ namespace ARDOUR {
|
||||||
OverlapEnd, // overlap begins within and covers end
|
OverlapEnd, // overlap begins within and covers end
|
||||||
OverlapExternal // overlap extends to (at least) begin+end
|
OverlapExternal // overlap extends to (at least) begin+end
|
||||||
};
|
};
|
||||||
|
|
||||||
OverlapType coverage (nframes_t start_a, nframes_t end_a,
|
ARDOUR::OverlapType coverage (framepos_t sa, framepos_t ea,
|
||||||
nframes_t start_b, nframes_t end_b);
|
framepos_t sb, framepos_t eb);
|
||||||
|
|
||||||
/** See parameter.h
|
/** See parameter.h
|
||||||
* XXX: I don't think/hope these hex values matter anymore.
|
* XXX: I don't think/hope these hex values matter anymore.
|
||||||
|
|
|
||||||
|
|
@ -222,7 +222,7 @@ AudioFileSource::old_peak_path (ustring audio_path)
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
snprintf (buf, sizeof (buf), "%u-%u-%d.peak", stat_mount.st_ino, stat_file.st_ino, _channel);
|
snprintf (buf, sizeof (buf), "%u-%u-%d.peak", stat_mount.st_ino, stat_file.st_ino, _channel);
|
||||||
#else
|
#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
|
#endif
|
||||||
|
|
||||||
ustring res = peak_dir;
|
ustring res = peak_dir;
|
||||||
|
|
|
||||||
|
|
@ -535,8 +535,8 @@ ARDOUR::setup_fpu ()
|
||||||
}
|
}
|
||||||
|
|
||||||
ARDOUR::OverlapType
|
ARDOUR::OverlapType
|
||||||
ARDOUR::coverage (nframes_t sa, nframes_t ea,
|
ARDOUR::coverage (framepos_t sa, framepos_t ea,
|
||||||
nframes_t sb, nframes_t eb)
|
framepos_t sb, framepos_t eb)
|
||||||
{
|
{
|
||||||
/* OverlapType returned reflects how the second (B)
|
/* OverlapType returned reflects how the second (B)
|
||||||
range overlaps the first (A).
|
range overlaps the first (A).
|
||||||
|
|
@ -563,11 +563,8 @@ ARDOUR::coverage (nframes_t sa, nframes_t ea,
|
||||||
"B is internal to A"
|
"B is internal to A"
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#ifdef OLD_COVERAGE
|
|
||||||
if ((sb >= sa) && (eb <= ea)) {
|
|
||||||
#else
|
|
||||||
if ((sb > sa) && (eb <= ea)) {
|
if ((sb > sa) && (eb <= ea)) {
|
||||||
#endif
|
|
||||||
return OverlapInternal;
|
return OverlapInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ public:
|
||||||
note() == other.note() &&
|
note() == other.note() &&
|
||||||
musical_time_equal (length(), other.length()) &&
|
musical_time_equal (length(), other.length()) &&
|
||||||
velocity() == other.velocity() &&
|
velocity() == other.velocity() &&
|
||||||
|
off_velocity() == other.off_velocity() &&
|
||||||
channel() == other.channel();
|
channel() == other.channel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,6 +50,7 @@ public:
|
||||||
inline Time end_time() const { return _off_event.time(); }
|
inline Time end_time() const { return _off_event.time(); }
|
||||||
inline uint8_t note() const { return _on_event.note(); }
|
inline uint8_t note() const { return _on_event.note(); }
|
||||||
inline uint8_t velocity() const { return _on_event.velocity(); }
|
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 Time length() const { return _off_event.time() - _on_event.time(); }
|
||||||
inline uint8_t channel() const {
|
inline uint8_t channel() const {
|
||||||
assert(_on_event.channel() == _off_event.channel());
|
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_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_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_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_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); }
|
inline void set_channel(uint8_t c) { _on_event.set_channel(c); _off_event.set_channel(c); }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -220,7 +220,9 @@ public:
|
||||||
bool edited() const { return _edited; }
|
bool edited() const { return _edited; }
|
||||||
void set_edited(bool yn) { _edited = yn; }
|
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 contains (const boost::shared_ptr< Note<Time> > ev) const;
|
||||||
|
|
||||||
bool add_note_unlocked(const boost::shared_ptr< Note<Time> > note);
|
bool add_note_unlocked(const boost::shared_ptr< Note<Time> > note);
|
||||||
void remove_note_unlocked(const boost::shared_ptr< const Note<Time> > note);
|
void remove_note_unlocked(const boost::shared_ptr< const Note<Time> > note);
|
||||||
|
|
||||||
|
|
@ -234,8 +236,11 @@ protected:
|
||||||
private:
|
private:
|
||||||
friend class const_iterator;
|
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_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_control_unlocked(const Parameter& param, Time time, double value);
|
||||||
void append_sysex_unlocked(const MIDIEvent<Time>& ev);
|
void append_sysex_unlocked(const MIDIEvent<Time>& ev);
|
||||||
|
|
||||||
|
|
@ -244,7 +249,7 @@ private:
|
||||||
Notes _notes;
|
Notes _notes;
|
||||||
SysExes _sysexes;
|
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];
|
WriteNotes _write_notes[16];
|
||||||
bool _writing;
|
bool _writing;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
|
|
||||||
|
#include "pbd/debug.h"
|
||||||
|
|
||||||
namespace Evoral {
|
namespace Evoral {
|
||||||
|
|
||||||
/** Frame count (i.e. length of time in audio frames) */
|
/** Frame count (i.e. length of time in audio frames) */
|
||||||
|
|
@ -53,4 +55,11 @@ struct RangeMove {
|
||||||
|
|
||||||
} // namespace Evoral
|
} // namespace Evoral
|
||||||
|
|
||||||
|
namespace PBD {
|
||||||
|
namespace DEBUG {
|
||||||
|
extern uint64_t Sequence;
|
||||||
|
extern uint64_t Note;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // EVORAL_TYPES_HPP
|
#endif // EVORAL_TYPES_HPP
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include "pbd/compose.h"
|
||||||
|
|
||||||
#include "evoral/Control.hpp"
|
#include "evoral/Control.hpp"
|
||||||
#include "evoral/ControlList.hpp"
|
#include "evoral/ControlList.hpp"
|
||||||
#include "evoral/ControlSet.hpp"
|
#include "evoral/ControlSet.hpp"
|
||||||
|
|
@ -33,16 +36,8 @@
|
||||||
#include "evoral/TypeMap.hpp"
|
#include "evoral/TypeMap.hpp"
|
||||||
#include "evoral/midi_util.h"
|
#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 std;
|
||||||
|
using namespace PBD;
|
||||||
|
|
||||||
namespace Evoral {
|
namespace Evoral {
|
||||||
|
|
||||||
|
|
@ -66,7 +61,7 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq, Time t
|
||||||
, _sysex_iter(seq.sysexes().end())
|
, _sysex_iter(seq.sysexes().end())
|
||||||
, _control_iter(_control_iters.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) {
|
if (!_is_end) {
|
||||||
_lock = seq.read_lock();
|
_lock = seq.read_lock();
|
||||||
|
|
@ -95,12 +90,12 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq, Time t
|
||||||
bool found = false;
|
bool found = false;
|
||||||
size_t earliest_control_index = 0;
|
size_t earliest_control_index = 0;
|
||||||
for (Controls::const_iterator i = seq._controls.begin(); i != seq._controls.end(); ++i) {
|
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;
|
double x, y;
|
||||||
bool ret = i->second->list()->rt_safe_earliest_event_unlocked(t, DBL_MAX, x, y, true);
|
bool ret = i->second->list()->rt_safe_earliest_event_unlocked(t, DBL_MAX, x, y, true);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
DUMP(format("Iterator: CC %1% (size %2%) has no events past %3%\n")
|
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);
|
i->first.id(), i->second->list()->size(), t));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,7 +108,7 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq, Time t
|
||||||
continue;
|
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);
|
const ControlIterator new_iter(i->second->list(), x, y);
|
||||||
_control_iters.push_back(new_iter);
|
_control_iters.push_back(new_iter);
|
||||||
|
|
@ -156,18 +151,18 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq, Time t
|
||||||
|
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case NOTE_ON:
|
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> >(
|
_event = boost::shared_ptr< Event<Time> >(
|
||||||
new Event<Time>((*_note_iter)->on_event(), true));
|
new Event<Time>((*_note_iter)->on_event(), true));
|
||||||
_active_notes.push(*_note_iter);
|
_active_notes.push(*_note_iter);
|
||||||
break;
|
break;
|
||||||
case SYSEX:
|
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> >(
|
_event = boost::shared_ptr< Event<Time> >(
|
||||||
new Event<Time>(*(*_sysex_iter), true));
|
new Event<Time>(*(*_sysex_iter), true));
|
||||||
break;
|
break;
|
||||||
case CONTROL:
|
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);
|
seq.control_to_midi_event(_event, earliest_control);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -175,14 +170,14 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq, Time t
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_type == NIL || !_event || _event->size() == 0) {
|
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;
|
_type = NIL;
|
||||||
_is_end = true;
|
_is_end = true;
|
||||||
} else {
|
} else {
|
||||||
DUMP(printf("New iterator = 0x%x : 0x%x @ %f\n",
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("New iterator = 0x%x : 0x%x @ %f\n",
|
||||||
(int)_event->event_type(),
|
(int)_event->event_type(),
|
||||||
(int)((MIDIEvent<Time>*)_event.get())->type(),
|
(int)((MIDIEvent<Time>*)_event.get())->type(),
|
||||||
_event->time()));
|
_event->time()));
|
||||||
assert(midi_event_is_valid(_event->buffer(), _event->size()));
|
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");
|
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);
|
assert(_event && _event->buffer() && _event->size() > 0);
|
||||||
|
|
||||||
const MIDIEvent<Time>& ev = *((MIDIEvent<Time>*)_event.get());
|
const MIDIEvent<Time>& ev = *((MIDIEvent<Time>*)_event.get());
|
||||||
|
|
@ -310,26 +305,26 @@ Sequence<Time>::const_iterator::operator++()
|
||||||
// Set event to reflect new position
|
// Set event to reflect new position
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case NOTE_ON:
|
case NOTE_ON:
|
||||||
DUMP("iterator = note on\n");
|
DEBUG_TRACE(DEBUG::Sequence, "iterator = note on\n");
|
||||||
*_event = (*_note_iter)->on_event();
|
*_event = (*_note_iter)->on_event();
|
||||||
_active_notes.push(*_note_iter);
|
_active_notes.push(*_note_iter);
|
||||||
break;
|
break;
|
||||||
case NOTE_OFF:
|
case NOTE_OFF:
|
||||||
DUMP("iterator = note off\n");
|
DEBUG_TRACE(DEBUG::Sequence, "iterator = note off\n");
|
||||||
assert(!_active_notes.empty());
|
assert(!_active_notes.empty());
|
||||||
*_event = _active_notes.top()->off_event();
|
*_event = _active_notes.top()->off_event();
|
||||||
_active_notes.pop();
|
_active_notes.pop();
|
||||||
break;
|
break;
|
||||||
case CONTROL:
|
case CONTROL:
|
||||||
DUMP("iterator = control\n");
|
DEBUG_TRACE(DEBUG::Sequence, "iterator = control\n");
|
||||||
_seq->control_to_midi_event(_event, *_control_iter);
|
_seq->control_to_midi_event(_event, *_control_iter);
|
||||||
break;
|
break;
|
||||||
case SYSEX:
|
case SYSEX:
|
||||||
DUMP("iterator = sysex\n");
|
DEBUG_TRACE(DEBUG::Sequence, "iterator = sysex\n");
|
||||||
*_event = *(*_sysex_iter);
|
*_event = *(*_sysex_iter);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
DUMP("iterator = end\n");
|
DEBUG_TRACE(DEBUG::Sequence, "iterator = end\n");
|
||||||
_is_end = true;
|
_is_end = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -393,7 +388,7 @@ Sequence<Time>::Sequence(const TypeMap& type_map)
|
||||||
, _lowest_note(127)
|
, _lowest_note(127)
|
||||||
, _highest_note(0)
|
, _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._is_end);
|
||||||
assert( ! _end_iter._lock);
|
assert( ! _end_iter._lock);
|
||||||
}
|
}
|
||||||
|
|
@ -419,7 +414,7 @@ Sequence<Time>::Sequence(const Sequence<Time>& other)
|
||||||
_sysexes.push_back (n);
|
_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._is_end);
|
||||||
assert(! _end_iter._lock);
|
assert(! _end_iter._lock);
|
||||||
}
|
}
|
||||||
|
|
@ -523,7 +518,7 @@ template<typename Time>
|
||||||
void
|
void
|
||||||
Sequence<Time>::start_write()
|
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());
|
WriteLock lock(write_lock());
|
||||||
_writing = true;
|
_writing = true;
|
||||||
for (int i = 0; i < 16; ++i) {
|
for (int i = 0; i < 16; ++i) {
|
||||||
|
|
@ -548,7 +543,7 @@ Sequence<Time>::end_write(bool delete_stuck)
|
||||||
return;
|
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) {
|
if (!_percussive && delete_stuck) {
|
||||||
for (typename Notes::iterator n = _notes.begin(); n != _notes.end() ;) {
|
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()) {
|
if (ev.is_note_on()) {
|
||||||
append_note_on_unlocked(ev.channel(), ev.time(), ev.note(), ev.velocity());
|
append_note_on_unlocked(ev.channel(), ev.time(), ev.note(), ev.velocity());
|
||||||
} else if (ev.is_note_off()) {
|
} 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()) {
|
} else if (ev.is_sysex()) {
|
||||||
append_sysex_unlocked(ev);
|
append_sysex_unlocked(ev);
|
||||||
} else if (!_type_map.type_is_midi(ev.event_type())) {
|
} else if (!_type_map.type_is_midi(ev.event_type())) {
|
||||||
|
|
@ -638,15 +633,15 @@ template<typename Time>
|
||||||
void
|
void
|
||||||
Sequence<Time>::append_note_on_unlocked(uint8_t chan, Time time, uint8_t note_num, uint8_t velocity)
|
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")
|
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);
|
this, (int)chan, (int)note_num, time, (int)velocity));
|
||||||
assert(note_num <= 127);
|
assert(note_num <= 127);
|
||||||
assert(chan < 16);
|
assert(chan < 16);
|
||||||
assert(_writing);
|
assert(_writing);
|
||||||
_edited = true;
|
_edited = true;
|
||||||
|
|
||||||
if (velocity == 0) {
|
if (velocity == 0) {
|
||||||
append_note_off_unlocked(chan, time, note_num);
|
append_note_off_unlocked(chan, time, note_num, velocity);
|
||||||
return;
|
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));
|
boost::shared_ptr< Note<Time> > new_note(new Note<Time>(chan, time, 0, note_num, velocity));
|
||||||
_notes.insert(new_note);
|
_notes.insert(new_note);
|
||||||
if (!_percussive) {
|
if (!_percussive) {
|
||||||
DUMP(format("Sustained: Appending active note on %1% channel %2%\n")
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("Sustained: Appending active note on %1 channel %2\n",
|
||||||
% (unsigned)(uint8_t)note_num % chan);
|
(unsigned)(uint8_t)note_num, chan));
|
||||||
_write_notes[chan].insert(new_note);
|
_write_notes[chan].insert(new_note);
|
||||||
} else {
|
} else {
|
||||||
DUMP("Percussive: NOT appending active note on\n");
|
DEBUG_TRACE(DEBUG::Sequence, "Percussive: NOT appending active note on\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Time>
|
template<typename Time>
|
||||||
void
|
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")
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 c=%2 note %3 off @ %4\n",
|
||||||
% this % (int)chan % (int)note_num % time);
|
this, (int)chan, (int)note_num, time));
|
||||||
assert(note_num <= 127);
|
assert(note_num <= 127);
|
||||||
assert(chan < 16);
|
assert(chan < 16);
|
||||||
assert(_writing);
|
assert(_writing);
|
||||||
_edited = true;
|
_edited = true;
|
||||||
|
|
||||||
if (_percussive) {
|
if (_percussive) {
|
||||||
DUMP("Sequence Ignoring note off (percussive mode)\n");
|
DEBUG_TRACE(DEBUG::Sequence, "Sequence Ignoring note off (percussive mode)\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support note off velocity
|
|
||||||
|
|
||||||
bool resolved = false;
|
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;
|
boost::shared_ptr< Note<Time> > note = *n;
|
||||||
if (note->note() == note_num) {
|
if (note->note() == note_num && note->channel() == chan) {
|
||||||
assert(time >= note->time());
|
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);
|
_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;
|
resolved = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -708,8 +708,8 @@ template<typename Time>
|
||||||
void
|
void
|
||||||
Sequence<Time>::append_control_unlocked(const Parameter& param, Time time, double value)
|
Sequence<Time>::append_control_unlocked(const Parameter& param, Time time, double value)
|
||||||
{
|
{
|
||||||
DUMP(format("%1% %2% @ %3%\t=\t%4% # controls: %5%\n")
|
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());
|
this, _type_map.to_symbol(param), time, value, _controls.size()));
|
||||||
boost::shared_ptr<Control> c = control(param, true);
|
boost::shared_ptr<Control> c = control(param, true);
|
||||||
c->list()->rt_add(time, value);
|
c->list()->rt_add(time, value);
|
||||||
}
|
}
|
||||||
|
|
@ -731,10 +731,15 @@ Sequence<Time>::append_sysex_unlocked(const MIDIEvent<Time>& ev)
|
||||||
|
|
||||||
template<typename Time>
|
template<typename Time>
|
||||||
bool
|
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());
|
for (typename Sequence<Time>::Notes::const_iterator i = note_lower_bound(note->time());
|
||||||
i != _notes.end() && (*i)->time() == note->time(); ++i) {
|
i != _notes.end() && (*i)->time() == note->time(); ++i) {
|
||||||
if (*i == note) {
|
if (*i == note) {
|
||||||
|
|
@ -746,19 +751,56 @@ Sequence<Time>::contains(const boost::shared_ptr< Note<Time> > note) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>
|
template<typename Time>
|
||||||
bool
|
bool
|
||||||
Sequence<Time>::add_note_unlocked(const boost::shared_ptr< Note<Time> > note)
|
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());
|
if (contains_unlocked (note)) {
|
||||||
i != _notes.end() && (*i)->time() == note->time(); ++i) {
|
return false;
|
||||||
if (*i == note) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (overlaps_unlocked (note)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
_edited = true;
|
_edited = true;
|
||||||
_notes.insert(note);
|
_notes.insert(note);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -769,7 +811,7 @@ void
|
||||||
Sequence<Time>::remove_note_unlocked(const boost::shared_ptr< const Note<Time> > note)
|
Sequence<Time>::remove_note_unlocked(const boost::shared_ptr< const Note<Time> > note)
|
||||||
{
|
{
|
||||||
_edited = true;
|
_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());
|
for (typename Sequence<Time>::Notes::iterator i = note_lower_bound(note->time());
|
||||||
i != _notes.end() && (*i)->time() == note->time(); ++i) {
|
i != _notes.end() && (*i)->time() == note->time(); ++i) {
|
||||||
if (*i == note) {
|
if (*i == note) {
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ def build(bld):
|
||||||
src/Note.cpp
|
src/Note.cpp
|
||||||
src/SMF.cpp
|
src/SMF.cpp
|
||||||
src/Sequence.cpp
|
src/Sequence.cpp
|
||||||
|
src/debug.cpp
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# Library
|
# Library
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue