From 2c59ddede5a4b6c1b9227e2a0288561b38f0763f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 21 Oct 2009 16:26:18 +0000 Subject: [PATCH] Fix MIDI rec regions. git-svn-id: svn://localhost/ardour2/branches/3.0@5842 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/audio_streamview.cc | 35 ++++++++-------- gtk2_ardour/audio_streamview.h | 2 - gtk2_ardour/midi_streamview.cc | 73 +++++++++++++++++++++------------ gtk2_ardour/midi_streamview.h | 10 ++--- gtk2_ardour/streamview.h | 2 +- libs/ardour/smf_source.cc | 4 ++ 6 files changed, 75 insertions(+), 51 deletions(-) diff --git a/gtk2_ardour/audio_streamview.cc b/gtk2_ardour/audio_streamview.cc index 6fcca999ce..1ffb37bb7f 100644 --- a/gtk2_ardour/audio_streamview.cc +++ b/gtk2_ardour/audio_streamview.cc @@ -470,22 +470,22 @@ AudioStreamView::setup_rec_box () SourceList sources; - for (list::iterator prc = rec_data_ready_connections.begin(); prc != rec_data_ready_connections.end(); ++prc) { + for (list::iterator prc = rec_data_ready_connections.begin(); + prc != rec_data_ready_connections.end(); ++prc) { (*prc).disconnect(); } rec_data_ready_connections.clear(); - // FIXME - boost::shared_ptr ads = boost::dynamic_pointer_cast(_trackview.get_diskstream()); - assert(ads); + boost::shared_ptr ads = _trackview.audio_track()->audio_diskstream(); for (uint32_t n=0; n < ads->n_channels().n_audio(); ++n) { - boost::shared_ptr src = boost::static_pointer_cast (ads->write_source (n)); + boost::shared_ptr src = ads->write_source (n); if (src) { sources.push_back (src); rec_data_ready_connections.push_back (src->PeakRangeReady.connect (bind - (mem_fun (*this, &AudioStreamView::rec_peak_range_ready), boost::weak_ptr(src)))); + (mem_fun (*this, &AudioStreamView::rec_peak_range_ready), + boost::weak_ptr(src)))); } } @@ -493,11 +493,12 @@ AudioStreamView::setup_rec_box () nframes_t start = 0; if (rec_regions.size() > 0) { - start = rec_regions.back().first->start() + _trackview.get_diskstream()->get_captured_frames(rec_regions.size()-1); + start = rec_regions.back().first->start() + + _trackview.get_diskstream()->get_captured_frames(rec_regions.size()-1); } - boost::shared_ptr region (boost::dynamic_pointer_cast - (RegionFactory::create (sources, start, 1 , "", 0, (Region::Flag)(Region::DefaultFlags), false))); + boost::shared_ptr region (boost::dynamic_pointer_cast( + RegionFactory::create (sources, start, 1, "", 0, Region::DefaultFlags, false))); assert(region); region->block_property_changes (); region->set_position (_trackview.session().transport_frame(), this); @@ -550,7 +551,8 @@ AudioStreamView::setup_rec_box () rec_rects.push_back (recbox); screen_update_connection.disconnect(); - screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (mem_fun (*this, &AudioStreamView::update_rec_box)); + screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect ( + mem_fun (*this, &AudioStreamView::update_rec_box)); rec_updating = true; rec_active = true; @@ -571,7 +573,8 @@ AudioStreamView::setup_rec_box () /* disconnect rapid update */ screen_update_connection.disconnect(); - for (list::iterator prc = rec_data_ready_connections.begin(); prc != rec_data_ready_connections.end(); ++prc) { + for (list::iterator prc = rec_data_ready_connections.begin(); + prc != rec_data_ready_connections.end(); ++prc) { (*prc).disconnect(); } rec_data_ready_connections.clear(); @@ -629,7 +632,7 @@ AudioStreamView::rec_peak_range_ready (nframes_t start, nframes_t cnt, boost::we // this is called from the peak building thread - if (rec_data_ready_map.size() == 0 || start+cnt > last_rec_data_frame) { + if (rec_data_ready_map.size() == 0 || start + cnt > last_rec_data_frame) { last_rec_data_frame = start + cnt; } @@ -647,11 +650,10 @@ AudioStreamView::update_rec_regions () if (use_rec_regions) { uint32_t n = 0; - for (list,RegionView*> >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); n++) { + for (list,RegionView*> >::iterator iter = rec_regions.begin(); + iter != rec_regions.end(); n++) { - list,RegionView*> >::iterator tmp; - - tmp = iter; + list,RegionView*> >::iterator tmp = iter; ++tmp; if (!canvas_item_visible (rec_rects[n].rectangle)) { @@ -662,6 +664,7 @@ AudioStreamView::update_rec_regions () boost::shared_ptr region = boost::dynamic_pointer_cast(iter->first); if (!region) { + iter = tmp; continue; } diff --git a/gtk2_ardour/audio_streamview.h b/gtk2_ardour/audio_streamview.h index 14c8465179..d17a67f23c 100644 --- a/gtk2_ardour/audio_streamview.h +++ b/gtk2_ardour/audio_streamview.h @@ -112,8 +112,6 @@ class AudioStreamView : public StreamView CrossfadeViewList crossfade_views; bool crossfades_visible; - std::list rec_data_ready_connections; - nframes_t last_rec_data_frame; std::map, bool> rec_data_ready_map; bool outline_region; diff --git a/gtk2_ardour/midi_streamview.cc b/gtk2_ardour/midi_streamview.cc index cb5537d601..537c4cb725 100644 --- a/gtk2_ardour/midi_streamview.cc +++ b/gtk2_ardour/midi_streamview.cc @@ -394,28 +394,31 @@ MidiStreamView::setup_rec_box () MidiRegion::SourceList sources; - for (list::iterator prc = rec_data_ready_connections.begin(); prc != rec_data_ready_connections.end(); ++prc) { + for (list::iterator prc = rec_data_ready_connections.begin(); + prc != rec_data_ready_connections.end(); ++prc) { (*prc).disconnect(); } rec_data_ready_connections.clear(); - // FIXME - boost::shared_ptr mds = boost::dynamic_pointer_cast(_trackview.get_diskstream()); - assert(mds); + boost::shared_ptr mds = _trackview.midi_track()->midi_diskstream(); sources.push_back(mds->write_source()); - rec_data_ready_connections.push_back (mds->write_source()->ViewDataRangeReady.connect (bind (mem_fun (*this, &MidiStreamView::rec_data_range_ready), boost::weak_ptr(mds->write_source())))); + rec_data_ready_connections.push_back (mds->write_source()->ViewDataRangeReady.connect (bind ( + mem_fun (*this, &MidiStreamView::rec_data_range_ready), + boost::weak_ptr(mds->write_source())))); // handle multi - jack_nframes_t start = 0; + nframes_t start = 0; if (rec_regions.size() > 0) { - start = rec_regions.back().first->position() + _trackview.get_diskstream()->get_captured_frames(rec_regions.size()-1); + start = rec_regions.back().first->start() + + _trackview.get_diskstream()->get_captured_frames(rec_regions.size()-1); } boost::shared_ptr region (boost::dynamic_pointer_cast (RegionFactory::create (sources, start, 1 , "", 0, Region::DefaultFlags, false))); + assert(region); region->block_property_changes (); region->set_position (_trackview.session().transport_frame(), this); @@ -430,7 +433,7 @@ MidiStreamView::setup_rec_box () boost::shared_ptr mt = _trackview.midi_track(); /* we know what it is already */ boost::shared_ptr ds = mt->midi_diskstream(); - jack_nframes_t frame_pos = ds->current_capture_start (); + nframes_t frame_pos = ds->current_capture_start (); gdouble xstart = _trackview.editor().frame_to_pixel (frame_pos); gdouble xend; uint32_t fill_color; @@ -457,18 +460,17 @@ MidiStreamView::setup_rec_box () rec_rects.push_back (recbox); screen_update_connection.disconnect(); - screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (mem_fun (*this, &MidiStreamView::update_rec_box)); + screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect ( + mem_fun (*this, &MidiStreamView::update_rec_box)); rec_updating = true; rec_active = true; } else if (rec_active && (_trackview.session().record_status() != Session::Recording || !_trackview.get_diskstream()->record_enabled())) { - screen_update_connection.disconnect(); rec_active = false; rec_updating = false; - } } else { @@ -480,7 +482,8 @@ MidiStreamView::setup_rec_box () /* disconnect rapid update */ screen_update_connection.disconnect(); - for (list::iterator prc = rec_data_ready_connections.begin(); prc != rec_data_ready_connections.end(); ++prc) { + for (list::iterator prc = rec_data_ready_connections.begin(); + prc != rec_data_ready_connections.end(); ++prc) { (*prc).disconnect(); } rec_data_ready_connections.clear(); @@ -527,21 +530,20 @@ MidiStreamView::update_rec_regions (boost::shared_ptr data, nframes_t uint32_t n = 0; bool update_range = false; - for (list,RegionView*> >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); n++) { + for (list,RegionView*> >::iterator iter = rec_regions.begin(); + iter != rec_regions.end(); n++) { - list,RegionView*> >::iterator tmp; - - tmp = iter; + list,RegionView*> >::iterator tmp = iter; ++tmp; - boost::shared_ptr region = boost::dynamic_pointer_cast(iter->first); - if (!region || !iter->second) { + if (!canvas_item_visible (rec_rects[n].rectangle)) { + /* rect already hidden, this region is done */ iter = tmp; continue; } - if (!canvas_item_visible (rec_rects[n].rectangle)) { - /* rect already hidden, this region is done */ + boost::shared_ptr region = boost::dynamic_pointer_cast(iter->first); + if (!region) { iter = tmp; continue; } @@ -572,21 +574,30 @@ MidiStreamView::update_rec_regions (boost::shared_ptr data, nframes_t gdouble xend = _trackview.editor().frame_to_pixel (region->position() + region->length()); rect->property_x2() = xend; + ARDOUR::BeatsFramesConverter tconv(_trackview.session(), region->position()); + /* draw events */ MidiRegionView* mrv = (MidiRegionView*)iter->second; + + // FIXME: this is offensively slow (linear search) for (MidiModel::Notes::const_iterator i = data->notes().begin(); i != data->notes().end(); ++i) { const boost::shared_ptr& note = *i; - if (note->length() > 0 && note->end_time() + region->position() > start) - mrv->resolve_note(note->note(), note->end_time()); + nframes_t note_start_frames = tconv.to(note->time()); + nframes_t note_end_frames = tconv.to(note->end_time()); - if (note->time() + region->position() < start) + if (note->length() > 0 && note_end_frames + region->position() > start) + mrv->resolve_note(note->note(), note_end_frames); + + if (note_start_frames + region->position() < start) { continue; + } - if (note->time() + region->position() > start + dur) + if (note_start_frames + region->position() > start + dur) { break; + } if (note->note() < _lowest_note) { _lowest_note = note->note(); @@ -638,15 +649,23 @@ MidiStreamView::update_rec_regions (boost::shared_ptr data, nframes_t } void -MidiStreamView::rec_data_range_ready (jack_nframes_t start, jack_nframes_t dur, boost::weak_ptr weak_src) +MidiStreamView::rec_data_range_ready (nframes_t start, nframes_t cnt, boost::weak_ptr weak_src) { // this is called from the butler thread for now - ENSURE_GUI_THREAD(bind (mem_fun (*this, &MidiStreamView::rec_data_range_ready), start, dur, weak_src)); + ENSURE_GUI_THREAD(bind (mem_fun (*this, &MidiStreamView::rec_data_range_ready), start, cnt, weak_src)); boost::shared_ptr src (boost::dynamic_pointer_cast(weak_src.lock())); - this->update_rec_regions (src->model(), start, dur); + if (!src) { + return; + } + + if (start + cnt > last_rec_data_frame) { + last_rec_data_frame = start + cnt; + } + + this->update_rec_regions (src->model(), start, cnt); } void diff --git a/gtk2_ardour/midi_streamview.h b/gtk2_ardour/midi_streamview.h index 87fc003283..ae2b907d1e 100644 --- a/gtk2_ardour/midi_streamview.h +++ b/gtk2_ardour/midi_streamview.h @@ -58,7 +58,7 @@ class MidiStreamView : public StreamView ~MidiStreamView (); void set_selected_regionviews (RegionSelection&); - void get_selectables (jack_nframes_t start, jack_nframes_t end, std::list&); + void get_selectables (nframes_t start, nframes_t end, std::list&); void get_inverted_selectables (Selection&, std::list& results); enum VisibleNoteRange { @@ -104,14 +104,14 @@ class MidiStreamView : public StreamView void setup_rec_box (); void rec_data_range_ready ( - jack_nframes_t start, - jack_nframes_t dur, + nframes_t start, + nframes_t dur, boost::weak_ptr src); void update_rec_regions ( boost::shared_ptr data, - jack_nframes_t start, - jack_nframes_t dur); + nframes_t start, + nframes_t dur); RegionView* add_region_view_internal ( boost::shared_ptr, diff --git a/gtk2_ardour/streamview.h b/gtk2_ardour/streamview.h index bfd3cb7b00..3b715ff099 100644 --- a/gtk2_ardour/streamview.h +++ b/gtk2_ardour/streamview.h @@ -167,7 +167,7 @@ protected: double height; std::list rec_data_ready_connections; - jack_nframes_t last_rec_data_frame; + nframes_t last_rec_data_frame; private: void update_coverage_frames (); diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 3e35e58fb9..c8b9e254fb 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -65,6 +65,8 @@ SMFSource::SMFSource (Session& s, const ustring& path, bool embedded, Source::Fl if (create(path)) { throw failed_constructor (); } + + _model = boost::shared_ptr(new MidiModel(this)); // FIXME } /** Constructor used for existing internal-to-session files. */ @@ -87,6 +89,8 @@ SMFSource::SMFSource (Session& s, const XMLNode& node, bool must_exist) if (open(_path)) { throw failed_constructor (); } + + _model = boost::shared_ptr(new MidiModel(this)); // FIXME } SMFSource::~SMFSource ()