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