mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-10 00:34:59 +01:00
Don't allocate then discard notes on note off.
Silly to make a junk Note just to pass to append_note_off_unlocked, which just uses the fields that are on the MIDIEvent anyway then throws it away. Also explicitly dispatch to append_note_off_unlocked in the caller for note ons with velocity 0 rather than make append_note_on_unlocked deal with it.
This commit is contained in:
parent
6a033a093b
commit
6fb4bd578e
2 changed files with 35 additions and 41 deletions
|
|
@ -331,11 +331,11 @@ private:
|
||||||
bool overlaps_unlocked (const NotePtr& ev, const NotePtr& ignore_this_note) const;
|
bool overlaps_unlocked (const NotePtr& ev, const NotePtr& ignore_this_note) const;
|
||||||
bool contains_unlocked (const NotePtr& ev) const;
|
bool contains_unlocked (const NotePtr& ev) const;
|
||||||
|
|
||||||
void append_note_on_unlocked (NotePtr, Evoral::event_id_t);
|
void append_note_on_unlocked(const MIDIEvent<Time>& event, Evoral::event_id_t);
|
||||||
void append_note_off_unlocked(NotePtr);
|
void append_note_off_unlocked(const MIDIEvent<Time>& event);
|
||||||
void append_control_unlocked(const Parameter& param, Time time, double value, Evoral::event_id_t);
|
void append_control_unlocked(const Parameter& param, Time time, double value, Evoral::event_id_t);
|
||||||
void append_sysex_unlocked(const MIDIEvent<Time>& ev, Evoral::event_id_t);
|
void append_sysex_unlocked(const MIDIEvent<Time>& ev, Evoral::event_id_t);
|
||||||
void append_patch_change_unlocked (const PatchChange<Time>&, Evoral::event_id_t);
|
void append_patch_change_unlocked(const PatchChange<Time>&, Evoral::event_id_t);
|
||||||
|
|
||||||
void get_notes_by_pitch (Notes&, NoteOperator, uint8_t val, int chan_mask = 0) const;
|
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;
|
void get_notes_by_velocity (Notes&, NoteOperator, uint8_t val, int chan_mask = 0) const;
|
||||||
|
|
|
||||||
|
|
@ -886,15 +886,13 @@ Sequence<Time>::append(const Event<Time>& event, event_id_t evid)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ev.is_note_on()) {
|
if (ev.is_note_on() && ev.velocity() > 0) {
|
||||||
NotePtr note(new Note<Time>(ev.channel(), ev.time(), Time(), ev.note(), ev.velocity()));
|
append_note_on_unlocked (ev, evid);
|
||||||
append_note_on_unlocked (note, evid);
|
} else if (ev.is_note_off() || (ev.is_note_on() && ev.velocity() == 0)) {
|
||||||
} else if (ev.is_note_off()) {
|
|
||||||
NotePtr note(new Note<Time>(ev.channel(), ev.time(), Time(), ev.note(), ev.velocity()));
|
|
||||||
/* XXX note: event ID is discarded because we merge the on+off events into
|
/* XXX note: event ID is discarded because we merge the on+off events into
|
||||||
a single note object
|
a single note object
|
||||||
*/
|
*/
|
||||||
append_note_off_unlocked (note);
|
append_note_off_unlocked (ev);
|
||||||
} else if (ev.is_sysex()) {
|
} else if (ev.is_sysex()) {
|
||||||
append_sysex_unlocked(ev, evid);
|
append_sysex_unlocked(ev, evid);
|
||||||
} else if (ev.is_cc() && (ev.cc_number() == MIDI_CTL_MSB_BANK || ev.cc_number() == MIDI_CTL_LSB_BANK)) {
|
} else if (ev.is_cc() && (ev.cc_number() == MIDI_CTL_MSB_BANK || ev.cc_number() == MIDI_CTL_LSB_BANK)) {
|
||||||
|
|
@ -938,30 +936,27 @@ Sequence<Time>::append(const Event<Time>& event, event_id_t evid)
|
||||||
|
|
||||||
template<typename Time>
|
template<typename Time>
|
||||||
void
|
void
|
||||||
Sequence<Time>::append_note_on_unlocked (NotePtr note, event_id_t evid)
|
Sequence<Time>::append_note_on_unlocked (const MIDIEvent<Time>& ev, event_id_t evid)
|
||||||
{
|
{
|
||||||
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 c=%2 note %3 on @ %4 v=%5\n", this,
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 c=%2 note %3 on @ %4 v=%5\n", this,
|
||||||
(int) note->channel(), (int) note->note(),
|
(int)ev.channel(), (int)ev.note(),
|
||||||
note->time(), (int) note->velocity()));
|
ev.time(), (int)ev.velocity()));
|
||||||
assert(_writing);
|
assert(_writing);
|
||||||
|
|
||||||
if (note->note() > 127) {
|
if (ev.note() > 127) {
|
||||||
error << string_compose (_("illegal note number (%1) used in Note on event - event will be ignored"), (int) note->note()) << endmsg;
|
error << string_compose (_("invalid note on number (%1) ignored"), (int) ev.note()) << endmsg;
|
||||||
return;
|
return;
|
||||||
}
|
} else if (ev.channel() >= 16) {
|
||||||
if (note->channel() >= 16) {
|
error << string_compose (_("invalid note on channel (%1) ignored"), (int) ev.channel()) << endmsg;
|
||||||
error << string_compose (_("illegal channel number (%1) used in Note on event - event will be ignored"), (int) note->channel()) << endmsg;
|
return;
|
||||||
|
} else if (ev.velocity() == 0) {
|
||||||
|
// Note on with velocity 0 handled as note off by caller
|
||||||
|
error << string_compose (_("invalid note on velocity (%1) ignored"), (int) ev.velocity()) << endmsg;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (note->id() < 0) {
|
NotePtr note(new Note<Time>(ev.channel(), ev.time(), Time(), ev.note(), ev.velocity()));
|
||||||
note->set_id (evid);
|
note->set_id (evid);
|
||||||
}
|
|
||||||
|
|
||||||
if (note->velocity() == 0) {
|
|
||||||
append_note_off_unlocked (note);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
add_note_unlocked (note);
|
add_note_unlocked (note);
|
||||||
|
|
||||||
|
|
@ -973,19 +968,18 @@ Sequence<Time>::append_note_on_unlocked (NotePtr note, event_id_t evid)
|
||||||
|
|
||||||
template<typename Time>
|
template<typename Time>
|
||||||
void
|
void
|
||||||
Sequence<Time>::append_note_off_unlocked (NotePtr note)
|
Sequence<Time>::append_note_off_unlocked (const MIDIEvent<Time>& ev)
|
||||||
{
|
{
|
||||||
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 c=%2 note %3 OFF @ %4 v=%5\n",
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 c=%2 note %3 OFF @ %4 v=%5\n",
|
||||||
this, (int)note->channel(),
|
this, (int)ev.channel(),
|
||||||
(int)note->note(), note->time(), (int)note->velocity()));
|
(int)ev.note(), ev.time(), (int)ev.velocity()));
|
||||||
assert(_writing);
|
assert(_writing);
|
||||||
|
|
||||||
if (note->note() > 127) {
|
if (ev.note() > 127) {
|
||||||
error << string_compose (_("illegal note number (%1) used in Note off event - event will be ignored"), (int) note->note()) << endmsg;
|
error << string_compose (_("invalid note off number (%1) ignored"), (int) ev.note()) << endmsg;
|
||||||
return;
|
return;
|
||||||
}
|
} else if (ev.channel() >= 16) {
|
||||||
if (note->channel() >= 16) {
|
error << string_compose (_("invalid note off channel (%1) ignored"), (int) ev.channel()) << endmsg;
|
||||||
error << string_compose (_("illegal channel number (%1) used in Note off event - event will be ignored"), (int) note->channel()) << endmsg;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1001,19 +995,19 @@ Sequence<Time>::append_note_off_unlocked (NotePtr note)
|
||||||
|
|
||||||
/* XXX use _overlap_pitch_resolution to determine FIFO/LIFO ... */
|
/* XXX use _overlap_pitch_resolution to determine FIFO/LIFO ... */
|
||||||
|
|
||||||
for (typename WriteNotes::iterator n = _write_notes[note->channel()].begin(); n != _write_notes[note->channel()].end(); ) {
|
for (typename WriteNotes::iterator n = _write_notes[ev.channel()].begin(); n != _write_notes[ev.channel()].end(); ) {
|
||||||
|
|
||||||
typename WriteNotes::iterator tmp = n;
|
typename WriteNotes::iterator tmp = n;
|
||||||
++tmp;
|
++tmp;
|
||||||
|
|
||||||
NotePtr nn = *n;
|
NotePtr nn = *n;
|
||||||
if (note->note() == nn->note() && nn->channel() == note->channel()) {
|
if (ev.note() == nn->note() && nn->channel() == ev.channel()) {
|
||||||
assert(note->time() >= nn->time());
|
assert(ev.time() >= nn->time());
|
||||||
|
|
||||||
nn->set_length (note->time() - nn->time());
|
nn->set_length (ev.time() - nn->time());
|
||||||
nn->set_off_velocity (note->velocity());
|
nn->set_off_velocity (ev.velocity());
|
||||||
|
|
||||||
_write_notes[note->channel()].erase(n);
|
_write_notes[ev.channel()].erase(n);
|
||||||
DEBUG_TRACE (DEBUG::Sequence, string_compose ("resolved note @ %2 length: %1\n", nn->length(), nn->time()));
|
DEBUG_TRACE (DEBUG::Sequence, string_compose ("resolved note @ %2 length: %1\n", nn->length(), nn->time()));
|
||||||
resolved = true;
|
resolved = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -1023,8 +1017,8 @@ Sequence<Time>::append_note_off_unlocked (NotePtr note)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!resolved) {
|
if (!resolved) {
|
||||||
cerr << this << " spurious note off chan " << (int)note->channel()
|
cerr << this << " spurious note off chan " << (int)ev.channel()
|
||||||
<< ", note " << (int)note->note() << " @ " << note->time() << endl;
|
<< ", note " << (int)ev.note() << " @ " << ev.time() << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue