mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-08 07:45:00 +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) */
|
/* second, use the nearest note in the region-view (consistent with get_velocity_for_add behavior) */
|
||||||
|
|
||||||
if (!_model->notes().empty()) {
|
if (!_model->notes().empty()) {
|
||||||
MidiModel::Notes::const_iterator m = _model->note_lower_bound(time);
|
MidiModel::Notes::const_iterator m = _model->note_lower_bound(time);
|
||||||
return (*m)->channel();
|
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 */
|
/* lastly: query the track's channel filter */
|
||||||
|
|
@ -4284,17 +4292,25 @@ MidiRegionView::get_velocity_for_add (MidiModel::TimeType time) const
|
||||||
return editor.draw_velocity();
|
return editor.draw_velocity();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_model->notes().empty()) {
|
if (_model->notes().size() < 2) {
|
||||||
return 0x40; // No notes, use default
|
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 (m == _model->notes().begin()) {
|
|
||||||
// Before the start, use the velocity of the first note
|
if (!_model->notes().empty()) {
|
||||||
return (*m)->velocity();
|
m = _model->note_lower_bound(time);
|
||||||
} else if (m == _model->notes().end()) {
|
if (m == _model->notes().begin()) {
|
||||||
// Past the end, use the velocity of the last note
|
// Before the start, use the velocity of the first note
|
||||||
--m;
|
return (*m)->velocity();
|
||||||
|
} else if (m == _model->notes().end()) {
|
||||||
|
// Past the end, use the velocity of the last note
|
||||||
|
--m;
|
||||||
|
return (*m)->velocity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_model->notes().size() == 1) {
|
||||||
return (*m)->velocity();
|
return (*m)->velocity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue