mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-06 06:44:57 +01:00
midi region view: fix crashes when adding notes
A region may have no notes, or none in the correct time range. Finding a note to get channel or velocity info from may fail
This commit is contained in:
parent
252ae56a08
commit
bc6766fc3f
1 changed files with 25 additions and 9 deletions
|
|
@ -4261,9 +4261,17 @@ MidiRegionView::get_channel_for_add (MidiModel::TimeType time) const
|
|||
}
|
||||
|
||||
/* second, use the nearest note in the region-view (consistent with get_velocity_for_add behavior) */
|
||||
|
||||
if (!_model->notes().empty()) {
|
||||
MidiModel::Notes::const_iterator m = _model->note_lower_bound(time);
|
||||
if (m == _model->notes().begin()) {
|
||||
// Before the start, use the channel of the first note
|
||||
return (*m)->channel();
|
||||
} else if (m == _model->notes().end()) {
|
||||
// Past the end, use the channel of the last note
|
||||
--m;
|
||||
return (*m)->channel();
|
||||
}
|
||||
}
|
||||
|
||||
/* lastly: query the track's channel filter */
|
||||
|
|
@ -4284,11 +4292,14 @@ MidiRegionView::get_velocity_for_add (MidiModel::TimeType time) const
|
|||
return editor.draw_velocity();
|
||||
}
|
||||
|
||||
if (_model->notes().empty()) {
|
||||
if (_model->notes().size() < 2) {
|
||||
return 0x40; // No notes, use default
|
||||
}
|
||||
|
||||
MidiModel::Notes::const_iterator m = _model->note_lower_bound(time);
|
||||
MidiModel::Notes::const_iterator m = _model->notes().end();
|
||||
|
||||
if (!_model->notes().empty()) {
|
||||
m = _model->note_lower_bound(time);
|
||||
if (m == _model->notes().begin()) {
|
||||
// Before the start, use the velocity of the first note
|
||||
return (*m)->velocity();
|
||||
|
|
@ -4297,6 +4308,11 @@ MidiRegionView::get_velocity_for_add (MidiModel::TimeType time) const
|
|||
--m;
|
||||
return (*m)->velocity();
|
||||
}
|
||||
}
|
||||
|
||||
if (_model->notes().size() == 1) {
|
||||
return (*m)->velocity();
|
||||
}
|
||||
|
||||
// Interpolate velocity of surrounding notes
|
||||
MidiModel::Notes::const_iterator n = m;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue