Don't do a linear search through controls for program change for no reason.

Clean up.


git-svn-id: svn://localhost/ardour2/branches/3.0@4600 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2009-02-16 05:33:23 +00:00
parent 458c588e2c
commit de88640598
2 changed files with 105 additions and 130 deletions

View file

@ -169,7 +169,6 @@ MidiRegionView::init (Gdk::Color& basic_color, bool wfd)
region_locked ();
reset_width_dependent_items (_pixel_width);
//reset_width_dependent_items ((double) _region->length() / samples_per_unit);
set_colors ();
@ -557,17 +556,6 @@ MidiRegionView::redisplay_model()
_model->read_lock();
MidiModel::Notes notes = _model->notes();
/*
cerr << _model->midi_source()->name() << " : redisplaying " << notes.size() << endl;
for (MidiModel::Notes::iterator i = notes.begin(); i != notes.end(); ++i) {
cerr << "NOTE time: " << (*i)->time()
<< " pitch: " << int((*i)->note())
<< " length: " << (*i)->length()
<< " end-time: " << (*i)->end_time()
<< " velocity: " << int((*i)->velocity())
<< endl;
}
*/
for (size_t i = 0; i < _model->n_notes(); ++i) {
add_note(_model->note_at(i));
@ -585,22 +573,21 @@ MidiRegionView::redisplay_model()
void
MidiRegionView::display_program_change_flags()
{
for (Automatable::Controls::iterator control = _model->controls().begin();
control != _model->controls().end(); ++control) {
if (control->first.type() == MidiPgmChangeAutomation) {
Glib::Mutex::Lock list_lock (control->second->list()->lock());
boost::shared_ptr<Evoral::Control> control = _model->control(MidiPgmChangeAutomation);
if (!control) {
return;
}
uint8_t channel = control->first.channel();
Glib::Mutex::Lock lock (control->list()->lock());
for (AutomationList::const_iterator event = control->second->list()->begin();
event != control->second->list()->end(); ++event) {
uint8_t channel = control->parameter().channel();
for (AutomationList::const_iterator event = control->list()->begin();
event != control->list()->end(); ++event) {
double event_time = (*event)->when;
double program_number = floor((*event)->value + 0.5);
//cerr << " got program change on channel " << int(channel)
// << " time: " << event_time << " number: " << program_number << endl;
// find bank select msb and lsb for the program change
// Get current value of bank select MSB at time of the program change
Evoral::Parameter bank_select_msb(MidiCCAutomation, channel, MIDI_CTL_MSB_BANK);
boost::shared_ptr<Evoral::Control> msb_control = _model->control(bank_select_msb);
uint8_t msb = 0;
@ -608,6 +595,7 @@ MidiRegionView::display_program_change_flags()
msb = uint8_t(floor(msb_control->get_float(true, event_time) + 0.5));
}
// Get current value of bank select LSB at time of the program change
Evoral::Parameter bank_select_lsb(MidiCCAutomation, channel, MIDI_CTL_LSB_BANK);
boost::shared_ptr<Evoral::Control> lsb_control = _model->control(bank_select_lsb);
uint8_t lsb = 0;
@ -615,24 +603,16 @@ MidiRegionView::display_program_change_flags()
lsb = uint8_t(floor(lsb_control->get_float(true, event_time) + 0.5));
}
//cerr << " got msb " << int(msb) << " and lsb " << int(lsb)
// << " thread_id: " << pthread_self() << endl;
MIDI::Name::PatchPrimaryKey patch_key(msb, lsb, program_number);
boost::shared_ptr<MIDI::Name::Patch> patch =
MIDI::Name::MidiPatchManager::instance().find_patch(
_model_name,
_custom_device_mode,
channel,
patch_key);
_model_name, _custom_device_mode, channel, patch_key);
ControlEvent program_change(beats_to_frames(event_time),
uint8_t(program_number), channel);
if (patch != 0) {
//cerr << " got patch with name " << patch->name()
// << " number " << patch->number() << endl;
add_pgm_change(program_change, patch->name());
} else {
char buf[4];
@ -640,9 +620,6 @@ MidiRegionView::display_program_change_flags()
add_pgm_change(program_change, buf);
}
}
break;
}
}
}
@ -710,7 +687,10 @@ MidiRegionView::set_height (double height)
void
MidiRegionView::apply_note_range (uint8_t min, uint8_t max, bool force)
{
if (_enable_display) {
if (!_enable_display) {
return;
}
if (!force && _current_range_min == min && _current_range_max == max) {
return;
}
@ -757,7 +737,7 @@ MidiRegionView::apply_note_range (uint8_t min, uint8_t max, bool force)
}
}
}
}
}
GhostRegion*
@ -772,9 +752,8 @@ MidiRegionView::add_ghost (TimeAxisView& tv)
MidiGhostRegion* ghost;
if (mtv && mtv->midi_view()) {
/* if ghost is inserted into midi track, use a dedicated midi ghost canvas group.
this is because it's nice to have midi notes on top of the note lines and
audio waveforms under it.
/* if ghost is inserted into midi track, use a dedicated midi ghost canvas group
to allow having midi notes on top of note lines and waveforms under it.
*/
ghost = new MidiGhostRegion (*mtv->midi_view(), trackview, unit_position);
} else {
@ -831,7 +810,8 @@ MidiRegionView::resolve_note(uint8_t note, double end_time)
}
if (_active_notes && _active_notes[note]) {
_active_notes[note]->property_x2() = trackview.editor().frame_to_pixel((nframes64_t)end_time);
const nframes64_t end_time_frames = beats_to_frames(end_time);
_active_notes[note]->property_x2() = trackview.editor().frame_to_pixel(end_time_frames);
_active_notes[note]->property_outline_what() = (guint32) 0xF; // all edges
_active_notes[note] = NULL;
}
@ -1005,18 +985,13 @@ MidiRegionView::add_pgm_change(ControlEvent& program, string displaytext)
double height = midi_stream_view()->contents_height();
boost::shared_ptr<CanvasProgramChange> pgm_change = boost::shared_ptr<CanvasProgramChange>(
new CanvasProgramChange(
*this,
*group,
new CanvasProgramChange(*this, *group,
displaytext,
height,
x,
1.0,
x, 1.0,
_model_name,
_custom_device_mode,
program.time,
program.channel,
program.value));
program.time, program.channel, program.value));
_pgm_changes.push_back(pgm_change);
}