mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-13 18:16:35 +01:00
add channel+pitch indexing for notes in a Sequence
git-svn-id: svn://localhost/ardour2/branches/3.0@7217 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
baacf1c7b4
commit
460d2d0675
2 changed files with 320 additions and 242 deletions
|
|
@ -137,6 +137,10 @@ public:
|
||||||
inline Notes& notes() { return _notes; }
|
inline Notes& notes() { return _notes; }
|
||||||
inline const Notes& notes() const { return _notes; }
|
inline const Notes& notes() const { return _notes; }
|
||||||
|
|
||||||
|
typedef std::multiset<boost::shared_ptr< Note<Time> >, NoteNumberComparator> Pitches;
|
||||||
|
inline Pitches& pitches(uint8_t chan) { return _pitches[chan&0xf]; }
|
||||||
|
inline const Pitches& pitches(uint8_t chan) const { return _pitches[chan&0xf]; }
|
||||||
|
|
||||||
enum NoteOperator {
|
enum NoteOperator {
|
||||||
PitchEqual,
|
PitchEqual,
|
||||||
PitchLessThan,
|
PitchLessThan,
|
||||||
|
|
@ -244,9 +248,13 @@ private:
|
||||||
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);
|
||||||
|
|
||||||
|
void get_notes_by_pitch (Notes&, NoteOperator, uint8_t val, int chan_mask = 0) const;
|
||||||
|
void get_notes_by_velocity (Notes&, NoteOperator, uint8_t val, int chan_mask = 0) const;
|
||||||
|
|
||||||
const TypeMap& _type_map;
|
const TypeMap& _type_map;
|
||||||
|
|
||||||
Notes _notes;
|
Notes _notes; // notes indexed by time
|
||||||
|
Pitches _pitches[16]; // notes indexed by channel+pitch
|
||||||
SysExes _sysexes;
|
SysExes _sysexes;
|
||||||
|
|
||||||
typedef std::multiset<boost::shared_ptr< Note<Time> >, EarlierNoteComparator> WriteNotes;
|
typedef std::multiset<boost::shared_ptr< Note<Time> >, EarlierNoteComparator> WriteNotes;
|
||||||
|
|
|
||||||
|
|
@ -599,6 +599,7 @@ Sequence<Time>::add_note_unlocked(const boost::shared_ptr< Note<Time> > note)
|
||||||
_highest_note = note->note();
|
_highest_note = note->note();
|
||||||
|
|
||||||
_notes.insert (note);
|
_notes.insert (note);
|
||||||
|
_pitches[note->channel()].insert (note);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -618,6 +619,7 @@ Sequence<Time>::remove_note_unlocked(const boost::shared_ptr< const Note<Time> >
|
||||||
|
|
||||||
if (*i == note) {
|
if (*i == note) {
|
||||||
|
|
||||||
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1\terasing note %2 @ %3\n", this, (int)(*i)->note(), (*i)->time()));
|
||||||
_notes.erase (i);
|
_notes.erase (i);
|
||||||
|
|
||||||
if ((*i)->note() == _lowest_note || (*i)->note() == _highest_note) {
|
if ((*i)->note() == _lowest_note || (*i)->note() == _highest_note) {
|
||||||
|
|
@ -635,7 +637,18 @@ Sequence<Time>::remove_note_unlocked(const boost::shared_ptr< const Note<Time> >
|
||||||
|
|
||||||
erased = true;
|
erased = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Pitches& p (pitches (note->channel()));
|
||||||
|
|
||||||
|
boost::shared_ptr< Note<Time> > search_note(new Note<Time>(0, 0, 0, note->note(), 0));
|
||||||
|
|
||||||
|
for (typename Pitches::iterator i = p.lower_bound (search_note);
|
||||||
|
i != p.end() && (*i)->note() == note->note(); ++i) {
|
||||||
|
if (*i == note) {
|
||||||
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1\terasing pitch %2 @ %3\n", this, (int)(*i)->note(), (*i)->time()));
|
||||||
|
p.erase (i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!erased) {
|
if (!erased) {
|
||||||
|
|
@ -875,44 +888,96 @@ Sequence<Time>::note_lower_bound (Time t) const
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename Time>
|
template<typename Time>
|
||||||
void
|
void
|
||||||
Sequence<Time>::get_notes (Notes& n, NoteOperator op, uint8_t val, int chan_mask) const
|
Sequence<Time>::get_notes (Notes& n, NoteOperator op, uint8_t val, int chan_mask) const
|
||||||
|
{
|
||||||
|
switch (op) {
|
||||||
|
case PitchEqual:
|
||||||
|
case PitchLessThan:
|
||||||
|
case PitchLessThanOrEqual:
|
||||||
|
case PitchGreater:
|
||||||
|
case PitchGreaterThanOrEqual:
|
||||||
|
get_notes_by_pitch (n, op, val, chan_mask);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VelocityEqual:
|
||||||
|
case VelocityLessThan:
|
||||||
|
case VelocityLessThanOrEqual:
|
||||||
|
case VelocityGreater:
|
||||||
|
case VelocityGreaterThanOrEqual:
|
||||||
|
get_notes_by_velocity (n, op, val, chan_mask);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Time>
|
||||||
|
void
|
||||||
|
Sequence<Time>::get_notes_by_pitch (Notes& n, NoteOperator op, uint8_t val, int chan_mask) const
|
||||||
|
{
|
||||||
|
for (uint8_t c = 0; c < 16; ++c) {
|
||||||
|
|
||||||
|
if (chan_mask != 0 && !((1<<c) & chan_mask)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Pitches& p (pitches (c));
|
||||||
|
boost::shared_ptr< Note<Time> > search_note(new Note<Time>(0, 0, 0, val, 0));
|
||||||
|
typename Pitches::const_iterator i;
|
||||||
|
switch (op) {
|
||||||
|
case PitchEqual:
|
||||||
|
i = p.lower_bound (search_note);
|
||||||
|
while (i != p.end() && (*i)->note() == val) {
|
||||||
|
n.insert (*i);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PitchLessThan:
|
||||||
|
i = p.upper_bound (search_note);
|
||||||
|
while (i != p.end() && (*i)->note() < val) {
|
||||||
|
n.insert (*i);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PitchLessThanOrEqual:
|
||||||
|
i = p.upper_bound (search_note);
|
||||||
|
while (i != p.end() && (*i)->note() <= val) {
|
||||||
|
n.insert (*i);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PitchGreater:
|
||||||
|
i = p.lower_bound (search_note);
|
||||||
|
while (i != p.end() && (*i)->note() > val) {
|
||||||
|
n.insert (*i);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PitchGreaterThanOrEqual:
|
||||||
|
i = p.lower_bound (search_note);
|
||||||
|
while (i != p.end() && (*i)->note() >= val) {
|
||||||
|
n.insert (*i);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
//fatal << string_compose (_("programming error: %1 %2", X_("get_notes_by_pitch() called with illegal operator"), op)) << endmsg;
|
||||||
|
abort ();
|
||||||
|
/* NOTREACHED*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Time>
|
||||||
|
void
|
||||||
|
Sequence<Time>::get_notes_by_velocity (Notes& n, NoteOperator op, uint8_t val, int chan_mask) const
|
||||||
{
|
{
|
||||||
ReadLock lock (read_lock());
|
ReadLock lock (read_lock());
|
||||||
|
|
||||||
for (typename Notes::const_iterator i = _notes.begin(); i != _notes.end(); ++i) {
|
for (typename Notes::const_iterator i = _notes.begin(); i != _notes.end(); ++i) {
|
||||||
|
|
||||||
if (chan_mask != 0 && !((1<<(*i)->channel()) & chan_mask)) {
|
if (chan_mask != 0 && !((1<<((*i)->channel())) & chan_mask)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case PitchEqual:
|
|
||||||
if ((*i)->note() == val) {
|
|
||||||
n.insert (*i);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PitchLessThan:
|
|
||||||
if ((*i)->note() < val) {
|
|
||||||
n.insert (*i);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PitchLessThanOrEqual:
|
|
||||||
if ((*i)->note() <= val) {
|
|
||||||
n.insert (*i);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PitchGreater:
|
|
||||||
if ((*i)->note() > val) {
|
|
||||||
n.insert (*i);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PitchGreaterThanOrEqual:
|
|
||||||
if ((*i)->note() >= val) {
|
|
||||||
n.insert (*i);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VelocityEqual:
|
case VelocityEqual:
|
||||||
if ((*i)->velocity() == val) {
|
if ((*i)->velocity() == val) {
|
||||||
n.insert (*i);
|
n.insert (*i);
|
||||||
|
|
@ -938,6 +1003,11 @@ Sequence<Time>::get_notes (Notes& n, NoteOperator op, uint8_t val, int chan_mask
|
||||||
n.insert (*i);
|
n.insert (*i);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
// fatal << string_compose (_("programming error: %1 %2", X_("get_notes_by_velocity() called with illegal operator"), op)) << endmsg;
|
||||||
|
abort ();
|
||||||
|
/* NOTREACHED*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue