From 82232f06ba3eea4a2b4342ad91fab552f4044402 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 29 Aug 2006 21:21:48 +0000 Subject: Merged with trunk R861 Possible new bugs - not very thoroughly tested, but at least functional at first glance git-svn-id: svn://localhost/ardour2/branches/midi@870 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/SConscript | 4 + gtk2_ardour/about.cc | 14 +- gtk2_ardour/analysis_window.cc | 8 +- gtk2_ardour/ardour_ui.cc | 6 +- gtk2_ardour/ardour_ui.h | 2 +- gtk2_ardour/arval | 2 +- gtk2_ardour/audio_region_editor.cc | 92 ++++----- gtk2_ardour/audio_region_editor.h | 4 +- gtk2_ardour/audio_region_view.cc | 116 +++++------ gtk2_ardour/audio_region_view.h | 88 ++++----- gtk2_ardour/audio_streamview.cc | 57 +++--- gtk2_ardour/audio_streamview.h | 10 +- gtk2_ardour/automation_line.h | 4 +- gtk2_ardour/crossfade_edit.cc | 72 +++---- gtk2_ardour/crossfade_edit.h | 4 +- gtk2_ardour/crossfade_view.cc | 2 +- gtk2_ardour/editor.cc | 108 +++++------ gtk2_ardour/editor.h | 52 ++--- gtk2_ardour/editor_audio_import.cc | 41 ++-- gtk2_ardour/editor_canvas.cc | 9 +- gtk2_ardour/editor_canvas_events.cc | 4 +- gtk2_ardour/editor_export_audio.cc | 51 +++-- gtk2_ardour/editor_keyboard.cc | 8 +- gtk2_ardour/editor_mixer.cc | 1 - gtk2_ardour/editor_mouse.cc | 225 +++++++++++----------- gtk2_ardour/editor_ops.cc | 328 ++++++++++++++++---------------- gtk2_ardour/editor_region_list.cc | 80 ++++---- gtk2_ardour/editor_timefx.cc | 12 +- gtk2_ardour/export_dialog.cc | 2 +- gtk2_ardour/export_region_dialog.cc | 5 +- gtk2_ardour/export_region_dialog.h | 4 +- gtk2_ardour/io_selector.cc | 6 +- gtk2_ardour/io_selector.h | 2 +- gtk2_ardour/location_ui.cc | 2 +- gtk2_ardour/meter_bridge.cc | 4 +- gtk2_ardour/midi_region_view.cc | 12 +- gtk2_ardour/midi_region_view.h | 20 +- gtk2_ardour/midi_streamview.cc | 47 ++--- gtk2_ardour/midi_streamview.h | 6 +- gtk2_ardour/mixer_ui.cc | 2 +- gtk2_ardour/playlist_selector.cc | 2 +- gtk2_ardour/plugin_selector.cc | 2 +- gtk2_ardour/plugin_ui.cc | 4 +- gtk2_ardour/plugin_ui.h | 2 +- gtk2_ardour/public_editor.h | 6 +- gtk2_ardour/region_gain_line.cc | 22 +-- gtk2_ardour/region_selection.cc | 26 +-- gtk2_ardour/region_view.cc | 79 ++++---- gtk2_ardour/region_view.h | 54 +++--- gtk2_ardour/route_params_ui.cc | 23 ++- gtk2_ardour/route_params_ui.h | 4 +- gtk2_ardour/route_time_axis.cc | 4 +- gtk2_ardour/route_time_axis.h | 2 +- gtk2_ardour/selection.cc | 2 +- gtk2_ardour/selection_templates.h | 24 +-- gtk2_ardour/send_ui.cc | 8 +- gtk2_ardour/send_ui.h | 4 +- gtk2_ardour/sfdb_ui.cc | 24 ++- gtk2_ardour/streamview.cc | 18 +- gtk2_ardour/streamview.h | 18 +- gtk2_ardour/tape_region_view.cc | 10 +- gtk2_ardour/tape_region_view.h | 2 +- gtk2_ardour/time_axis_view.h | 4 +- libs/ardour/SConscript | 2 + libs/ardour/ardour/audio_diskstream.h | 14 +- libs/ardour/ardour/audiofilesource.h | 10 - libs/ardour/ardour/audiofilter.h | 8 +- libs/ardour/ardour/audioplaylist.h | 14 +- libs/ardour/ardour/audioregion.h | 20 +- libs/ardour/ardour/audiosource.h | 4 +- libs/ardour/ardour/auditioner.h | 4 +- libs/ardour/ardour/automation_event.h | 5 +- libs/ardour/ardour/crossfade.h | 29 +-- libs/ardour/ardour/diskstream.h | 10 +- libs/ardour/ardour/io.h | 6 +- libs/ardour/ardour/location.h | 6 +- libs/ardour/ardour/midi_diskstream.h | 4 +- libs/ardour/ardour/midi_playlist.h | 17 +- libs/ardour/ardour/midi_region.h | 20 +- libs/ardour/ardour/playlist.h | 75 ++++---- libs/ardour/ardour/playlist_templates.h | 4 +- libs/ardour/ardour/plugin.h | 6 +- libs/ardour/ardour/redirect.h | 1 - libs/ardour/ardour/region.h | 59 +++--- libs/ardour/ardour/region_factory.h | 30 ++- libs/ardour/ardour/reverse.h | 2 +- libs/ardour/ardour/route.h | 2 +- libs/ardour/ardour/session.h | 134 ++++++------- libs/ardour/ardour/session_region.h | 4 +- libs/ardour/ardour/source.h | 20 +- libs/ardour/ardour/source_factory.h | 28 +++ libs/ardour/ardour/tempo.h | 6 +- libs/ardour/ardour/types.h | 4 + libs/ardour/audio_diskstream.cc | 95 ++++----- libs/ardour/audio_playlist.cc | 151 ++++++--------- libs/ardour/audio_track.cc | 18 +- libs/ardour/audioengine.cc | 24 +-- libs/ardour/audiofilesource.cc | 83 +------- libs/ardour/audiofilter.cc | 32 ++-- libs/ardour/audioregion.cc | 96 ++++------ libs/ardour/audiosource.cc | 14 +- libs/ardour/auditioner.cc | 25 ++- libs/ardour/automation_event.cc | 2 + libs/ardour/control_protocol_manager.cc | 2 +- libs/ardour/coreaudiosource.cc | 2 +- libs/ardour/crossfade.cc | 38 ++-- libs/ardour/destructive_filesource.cc | 2 +- libs/ardour/diskstream.cc | 6 +- libs/ardour/import.cc | 40 ++-- libs/ardour/insert.cc | 4 +- libs/ardour/io.cc | 19 +- libs/ardour/ladspa_plugin.cc | 2 +- libs/ardour/location.cc | 34 +++- libs/ardour/midi_diskstream.cc | 39 ++-- libs/ardour/midi_playlist.cc | 174 +++-------------- libs/ardour/midi_region.cc | 47 ++--- libs/ardour/osc.cc | 2 +- libs/ardour/playlist.cc | 222 +++++++++++---------- libs/ardour/playlist_factory.cc | 46 ----- libs/ardour/region.cc | 180 ++++++++---------- libs/ardour/region_factory.cc | 182 ++++++++++++++++++ libs/ardour/reverse.cc | 25 +-- libs/ardour/send.cc | 2 +- libs/ardour/session.cc | 312 +++++++++++++++--------------- libs/ardour/session_butler.cc | 2 +- libs/ardour/session_command.cc | 7 +- libs/ardour/session_events.cc | 2 +- libs/ardour/session_state.cc | 172 ++++++++--------- libs/ardour/session_timefx.cc | 38 ++-- libs/ardour/smf_source.cc | 4 - libs/ardour/sndfilesource.cc | 21 +- libs/ardour/source.cc | 15 +- libs/ardour/source_factory.cc | 219 +++++++++++++++++++++ libs/ardour/vst_plugin.cc | 2 +- libs/pbd/pbd/command.h | 3 +- libs/pbd/pbd/memento_command.h | 39 +++- libs/pbd/pbd/statefuldestructible.h | 13 ++ libs/pbd/pbd/undo.h | 34 ++-- libs/pbd/undo.cc | 78 ++++++-- 139 files changed, 2557 insertions(+), 2420 deletions(-) create mode 100644 libs/ardour/ardour/source_factory.h create mode 100644 libs/ardour/region_factory.cc create mode 100644 libs/ardour/source_factory.cc create mode 100644 libs/pbd/pbd/statefuldestructible.h diff --git a/gtk2_ardour/SConscript b/gtk2_ardour/SConscript index 9035666bbb..aaa686d246 100644 --- a/gtk2_ardour/SConscript +++ b/gtk2_ardour/SConscript @@ -212,6 +212,10 @@ itest_files=Split(""" itest.cc """) +stest_files=Split(""" +stest.cc +""") + extra_sources = [] vst_files = [ 'vst_pluginui.cc' ] diff --git a/gtk2_ardour/about.cc b/gtk2_ardour/about.cc index 033b5c4604..e48e08f130 100644 --- a/gtk2_ardour/about.cc +++ b/gtk2_ardour/about.cc @@ -186,13 +186,13 @@ About::About () set_website (X_("http://ardour.org/")); set_website_label (X_("ardour.org")); set_version ((string_compose(_("%1\n(built with ardour/gtk %2.%3.%4 libardour: %5.%6.%7)"), - VERSIONSTRING, - gtk_ardour_major_version, - gtk_ardour_minor_version, - gtk_ardour_micro_version, - libardour_major_version, - libardour_minor_version, - libardour_micro_version))); + VERSIONSTRING, + gtk_ardour_major_version, + gtk_ardour_minor_version, + gtk_ardour_micro_version, + libardour_major_version, + libardour_minor_version, + libardour_micro_version))); #ifdef WITH_PAYMENT_OPTIONS diff --git a/gtk2_ardour/analysis_window.cc b/gtk2_ardour/analysis_window.cc index 24c6cc4fb8..d89c106831 100644 --- a/gtk2_ardour/analysis_window.cc +++ b/gtk2_ardour/analysis_window.cc @@ -292,15 +292,15 @@ AnalysisWindow::analyze_data (Gtk::Button *button) jack_nframes_t i = 0; int n; - while ( i < arv->region().length() ) { + while ( i < arv->region()->length() ) { // TODO: What about stereo+ channels? composite all to one, I guess n = fft_graph.windowSize(); - if (i + n >= arv->region().length() ) { - n = arv->region().length() - i; + if (i + n >= arv->region()->length() ) { + n = arv->region()->length() - i; } - n = arv->audio_region().read_at(buf, mixbuf, gain, arv->region().position() + i, n); + n = arv->audio_region()->read_at(buf, mixbuf, gain, arv->region()->position() + i, n); if ( n < fft_graph.windowSize()) { for (int j = n; j < fft_graph.windowSize(); j++) { diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index de117a1399..d0b9136bcb 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -2202,12 +2202,12 @@ ARDOUR_UI::halt_on_xrun_message () } void -ARDOUR_UI::delete_sources_in_the_right_thread (list* deletion_list) +ARDOUR_UI::delete_sources_in_the_right_thread (list >* deletion_list) { ENSURE_GUI_THREAD (bind (mem_fun(*this, &ARDOUR_UI::delete_sources_in_the_right_thread), deletion_list)); - for (list::iterator i = deletion_list->begin(); i != deletion_list->end(); ++i) { - delete *i; + for (list >::iterator i = deletion_list->begin(); i != deletion_list->end(); ++i) { + (*i)->drop_references (); } delete deletion_list; diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index 1f5277b5fe..821899c3af 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -645,7 +645,7 @@ class ARDOUR_UI : public Gtkmm2ext::UI struct timeval last_peak_grab; struct timeval last_shuttle_request; - void delete_sources_in_the_right_thread (list*); + void delete_sources_in_the_right_thread (list >*); void editor_display_control_changed (Editing::DisplayControl c); diff --git a/gtk2_ardour/arval b/gtk2_ardour/arval index dcbef15a0f..cea6299d05 100755 --- a/gtk2_ardour/arval +++ b/gtk2_ardour/arval @@ -1,3 +1,3 @@ #!/bin/sh source ardev_common.sh -exec valgrind --num-callers=15 --tool=memcheck ./ardour.bin --novst $* +exec valgrind --num-callers=50 --tool=memcheck gtk2_ardour/ardour.bin --novst $* diff --git a/gtk2_ardour/audio_region_editor.cc b/gtk2_ardour/audio_region_editor.cc index 194f358b42..3149a863ad 100644 --- a/gtk2_ardour/audio_region_editor.cc +++ b/gtk2_ardour/audio_region_editor.cc @@ -37,7 +37,7 @@ using namespace PBD; using namespace sigc; using namespace std; -AudioRegionEditor::AudioRegionEditor (Session& s, AudioRegion& r, AudioRegionView& rv) +AudioRegionEditor::AudioRegionEditor (Session& s, boost::shared_ptr r, AudioRegionView& rv) : RegionEditor (s), _region (r), _region_view (rv), @@ -262,7 +262,7 @@ AudioRegionEditor::AudioRegionEditor (Session& s, AudioRegion& r, AudioRegionVie signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast (this))); string title = _("ardour: region "); - title += _region.name(); + title += _region->name(); set_title (title); show_all(); @@ -277,7 +277,7 @@ AudioRegionEditor::AudioRegionEditor (Session& s, AudioRegion& r, AudioRegionVie fade_in_changed (); fade_out_changed (); - XMLNode *node = _region.extra_xml ("GUI"); + XMLNode *node = _region->extra_xml ("GUI"); XMLProperty *prop = 0; bool showing_envelope = false; @@ -293,7 +293,7 @@ AudioRegionEditor::AudioRegionEditor (Session& s, AudioRegion& r, AudioRegionVie envelope_view_button.set_active (false); } - _region.StateChanged.connect (mem_fun(*this, &AudioRegionEditor::region_changed)); + _region->StateChanged.connect (mem_fun(*this, &AudioRegionEditor::region_changed)); spin_arrow_grab = false; @@ -392,25 +392,25 @@ AudioRegionEditor::breleased (GdkEventButton* ev, Gtk::SpinButton* but, void (Au void AudioRegionEditor::start_editing_fade_in () { - _region.freeze (); + _region->freeze (); } void AudioRegionEditor::stop_editing_fade_in () { - _region.thaw (_("fade in edit")); + _region->thaw (_("fade in edit")); } void AudioRegionEditor::start_editing_fade_out () { - _region.freeze (); + _region->freeze (); } void AudioRegionEditor::stop_editing_fade_out () { - _region.thaw (_("fade out edit")); + _region->thaw (_("fade out edit")); } void @@ -453,24 +453,24 @@ AudioRegionEditor::connect_editor_events () void AudioRegionEditor::start_clock_changed () { - _region.set_position (start_clock.current_time(), this); + _region->set_position (start_clock.current_time(), this); } void AudioRegionEditor::end_clock_changed () { - _region.trim_end (end_clock.current_time(), this); + _region->trim_end (end_clock.current_time(), this); - end_clock.set (_region.position() + _region.length(), true); + end_clock.set (_region->position() + _region->length(), true); } void AudioRegionEditor::length_clock_changed () { jack_nframes_t frames = length_clock.current_time(); - _region.trim_end (_region.position() + frames, this); + _region->trim_end (_region->position() + frames, this); - length_clock.set (_region.length()); + length_clock.set (_region->length()); } gint @@ -482,7 +482,7 @@ AudioRegionEditor::envelope_active_button_press(GdkEventButton *ev) gint AudioRegionEditor::envelope_active_button_release (GdkEventButton *ev) { - _region.set_envelope_active (!_region.envelope_active()); + _region->set_envelope_active (!_region->envelope_active()); return stop_signal (envelope_active_button, "button_release_event"); } @@ -507,42 +507,42 @@ AudioRegionEditor::audition_button_toggled () void AudioRegionEditor::raise_button_clicked () { - _region.raise (); + _region->raise (); } void AudioRegionEditor::lower_button_clicked () { - _region.lower (); + _region->lower (); } void AudioRegionEditor::opaque_button_clicked () { - bool ractive = _region.opaque(); + bool ractive = _region->opaque(); if (opaque_button.get_active() != ractive) { - _region.set_opaque (!ractive); + _region->set_opaque (!ractive); } } void AudioRegionEditor::mute_button_clicked () { - bool ractive = _region.muted(); + bool ractive = _region->muted(); if (mute_button.get_active() != ractive) { - _region.set_muted (!ractive); + _region->set_muted (!ractive); } } void AudioRegionEditor::lock_button_clicked () { - bool ractive = _region.locked(); + bool ractive = _region->locked(); if (lock_button.get_active() != ractive) { - _region.set_locked (!ractive); + _region->set_locked (!ractive); } } @@ -550,15 +550,15 @@ void AudioRegionEditor::layer_changed () { char buf[8]; - snprintf (buf, sizeof(buf), "%d", (int) _region.layer() + 1); + snprintf (buf, sizeof(buf), "%d", (int) _region->layer() + 1); layer_value_label.set_text (buf); } void AudioRegionEditor::name_changed () { - if (name_entry.get_text() != _region.name()) { - name_entry.set_text (_region.name()); + if (name_entry.get_text() != _region->name()) { + name_entry.set_text (_region->name()); } } @@ -567,7 +567,7 @@ AudioRegionEditor::lock_changed () { bool yn; - if ((yn = _region.locked()) != lock_button.get_active()) { + if ((yn = _region->locked()) != lock_button.get_active()) { lock_button.set_active (yn); } @@ -581,7 +581,7 @@ AudioRegionEditor::envelope_active_changed () { bool yn; - if ((yn = _region.envelope_active()) != envelope_active_button.get_active()) { + if ((yn = _region->envelope_active()) != envelope_active_button.get_active()) { envelope_active_button.set_active (yn); } } @@ -590,7 +590,7 @@ void AudioRegionEditor::opacity_changed () { bool yn; - if ((yn = _region.opaque()) != opaque_button.get_active()) { + if ((yn = _region->opaque()) != opaque_button.get_active()) { opaque_button.set_active (yn); } } @@ -599,7 +599,7 @@ void AudioRegionEditor::mute_changed () { bool yn; - if ((yn = _region.muted()) != mute_button.get_active()) { + if ((yn = _region->muted()) != mute_button.get_active()) { mute_button.set_active (yn); } } @@ -608,9 +608,9 @@ void AudioRegionEditor::bounds_changed (Change what_changed) { if (what_changed & Change ((PositionChanged|LengthChanged))) { - start_clock.set (_region.position(), true); - end_clock.set (_region.position() + _region.length(), true); - length_clock.set (_region.length(), true); + start_clock.set (_region->position(), true); + end_clock.set (_region->position() + _region->length(), true); + length_clock.set (_region->length(), true); } } @@ -623,8 +623,8 @@ AudioRegionEditor::activation () void AudioRegionEditor::name_entry_changed () { - if (name_entry.get_text() != _region.name()) { - _region.set_name (name_entry.get_text()); + if (name_entry.get_text() != _region->name()) { + _region->set_name (name_entry.get_text()); } } @@ -637,11 +637,11 @@ AudioRegionEditor::fade_in_changed () jack_nframes_t frames; bool x; - if (adj_frames != (frames = (jack_nframes_t) _region.fade_in().back()->when)) { + if (adj_frames != (frames = (jack_nframes_t) _region->fade_in().back()->when)) { fade_in_length_adjustment.set_value ((frames * 1000.0f) / sr); } - if ((x = _region.fade_in_active()) != fade_in_active_button.get_active()) { + if ((x = _region->fade_in_active()) != fade_in_active_button.get_active()) { fade_in_active_button.set_active (x); } } @@ -654,11 +654,11 @@ AudioRegionEditor::fade_out_changed () jack_nframes_t adj_frames = (jack_nframes_t) floor (msecs * (sr/1000.0f)); jack_nframes_t frames; bool x; - if (adj_frames != (frames = (jack_nframes_t) _region.fade_out().back()->when)) { + if (adj_frames != (frames = (jack_nframes_t) _region->fade_out().back()->when)) { fade_out_length_adjustment.set_value ((frames * 1000.0f) / sr); } - if ((x = _region.fade_out_active()) != fade_out_active_button.get_active()) { + if ((x = _region->fade_out_active()) != fade_out_active_button.get_active()) { fade_out_active_button.set_active (x); } } @@ -668,9 +668,9 @@ AudioRegionEditor::fade_in_length_adjustment_changed () { jack_nframes_t fade_length = (jack_nframes_t) floor (fade_in_length_adjustment.get_value() * _session.frame_rate() * 0.001); fade_length = max (fade_length, (jack_nframes_t) 64); - fade_length = min (fade_length, _region.length()); + fade_length = min (fade_length, _region->length()); - _region.set_fade_in_length (fade_length); + _region->set_fade_in_length (fade_length); /* region is frozen, no worries */ fade_in_changed(); } @@ -680,9 +680,9 @@ AudioRegionEditor::fade_out_length_adjustment_changed () { jack_nframes_t fade_length = (jack_nframes_t) floor (fade_out_length_adjustment.get_value() * _session.frame_rate() * 0.001); fade_length = max (fade_length, (jack_nframes_t) 64); - fade_length = min (fade_length, _region.length()); + fade_length = min (fade_length, _region->length()); - _region.set_fade_out_length (fade_length); + _region->set_fade_out_length (fade_length); /* region is frozen, no worries */ fade_out_changed(); } @@ -690,13 +690,13 @@ AudioRegionEditor::fade_out_length_adjustment_changed () void AudioRegionEditor::fade_in_active_toggled () { - _region.set_fade_in_active (fade_in_active_button.get_active()); + _region->set_fade_in_active (fade_in_active_button.get_active()); } void AudioRegionEditor::fade_out_active_toggled () { - _region.set_fade_out_active (fade_out_active_button.get_active()); + _region->set_fade_out_active (fade_out_active_button.get_active()); } void @@ -704,7 +704,7 @@ AudioRegionEditor::fade_out_active_changed () { bool x; - if ((x = _region.fade_out_active()) != fade_out_active_button.get_active()) { + if ((x = _region->fade_out_active()) != fade_out_active_button.get_active()) { fade_out_active_button.set_active (x); } } @@ -714,7 +714,7 @@ AudioRegionEditor::fade_in_active_changed () { bool x; - if ((x = _region.fade_in_active()) != fade_in_active_button.get_active()) { + if ((x = _region->fade_in_active()) != fade_in_active_button.get_active()) { fade_in_active_button.set_active (x); } } diff --git a/gtk2_ardour/audio_region_editor.h b/gtk2_ardour/audio_region_editor.h index 38cd920e5e..dbbc40f9ba 100644 --- a/gtk2_ardour/audio_region_editor.h +++ b/gtk2_ardour/audio_region_editor.h @@ -53,11 +53,11 @@ class AudioRegionView; class AudioRegionEditor : public RegionEditor { public: - AudioRegionEditor (ARDOUR::Session&, ARDOUR::AudioRegion&, AudioRegionView& rv); + AudioRegionEditor (ARDOUR::Session&, boost::shared_ptr, AudioRegionView& rv); ~AudioRegionEditor (); private: - ARDOUR::AudioRegion& _region; + boost::shared_ptr _region; AudioRegionView& _region_view; void connect_editor_events (); diff --git a/gtk2_ardour/audio_region_view.cc b/gtk2_ardour/audio_region_view.cc index 93af5b3ec0..41b95b0d42 100644 --- a/gtk2_ardour/audio_region_view.cc +++ b/gtk2_ardour/audio_region_view.cc @@ -55,7 +55,7 @@ using namespace ArdourCanvas; static const int32_t sync_mark_width = 9; -AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, AudioRegion& r, double spu, +AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr r, double spu, Gdk::Color& basic_color) : RegionView (parent, tv, r, spu, basic_color) , sync_mark(0) @@ -71,7 +71,7 @@ AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView { } -AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, AudioRegion& r, double spu, +AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr r, double spu, Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility) : RegionView (parent, tv, r, spu, basic_color, visibility) , sync_mark(0) @@ -101,7 +101,7 @@ AudioRegionView::init (Gdk::Color& basic_color, bool wfd) zero_line = 0; _flags = 0; - if ((node = _region.extra_xml ("GUI")) != 0) { + if ((node = _region->extra_xml ("GUI")) != 0) { set_flags (node); } else { _flags = WaveformVisible; @@ -147,11 +147,11 @@ AudioRegionView::init (Gdk::Color& basic_color, bool wfd) fade_out_handle->set_data ("regionview", this); } - string foo = _region.name(); + string foo = _region->name(); foo += ':'; foo += "gain"; - gain_line = new AudioRegionGainLine (foo, trackview.session(), *this, *group, audio_region().envelope()); + gain_line = new AudioRegionGainLine (foo, trackview.session(), *this, *group, audio_region()->envelope()); if (!(_flags & EnvelopeVisible)) { gain_line->hide (); @@ -159,7 +159,7 @@ AudioRegionView::init (Gdk::Color& basic_color, bool wfd) gain_line->show (); } - reset_width_dependent_items ((double) _region.length() / samples_per_unit); + reset_width_dependent_items ((double) _region->length() / samples_per_unit); gain_line->reset (); @@ -174,7 +174,7 @@ AudioRegionView::init (Gdk::Color& basic_color, bool wfd) fade_in_active_changed (); fade_out_active_changed (); - _region.StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed)); + _region->StateChanged.connect (mem_fun(*this, &AudioRegionView::region_changed)); fade_in_shape->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this)); fade_in_handle->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this)); @@ -203,11 +203,11 @@ AudioRegionView::~AudioRegionView () } } -ARDOUR::AudioRegion& +boost::shared_ptr AudioRegionView::audio_region() const { // "Guaranteed" to succeed... - return dynamic_cast(_region); + return boost::dynamic_pointer_cast(_region); } void @@ -252,13 +252,13 @@ AudioRegionView::fade_out_changed () void AudioRegionView::set_fade_in_active (bool yn) { - audio_region().set_fade_in_active (yn); + audio_region()->set_fade_in_active (yn); } void AudioRegionView::set_fade_out_active (bool yn) { - audio_region().set_fade_out_active (yn); + audio_region()->set_fade_out_active (yn); } void @@ -268,7 +268,7 @@ AudioRegionView::fade_in_active_changed () uint32_t col; UINT_TO_RGBA(fade_color,&r,&g,&b,&a); - if (audio_region().fade_in_active()) { + if (audio_region()->fade_in_active()) { col = RGBA_TO_UINT(r,g,b,120); fade_in_shape->property_fill_color_rgba() = col; fade_in_shape->property_width_pixels() = 0; @@ -288,7 +288,7 @@ AudioRegionView::fade_out_active_changed () uint32_t col; UINT_TO_RGBA(fade_color,&r,&g,&b,&a); - if (audio_region().fade_out_active()) { + if (audio_region()->fade_out_active()) { col = RGBA_TO_UINT(r,g,b,120); fade_out_shape->property_fill_color_rgba() = col; fade_out_shape->property_width_pixels() = 0; @@ -309,7 +309,7 @@ AudioRegionView::region_scale_amplitude_changed () for (uint32_t n = 0; n < waves.size(); ++n) { // force a reload of the cache - waves[n]->property_data_src() = &_region; + waves[n]->property_data_src() = _region.get(); } } @@ -320,20 +320,20 @@ AudioRegionView::region_renamed () string str; - if (_region.locked()) { + if (_region->locked()) { str += '>'; - str += _region.name(); + str += _region->name(); str += '<'; } else { - str = _region.name(); + str = _region->name(); } // ... because of this - if (audio_region().speed_mismatch (trackview.session().frame_rate())) { + if (audio_region()->speed_mismatch (trackview.session().frame_rate())) { str = string ("*") + str; } - if (_region.muted()) { + if (_region->muted()) { str = string ("!") + str; } @@ -349,13 +349,13 @@ AudioRegionView::region_resized (Change what_changed) if (what_changed & Change (StartChanged|LengthChanged)) { for (uint32_t n = 0; n < waves.size(); ++n) { - waves[n]->property_region_start() = _region.start(); + waves[n]->property_region_start() = _region->start(); } for (vector::iterator i = ghosts.begin(); i != ghosts.end(); ++i) { for (vector::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) { - (*w)->property_region_start() = _region.start(); + (*w)->property_region_start() = _region->start(); } } } @@ -395,7 +395,7 @@ AudioRegionView::region_muted () RegionView::region_muted(); for (uint32_t n=0; n < waves.size(); ++n) { - if (_region.muted()) { + if (_region->muted()) { waves[n]->property_wave_color() = color_map[cMutedWaveForm]; } else { waves[n]->property_wave_color() = color_map[cWaveForm]; @@ -471,7 +471,7 @@ AudioRegionView::reset_fade_shapes () void AudioRegionView::reset_fade_in_shape () { - reset_fade_in_shape_width ((jack_nframes_t) audio_region().fade_in().back()->when); + reset_fade_in_shape_width ((jack_nframes_t) audio_region()->fade_in().back()->when); } void @@ -516,7 +516,7 @@ AudioRegionView::reset_fade_in_shape_width (jack_nframes_t width) fade_in_shape->show(); float curve[npoints]; - audio_region().fade_in().get_vector (0, audio_region().fade_in().back()->when, curve, npoints); + audio_region()->fade_in().get_vector (0, audio_region()->fade_in().back()->when, curve, npoints); points = get_canvas_points ("fade in shape", npoints+3); @@ -555,7 +555,7 @@ AudioRegionView::reset_fade_in_shape_width (jack_nframes_t width) void AudioRegionView::reset_fade_out_shape () { - reset_fade_out_shape_width ((jack_nframes_t) audio_region().fade_out().back()->when); + reset_fade_out_shape_width ((jack_nframes_t) audio_region()->fade_out().back()->when); } void @@ -581,7 +581,7 @@ AudioRegionView::reset_fade_out_shape_width (jack_nframes_t width) } double handle_center; - handle_center = (_region.length() - width) / samples_per_unit; + handle_center = (_region->length() - width) / samples_per_unit; if (handle_center > 7.0) { handle_center -= 3.0; @@ -602,7 +602,7 @@ AudioRegionView::reset_fade_out_shape_width (jack_nframes_t width) fade_out_shape->show(); float curve[npoints]; - audio_region().fade_out().get_vector (0, audio_region().fade_out().back()->when, curve, npoints); + audio_region()->fade_out().get_vector (0, audio_region()->fade_out().back()->when, curve, npoints); if (_height > NAME_HIGHLIGHT_THRESH) { h = _height - NAME_HIGHLIGHT_SIZE; @@ -680,11 +680,11 @@ AudioRegionView::set_colors () RegionView::set_colors(); if (gain_line) { - gain_line->set_line_color (audio_region().envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]); + gain_line->set_line_color (audio_region()->envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]); } for (uint32_t n=0; n < waves.size(); ++n) { - if (_region.muted()) { + if (_region->muted()) { waves[n]->property_wave_color() = color_map[cMutedWaveForm]; } else { waves[n]->property_wave_color() = color_map[cWaveForm]; @@ -776,14 +776,14 @@ AudioRegionView::create_waves () for (uint32_t n = 0; n < nchans; ++n) { - if (n >= audio_region().n_channels()) { + if (n >= audio_region()->n_channels()) { break; } wave_caches.push_back (WaveView::create_cache ()); if (wait_for_data) { - if (audio_region().audio_source(n).peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) { + if (audio_region()->audio_source(n)->peaks_ready (bind (mem_fun(*this, &AudioRegionView::peaks_ready_handler), n), data_ready_connection)) { create_one_wave (n, true); } else { create_zero_line = false; @@ -796,7 +796,7 @@ AudioRegionView::create_waves () if (create_zero_line) { zero_line = new ArdourCanvas::SimpleLine (*group); zero_line->property_x1() = (gdouble) 1.0; - zero_line->property_x2() = (gdouble) (_region.length() / samples_per_unit) - 1.0; + zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0; zero_line->property_color_rgba() = (guint) color_map[cZeroLine]; manage_zero_line (); } @@ -808,7 +808,7 @@ AudioRegionView::create_one_wave (uint32_t which, bool direct) RouteTimeAxisView& atv (*(dynamic_cast(&trackview))); // ick uint32_t nchans = atv.get_diskstream()->n_channels().get(DataType::AUDIO); uint32_t n; - uint32_t nwaves = std::min (nchans, audio_region().n_channels()); + uint32_t nwaves = std::min (nchans, audio_region()->n_channels()); gdouble ht; if (trackview.height < NAME_HIGHLIGHT_SIZE) { @@ -821,7 +821,7 @@ AudioRegionView::create_one_wave (uint32_t which, bool direct) WaveView *wave = new WaveView(*group); - wave->property_data_src() = (gpointer) &_region; + wave->property_data_src() = (gpointer) _region.get(); wave->property_cache() = wave_caches[which]; wave->property_cache_updater() = true; wave->property_channel() = which; @@ -833,8 +833,8 @@ AudioRegionView::create_one_wave (uint32_t which, bool direct) wave->property_height() = (double) ht; wave->property_samples_per_unit() = samples_per_unit; wave->property_amplitude_above_axis() = _amplitude_above_axis; - wave->property_wave_color() = _region.muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm]; - wave->property_region_start() = _region.start(); + wave->property_wave_color() = _region->muted() ? color_map[cMutedWaveForm] : color_map[cWaveForm]; + wave->property_region_start() = _region->start(); if (!(_flags & WaveformVisible)) { wave->hide(); @@ -870,7 +870,7 @@ AudioRegionView::create_one_wave (uint32_t which, bool direct) if (!zero_line) { zero_line = new ArdourCanvas::SimpleLine (*group); zero_line->property_x1() = (gdouble) 1.0; - zero_line->property_x2() = (gdouble) (_region.length() / samples_per_unit) - 1.0; + zero_line->property_x2() = (gdouble) (_region->length() / samples_per_unit) - 1.0; zero_line->property_color_rgba() = (guint) color_map[cZeroLine]; manage_zero_line (); } @@ -908,7 +908,7 @@ AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev) jack_nframes_t fx = trackview.editor.pixel_to_frame (x); - if (fx > _region.length()) { + if (fx > _region->length()) { return; } @@ -921,20 +921,20 @@ AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev) gain_line->view_to_model_y (y); trackview.session().begin_reversible_command (_("add gain control point")); - XMLNode &before = audio_region().envelope().get_state(); + XMLNode &before = audio_region()->envelope().get_state(); - if (!audio_region().envelope_active()) { - XMLNode &before = audio_region().get_state(); - audio_region().set_envelope_active(true); - XMLNode &after = audio_region().get_state(); - trackview.session().add_command (new MementoCommand(audio_region(), &before, &after)); + if (!audio_region()->envelope_active()) { + XMLNode &before = audio_region()->get_state(); + audio_region()->set_envelope_active(true); + XMLNode &after = audio_region()->get_state(); + trackview.session().add_command (new MementoCommand(*(audio_region().get()), &before, &after)); } - audio_region().envelope().add (fx, y); + audio_region()->envelope().add (fx, y); - XMLNode &after = audio_region().envelope().get_state(); - trackview.session().add_command (new MementoCommand(audio_region().envelope(), &before, &after)); + XMLNode &after = audio_region()->envelope().get_state(); + trackview.session().add_command (new MementoCommand(audio_region()->envelope(), &before, &after)); trackview.session().commit_reversible_command (); } @@ -942,7 +942,7 @@ void AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev) { ControlPoint *cp = reinterpret_cast (item->get_data ("control_point")); - audio_region().envelope().erase (cp->model); + audio_region()->envelope().erase (cp->model); } void @@ -953,7 +953,7 @@ AudioRegionView::store_flags() node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no"); node->add_property ("envelope-visible", (_flags & EnvelopeVisible) ? "yes" : "no"); - _region.add_extra_xml (*node); + _region->add_extra_xml (*node); } void @@ -1020,7 +1020,7 @@ AudioRegionView::add_ghost (AutomationTimeAxisView& atv) RouteTimeAxisView* rtv = dynamic_cast(&trackview); assert(rtv); - double unit_position = _region.position () / samples_per_unit; + double unit_position = _region->position () / samples_per_unit; GhostRegion* ghost = new GhostRegion (atv, unit_position); uint32_t nchans; @@ -1028,13 +1028,13 @@ AudioRegionView::add_ghost (AutomationTimeAxisView& atv) for (uint32_t n = 0; n < nchans; ++n) { - if (n >= audio_region().n_channels()) { + if (n >= audio_region()->n_channels()) { break; } WaveView *wave = new WaveView(*ghost->group); - wave->property_data_src() = &_region; + wave->property_data_src() = _region.get(); wave->property_cache() = wave_caches[n]; wave->property_cache_updater() = false; wave->property_channel() = n; @@ -1045,13 +1045,13 @@ AudioRegionView::add_ghost (AutomationTimeAxisView& atv) wave->property_samples_per_unit() = samples_per_unit; wave->property_amplitude_above_axis() = _amplitude_above_axis; wave->property_wave_color() = color_map[cGhostTrackWave]; - wave->property_region_start() = _region.start(); + wave->property_region_start() = _region->start(); ghost->waves.push_back(wave); } ghost->set_height (); - ghost->set_duration (_region.length() / samples_per_unit); + ghost->set_duration (_region->length() / samples_per_unit); ghosts.push_back (ghost); ghost->GoingAway.connect (mem_fun(*this, &AudioRegionView::remove_ghost)); @@ -1097,7 +1097,7 @@ void AudioRegionView::envelope_active_changed () { if (gain_line) { - gain_line->set_line_color (audio_region().envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]); + gain_line->set_line_color (audio_region()->envelope_active() ? color_map[cGainLine] : color_map[cGainLineInactive]); } } @@ -1105,11 +1105,11 @@ void AudioRegionView::set_waveview_data_src() { - double unit_length= _region.length() / samples_per_unit; + double unit_length= _region->length() / samples_per_unit; for (uint32_t n = 0; n < waves.size(); ++n) { // TODO: something else to let it know the channel - waves[n]->property_data_src() = &_region; + waves[n]->property_data_src() = _region.get(); } for (vector::iterator i = ghosts.begin(); i != ghosts.end(); ++i) { @@ -1117,7 +1117,7 @@ AudioRegionView::set_waveview_data_src() (*i)->set_duration (unit_length); for (vector::iterator w = (*i)->waves.begin(); w != (*i)->waves.end(); ++w) { - (*w)->property_data_src() = &_region; + (*w)->property_data_src() = _region.get(); } } diff --git a/gtk2_ardour/audio_region_view.h b/gtk2_ardour/audio_region_view.h index e9172dec97..21fd519606 100644 --- a/gtk2_ardour/audio_region_view.h +++ b/gtk2_ardour/audio_region_view.h @@ -51,7 +51,7 @@ class AudioRegionView : public RegionView public: AudioRegionView (ArdourCanvas::Group *, RouteTimeAxisView&, - ARDOUR::AudioRegion&, + boost::shared_ptr, double initial_samples_per_unit, Gdk::Color& basic_color); @@ -59,44 +59,44 @@ class AudioRegionView : public RegionView virtual void init (Gdk::Color& base_color, bool wait_for_data = false); - ARDOUR::AudioRegion& audio_region() const; - - void set_height (double); - void set_samples_per_unit (double); - - void set_amplitude_above_axis (gdouble spp); - - void temporarily_hide_envelope (); ///< Dangerous! - void unhide_envelope (); ///< Dangerous! - - void set_envelope_visible (bool); - void set_waveform_visible (bool yn); - void set_waveform_shape (WaveformShape); - - bool waveform_rectified() const { return _flags & WaveformRectified; } - bool waveform_visible() const { return _flags & WaveformVisible; } - bool envelope_visible() const { return _flags & EnvelopeVisible; } - - void show_region_editor (); - - void add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event); - void remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event); - - AudioRegionGainLine* get_gain_line() const { return gain_line; } - - void region_changed (ARDOUR::Change); - void envelope_active_changed (); - - GhostRegion* add_ghost (AutomationTimeAxisView&); - - void reset_fade_in_shape_width (jack_nframes_t); - void reset_fade_out_shape_width (jack_nframes_t); - void set_fade_in_active (bool); - void set_fade_out_active (bool); - - virtual void entered (); - virtual void exited (); - + boost::shared_ptr audio_region() const; + + void set_height (double); + void set_samples_per_unit (double); + + void set_amplitude_above_axis (gdouble spp); + + void temporarily_hide_envelope (); ///< Dangerous! + void unhide_envelope (); ///< Dangerous! + + void set_envelope_visible (bool); + void set_waveform_visible (bool yn); + void set_waveform_shape (WaveformShape); + + bool waveform_rectified() const { return _flags & WaveformRectified; } + bool waveform_visible() const { return _flags & WaveformVisible; } + bool envelope_visible() const { return _flags & EnvelopeVisible; } + + void show_region_editor (); + + void add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event); + void remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent *event); + + AudioRegionGainLine* get_gain_line() const { return gain_line; } + + void region_changed (ARDOUR::Change); + void envelope_active_changed (); + + GhostRegion* add_ghost (AutomationTimeAxisView&); + + void reset_fade_in_shape_width (jack_nframes_t); + void reset_fade_out_shape_width (jack_nframes_t); + void set_fade_in_active (bool); + void set_fade_out_active (bool); + + virtual void entered (); + virtual void exited (); + protected: /* this constructor allows derived types @@ -105,11 +105,11 @@ class AudioRegionView : public RegionView */ AudioRegionView (ArdourCanvas::Group *, - RouteTimeAxisView&, - ARDOUR::AudioRegion&, - double samples_per_unit, - Gdk::Color& basic_color, - TimeAxisViewItem::Visibility); + RouteTimeAxisView&, + boost::shared_ptr, + double samples_per_unit, + Gdk::Color& basic_color, + TimeAxisViewItem::Visibility); enum Flags { EnvelopeVisible = 0x1, diff --git a/gtk2_ardour/audio_streamview.cc b/gtk2_ardour/audio_streamview.cc index 83d1825ef5..2b9cd23567 100644 --- a/gtk2_ardour/audio_streamview.cc +++ b/gtk2_ardour/audio_streamview.cc @@ -25,11 +25,12 @@ #include #include -#include +#include #include #include #include #include +#include #include "audio_streamview.h" #include "audio_region_view.h" @@ -123,11 +124,11 @@ AudioStreamView::set_amplitude_above_axis (gdouble app) } void -AudioStreamView::add_region_view_internal (Region *r, bool wait_for_waves) +AudioStreamView::add_region_view_internal (boost::shared_ptr r, bool wait_for_waves) { ENSURE_GUI_THREAD (bind (mem_fun (*this, &AudioStreamView::add_region_view), r)); - AudioRegion* region = dynamic_cast (r); + boost::shared_ptr region = boost::dynamic_pointer_cast (r); if (region == 0) { return; @@ -137,7 +138,7 @@ AudioStreamView::add_region_view_internal (Region *r, bool wait_for_waves) list::iterator i; for (i = region_views.begin(); i != region_views.end(); ++i) { - if (&(*i)->region() == r) { + if ((*i)->region() == r) { /* great. we already have a AudioRegionView for this Region. use it again. */ @@ -148,11 +149,11 @@ AudioStreamView::add_region_view_internal (Region *r, bool wait_for_waves) switch (_trackview.audio_track()->mode()) { case Normal: - region_view = new AudioRegionView (canvas_group, _trackview, *region, + region_view = new AudioRegionView (canvas_group, _trackview, region, _samples_per_unit, region_color); break; case Destructive: - region_view = new TapeAudioRegionView (canvas_group, _trackview, *region, + region_view = new TapeAudioRegionView (canvas_group, _trackview, region, _samples_per_unit, region_color); break; } @@ -167,13 +168,13 @@ AudioStreamView::add_region_view_internal (Region *r, bool wait_for_waves) /* catch regionview going away */ - region->GoingAway.connect (mem_fun (*this, &AudioStreamView::remove_region_view)); + region->GoingAway.connect (bind (mem_fun (*this, &AudioStreamView::remove_region_view), region)); RegionViewAdded (region_view); } void -AudioStreamView::remove_region_view (Region *r) +AudioStreamView::remove_region_view (boost::shared_ptr r) { ENSURE_GUI_THREAD (bind (mem_fun (*this, &AudioStreamView::remove_region_view), r)); @@ -183,8 +184,8 @@ AudioStreamView::remove_region_view (Region *r) tmp = i; ++tmp; - AudioRegion* ar = dynamic_cast(r); - if (ar && (*i)->crossfade.involves (*ar)) { + boost::shared_ptr ar = boost::dynamic_pointer_cast(r); + if (ar && (*i)->crossfade.involves (ar)) { delete *i; crossfade_views.erase (i); } @@ -262,10 +263,10 @@ AudioStreamView::add_crossfade (Crossfade *crossfade) for (list::iterator i = region_views.begin(); i != region_views.end(); ++i) { AudioRegionView* arv = dynamic_cast(*i); - if (!lview && arv && &(arv->region()) == &crossfade->out()) { + if (!lview && arv && (arv->region() == crossfade->out())) { lview = arv; } - if (!rview && arv && &(arv->region()) == &crossfade->in()) { + if (!rview && arv && (arv->region() == crossfade->in())) { rview = arv; } } @@ -390,7 +391,7 @@ AudioStreamView::setup_rec_box () /* add a new region, but don't bother if they set use_rec_regions mid-record */ - AudioRegion::SourceList sources; + SourceList sources; for (list::iterator prc = rec_data_ready_connections.begin(); prc != rec_data_ready_connections.end(); ++prc) { (*prc).disconnect(); @@ -402,7 +403,7 @@ AudioStreamView::setup_rec_box () assert(ads); for (uint32_t n=0; n < ads->n_channels().get(DataType::AUDIO); ++n) { - AudioSource *src = (AudioSource *) ads->write_source (n); + boost::shared_ptr src = boost::static_pointer_cast (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), src))); @@ -416,11 +417,12 @@ AudioStreamView::setup_rec_box () start = rec_regions.back()->start() + _trackview.get_diskstream()->get_captured_frames(rec_regions.size()-1); } - AudioRegion * region = new AudioRegion(sources, start, 1 , "", 0, (Region::Flag)(Region::DefaultFlags | Region::DoNotSaveState), false); + boost::shared_ptr region (boost::dynamic_pointer_cast + (RegionFactory::create (sources, start, 1 , "", 0, (Region::Flag)(Region::DefaultFlags | Region::DoNotSaveState), false))); region->set_position (_trackview.session().transport_frame(), this); rec_regions.push_back (region); /* catch it if it goes away */ - region->GoingAway.connect (mem_fun (*this, &AudioStreamView::remove_rec_region)); + region->GoingAway.connect (bind (mem_fun (*this, &AudioStreamView::remove_rec_region), region)); /* we add the region later */ } @@ -501,23 +503,10 @@ AudioStreamView::setup_rec_box () last_rec_data_frame = 0; /* remove temp regions */ - for (list::iterator iter=rec_regions.begin(); iter != rec_regions.end(); ) - { - list::iterator tmp; - - tmp = iter; - ++tmp; - - /* this will trigger the remove_region_view */ - delete *iter; - - iter = tmp; - } rec_regions.clear(); // cerr << "\tclear " << rec_rects.size() << " rec rects\n"; - /* transport stopped, clear boxes */ for (vector::iterator iter=rec_rects.begin(); iter != rec_rects.end(); ++iter) { @@ -540,7 +529,7 @@ AudioStreamView::foreach_crossfadeview (void (CrossfadeView::*pmf)(void)) } void -AudioStreamView::rec_peak_range_ready (jack_nframes_t start, jack_nframes_t cnt, Source * src) +AudioStreamView::rec_peak_range_ready (jack_nframes_t start, jack_nframes_t cnt, boost::shared_ptr src) { // this is called from the peak building thread @@ -565,9 +554,9 @@ AudioStreamView::update_rec_regions () uint32_t n = 0; - for (list::iterator iter = rec_regions.begin(); iter != rec_regions.end(); n++) { + for (list >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); n++) { - list::iterator tmp; + list >::iterator tmp; tmp = iter; ++tmp; @@ -579,7 +568,7 @@ AudioStreamView::update_rec_regions () } // FIXME - AudioRegion * region = dynamic_cast(*iter); + boost::shared_ptr region = boost::dynamic_pointer_cast(*iter); assert(region); jack_nframes_t origlen = region->length(); @@ -615,7 +604,7 @@ AudioStreamView::update_rec_regions () if (nlen != region->length()) { - if (region->source(0).length() >= region->start() + nlen) { + if (region->source(0)->length() >= region->start() + nlen) { region->freeze (); region->set_position (_trackview.get_diskstream()->get_capture_start_frame(n), this); diff --git a/gtk2_ardour/audio_streamview.h b/gtk2_ardour/audio_streamview.h index cf66637b9b..242b97f840 100644 --- a/gtk2_ardour/audio_streamview.h +++ b/gtk2_ardour/audio_streamview.h @@ -76,13 +76,13 @@ class AudioStreamView : public StreamView private: void setup_rec_box (); - void rec_peak_range_ready (jack_nframes_t start, jack_nframes_t cnt, ARDOUR::Source* src); + void rec_peak_range_ready (jack_nframes_t start, jack_nframes_t cnt, boost::shared_ptr src); void update_rec_regions (); - void add_region_view_internal (ARDOUR::Region*, bool wait_for_waves); - void remove_region_view (ARDOUR::Region* ); - void remove_audio_region_view (ARDOUR::AudioRegion* ); - void remove_audio_rec_region (ARDOUR::AudioRegion*); + void add_region_view_internal (boost::shared_ptr, bool wait_for_waves); + void remove_region_view (boost::shared_ptr ); + void remove_audio_region_view (boost::shared_ptr ); + void remove_audio_rec_region (boost::shared_ptr); void undisplay_diskstream (); void redisplay_diskstream (); diff --git a/gtk2_ardour/automation_line.h b/gtk2_ardour/automation_line.h index ec86b7455f..f8262d2a2d 100644 --- a/gtk2_ardour/automation_line.h +++ b/gtk2_ardour/automation_line.h @@ -30,7 +30,9 @@ #include #include "canvas.h" #include "simplerect.h" + #include +#include #include @@ -94,7 +96,7 @@ class ControlPoint ShapeType _shape; }; -class AutomationLine : public sigc::trackable, public Stateful +class AutomationLine : public sigc::trackable, public PBD::StatefulDestructible { public: AutomationLine (const string & name, TimeAxisView&, ArdourCanvas::Group&, ARDOUR::AutomationList&); diff --git a/gtk2_ardour/crossfade_edit.cc b/gtk2_ardour/crossfade_edit.cc index c56f51fcfa..888eecdba2 100644 --- a/gtk2_ardour/crossfade_edit.cc +++ b/gtk2_ardour/crossfade_edit.cc @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -590,7 +591,7 @@ CrossfadeEditor::canvas_allocation (Gtk::Allocation& alloc) vector::iterator i; uint32_t n; - ht = canvas->get_allocation().get_height() / xfade.in().n_channels(); + ht = canvas->get_allocation().get_height() / xfade.in()->n_channels(); for (n = 0, i = fade[In].waves.begin(); i != fade[In].waves.end(); ++i, ++n) { double yoff; @@ -602,7 +603,7 @@ CrossfadeEditor::canvas_allocation (Gtk::Allocation& alloc) (*i)->property_samples_per_unit() = spu; } - ht = canvas->get_allocation().get_height() / xfade.out().n_channels(); + ht = canvas->get_allocation().get_height() / xfade.out()->n_channels(); for (n = 0, i = fade[Out].waves.begin(); i != fade[Out].waves.end(); ++i, ++n) { double yoff; @@ -1015,10 +1016,10 @@ CrossfadeEditor::y_coordinate (double& yfract) const } void -CrossfadeEditor::make_waves (AudioRegion& region, WhichFade which) +CrossfadeEditor::make_waves (boost::shared_ptr region, WhichFade which) { gdouble ht; - uint32_t nchans = region.n_channels(); + uint32_t nchans = region->n_channels(); guint32 color; double spu; @@ -1035,11 +1036,10 @@ CrossfadeEditor::make_waves (AudioRegion& region, WhichFade which) gdouble yoff = n * ht; - if (region.audio_source(n).peaks_ready (bind (mem_fun(*this, &CrossfadeEditor::peaks_ready), ®ion, which), peaks_ready_connection)) { - + if (region->audio_source(n)->peaks_ready (bind (mem_fun(*this, &CrossfadeEditor::peaks_ready), region, which), peaks_ready_connection)) { WaveView* waveview = new WaveView (*(canvas->root())); - waveview->property_data_src() = ®ion; + waveview->property_data_src() = region.get(); waveview->property_cache_updater() = true; waveview->property_cache() = WaveView::create_cache(); waveview->property_channel() = n; @@ -1064,14 +1064,14 @@ CrossfadeEditor::make_waves (AudioRegion& region, WhichFade which) } void -CrossfadeEditor::peaks_ready (AudioRegion* r, WhichFade which) +CrossfadeEditor::peaks_ready (boost::shared_ptr r, WhichFade which) { /* this should never be called, because the peak files for an xfade will be ready by the time we want them. but our API forces us to provide this, so .. */ peaks_ready_connection.disconnect (); - make_waves (*r, which); + make_waves (r, which); } void @@ -1097,29 +1097,29 @@ CrossfadeEditor::audition_both () postroll = 0; } - if ((left_start_offset = xfade.out().length() - xfade.length()) >= preroll) { + if ((left_start_offset = xfade.out()->length() - xfade.length()) >= preroll) { left_start_offset -= preroll; } length = 0; - if ((left_length = xfade.length()) < xfade.out().length() - left_start_offset) { + if ((left_length = xfade.length()) < xfade.out()->length() - left_start_offset) { length += postroll; } right_length = xfade.length(); - if (xfade.in().length() - right_length < postroll) { + if (xfade.in()->length() - right_length < postroll) { right_length += postroll; } - AudioRegion* left = new AudioRegion (xfade.out(), left_start_offset, left_length, "xfade out", - 0, Region::DefaultFlags, false); - AudioRegion* right = new AudioRegion (xfade.in(), 0, right_length, "xfade in", - 0, Region::DefaultFlags, false); + boost::shared_ptr left (boost::dynamic_pointer_cast (RegionFactory::create (xfade.out(), left_start_offset, left_length, "xfade out", + 0, Region::DefaultFlags, false))); + boost::shared_ptr right (boost::dynamic_pointer_cast (RegionFactory::create (xfade.in(), 0, right_length, "xfade in", + 0, Region::DefaultFlags, false))); - pl.add_region (*left, 0); - pl.add_region (*right, 1+preroll); + pl.add_region (left, 0); + pl.add_region (right, 1+preroll); /* there is only one ... */ @@ -1131,10 +1131,10 @@ CrossfadeEditor::audition_both () void CrossfadeEditor::audition_left_dry () { - AudioRegion* left = new AudioRegion (xfade.out(), xfade.out().length() - xfade.length(), xfade.length(), "xfade left", - 0, Region::DefaultFlags, false); + boost::shared_ptr left (boost::dynamic_pointer_cast (RegionFactory::create (xfade.out(), xfade.out()->length() - xfade.length(), xfade.length(), "xfade left", + 0, Region::DefaultFlags, false))); - session.audition_region (*left); + session.audition_region (left); } void @@ -1142,13 +1142,13 @@ CrossfadeEditor::audition_left () { AudioPlaylist& pl (session.the_auditioner()->prepare_playlist()); - AudioRegion* left = new AudioRegion (xfade.out(), xfade.out().length() - xfade.length(), xfade.length(), "xfade left", - 0, Region::DefaultFlags, false); - AudioRegion* right = new AudioRegion (xfade.in(), 0, xfade.length(), "xfade in", - 0, Region::DefaultFlags, false); + boost::shared_ptr left (boost::dynamic_pointer_cast (RegionFactory::create (xfade.out(), xfade.out()->length() - xfade.length(), xfade.length(), "xfade left", + 0, Region::DefaultFlags, false))); + boost::shared_ptr right (boost::dynamic_pointer_cast (RegionFactory::create (xfade.in(), 0, xfade.length(), "xfade in", + 0, Region::DefaultFlags, false))); - pl.add_region (*left, 0); - pl.add_region (*right, 1); + pl.add_region (left, 0); + pl.add_region (right, 1); right->set_muted (true); @@ -1164,9 +1164,9 @@ CrossfadeEditor::audition_left () void CrossfadeEditor::audition_right_dry () { - AudioRegion* right = new AudioRegion (xfade.in(), 0, xfade.length(), "xfade in", - 0, Region::DefaultFlags, false); - session.audition_region (*right); + boost::shared_ptr right (boost::dynamic_pointer_cast (RegionFactory::create (xfade.in(), 0, xfade.length(), "xfade in", + 0, Region::DefaultFlags, false))); + session.audition_region (right); } void @@ -1174,13 +1174,13 @@ CrossfadeEditor::audition_right () { AudioPlaylist& pl (session.the_auditioner()->prepare_playlist()); - AudioRegion* left = new AudioRegion (xfade.out(), xfade.out().length() - xfade.length(), xfade.length(), "xfade out", - 0, Region::DefaultFlags, false); - AudioRegion* right = new AudioRegion (xfade.out(), 0, xfade.length(), "xfade out", - 0, Region::DefaultFlags, false); + boost::shared_ptr left (boost::dynamic_pointer_cast (RegionFactory::create (xfade.out(), xfade.out()->length() - xfade.length(), xfade.length(), "xfade out", + 0, Region::DefaultFlags, false))); + boost::shared_ptr right (boost::dynamic_pointer_cast (RegionFactory::create (xfade.out(), 0, xfade.length(), "xfade out", + 0, Region::DefaultFlags, false))); - pl.add_region (*left, 0); - pl.add_region (*right, 1); + pl.add_region (left, 0); + pl.add_region (right, 1); left->set_muted (true); diff --git a/gtk2_ardour/crossfade_edit.h b/gtk2_ardour/crossfade_edit.h index b156ee69fe..ad0661c036 100644 --- a/gtk2_ardour/crossfade_edit.h +++ b/gtk2_ardour/crossfade_edit.h @@ -162,8 +162,8 @@ class CrossfadeEditor : public ArdourDialog sigc::connection peaks_ready_connection; - void make_waves (ARDOUR::AudioRegion&, WhichFade); - void peaks_ready (ARDOUR::AudioRegion* r, WhichFade); + void make_waves (boost::shared_ptr, WhichFade); + void peaks_ready (boost::shared_ptr r, WhichFade); void _apply_to (ARDOUR::Crossfade* xf); void setup (ARDOUR::Crossfade*); diff --git a/gtk2_ardour/crossfade_view.cc b/gtk2_ardour/crossfade_view.cc index 087af25e73..49fe40ca63 100644 --- a/gtk2_ardour/crossfade_view.cc +++ b/gtk2_ardour/crossfade_view.cc @@ -227,7 +227,7 @@ CrossfadeView::set_valid (bool yn) AudioRegionView& CrossfadeView::upper_regionview () const { - if (left_view.region().layer() > right_view.region().layer()) { + if (left_view.region()->layer() > right_view.region()->layer()) { return left_view; } else { return right_view; diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index eceaf24d38..da248c828c 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -246,7 +246,6 @@ Editor::Editor (AudioEngine& eng) latest_regionview = 0; last_update_frame = 0; drag_info.item = 0; - last_audition_region = 0; current_mixer_strip = 0; current_bbt_points = 0; @@ -1169,7 +1168,7 @@ Editor::connect_to_session (Session *t) update_title (); - session->going_away.connect (mem_fun(*this, &Editor::session_going_away)); + session->GoingAway.connect (mem_fun(*this, &Editor::session_going_away)); /* These signals can all be emitted by a non-GUI thread. Therefore the handlers for them must not attempt to directly interact with the GUI, @@ -1399,13 +1398,14 @@ Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* i } MenuList& items (fade_context_menu.items()); + AudioRegion& ar (*arv->audio_region().get()); // FIXME items.clear (); switch (item_type) { case FadeInItem: case FadeInHandleItem: - if (arv->audio_region().fade_in_active()) { + if (arv->audio_region()->fade_in_active()) { items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*arv, &AudioRegionView::set_fade_in_active), false))); } else { items.push_back (MenuElem (_("Activate"), bind (mem_fun (*arv, &AudioRegionView::set_fade_in_active), true))); @@ -1413,16 +1413,16 @@ Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* i items.push_back (SeparatorElem()); - items.push_back (MenuElem (_("Linear"), bind (mem_fun (arv->audio_region(), &AudioRegion::set_fade_in_shape), AudioRegion::Linear))); - items.push_back (MenuElem (_("Slowest"), bind (mem_fun (arv->audio_region(), &AudioRegion::set_fade_in_shape), AudioRegion::LogB))); - items.push_back (MenuElem (_("Slow"), bind (mem_fun (arv->audio_region(), &AudioRegion::set_fade_in_shape), AudioRegion::Fast))); - items.push_back (MenuElem (_("Fast"), bind (mem_fun (arv->audio_region(), &AudioRegion::set_fade_in_shape), AudioRegion::LogA))); - items.push_back (MenuElem (_("Fastest"), bind (mem_fun (arv->audio_region(), &AudioRegion::set_fade_in_shape), AudioRegion::Slow))); + items.push_back (MenuElem (_("Linear"), bind (mem_fun (ar, &AudioRegion::set_fade_in_shape), AudioRegion::Linear))); + items.push_back (MenuElem (_("Slowest"), bind (mem_fun (ar, &AudioRegion::set_fade_in_shape), AudioRegion::LogB))); + items.push_back (MenuElem (_("Slow"), bind (mem_fun (ar, &AudioRegion::set_fade_in_shape), AudioRegion::Fast))); + items.push_back (MenuElem (_("Fast"), bind (mem_fun (ar, &AudioRegion::set_fade_in_shape), AudioRegion::LogA))); + items.push_back (MenuElem (_("Fastest"), bind (mem_fun (ar, &AudioRegion::set_fade_in_shape), AudioRegion::Slow))); break; case FadeOutItem: case FadeOutHandleItem: - if (arv->audio_region().fade_out_active()) { + if (arv->audio_region()->fade_out_active()) { items.push_back (MenuElem (_("Deactivate"), bind (mem_fun (*arv, &AudioRegionView::set_fade_out_active), false))); } else { items.push_back (MenuElem (_("Activate"), bind (mem_fun (*arv, &AudioRegionView::set_fade_out_active), true))); @@ -1430,11 +1430,11 @@ Editor::popup_fade_context_menu (int button, int32_t time, ArdourCanvas::Item* i items.push_back (SeparatorElem()); - items.push_back (MenuElem (_("Linear"), bind (mem_fun (arv->audio_region(), &AudioRegion::set_fade_out_shape), AudioRegion::Linear))); - items.push_back (MenuElem (_("Slowest"), bind (mem_fun (arv->audio_region(), &AudioRegion::set_fade_out_shape), AudioRegion::Fast))); - items.push_back (MenuElem (_("Slow"), bind (mem_fun (arv->audio_region(), &AudioRegion::set_fade_out_shape), AudioRegion::LogB))); - items.push_back (MenuElem (_("Fast"), bind (mem_fun (arv->audio_region(), &AudioRegion::set_fade_out_shape), AudioRegion::LogA))); - items.push_back (MenuElem (_("Fastest"), bind (mem_fun (arv->audio_region(), &AudioRegion::set_fade_out_shape), AudioRegion::Slow))); + items.push_back (MenuElem (_("Linear"), bind (mem_fun (ar, &AudioRegion::set_fade_out_shape), AudioRegion::Linear))); + items.push_back (MenuElem (_("Slowest"), bind (mem_fun (ar, &AudioRegion::set_fade_out_shape), AudioRegion::Fast))); + items.push_back (MenuElem (_("Slow"), bind (mem_fun (ar, &AudioRegion::set_fade_out_shape), AudioRegion::LogB))); + items.push_back (MenuElem (_("Fast"), bind (mem_fun (ar, &AudioRegion::set_fade_out_shape), AudioRegion::LogA))); + items.push_back (MenuElem (_("Fastest"), bind (mem_fun (ar, &AudioRegion::set_fade_out_shape), AudioRegion::Slow))); break; default: @@ -1501,7 +1501,7 @@ Editor::popup_track_context_menu (int button, int32_t time, ItemType item_type, case RegionViewNameHighlight: if (!with_selection) { if (region_edit_menu_split_item) { - if (clicked_regionview && clicked_regionview->region().covers (edit_cursor->current_frame)) { + if (clicked_regionview && clicked_regionview->region()->covers (edit_cursor->current_frame)) { ActionManager::set_sensitive (ActionManager::edit_cursor_in_region_sensitive_actions, true); } else { ActionManager::set_sensitive (ActionManager::edit_cursor_in_region_sensitive_actions, false); @@ -1736,9 +1736,9 @@ Editor::add_crossfade_context_items (AudioStreamView* view, Crossfade* xfade, Me } if (many) { - str = xfade->out().name(); + str = xfade->out()->name(); str += "->"; - str += xfade->in().name(); + str += xfade->in()->name(); } else { str = _("Crossfade"); } @@ -1764,17 +1764,17 @@ Editor::xfade_edit_right_region () } void -Editor::add_region_context_items (AudioStreamView* sv, Region* region, Menu_Helpers::MenuList& edit_items) +Editor::add_region_context_items (AudioStreamView* sv, boost::shared_ptr region, Menu_Helpers::MenuList& edit_items) { using namespace Menu_Helpers; Menu *region_menu = manage (new Menu); MenuList& items = region_menu->items(); region_menu->set_name ("ArdourContextMenu"); - AudioRegion* ar = 0; + boost::shared_ptr ar; if (region) { - ar = dynamic_cast (region); + ar = boost::dynamic_pointer_cast (region); } /* when this particular menu pops up, make the relevant region @@ -3015,10 +3015,10 @@ Editor::mapover_tracks (slot sl) void Editor::mapped_set_selected_regionview_from_click (RouteTimeAxisView& tv, uint32_t ignored, - RegionView* basis, vector* all_equivs) + RegionView* basis, vector* all_equivs) { Playlist* pl; - vector results; + vector > results; RegionView* marv; boost::shared_ptr ds; @@ -3037,8 +3037,8 @@ Editor::mapped_set_selected_regionview_from_click (RouteTimeAxisView& tv, uint32 pl->get_equivalent_regions (basis->region(), results); } - for (vector::iterator ir = results.begin(); ir != results.end(); ++ir) { - if ((marv = tv.view()->find_view (**ir)) != 0) { + for (vector >::iterator ir = results.begin(); ir != results.end(); ++ir) { + if ((marv = tv.view()->find_view (*ir)) != 0) { all_equivs->push_back (marv); } } @@ -3138,55 +3138,55 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, for (RegionSelection::iterator x = selection->regions.begin(); x != selection->regions.end(); ++x) { if (&(*x)->get_time_axis_view() == &clicked_regionview->get_time_axis_view()) { - if ((*x)->region().last_frame() > last_frame) { - last_frame = (*x)->region().last_frame(); + if ((*x)->region()->last_frame() > last_frame) { + last_frame = (*x)->region()->last_frame(); } - if ((*x)->region().first_frame() < first_frame) { - first_frame = (*x)->region().first_frame(); + if ((*x)->region()->first_frame() < first_frame) { + first_frame = (*x)->region()->first_frame(); } } } /* 2. figure out the boundaries for our search for new objects */ - switch (clicked_regionview->region().coverage (first_frame, last_frame)) { + switch (clicked_regionview->region()->coverage (first_frame, last_frame)) { case OverlapNone: cerr << "no overlap, first = " << first_frame << " last = " << last_frame << " region = " - << clicked_regionview->region().first_frame() << " .. " << clicked_regionview->region().last_frame() << endl; + << clicked_regionview->region()->first_frame() << " .. " << clicked_regionview->region()->last_frame() << endl; - if (last_frame < clicked_regionview->region().first_frame()) { + if (last_frame < clicked_regionview->region()->first_frame()) { first_frame = last_frame; - last_frame = clicked_regionview->region().last_frame(); + last_frame = clicked_regionview->region()->last_frame(); } else { last_frame = first_frame; - first_frame = clicked_regionview->region().first_frame(); + first_frame = clicked_regionview->region()->first_frame(); } break; case OverlapExternal: cerr << "external overlap, first = " << first_frame << " last = " << last_frame << " region = " - << clicked_regionview->region().first_frame() << " .. " << clicked_regionview->region().last_frame() << endl; + << clicked_regionview->region()->first_frame() << " .. " << clicked_regionview->region()->last_frame() << endl; - if (last_frame < clicked_regionview->region().first_frame()) { + if (last_frame < clicked_regionview->region()->first_frame()) { first_frame = last_frame; - last_frame = clicked_regionview->region().last_frame(); + last_frame = clicked_regionview->region()->last_frame(); } else { last_frame = first_frame; - first_frame = clicked_regionview->region().first_frame(); + first_frame = clicked_regionview->region()->first_frame(); } break; case OverlapInternal: cerr << "internal overlap, first = " << first_frame << " last = " << last_frame << " region = " - << clicked_regionview->region().first_frame() << " .. " << clicked_regionview->region().last_frame() << endl; + << clicked_regionview->region()->first_frame() << " .. " << clicked_regionview->region()->last_frame() << endl; - if (last_frame < clicked_regionview->region().first_frame()) { + if (last_frame < clicked_regionview->region()->first_frame()) { first_frame = last_frame; - last_frame = clicked_regionview->region().last_frame(); + last_frame = clicked_regionview->region()->last_frame(); } else { last_frame = first_frame; - first_frame = clicked_regionview->region().first_frame(); + first_frame = clicked_regionview->region()->first_frame(); } break; @@ -3233,7 +3233,7 @@ Editor::set_selected_regionview_from_click (bool press, Selection::Operation op, } void -Editor::set_selected_regionview_from_region_list (Region& region, Selection::Operation op) +Editor::set_selected_regionview_from_region_list (boost::shared_ptr region, Selection::Operation op) { vector all_equivalent_regions; @@ -3244,7 +3244,7 @@ Editor::set_selected_regionview_from_region_list (Region& region, Selection::Ope if ((tatv = dynamic_cast (*i)) != 0) { Playlist* pl; - vector results; + vector > results; RegionView* marv; boost::shared_ptr ds; @@ -3257,8 +3257,8 @@ Editor::set_selected_regionview_from_region_list (Region& region, Selection::Ope pl->get_region_list_equivalent_regions (region, results); } - for (vector::iterator ir = results.begin(); ir != results.end(); ++ir) { - if ((marv = tatv->view()->find_view (**ir)) != 0) { + for (vector >::iterator ir = results.begin(); ir != results.end(); ++ir) { + if ((marv = tatv->view()->find_view (*ir)) != 0) { all_equivalent_regions.push_back (marv); } } @@ -3285,17 +3285,17 @@ Editor::set_selected_regionview_from_region_list (Region& region, Selection::Ope } bool -Editor::set_selected_regionview_from_map_event (GdkEventAny* ev, StreamView* sv, Region* r) +Editor::set_selected_regionview_from_map_event (GdkEventAny* ev, StreamView* sv, boost::shared_ptr r) { RegionView* rv; - Region* ar; + boost::shared_ptr ar; - if ((ar = dynamic_cast (r)) == 0) { - return TRUE; + if ((ar = boost::dynamic_pointer_cast (r)) == 0) { + return true; } - if ((rv = sv->find_view (*ar)) == 0) { - return TRUE; + if ((rv = sv->find_view (ar)) == 0) { + return true; } /* don't reset the selection if its something other than @@ -3303,7 +3303,7 @@ Editor::set_selected_regionview_from_map_event (GdkEventAny* ev, StreamView* sv, */ if (selection->regions.size() > 1) { - return TRUE; + return true; } begin_reversible_command (_("set selected regions")); @@ -3312,7 +3312,7 @@ Editor::set_selected_regionview_from_map_event (GdkEventAny* ev, StreamView* sv, commit_reversible_command () ; - return TRUE; + return true; } void @@ -3962,7 +3962,7 @@ bool Editor::audio_region_selection_covers (jack_nframes_t where) { for (RegionSelection::iterator a = selection->regions.begin(); a != selection->regions.end(); ++a) { - if ((*a)->region().covers (where)) { + if ((*a)->region()->covers (where)) { return true; } } diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 970acdc3a9..34b3462228 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -155,9 +155,9 @@ class Editor : public PublicEditor void scroll_timeaxis_to_imageframe_item(const TimeAxisViewItem* item) ; TimeAxisView* get_named_time_axis(const string & name) ; - void consider_auditioning (ARDOUR::Region&); - void hide_a_region (ARDOUR::Region&); - void remove_a_region (ARDOUR::Region&); + void consider_auditioning (boost::shared_ptr); + void hide_a_region (boost::shared_ptr); + void remove_a_region (boost::shared_ptr); /* option editor-access */ @@ -439,8 +439,8 @@ class Editor : public PublicEditor bool set_selected_track_from_click (bool press, Selection::Operation op = Selection::Set, bool with_undo = true, bool no_remove=false); bool set_selected_regionview_from_click (bool press, Selection::Operation op = Selection::Set, bool no_track_remove=false); - void set_selected_regionview_from_region_list (ARDOUR::Region& region, Selection::Operation op = Selection::Set); - bool set_selected_regionview_from_map_event (GdkEventAny*, StreamView*, ARDOUR::Region*); + void set_selected_regionview_from_region_list (boost::shared_ptr region, Selection::Operation op = Selection::Set); + bool set_selected_regionview_from_map_event (GdkEventAny*, StreamView*, boost::shared_ptr); void collect_new_region_view (RegionView *); Gtk::Menu track_context_menu; @@ -462,7 +462,7 @@ class Editor : public PublicEditor Gtk::Menu* build_track_selection_context_menu (jack_nframes_t); void add_dstream_context_items (Gtk::Menu_Helpers::MenuList&); void add_bus_context_items (Gtk::Menu_Helpers::MenuList&); - void add_region_context_items (AudioStreamView*, ARDOUR::Region*, Gtk::Menu_Helpers::MenuList&); + void add_region_context_items (AudioStreamView*, boost::shared_ptr, Gtk::Menu_Helpers::MenuList&); void add_crossfade_context_items (AudioStreamView*, ARDOUR::Crossfade*, Gtk::Menu_Helpers::MenuList&, bool many); void add_selection_context_items (Gtk::Menu_Helpers::MenuList&); @@ -630,7 +630,7 @@ class Editor : public PublicEditor void select_all_selectables_using_cursor (Cursor *, bool); void select_all_selectables_between_cursors (Cursor *, Cursor *); - ARDOUR::Region* find_next_region (jack_nframes_t, ARDOUR::RegionPoint, int32_t dir, TrackViewList&, TimeAxisView ** = 0); + boost::shared_ptr find_next_region (jack_nframes_t, ARDOUR::RegionPoint, int32_t dir, TrackViewList&, TimeAxisView ** = 0); vector region_boundary_cache; void build_region_boundary_cache (); @@ -698,7 +698,7 @@ class Editor : public PublicEditor add (color_); } Gtk::TreeModelColumn name; - Gtk::TreeModelColumn region; + Gtk::TreeModelColumn > region; Gtk::TreeModelColumn color_; }; @@ -720,7 +720,7 @@ class Editor : public PublicEditor bool region_list_display_button_press (GdkEventButton *); bool region_list_display_button_release (GdkEventButton *); void region_list_clear (); - void region_list_selection_mapover (sigc::slot); + void region_list_selection_mapover (sigc::slot >); void build_region_list_menu (); void show_region_list_display_context_menu (int button, int time); @@ -832,14 +832,14 @@ class Editor : public PublicEditor int ensure_cursor (jack_nframes_t* pos); - void handle_new_region (ARDOUR::Region *); - void handle_region_removed (ARDOUR::Region *); - void add_region_to_region_display (ARDOUR::Region *); - void region_hidden (ARDOUR::Region*); + void handle_new_region (boost::shared_ptr); + void handle_region_removed (boost::shared_ptr); + void add_region_to_region_display (boost::shared_ptr); + void region_hidden (boost::shared_ptr); void redisplay_regions (); - void insert_into_tmp_regionlist(ARDOUR::Region *); + void insert_into_tmp_regionlist(boost::shared_ptr); - list tmp_region_list; + list > tmp_region_list; void cut_copy (Editing::CutCopyOp); void cut_copy_points (Editing::CutCopyOp); @@ -862,13 +862,13 @@ class Editor : public PublicEditor void split_region_at (jack_nframes_t); void split_regions_at (jack_nframes_t, RegionSelection&); void crop_region_to_selection (); - void set_a_regions_sync_position (ARDOUR::Region&, jack_nframes_t); + void set_a_regions_sync_position (boost::shared_ptr, jack_nframes_t); void set_region_sync_from_edit_cursor (); void remove_region_sync(); void align_selection (ARDOUR::RegionPoint, jack_nframes_t position); void align_selection_relative (ARDOUR::RegionPoint point, jack_nframes_t position); - void align_region (ARDOUR::Region&, ARDOUR::RegionPoint point, jack_nframes_t position); - void align_region_internal (ARDOUR::Region&, ARDOUR::RegionPoint point, jack_nframes_t position); + void align_region (boost::shared_ptr, ARDOUR::RegionPoint point, jack_nframes_t position); + void align_region_internal (boost::shared_ptr, ARDOUR::RegionPoint point, jack_nframes_t position); void remove_some_regions (); void remove_clicked_region (); void destroy_clicked_region (); @@ -878,8 +878,8 @@ class Editor : public PublicEditor void region_fill_selection (); void region_fill_track (); - void audition_playlist_region_standalone (ARDOUR::Region&); - void audition_playlist_region_via_route (ARDOUR::Region&, ARDOUR::Route&); + void audition_playlist_region_standalone (boost::shared_ptr); + void audition_playlist_region_via_route (boost::shared_ptr, ARDOUR::Route&); void split_multichannel_region(); void reverse_region (); void normalize_region (); @@ -906,7 +906,7 @@ class Editor : public PublicEditor void keyboard_insert_region_list_selection (); void region_from_selection (); - void create_region_from_selection (std::vector&); + void create_region_from_selection (std::vector >&); bool region_renamed; void rename_region (); @@ -932,7 +932,7 @@ class Editor : public PublicEditor void amplitude_zoom (gdouble scale); void amplitude_zoom_step (bool in); - void insert_region_list_drag (ARDOUR::AudioRegion&, int x, int y); + void insert_region_list_drag (boost::shared_ptr, int x, int y); void insert_region_list_selection (float times); void add_external_audio_action (Editing::ImportMode); @@ -943,7 +943,7 @@ class Editor : public PublicEditor int import_sndfile (Glib::ustring path, Editing::ImportMode mode, ARDOUR::AudioTrack* track, jack_nframes_t& pos); int embed_sndfile (Glib::ustring path, bool split, bool multiple_files, bool& check_sample_rate, Editing::ImportMode mode, ARDOUR::AudioTrack* track, jack_nframes_t& pos, bool prompt); - int finish_bringing_in_audio (ARDOUR::AudioRegion& region, uint32_t, uint32_t, ARDOUR::AudioTrack* track, jack_nframes_t& pos, Editing::ImportMode mode); + int finish_bringing_in_audio (boost::shared_ptr region, uint32_t, uint32_t, ARDOUR::AudioTrack* track, jack_nframes_t& pos, Editing::ImportMode mode); /* generic interthread progress window */ @@ -1026,7 +1026,7 @@ class Editor : public PublicEditor bool have_pending_keyboard_selection; jack_nframes_t pending_keyboard_selection_start; - ARDOUR::Region* select_region_for_operation (int dir, TimeAxisView **tv); + boost::shared_ptr select_region_for_operation (int dir, TimeAxisView **tv); void extend_selection_to_end_of_region (bool next); void extend_selection_to_start_of_region (bool previous); @@ -1585,7 +1585,7 @@ class Editor : public PublicEditor void export_range_markers (); int write_region_selection(RegionSelection&); - bool write_region (string path, ARDOUR::AudioRegion&); + bool write_region (string path, boost::shared_ptr); void export_region (); void bounce_region_selection (); void bounce_range_selection (); @@ -1629,7 +1629,7 @@ class Editor : public PublicEditor void instant_save (); - ARDOUR::AudioRegion* last_audition_region; + boost::shared_ptr last_audition_region; /* freeze operations */ diff --git a/gtk2_ardour/editor_audio_import.cc b/gtk2_ardour/editor_audio_import.cc index 2b704e7372..8efdca2dd4 100644 --- a/gtk2_ardour/editor_audio_import.cc +++ b/gtk2_ardour/editor_audio_import.cc @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include "ardour_ui.h" @@ -176,9 +178,8 @@ Editor::import_sndfile (Glib::ustring path, ImportMode mode, AudioTrack* track, /* import thread finished - see if we should build a new track */ if (!import_status.new_regions.empty()) { - AudioRegion* const aregion = dynamic_cast(import_status.new_regions.front()); - assert(aregion); - finish_bringing_in_audio (*aregion, aregion->n_channels(), aregion->n_channels(), track, pos, mode); + boost::shared_ptr region = boost::dynamic_pointer_cast(import_status.new_regions.front()); + finish_bringing_in_audio (region, region->n_channels(), region->n_channels(), track, pos, mode); } track_canvas.get_window()->set_cursor (*current_canvas_cursor); @@ -189,9 +190,9 @@ int Editor::embed_sndfile (Glib::ustring path, bool split, bool multiple_files, bool& check_sample_rate, ImportMode mode, AudioTrack* track, jack_nframes_t& pos, bool prompt) { - AudioFileSource *source = 0; /* keep g++ quiet */ - AudioRegion::SourceList sources; - AudioRegion* region; + boost::shared_ptr source; + SourceList sources; + boost::shared_ptr region; string idspec; string linked_path; SoundFileInfo finfo; @@ -269,7 +270,7 @@ Editor::embed_sndfile (Glib::ustring path, bool split, bool multiple_files, bool idspec += string_compose(":%1", n); try { - source = AudioFileSource::create (idspec.c_str(), (mode == ImportAsTrack ? AudioFileSource::Destructive : AudioFileSource::Flag (0))); + source = boost::dynamic_pointer_cast (SourceFactory::createReadable (DataType::AUDIO, idspec, (mode == ImportAsTrack ? AudioFileSource::Destructive : AudioFileSource::Flag (0)))); sources.push_back(source); } @@ -288,18 +289,18 @@ Editor::embed_sndfile (Glib::ustring path, bool split, bool multiple_files, bool region_name = PBD::basename_nosuffix (path); region_name += "-0"; - region = new AudioRegion (sources, 0, sources[0]->length(), region_name, 0, - Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External)); + region = boost::dynamic_pointer_cast (RegionFactory::create (sources, 0, sources[0]->length(), region_name, 0, + Region::Flag (Region::DefaultFlags|Region::WholeFile|Region::External))); input_chan = finfo.channels; - + if (session->get_output_auto_connect() & Session::AutoConnectMaster) { output_chan = (session->master_out() ? session->master_out()->n_inputs().get(DataType::AUDIO) : input_chan); } else { output_chan = input_chan; } - finish_bringing_in_audio (*region, input_chan, output_chan, track, pos, mode); + finish_bringing_in_audio (region, input_chan, output_chan, track, pos, mode); out: track_canvas.get_window()->set_cursor (*current_canvas_cursor); @@ -307,10 +308,8 @@ Editor::embed_sndfile (Glib::ustring path, bool split, bool multiple_files, bool } int -Editor::finish_bringing_in_audio (AudioRegion& region, uint32_t in_chans, uint32_t out_chans, AudioTrack* track, jack_nframes_t& pos, ImportMode mode) +Editor::finish_bringing_in_audio (boost::shared_ptr region, uint32_t in_chans, uint32_t out_chans, AudioTrack* track, jack_nframes_t& pos, ImportMode mode) { - AudioRegion* copy; - switch (mode) { case ImportAsRegion: /* relax, its been done */ @@ -320,14 +319,14 @@ Editor::finish_bringing_in_audio (AudioRegion& region, uint32_t in_chans, uint32 if (track) { Playlist* playlist = track->diskstream()->playlist(); - AudioRegion* copy = new AudioRegion (region); + boost::shared_ptr copy (boost::dynamic_pointer_cast (RegionFactory::create (region))); begin_reversible_command (_("insert sndfile")); XMLNode &before = playlist->get_state(); - playlist->add_region (*copy, pos); + playlist->add_region (copy, pos); session->add_command (new MementoCommand(*playlist, &before, &playlist->get_state())); commit_reversible_command (); - pos += region.length(); + pos += region->length(); } break; @@ -335,8 +334,8 @@ Editor::finish_bringing_in_audio (AudioRegion& region, uint32_t in_chans, uint32 { list > at (session->new_audio_track (in_chans, out_chans, Normal, 1)); if (!at.empty()) { - copy = new AudioRegion (region); - at.front()->diskstream()->playlist()->add_region (*copy, pos); + boost::shared_ptr copy (boost::dynamic_pointer_cast (RegionFactory::create (region))); + at.front()->diskstream()->playlist()->add_region (copy, pos); } break; } @@ -345,8 +344,8 @@ Editor::finish_bringing_in_audio (AudioRegion& region, uint32_t in_chans, uint32 { list > at (session->new_audio_track (in_chans, out_chans, Destructive)); if (!at.empty()) { - copy = new AudioRegion (region); - at.front()->diskstream()->playlist()->add_region (*copy, pos); + boost::shared_ptr copy (boost::dynamic_pointer_cast (RegionFactory::create (region))); + at.front()->diskstream()->playlist()->add_region (copy, pos); } break; } diff --git a/gtk2_ardour/editor_canvas.cc b/gtk2_ardour/editor_canvas.cc index 2f3aab1eb6..34ea808821 100644 --- a/gtk2_ardour/editor_canvas.cc +++ b/gtk2_ardour/editor_canvas.cc @@ -485,12 +485,9 @@ Editor::drop_regions (const RefPtr& context, for (uint32_t i = 0; i < sr->cnt; ++i) { - Region* r = reinterpret_cast (sr->ptr[i]); - - AudioRegion* ar = dynamic_cast(r); - if (ar) { - insert_region_list_drag (*ar, x, y); - } + boost::shared_ptr r (reinterpret_cast (sr->ptr[i])); + + insert_region_list_drag (r, x, y); } context->drag_finish (true, false, time); diff --git a/gtk2_ardour/editor_canvas_events.cc b/gtk2_ardour/editor_canvas_events.cc index c6b5d1e1c5..58f9deebbd 100644 --- a/gtk2_ardour/editor_canvas_events.cc +++ b/gtk2_ardour/editor_canvas_events.cc @@ -468,7 +468,7 @@ Editor::canvas_fade_out_handle_event (GdkEvent *event, ArdourCanvas::Item* item, } struct DescendingRegionLayerSorter { - bool operator()(Region* a, Region* b) { + bool operator()(boost::shared_ptr a, boost::shared_ptr b) { return a->layer() > b->layer(); } }; @@ -522,7 +522,7 @@ Editor::canvas_crossfade_view_event (GdkEvent* event, ArdourCanvas::Item* item, DescendingRegionLayerSorter cmp; rl->sort (cmp); - RegionView* rv = atv->view()->find_view (*rl->front()); + RegionView* rv = atv->view()->find_view (rl->front()); /* proxy */ diff --git a/gtk2_ardour/editor_export_audio.cc b/gtk2_ardour/editor_export_audio.cc index ec4727ad04..6c67a8fb0e 100644 --- a/gtk2_ardour/editor_export_audio.cc +++ b/gtk2_ardour/editor_export_audio.cc @@ -42,6 +42,8 @@ #include #include #include +#include +#include #include "i18n.h" @@ -93,12 +95,12 @@ Editor::export_region () return; } - ExportDialog* dialog = new ExportRegionDialog (*this, &clicked_regionview->region()); + ExportDialog* dialog = new ExportRegionDialog (*this, clicked_regionview->region()); dialog->connect_to_session (session); dialog->set_range ( - clicked_regionview->region().first_frame(), - clicked_regionview->region().last_frame()); + clicked_regionview->region()->first_frame(), + clicked_regionview->region()->last_frame()); dialog->start_export(); } @@ -142,7 +144,7 @@ Editor::bounce_region_selection () { for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - Region& region ((*i)->region()); + boost::shared_ptr region ((*i)->region()); RouteTimeAxisView* rtv = dynamic_cast(&(*i)->get_time_axis_view()); Track* track = dynamic_cast(rtv->route().get()); @@ -152,14 +154,14 @@ Editor::bounce_region_selection () itt.cancel = false; itt.progress = 0.0f; - track->bounce_range (region.position(), region.position() + region.length(), itt); + track->bounce_range (region->position(), region->position() + region->length(), itt); } } bool -Editor::write_region (string path, AudioRegion& region) +Editor::write_region (string path, boost::shared_ptr region) { - AudioFileSource* fs; + boost::shared_ptr fs; const jack_nframes_t chunk_size = 4096; jack_nframes_t to_read; Sample buf[chunk_size]; @@ -167,14 +169,14 @@ Editor::write_region (string path, AudioRegion& region) jack_nframes_t pos; char s[PATH_MAX+1]; uint32_t cnt; - vector sources; + vector > sources; uint32_t nchans; - nchans = region.n_channels(); + nchans = region->n_channels(); /* don't do duplicate of the entire source if that's what is going on here */ - if (region.start() == 0 && region.length() == region.source().length()) { + if (region->start() == 0 && region->length() == region->source()->length()) { /* XXX should link(2) to create a new inode with "path" */ return true; } @@ -186,11 +188,11 @@ Editor::write_region (string path, AudioRegion& region) for (cnt = 0; cnt < 999999; ++cnt) { if (nchans == 1) { snprintf (s, sizeof(s), "%s/%s_%" PRIu32 ".wav", session->sound_dir().c_str(), - legalize_for_path(region.name()).c_str(), cnt); + legalize_for_path(region->name()).c_str(), cnt); } else { snprintf (s, sizeof(s), "%s/%s_%" PRIu32 "-%" PRId32 ".wav", session->sound_dir().c_str(), - legalize_for_path(region.name()).c_str(), cnt, n); + legalize_for_path(region->name()).c_str(), cnt, n); } path = s; @@ -208,7 +210,7 @@ Editor::write_region (string path, AudioRegion& region) try { - fs = AudioFileSource::create (path); + fs = boost::dynamic_pointer_cast (SourceFactory::createReadable (DataType::AUDIO, path, AudioFileSource::Flag (0))); } catch (failed_constructor& err) { @@ -223,19 +225,19 @@ Editor::write_region (string path, AudioRegion& region) } - to_read = region.length(); - pos = region.position(); + to_read = region->length(); + pos = region->position(); while (to_read) { jack_nframes_t this_time; this_time = min (to_read, chunk_size); - for (vector::iterator src=sources.begin(); src != sources.end(); ++src) { + for (vector >::iterator src=sources.begin(); src != sources.end(); ++src) { fs = (*src); - if (region.read_at (buf, buf, gain_buffer, pos, this_time) != this_time) { + if (region->read_at (buf, buf, gain_buffer, pos, this_time) != this_time) { break; } @@ -254,7 +256,7 @@ Editor::write_region (string path, AudioRegion& region) time (&tnow); now = localtime (&tnow); - for (vector::iterator src = sources.begin(); src != sources.end(); ++src) { + for (vector >::iterator src = sources.begin(); src != sources.end(); ++src) { (*src)->update_header (0, *now, tnow); } @@ -262,10 +264,8 @@ Editor::write_region (string path, AudioRegion& region) error_out: - for (vector::iterator i = sources.begin(); i != sources.end(); ++i) { - + for (vector >::iterator i = sources.begin(); i != sources.end(); ++i) { (*i)->mark_for_remove (); - delete (*i); } return 0; @@ -305,7 +305,7 @@ Editor::write_audio_selection (TimeSelection& ts) bool Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list& range) { - AudioFileSource* fs; + boost::shared_ptr fs; const jack_nframes_t chunk_size = 4096; jack_nframes_t nframes; Sample buf[chunk_size]; @@ -314,7 +314,7 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list char s[PATH_MAX+1]; uint32_t cnt; string path; - vector sources; + vector > sources; uint32_t channels = count.get(DataType::AUDIO); @@ -343,7 +343,7 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list path = s; try { - fs = AudioFileSource::create (path); + fs = boost::dynamic_pointer_cast (SourceFactory::createReadable (DataType::AUDIO, path, AudioFileSource::Flag (0))); } catch (failed_constructor& err) { @@ -426,9 +426,8 @@ Editor::write_audio_range (AudioPlaylist& playlist, const ChanCount& count, list error_out: /* unref created files */ - for (vector::iterator i = sources.begin(); i != sources.end(); ++i) { + for (vector >::iterator i = sources.begin(); i != sources.end(); ++i) { (*i)->mark_for_remove (); - delete *i; } return false; diff --git a/gtk2_ardour/editor_keyboard.cc b/gtk2_ardour/editor_keyboard.cc index 95289c7f5a..e9ccd26f46 100644 --- a/gtk2_ardour/editor_keyboard.cc +++ b/gtk2_ardour/editor_keyboard.cc @@ -103,12 +103,12 @@ Editor::kbd_mute_unmute_region () { if (entered_regionview) { begin_reversible_command (_("mute region")); - XMLNode &before = entered_regionview->region().playlist()->get_state(); + XMLNode &before = entered_regionview->region()->playlist()->get_state(); - entered_regionview->region().set_muted (!entered_regionview->region().muted()); + entered_regionview->region()->set_muted (!entered_regionview->region()->muted()); - XMLNode &after = entered_regionview->region().playlist()->get_state(); - session->add_command (new MementoCommand(*(entered_regionview->region().playlist()), &before, &after)); + XMLNode &after = entered_regionview->region()->playlist()->get_state(); + session->add_command (new MementoCommand(*(entered_regionview->region()->playlist()), &before, &after)); commit_reversible_command(); } } diff --git a/gtk2_ardour/editor_mixer.cc b/gtk2_ardour/editor_mixer.cc index 0e50df2137..f9ce22ed4b 100644 --- a/gtk2_ardour/editor_mixer.cc +++ b/gtk2_ardour/editor_mixer.cc @@ -266,7 +266,6 @@ Editor::session_going_away () latest_regionview = 0; last_update_frame = 0; drag_info.item = 0; - last_audition_region = 0; last_canvas_frame = 0; /* hide all tracks */ diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index df2c1d101c..4a8853e320 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -1752,7 +1752,7 @@ Editor::start_fade_in_grab (ArdourCanvas::Item* item, GdkEvent* event) AudioRegionView* arv = static_cast(drag_info.data); - drag_info.pointer_frame_offset = drag_info.grab_frame - ((jack_nframes_t) arv->audio_region().fade_in().back()->when + arv->region().position()); + drag_info.pointer_frame_offset = drag_info.grab_frame - ((jack_nframes_t) arv->audio_region()->fade_in().back()->when + arv->region()->position()); } void @@ -1773,17 +1773,17 @@ Editor::fade_in_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) snap_to (pos); } - if (pos < (arv->region().position() + 64)) { + if (pos < (arv->region()->position() + 64)) { fade_length = 64; // this should be a minimum defined somewhere - } else if (pos > arv->region().last_frame()) { - fade_length = arv->region().length(); + } else if (pos > arv->region()->last_frame()) { + fade_length = arv->region()->length(); } else { - fade_length = pos - arv->region().position(); + fade_length = pos - arv->region()->position(); } arv->reset_fade_in_shape_width (fade_length); - show_verbose_duration_cursor (arv->region().position(), arv->region().position() + fade_length, 10); + show_verbose_duration_cursor (arv->region()->position(), arv->region()->position() + fade_length, 10); drag_info.first_move = false; } @@ -1808,25 +1808,23 @@ Editor::fade_in_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* even snap_to (pos); } - if (pos < (arv->region().position() + 64)) { + if (pos < (arv->region()->position() + 64)) { fade_length = 64; // this should be a minimum defined somewhere } - else if (pos > arv->region().last_frame()) { - fade_length = arv->region().length(); + else if (pos > arv->region()->last_frame()) { + fade_length = arv->region()->length(); } else { - fade_length = pos - arv->region().position(); + fade_length = pos - arv->region()->position(); } begin_reversible_command (_("change fade in length")); - XMLNode &before = arv->audio_region().get_state(); + XMLNode &before = arv->audio_region()->get_state(); - arv->audio_region().set_fade_in_length (fade_length); + arv->audio_region()->set_fade_in_length (fade_length); - XMLNode &after = arv->audio_region().get_state(); - session->add_command(new MementoCommand(arv->audio_region(), - &before, - &after)); + XMLNode &after = arv->audio_region()->get_state(); + session->add_command(new MementoCommand(*arv->audio_region().get(), &before, &after)); commit_reversible_command (); fade_in_drag_motion_callback (item, event); } @@ -1847,7 +1845,7 @@ Editor::start_fade_out_grab (ArdourCanvas::Item* item, GdkEvent* event) AudioRegionView* arv = static_cast(drag_info.data); - drag_info.pointer_frame_offset = drag_info.grab_frame - (arv->region().length() - (jack_nframes_t) arv->audio_region().fade_out().back()->when + arv->region().position()); + drag_info.pointer_frame_offset = drag_info.grab_frame - (arv->region()->length() - (jack_nframes_t) arv->audio_region()->fade_out().back()->when + arv->region()->position()); } void @@ -1868,19 +1866,19 @@ Editor::fade_out_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event snap_to (pos); } - if (pos > (arv->region().last_frame() - 64)) { + if (pos > (arv->region()->last_frame() - 64)) { fade_length = 64; // this should really be a minimum fade defined somewhere } - else if (pos < arv->region().position()) { - fade_length = arv->region().length(); + else if (pos < arv->region()->position()) { + fade_length = arv->region()->length(); } else { - fade_length = arv->region().last_frame() - pos; + fade_length = arv->region()->last_frame() - pos; } arv->reset_fade_out_shape_width (fade_length); - show_verbose_duration_cursor (arv->region().last_frame() - fade_length, arv->region().last_frame(), 10); + show_verbose_duration_cursor (arv->region()->last_frame() - fade_length, arv->region()->last_frame(), 10); drag_info.first_move = false; } @@ -1905,23 +1903,23 @@ Editor::fade_out_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* eve snap_to (pos); } - if (pos > (arv->region().last_frame() - 64)) { + if (pos > (arv->region()->last_frame() - 64)) { fade_length = 64; // this should really be a minimum fade defined somewhere } - else if (pos < arv->region().position()) { - fade_length = arv->region().length(); + else if (pos < arv->region()->position()) { + fade_length = arv->region()->length(); } else { - fade_length = arv->region().last_frame() - pos; + fade_length = arv->region()->last_frame() - pos; } begin_reversible_command (_("change fade out length")); - XMLNode &before = arv->region().get_state(); + XMLNode &before = arv->region()->get_state(); - arv->audio_region().set_fade_out_length (fade_length); + arv->audio_region()->set_fade_out_length (fade_length); - XMLNode &after = arv->region().get_state(); - session->add_command(new MementoCommand(arv->region(), &before, &after)); + XMLNode &after = arv->region()->get_state(); + session->add_command(new MementoCommand(*arv->region().get(), &before, &after)); commit_reversible_command (); fade_out_drag_motion_callback (item, event); @@ -2686,7 +2684,7 @@ Editor::start_region_grab (ArdourCanvas::Item* item, GdkEvent* event) speed = tv->get_diskstream()->speed(); } - drag_info.last_frame_position = (jack_nframes_t) (clicked_regionview->region().position() / speed); + drag_info.last_frame_position = (jack_nframes_t) (clicked_regionview->region()->position() / speed); drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position; drag_info.last_trackview = &clicked_regionview->get_time_axis_view(); // we want a move threshold @@ -2719,7 +2717,7 @@ Editor::start_region_copy_grab (ArdourCanvas::Item* item, GdkEvent* event) } drag_info.last_trackview = &clicked_regionview->get_time_axis_view(); - drag_info.last_frame_position = (jack_nframes_t) (clicked_regionview->region().position() / speed); + drag_info.last_frame_position = (jack_nframes_t) (clicked_regionview->region()->position() / speed); drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position; // we want a move threshold drag_info.want_move_threshold = true; @@ -2750,7 +2748,7 @@ Editor::start_region_brush_grab (ArdourCanvas::Item* item, GdkEvent* event) speed = tv->get_diskstream()->speed(); } - drag_info.last_frame_position = (jack_nframes_t) (clicked_regionview->region().position() / speed); + drag_info.last_frame_position = (jack_nframes_t) (clicked_regionview->region()->position() / speed); drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position; drag_info.last_trackview = &clicked_regionview->get_time_axis_view(); // we want a move threshold @@ -2795,7 +2793,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) rv = (*i); - Playlist* to_playlist = rv->region().playlist(); + Playlist* to_playlist = rv->region()->playlist(); RouteTimeAxisView* rtv = dynamic_cast(&rv->get_time_axis_view()); insert_result = affected_playlists.insert (to_playlist); @@ -2809,19 +2807,16 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) /* create a new region with the same name. */ - // FIXME: ew. need a (virtual) Region::duplicate() or something? - Region* newregion = NULL; - if (dynamic_cast(&rv->region())) - newregion = new AudioRegion (dynamic_cast(rv->region())); - else if (dynamic_cast(&rv->region())) - newregion = new MidiRegion (dynamic_cast(rv->region())); - assert(newregion); + boost::shared_ptr newregion; + + newregion = RegionFactory::create (rv->region()); + assert(newregion != 0); /* if the original region was locked, we don't care */ newregion->set_locked (false); - to_playlist->add_region (*newregion, (jack_nframes_t) (rv->region().position() * rtv->get_diskstream()->speed())); + to_playlist->add_region (newregion, (jack_nframes_t) (rv->region()->position() * rtv->get_diskstream()->speed())); c.disconnect (); @@ -3036,8 +3031,8 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) pending_region_position = drag_info.current_pointer_frame - drag_info.pointer_frame_offset; - sync_offset = rv->region().sync_offset (sync_dir); - sync_frame = rv->region().adjust_to_sync (pending_region_position); + sync_offset = rv->region()->sync_offset (sync_dir); + sync_frame = rv->region()->adjust_to_sync (pending_region_position); /* we snap if the snap modifier is not enabled. */ @@ -3056,7 +3051,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) pending_region_position = 0; } - if (pending_region_position > max_frames - rv->region().length()) { + if (pending_region_position > max_frames - rv->region()->length()) { pending_region_position = drag_info.last_frame_position; } @@ -3205,8 +3200,8 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) if (-x_delta > ix1) { x_delta = -ix1; } - } else if ((x_delta > 0) &&(rv->region().last_frame() > max_frames - x_delta)) { - x_delta = max_frames - rv->region().last_frame(); + } else if ((x_delta > 0) &&(rv->region()->last_frame() > max_frames - x_delta)) { + x_delta = max_frames - rv->region()->last_frame(); } if (drag_info.first_move) { @@ -3305,7 +3300,7 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event speed = atv->get_diskstream()->speed(); } - regionview_x_movement = (drag_info.last_frame_position != (jack_nframes_t) (rv->region().position()/speed)); + regionview_x_movement = (drag_info.last_frame_position != (jack_nframes_t) (rv->region()->position()/speed)); regionview_y_movement = (drag_info.last_trackview != &rv->get_time_axis_view()); //printf ("last_frame: %s position is %lu %g\n", rv->get_time_axis_view().name().c_str(), drag_info.last_frame_position, speed); @@ -3350,7 +3345,7 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event TimeAxisView* tvp2 = trackview_by_y_position (iy1); RouteTimeAxisView* atv2 = dynamic_cast(tvp2); - from_playlist = (*i)->region().playlist(); + from_playlist = (*i)->region()->playlist(); to_playlist = atv2->playlist(); /* the from_playlist was frozen in the "first_move" case @@ -3385,20 +3380,20 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event TimeAxisView* tvp2 = trackview_by_y_position (iy1); RouteTimeAxisView* atv2 = dynamic_cast(tvp2); - from_playlist = (*i)->region().playlist(); + from_playlist = (*i)->region()->playlist(); to_playlist = atv2->playlist(); latest_regionview = 0; where = (jack_nframes_t) (unit_to_frame (ix1) * speed); - Region* new_region = createRegion ((*i)->region()); + boost::shared_ptr new_region (RegionFactory::create ((*i)->region())); - from_playlist->remove_region (&((*i)->region())); - + from_playlist->remove_region (((*i)->region())); + sigc::connection c = atv2->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view)); - to_playlist->add_region (*new_region, where); + to_playlist->add_region (new_region, where); c.disconnect (); - + if (latest_regionview) { selection->add (latest_regionview); } @@ -3412,7 +3407,7 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event rv = (*i); - if (rv->region().locked()) { + if (rv->region()->locked()) { continue; } @@ -3434,14 +3429,14 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event } else { - where = rv->region().position(); + where = rv->region()->position(); } rv->get_time_axis_view().reveal_dependent_views (*rv); /* no need to add an undo here, we did that when we added this playlist to motion_frozen playlists */ - rv->region().set_position (where, (void *) this); + rv->region()->set_position (where, (void *) this); } } @@ -3614,7 +3609,7 @@ Editor::start_selection_grab (ArdourCanvas::Item* item, GdkEvent* event) /* lets try to create new Region for the selection */ - vector new_regions; + vector > new_regions; create_region_from_selection (new_regions); if (new_regions.empty()) { @@ -3623,7 +3618,7 @@ Editor::start_selection_grab (ArdourCanvas::Item* item, GdkEvent* event) /* XXX fix me one day to use all new regions */ - Region* region = new_regions.front(); + boost::shared_ptr region (new_regions.front()); /* add it to the current stream/playlist. @@ -3643,9 +3638,9 @@ Editor::start_selection_grab (ArdourCanvas::Item* item, GdkEvent* event) Playlist* playlist = clicked_axisview->playlist(); - XMLNode *before = &(playlist->get_state()); - clicked_axisview->playlist()->add_region (*region, selection->time[clicked_selection].start); - XMLNode *after = &(playlist->get_state()); + XMLNode *before = &(playlist->get_state()); + clicked_routeview->playlist()->add_region (region, selection->time[clicked_selection].start); + XMLNode *after = &(playlist->get_state()); session->add_command(new MementoCommand(*playlist, before, after)); commit_reversible_command (); @@ -3669,7 +3664,7 @@ Editor::start_selection_grab (ArdourCanvas::Item* item, GdkEvent* event) start_grab (event); drag_info.last_trackview = clicked_axisview; - drag_info.last_frame_position = latest_regionview->region().position(); + drag_info.last_frame_position = latest_regionview->region()->position(); drag_info.pointer_frame_offset = drag_info.grab_frame - drag_info.last_frame_position; show_verbose_time_cursor (drag_info.last_frame_position, 10); @@ -3910,9 +3905,9 @@ Editor::start_trim (ArdourCanvas::Item* item, GdkEvent* event) speed = tv->get_diskstream()->speed(); } - jack_nframes_t region_start = (jack_nframes_t) (clicked_regionview->region().position() / speed); - jack_nframes_t region_end = (jack_nframes_t) (clicked_regionview->region().last_frame() / speed); - jack_nframes_t region_length = (jack_nframes_t) (clicked_regionview->region().length() / speed); + jack_nframes_t region_start = (jack_nframes_t) (clicked_regionview->region()->position() / speed); + jack_nframes_t region_end = (jack_nframes_t) (clicked_regionview->region()->last_frame() / speed); + jack_nframes_t region_length = (jack_nframes_t) (clicked_regionview->region()->length() / speed); motion_frozen_playlists.clear(); @@ -4004,13 +3999,13 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) begin_reversible_command (trim_type); for (list::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) { - (*i)->region().freeze (); + (*i)->region()->freeze (); AudioRegionView* const arv = dynamic_cast(*i); if (arv) arv->temporarily_hide_envelope (); - Playlist * pl = (*i)->region().playlist(); + Playlist * pl = (*i)->region()->playlist(); insert_result = motion_frozen_playlists.insert (pl); if (insert_result.second) { session->add_command(new MementoCommand(*pl, &pl->get_state(), 0)); @@ -4026,7 +4021,7 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) switch (trim_op) { case StartTrim: - if ((left_direction == false) && (drag_info.current_pointer_frame <= rv->region().first_frame()/speed)) { + if ((left_direction == false) && (drag_info.current_pointer_frame <= rv->region()->first_frame()/speed)) { break; } else { for (list::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) { @@ -4036,7 +4031,7 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) } case EndTrim: - if ((left_direction == true) && (drag_info.current_pointer_frame > (jack_nframes_t) (rv->region().last_frame()/speed))) { + if ((left_direction == true) && (drag_info.current_pointer_frame > (jack_nframes_t) (rv->region()->last_frame()/speed))) { break; } else { for (list::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) { @@ -4064,10 +4059,10 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) switch (trim_op) { case StartTrim: - show_verbose_time_cursor((jack_nframes_t) (rv->region().position()/speed), 10); + show_verbose_time_cursor((jack_nframes_t) (rv->region()->position()/speed), 10); break; case EndTrim: - show_verbose_time_cursor((jack_nframes_t) (rv->region().last_frame()/speed), 10); + show_verbose_time_cursor((jack_nframes_t) (rv->region()->last_frame()/speed), 10); break; case ContentsTrim: show_verbose_time_cursor(drag_info.current_pointer_frame, 10); @@ -4081,9 +4076,9 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) void Editor::single_contents_trim (RegionView& rv, jack_nframes_t frame_delta, bool left_direction, bool swap_direction, bool obey_snap) { - Region& region (rv.region()); + boost::shared_ptr region (rv.region()); - if (region.locked()) { + if (region->locked()) { return; } @@ -4099,31 +4094,31 @@ Editor::single_contents_trim (RegionView& rv, jack_nframes_t frame_delta, bool l if (left_direction) { if (swap_direction) { - new_bound = (jack_nframes_t) (region.position()/speed) + frame_delta; + new_bound = (jack_nframes_t) (region->position()/speed) + frame_delta; } else { - new_bound = (jack_nframes_t) (region.position()/speed) - frame_delta; + new_bound = (jack_nframes_t) (region->position()/speed) - frame_delta; } } else { if (swap_direction) { - new_bound = (jack_nframes_t) (region.position()/speed) - frame_delta; + new_bound = (jack_nframes_t) (region->position()/speed) - frame_delta; } else { - new_bound = (jack_nframes_t) (region.position()/speed) + frame_delta; + new_bound = (jack_nframes_t) (region->position()/speed) + frame_delta; } } if (obey_snap) { snap_to (new_bound); } - region.trim_start ((jack_nframes_t) (new_bound * speed), this); + region->trim_start ((jack_nframes_t) (new_bound * speed), this); rv.region_changed (StartChanged); } void Editor::single_start_trim (RegionView& rv, jack_nframes_t frame_delta, bool left_direction, bool obey_snap) { - Region& region (rv.region()); + boost::shared_ptr region (rv.region()); - if (region.locked()) { + if (region->locked()) { return; } @@ -4138,16 +4133,16 @@ Editor::single_start_trim (RegionView& rv, jack_nframes_t frame_delta, bool left } if (left_direction) { - new_bound = (jack_nframes_t) (region.position()/speed) - frame_delta; + new_bound = (jack_nframes_t) (region->position()/speed) - frame_delta; } else { - new_bound = (jack_nframes_t) (region.position()/speed) + frame_delta; + new_bound = (jack_nframes_t) (region->position()/speed) + frame_delta; } if (obey_snap) { snap_to (new_bound, (left_direction ? 0 : 1)); } - region.trim_front ((jack_nframes_t) (new_bound * speed), this); + region->trim_front ((jack_nframes_t) (new_bound * speed), this); rv.region_changed (Change (LengthChanged|PositionChanged|StartChanged)); } @@ -4155,9 +4150,9 @@ Editor::single_start_trim (RegionView& rv, jack_nframes_t frame_delta, bool left void Editor::single_end_trim (RegionView& rv, jack_nframes_t frame_delta, bool left_direction, bool obey_snap) { - Region& region (rv.region()); + boost::shared_ptr region (rv.region()); - if (region.locked()) { + if (region->locked()) { return; } @@ -4172,15 +4167,15 @@ Editor::single_end_trim (RegionView& rv, jack_nframes_t frame_delta, bool left_d } if (left_direction) { - new_bound = (jack_nframes_t) ((region.last_frame() + 1)/speed) - frame_delta; + new_bound = (jack_nframes_t) ((region->last_frame() + 1)/speed) - frame_delta; } else { - new_bound = (jack_nframes_t) ((region.last_frame() + 1)/speed) + frame_delta; + new_bound = (jack_nframes_t) ((region->last_frame() + 1)/speed) + frame_delta; } if (obey_snap) { snap_to (new_bound); } - region.trim_end ((jack_nframes_t) (new_bound * speed), this); + region->trim_end ((jack_nframes_t) (new_bound * speed), this); rv.region_changed (LengthChanged); } @@ -4236,10 +4231,10 @@ Editor::point_trim (GdkEvent* event) for (list::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) { - if (!(*i)->region().locked()) { - Playlist *pl = (*i)->region().playlist(); + if (!(*i)->region()->locked()) { + Playlist *pl = (*i)->region()->playlist(); XMLNode &before = pl->get_state(); - (*i)->region().trim_front (new_bound, this); + (*i)->region()->trim_front (new_bound, this); XMLNode &after = pl->get_state(); session->add_command(new MementoCommand(*pl, &before, &after)); } @@ -4247,10 +4242,10 @@ Editor::point_trim (GdkEvent* event) } else { - if (!rv->region().locked()) { - Playlist *pl = rv->region().playlist(); + if (!rv->region()->locked()) { + Playlist *pl = rv->region()->playlist(); XMLNode &before = pl->get_state(); - rv->region().trim_front (new_bound, this); + rv->region()->trim_front (new_bound, this); XMLNode &after = pl->get_state(); session->add_command(new MementoCommand(*pl, &before, &after)); } @@ -4267,10 +4262,10 @@ Editor::point_trim (GdkEvent* event) for (list::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ++i) { - if (!(*i)->region().locked()) { - Playlist *pl = (*i)->region().playlist(); + if (!(*i)->region()->locked()) { + Playlist *pl = (*i)->region()->playlist(); XMLNode &before = pl->get_state(); - (*i)->region().trim_end (new_bound, this); + (*i)->region()->trim_end (new_bound, this); XMLNode &after = pl->get_state(); session->add_command(new MementoCommand(*pl, &before, &after)); } @@ -4278,10 +4273,10 @@ Editor::point_trim (GdkEvent* event) } else { - if (!rv->region().locked()) { - Playlist *pl = rv->region().playlist(); + if (!rv->region()->locked()) { + Playlist *pl = rv->region()->playlist(); XMLNode &before = pl->get_state(); - rv->region().trim_end (new_bound, this); + rv->region()->trim_end (new_bound, this); XMLNode &after = pl->get_state(); session->add_command (new MementoCommand(*pl, &before, &after)); } @@ -4298,15 +4293,15 @@ Editor::point_trim (GdkEvent* event) void Editor::thaw_region_after_trim (RegionView& rv) { - Region& region (rv.region()); + boost::shared_ptr region (rv.region()); - if (region.locked()) { + if (region->locked()) { return; } - region.thaw (_("trimmed region")); - XMLNode &after = region.playlist()->get_state(); - session->add_command (new MementoCommand(*(region.playlist()), 0, &after)); + region->thaw (_("trimmed region")); + XMLNode &after = region->playlist()->get_state(); + session->add_command (new MementoCommand(*(region->playlist()), 0, &after)); AudioRegionView* arv = dynamic_cast(&rv); if (arv) @@ -4720,7 +4715,7 @@ Editor::mouse_rename_region (ArdourCanvas::Item* item, GdkEvent* event) ArdourPrompter prompter (false); prompter.set_prompt (_("Name for region:")); - prompter.set_initial_text (clicked_regionview->region().name()); + prompter.set_initial_text (clicked_regionview->region()->name()); prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT); prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false); prompter.show_all (); @@ -4729,7 +4724,7 @@ Editor::mouse_rename_region (ArdourCanvas::Item* item, GdkEvent* event) string str; prompter.get_result(str); if (str.length()) { - clicked_regionview->region().set_name (str); + clicked_regionview->region()->set_name (str); } break; } @@ -4761,8 +4756,8 @@ Editor::time_fx_motion (ArdourCanvas::Item *item, GdkEvent* event) return; } - if (drag_info.current_pointer_frame > rv->region().position()) { - rv->get_time_axis_view().show_timestretch (rv->region().position(), drag_info.current_pointer_frame); + if (drag_info.current_pointer_frame > rv->region()->position()) { + rv->get_time_axis_view().show_timestretch (rv->region()->position(), drag_info.current_pointer_frame); } drag_info.last_pointer_frame = drag_info.current_pointer_frame; @@ -4780,8 +4775,8 @@ Editor::end_time_fx (ArdourCanvas::Item* item, GdkEvent* event) return; } - jack_nframes_t newlen = drag_info.last_pointer_frame - clicked_regionview->region().position(); - float percentage = (float) ((double) newlen - (double) clicked_regionview->region().length()) / ((double) newlen) * 100.0f; + jack_nframes_t newlen = drag_info.last_pointer_frame - clicked_regionview->region()->position(); + float percentage = (float) ((double) newlen - (double) clicked_regionview->region()->length()) / ((double) newlen) * 100.0f; begin_reversible_command (_("timestretch")); @@ -4818,7 +4813,7 @@ Editor::mouse_brush_insert_region (RegionView* rv, jack_nframes_t pos) /* don't brush a copy over the original */ - if (pos == rv->region().position()) { + if (pos == rv->region()->position()) { return; } @@ -4832,7 +4827,7 @@ Editor::mouse_brush_insert_region (RegionView* rv, jack_nframes_t pos) double speed = atv->get_diskstream()->speed(); XMLNode &before = playlist->get_state(); - playlist->add_region (*(new AudioRegion (arv->audio_region())), (jack_nframes_t) (pos * speed)); + playlist->add_region (boost::dynamic_pointer_cast (RegionFactory::create (arv->audio_region())), (jack_nframes_t) (pos * speed)); XMLNode &after = playlist->get_state(); session->add_command(new MementoCommand(*playlist, &before, &after)); diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 2532222c0d..22eefabea8 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -203,7 +203,7 @@ Editor::split_regions_at (jack_nframes_t where, RegionSelection& regions) tmp = a; ++tmp; - Playlist* pl = (*a)->region().playlist(); + Playlist* pl = (*a)->region()->playlist(); AudioRegionView* const arv = dynamic_cast(*a); if (arv) @@ -234,7 +234,7 @@ Editor::remove_clicked_region () begin_reversible_command (_("remove region")); XMLNode &before = playlist->get_state(); - playlist->remove_region (&clicked_regionview->region()); + playlist->remove_region (clicked_regionview->region()); XMLNode &after = playlist->get_state(); session->add_command(new MementoCommand(*playlist, &before, &after)); commit_reversible_command (); @@ -273,24 +273,24 @@ Do you really want to destroy %1 ?"), } if (selected > 0) { - list r; + list > r; for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - r.push_back (&(*i)->region()); + r.push_back ((*i)->region()); } session->destroy_regions (r); } else if (clicked_regionview) { - session->destroy_region (&clicked_regionview->region()); + session->destroy_region (clicked_regionview->region()); } } -Region * +boost::shared_ptr Editor::select_region_for_operation (int dir, TimeAxisView **tv) { RegionView* rv; - Region *region; + boost::shared_ptr region; jack_nframes_t start = 0; if (selection->time.start () == selection->time.end_frame ()) { @@ -298,18 +298,16 @@ Editor::select_region_for_operation (int dir, TimeAxisView **tv) /* no current selection-> is there a selected regionview? */ if (selection->regions.empty()) { - return 0; + return region; } } - region = 0; - if (!selection->regions.empty()) { rv = *(selection->regions.begin()); (*tv) = &rv->get_time_axis_view(); - region = &rv->region(); + region = rv->region(); } else if (!selection->tracks.empty()) { @@ -321,7 +319,7 @@ Editor::select_region_for_operation (int dir, TimeAxisView **tv) Playlist *pl; if ((pl = rtv->playlist()) == 0) { - return 0; + return region; } region = pl->top_region_at (start); @@ -335,7 +333,7 @@ void Editor::extend_selection_to_end_of_region (bool next) { TimeAxisView *tv; - Region *region; + boost::shared_ptr region; jack_nframes_t start; if ((region = select_region_for_operation (next ? 1 : 0, &tv)) == 0) { @@ -363,7 +361,7 @@ void Editor::extend_selection_to_start_of_region (bool previous) { TimeAxisView *tv; - Region *region; + boost::shared_ptr region; jack_nframes_t end; if ((region = select_region_for_operation (previous ? -1 : 0, &tv)) == 0) { @@ -401,18 +399,18 @@ Editor::nudge_forward (bool next) begin_reversible_command (_("nudge forward")); for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - Region& r ((*i)->region()); + boost::shared_ptr r ((*i)->region()); - distance = get_nudge_distance (r.position(), next_distance); + distance = get_nudge_distance (r->position(), next_distance); if (next) { distance = next_distance; } - XMLNode &before = r.playlist()->get_state(); - r.set_position (r.position() + distance, this); - XMLNode &after = r.playlist()->get_state(); - session->add_command (new MementoCommand(*(r.playlist()), &before, &after)); + XMLNode &before = r->playlist()->get_state(); + r->set_position (r->position() + distance, this); + XMLNode &after = r->playlist()->get_state(); + session->add_command (new MementoCommand(*(r->playlist()), &before, &after)); } commit_reversible_command (); @@ -436,23 +434,23 @@ Editor::nudge_backward (bool next) begin_reversible_command (_("nudge forward")); for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - Region& r ((*i)->region()); + boost::shared_ptr r ((*i)->region()); - distance = get_nudge_distance (r.position(), next_distance); + distance = get_nudge_distance (r->position(), next_distance); if (next) { distance = next_distance; } - XMLNode &before = r.playlist()->get_state(); + XMLNode &before = r->playlist()->get_state(); - if (r.position() > distance) { - r.set_position (r.position() - distance, this); + if (r->position() > distance) { + r->set_position (r->position() - distance, this); } else { - r.set_position (0, this); + r->set_position (0, this); } - XMLNode &after = r.playlist()->get_state(); - session->add_command(new MementoCommand(*(r.playlist()), &before, &after)); + XMLNode &after = r->playlist()->get_state(); + session->add_command(new MementoCommand(*(r->playlist()), &before, &after)); } commit_reversible_command (); @@ -483,12 +481,12 @@ Editor::nudge_forward_capture_offset () distance = session->worst_output_latency(); for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - Region& r ((*i)->region()); + boost::shared_ptr r ((*i)->region()); - XMLNode &before = r.playlist()->get_state(); - r.set_position (r.position() + distance, this); - XMLNode &after = r.playlist()->get_state(); - session->add_command(new MementoCommand(*(r.playlist()), &before, &after)); + XMLNode &before = r->playlist()->get_state(); + r->set_position (r->position() + distance, this); + XMLNode &after = r->playlist()->get_state(); + session->add_command(new MementoCommand(*(r->playlist()), &before, &after)); } commit_reversible_command (); @@ -510,17 +508,17 @@ Editor::nudge_backward_capture_offset () distance = session->worst_output_latency(); for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - Region& r ((*i)->region()); + boost::shared_ptr r ((*i)->region()); - XMLNode &before = r.playlist()->get_state(); + XMLNode &before = r->playlist()->get_state(); - if (r.position() > distance) { - r.set_position (r.position() - distance, this); + if (r->position() > distance) { + r->set_position (r->position() - distance, this); } else { - r.set_position (0, this); + r->set_position (0, this); } - XMLNode &after = r.playlist()->get_state(); - session->add_command(new MementoCommand(*(r.playlist()), &before, &after)); + XMLNode &after = r->playlist()->get_state(); + session->add_command(new MementoCommand(*(r->playlist()), &before, &after)); } commit_reversible_command (); @@ -547,7 +545,7 @@ Editor::build_region_boundary_cache () { jack_nframes_t pos = 0; RegionPoint point; - Region *r; + boost::shared_ptr r; TrackViewList tracks; region_boundary_cache.clear (); @@ -643,12 +641,12 @@ Editor::build_region_boundary_cache () } } -Region* +boost::shared_ptr Editor::find_next_region (jack_nframes_t frame, RegionPoint point, int32_t dir, TrackViewList& tracks, TimeAxisView **ontrack) { TrackViewList::iterator i; jack_nframes_t closest = max_frames; - Region* ret = 0; + boost::shared_ptr ret; jack_nframes_t rpos = 0; float track_speed; @@ -658,8 +656,8 @@ Editor::find_next_region (jack_nframes_t frame, RegionPoint point, int32_t dir, for (i = tracks.begin(); i != tracks.end(); ++i) { jack_nframes_t distance; - Region* r; - + boost::shared_ptr r; + track_speed = 1.0f; if ( (atav = dynamic_cast(*i)) != 0 ) { if (atav->get_diskstream()!=0) @@ -708,7 +706,7 @@ Editor::find_next_region (jack_nframes_t frame, RegionPoint point, int32_t dir, void Editor::cursor_to_region_point (Cursor* cursor, RegionPoint point, int32_t dir) { - Region* r; + boost::shared_ptr r; jack_nframes_t pos = cursor->current_frame; if (!session) { @@ -1326,9 +1324,9 @@ Editor::add_location_from_audio_region () } RegionView* rv = *(selection->regions.begin()); - Region& region = rv->region(); + boost::shared_ptr region = rv->region(); - Location *location = new Location (region.position(), region.last_frame(), region.name()); + Location *location = new Location (region->position(), region->last_frame(), region->name()); session->begin_reversible_command (_("add marker")); XMLNode &before = session->locations()->get_state(); session->locations()->add (location, true); @@ -1459,10 +1457,10 @@ Editor::set_selection_from_audio_region () } RegionView* rv = *(selection->regions.begin()); - Region& region = rv->region(); + boost::shared_ptr region = rv->region(); begin_reversible_command (_("set selection from region")); - selection->set (0, region.position(), region.last_frame()); + selection->set (0, region->position(), region->last_frame()); commit_reversible_command (); set_mouse_mode (Editing::MouseRange, false); @@ -1793,7 +1791,7 @@ Editor::clear_locations () /* INSERT/REPLACE */ void -Editor::insert_region_list_drag (AudioRegion& region, int x, int y) +Editor::insert_region_list_drag (boost::shared_ptr region, int x, int y) { double wx, wy; double cx, cy; @@ -1834,7 +1832,7 @@ Editor::insert_region_list_drag (AudioRegion& region, int x, int y) begin_reversible_command (_("insert dragged region")); XMLNode &before = playlist->get_state(); - playlist->add_region (*(new AudioRegion (region)), where, 1.0); + playlist->add_region (RegionFactory::create (region), where, 1.0); session->add_command(new MementoCommand(*playlist, &before, &playlist->get_state())); commit_reversible_command (); } @@ -1866,11 +1864,11 @@ Editor::insert_region_list_selection (float times) } TreeModel::iterator i = region_list_display.get_selection()->get_selected(); - Region* region = (*i)[region_list_columns.region]; + boost::shared_ptr region = (*i)[region_list_columns.region]; begin_reversible_command (_("insert region")); XMLNode &before = playlist->get_state(); - playlist->add_region (*(createRegion (*region)), edit_cursor->current_frame, times); + playlist->add_region ((RegionFactory::create (region)), edit_cursor->current_frame, times); session->add_command(new MementoCommand(*playlist, &before, &playlist->get_state())); commit_reversible_command (); } @@ -1946,7 +1944,7 @@ Editor::play_selected_region () if (!selection->regions.empty()) { RegionView *rv = *(selection->regions.begin()); - session->request_bounded_roll (rv->region().position(), rv->region().last_frame()); + session->request_bounded_roll (rv->region()->position(), rv->region()->last_frame()); } } @@ -1959,7 +1957,7 @@ Editor::loop_selected_region () if ((tll = transport_loop_location()) != 0) { - tll->set (rv->region().position(), rv->region().last_frame()); + tll->set (rv->region()->position(), rv->region()->last_frame()); // enable looping, reposition and start rolling @@ -2002,9 +2000,9 @@ void Editor::toggle_region_mute () { if (clicked_regionview) { - clicked_regionview->region().set_muted (!clicked_regionview->region().muted()); + clicked_regionview->region()->set_muted (!clicked_regionview->region()->muted()); } else if (!selection->regions.empty()) { - bool yn = ! (*selection->regions.begin())->region().muted(); + bool yn = ! (*selection->regions.begin())->region()->muted(); selection->foreach_region (&Region::set_muted, yn); } } @@ -2013,9 +2011,9 @@ void Editor::toggle_region_opaque () { if (clicked_regionview) { - clicked_regionview->region().set_opaque (!clicked_regionview->region().opaque()); + clicked_regionview->region()->set_opaque (!clicked_regionview->region()->opaque()); } else if (!selection->regions.empty()) { - bool yn = ! (*selection->regions.begin())->region().opaque(); + bool yn = ! (*selection->regions.begin())->region()->opaque(); selection->foreach_region (&Region::set_opaque, yn); } } @@ -2093,7 +2091,7 @@ Editor::rename_region () Main::run (); if (region_renamed) { - (*selection->regions.begin())->region().set_name (entry.get_text()); + (*selection->regions.begin())->region()->set_name (entry.get_text()); redisplay_regions (); } } @@ -2107,7 +2105,7 @@ Editor::rename_region_finished (bool status) } void -Editor::audition_playlist_region_via_route (Region& region, Route& route) +Editor::audition_playlist_region_via_route (boost::shared_ptr region, Route& route) { if (session->is_auditioning()) { session->cancel_audition (); @@ -2120,7 +2118,7 @@ Editor::audition_playlist_region_via_route (Region& region, Route& route) route.set_solo (true, this); - session->request_bounded_roll (region.position(), region.position() + region.length()); + session->request_bounded_roll (region->position(), region->position() + region->length()); /* XXX how to unset the solo state ? */ } @@ -2135,7 +2133,7 @@ Editor::audition_selected_region () } void -Editor::audition_playlist_region_standalone (Region& region) +Editor::audition_playlist_region_standalone (boost::shared_ptr region) { session->audition_region (region); } @@ -2185,10 +2183,8 @@ Editor::region_from_selection () jack_nframes_t selection_cnt = end - start + 1; for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { - - AudioRegion *region; - AudioRegion *current; - Region* current_r; + boost::shared_ptr current; + boost::shared_ptr current_r; Playlist *pl; jack_nframes_t internal_start; @@ -2202,18 +2198,18 @@ Editor::region_from_selection () continue; } - current = dynamic_cast (current_r); + current = boost::dynamic_pointer_cast (current_r); assert(current); // FIXME if (current != 0) { internal_start = start - current->position(); session->region_name (new_name, current->name(), true); - region = new AudioRegion (*current, internal_start, selection_cnt, new_name); + boost::shared_ptr region (RegionFactory::create (current, internal_start, selection_cnt, new_name)); } } } void -Editor::create_region_from_selection (vector& new_regions) +Editor::create_region_from_selection (vector >& new_regions) { if (selection->time.empty() || selection->tracks.empty()) { return; @@ -2224,8 +2220,8 @@ Editor::create_region_from_selection (vector& new_regions) for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) { - AudioRegion* current; - Region* current_r; + boost::shared_ptr current; + boost::shared_ptr current_r; Playlist* playlist; jack_nframes_t internal_start; string new_name; @@ -2238,14 +2234,14 @@ Editor::create_region_from_selection (vector& new_regions) continue; } - if ((current = dynamic_cast(current_r)) == 0) { + if ((current = boost::dynamic_pointer_cast(current_r)) == 0) { continue; } internal_start = start - current->position(); session->region_name (new_name, current->name(), true); - new_regions.push_back (new AudioRegion (*current, internal_start, end - start + 1, new_name)); + new_regions.push_back (boost::dynamic_pointer_cast (RegionFactory::create (current, internal_start, end - start + 1, new_name))); } } @@ -2256,11 +2252,11 @@ Editor::split_multichannel_region () AudioRegionView* clicked_arv = dynamic_cast(clicked_regionview); - if (!clicked_arv || clicked_arv->audio_region().n_channels() < 2) { + if (!clicked_arv || clicked_arv->audio_region()->n_channels() < 2) { return; } - clicked_arv->audio_region().separate_by_channel (*session, v); + clicked_arv->audio_region()->separate_by_channel (*session, v); /* nothing else to do, really */ } @@ -2416,7 +2412,7 @@ Editor::crop_region_to_selection () for (vector::iterator i = playlists.begin(); i != playlists.end(); ++i) { - Region *region; + boost::shared_ptr region; start = selection->time.start(); @@ -2457,26 +2453,26 @@ Editor::region_fill_track () for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - Region& region ((*i)->region()); + boost::shared_ptr region ((*i)->region()); // FIXME - AudioRegion* const ar = dynamic_cast(®ion); + boost::shared_ptr ar = boost::dynamic_pointer_cast(region); assert(ar); - Playlist* pl = region.playlist(); + Playlist* pl = region->playlist(); - if (end <= region.last_frame()) { + if (end <= region->last_frame()) { return; } - double times = (double) (end - region.last_frame()) / (double) region.length(); + double times = (double) (end - region->last_frame()) / (double) region->length(); if (times == 0) { return; } XMLNode &before = pl->get_state(); - pl->add_region (*(new AudioRegion (*ar)), ar->last_frame(), times); + pl->add_region (RegionFactory::create (ar), ar->last_frame(), times); session->add_command (new MementoCommand(*pl, &before, &pl->get_state())); } @@ -2494,7 +2490,6 @@ Editor::region_fill_selection () return; } - Region *region; Glib::RefPtr selected = region_list_display.get_selection(); @@ -2503,7 +2498,7 @@ Editor::region_fill_selection () } TreeModel::iterator i = region_list_display.get_selection()->get_selected(); - region = (*i)[region_list_columns.region]; + boost::shared_ptr region = (*i)[region_list_columns.region]; jack_nframes_t start = selection->time[clicked_selection].start; jack_nframes_t end = selection->time[clicked_selection].end; @@ -2526,7 +2521,7 @@ Editor::region_fill_selection () } XMLNode &before = playlist->get_state(); - playlist->add_region (*(createRegion (*region)), start, times); + playlist->add_region (RegionFactory::create (region), start, times); session->add_command (new MementoCommand(*playlist, &before, &playlist->get_state())); } @@ -2534,18 +2529,18 @@ Editor::region_fill_selection () } void -Editor::set_a_regions_sync_position (Region& region, jack_nframes_t position) +Editor::set_a_regions_sync_position (boost::shared_ptr region, jack_nframes_t position) { - if (!region.covers (position)) { + if (!region->covers (position)) { error << _("Programming error. that region doesn't cover that position") << __FILE__ << " +" << __LINE__ << endmsg; return; } begin_reversible_command (_("set region sync position")); - XMLNode &before = region.playlist()->get_state(); - region.set_sync_position (position); - XMLNode &after = region.playlist()->get_state(); - session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); + XMLNode &before = region->playlist()->get_state(); + region->set_sync_position (position); + XMLNode &after = region->playlist()->get_state(); + session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); commit_reversible_command (); } @@ -2556,17 +2551,17 @@ Editor::set_region_sync_from_edit_cursor () return; } - if (!clicked_regionview->region().covers (edit_cursor->current_frame)) { + if (!clicked_regionview->region()->covers (edit_cursor->current_frame)) { error << _("Place the edit cursor at the desired sync point") << endmsg; return; } - Region& region (clicked_regionview->region()); + boost::shared_ptr region (clicked_regionview->region()); begin_reversible_command (_("set sync from edit cursor")); - XMLNode &before = region.playlist()->get_state(); - region.set_sync_position (edit_cursor->current_frame); - XMLNode &after = region.playlist()->get_state(); - session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); + XMLNode &before = region->playlist()->get_state(); + region->set_sync_position (edit_cursor->current_frame); + XMLNode &after = region->playlist()->get_state(); + session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); commit_reversible_command (); } @@ -2574,12 +2569,12 @@ void Editor::remove_region_sync () { if (clicked_regionview) { - Region& region (clicked_regionview->region()); + boost::shared_ptr region (clicked_regionview->region()); begin_reversible_command (_("remove sync")); - XMLNode &before = region.playlist()->get_state(); - region.clear_sync_position (); - XMLNode &after = region.playlist()->get_state(); - session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); + XMLNode &before = region->playlist()->get_state(); + region->clear_sync_position (); + XMLNode &after = region->playlist()->get_state(); + session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); commit_reversible_command (); } } @@ -2592,10 +2587,10 @@ Editor::naturalize () } begin_reversible_command (_("naturalize")); for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - XMLNode &before = (*i)->region().get_state(); - (*i)->region().move_to_natural_position (this); - XMLNode &after = (*i)->region().get_state(); - session->add_command (new MementoCommand((*i)->region(), &before, &after)); + XMLNode &before = (*i)->region()->get_state(); + (*i)->region()->move_to_natural_position (this); + XMLNode &after = (*i)->region()->get_state(); + session->add_command (new MementoCommand(*((*i)->region().get()), &before, &after)); } commit_reversible_command (); } @@ -2614,7 +2609,7 @@ Editor::align_relative (RegionPoint what) struct RegionSortByTime { bool operator() (const RegionView* a, const RegionView* b) { - return a->region().position() < b->region().position(); + return a->region()->position() < b->region()->position(); } }; @@ -2631,19 +2626,19 @@ Editor::align_selection_relative (RegionPoint point, jack_nframes_t position) list sorted; selection->regions.by_position (sorted); - Region& r ((*sorted.begin())->region()); + boost::shared_ptr r ((*sorted.begin())->region()); switch (point) { case Start: - pos = r.first_frame (); + pos = r->first_frame (); break; case End: - pos = r.last_frame(); + pos = r->last_frame(); break; case SyncPoint: - pos = r.adjust_to_sync (r.first_frame()); + pos = r->adjust_to_sync (r->first_frame()); break; } @@ -2659,18 +2654,18 @@ Editor::align_selection_relative (RegionPoint point, jack_nframes_t position) for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - Region& region ((*i)->region()); + boost::shared_ptr region ((*i)->region()); - XMLNode &before = region.playlist()->get_state(); + XMLNode &before = region->playlist()->get_state(); if (dir > 0) { - region.set_position (region.position() + distance, this); + region->set_position (region->position() + distance, this); } else { - region.set_position (region.position() - distance, this); + region->set_position (region->position() - distance, this); } - XMLNode &after = region.playlist()->get_state(); - session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); + XMLNode &after = region->playlist()->get_state(); + session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); } @@ -2694,7 +2689,7 @@ Editor::align_selection (RegionPoint point, jack_nframes_t position) } void -Editor::align_region (Region& region, RegionPoint point, jack_nframes_t position) +Editor::align_region (boost::shared_ptr region, RegionPoint point, jack_nframes_t position) { begin_reversible_command (_("align region")); align_region_internal (region, point, position); @@ -2702,28 +2697,28 @@ Editor::align_region (Region& region, RegionPoint point, jack_nframes_t position } void -Editor::align_region_internal (Region& region, RegionPoint point, jack_nframes_t position) +Editor::align_region_internal (boost::shared_ptr region, RegionPoint point, jack_nframes_t position) { - XMLNode &before = region.playlist()->get_state(); + XMLNode &before = region->playlist()->get_state(); switch (point) { case SyncPoint: - region.set_position (region.adjust_to_sync (position), this); + region->set_position (region->adjust_to_sync (position), this); break; case End: - if (position > region.length()) { - region.set_position (position - region.length(), this); + if (position > region->length()) { + region->set_position (position - region->length(), this); } break; case Start: - region.set_position (position, this); + region->set_position (position, this); break; } - XMLNode &after = region.playlist()->get_state(); - session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); + XMLNode &after = region->playlist()->get_state(); + session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); } void @@ -2733,7 +2728,7 @@ Editor::trim_region_to_edit_cursor () return; } - Region& region (clicked_regionview->region()); + boost::shared_ptr region (clicked_regionview->region()); float speed = 1.0f; AudioTimeAxisView *atav; @@ -2745,10 +2740,10 @@ Editor::trim_region_to_edit_cursor () } begin_reversible_command (_("trim to edit")); - XMLNode &before = region.playlist()->get_state(); - region.trim_end( session_frame_to_track_frame(edit_cursor->current_frame, speed), this); - XMLNode &after = region.playlist()->get_state(); - session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); + XMLNode &before = region->playlist()->get_state(); + region->trim_end( session_frame_to_track_frame(edit_cursor->current_frame, speed), this); + XMLNode &after = region->playlist()->get_state(); + session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); commit_reversible_command (); } @@ -2759,7 +2754,7 @@ Editor::trim_region_from_edit_cursor () return; } - Region& region (clicked_regionview->region()); + boost::shared_ptr region (clicked_regionview->region()); float speed = 1.0f; AudioTimeAxisView *atav; @@ -2771,10 +2766,10 @@ Editor::trim_region_from_edit_cursor () } begin_reversible_command (_("trim to edit")); - XMLNode &before = region.playlist()->get_state(); - region.trim_front ( session_frame_to_track_frame(edit_cursor->current_frame, speed), this); - XMLNode &after = region.playlist()->get_state(); - session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); + XMLNode &before = region->playlist()->get_state(); + region->trim_front ( session_frame_to_track_frame(edit_cursor->current_frame, speed), this); + XMLNode &after = region->playlist()->get_state(); + session->add_command(new MementoCommand(*(region->playlist()), &before, &after)); commit_reversible_command (); } @@ -2999,10 +2994,10 @@ Editor::cut_copy_regions (CutCopyOp op) pair::iterator,bool> insert_result; for (RegionSelection::iterator x = selection->regions.begin(); x != selection->regions.end(); ++x) { - first_position = min ((*x)->region().position(), first_position); + first_position = min ((*x)->region()->position(), first_position); if (op == Cut || op == Clear) { - AudioPlaylist *pl = dynamic_cast((*x)->region().playlist()); + AudioPlaylist *pl = dynamic_cast((*x)->region()->playlist()); if (pl) { insert_result = freezelist.insert (pl); if (insert_result.second) { @@ -3015,7 +3010,7 @@ Editor::cut_copy_regions (CutCopyOp op) for (RegionSelection::iterator x = selection->regions.begin(); x != selection->regions.end(); ) { - AudioPlaylist *pl = dynamic_cast((*x)->region().playlist()); + AudioPlaylist *pl = dynamic_cast((*x)->region()->playlist()); AudioPlaylist* npl; RegionSelection::iterator tmp; @@ -3035,23 +3030,23 @@ Editor::cut_copy_regions (CutCopyOp op) } // FIXME - AudioRegion* const ar = dynamic_cast(&(*x)->region()); + boost::shared_ptr ar = boost::dynamic_pointer_cast((*x)->region()); switch (op) { case Cut: if (!ar) break; - npl->add_region (*(new AudioRegion (*ar)), (*x)->region().position() - first_position); - pl->remove_region (&((*x)->region())); + npl->add_region (RegionFactory::create (ar), (*x)->region()->position() - first_position); + pl->remove_region (((*x)->region())); break; case Copy: if (!ar) break; - npl->add_region (*(new AudioRegion (*ar)), (*x)->region().position() - first_position); + npl->add_region (RegionFactory::create (ar), (*x)->region()->position() - first_position); break; case Clear: - pl->remove_region (&((*x)->region())); + pl->remove_region (((*x)->region())); break; } } @@ -3208,15 +3203,15 @@ Editor::duplicate_some_regions (RegionSelection& regions, float times) for (RegionSelection::iterator i = sel.begin(); i != sel.end(); ++i) { - Region& r ((*i)->region()); + boost::shared_ptr r ((*i)->region()); TimeAxisView& tv = (*i)->get_time_axis_view(); AudioTimeAxisView* atv = dynamic_cast (&tv); sigc::connection c = atv->view()->RegionViewAdded.connect (mem_fun(*this, &Editor::collect_new_region_view)); - playlist = (*i)->region().playlist(); + playlist = (*i)->region()->playlist(); XMLNode &before = playlist->get_state(); - playlist->duplicate (r, r.last_frame(), times); + playlist->duplicate (r, r->last_frame(), times); session->add_command(new MementoCommand(*playlist, &before, &playlist->get_state())); c.disconnect (); @@ -3238,8 +3233,8 @@ Editor::duplicate_selection (float times) } Playlist *playlist; - vector new_regions; - vector::iterator ri; + vector > new_regions; + vector >::iterator ri; create_region_from_selection (new_regions); @@ -3256,7 +3251,7 @@ Editor::duplicate_selection (float times) continue; } XMLNode &before = playlist->get_state(); - playlist->duplicate (**ri, selection->time[clicked_selection].end, times); + playlist->duplicate (*ri, selection->time[clicked_selection].end, times); XMLNode &after = playlist->get_state(); session->add_command (new MementoCommand(*playlist, &before, &after)); @@ -3400,9 +3395,9 @@ Editor::normalize_region () AudioRegionView* const arv = dynamic_cast(*r); if (!arv) continue; - XMLNode &before = arv->region().get_state(); - arv->audio_region().normalize_to (0.0f); - session->add_command (new MementoCommand(arv->region(), &before, &arv->region().get_state())); + XMLNode &before = arv->region()->get_state(); + arv->audio_region()->normalize_to (0.0f); + session->add_command (new MementoCommand(*(arv->region().get()), &before, &arv->region()->get_state())); } commit_reversible_command (); @@ -3427,9 +3422,9 @@ Editor::denormalize_region () AudioRegionView* const arv = dynamic_cast(*r); if (!arv) continue; - XMLNode &before = arv->region().get_state(); - arv->audio_region().set_scale_amplitude (1.0f); - session->add_command (new MementoCommand(arv->region(), &before, &arv->region().get_state())); + XMLNode &before = arv->region()->get_state(); + arv->audio_region()->set_scale_amplitude (1.0f); + session->add_command (new MementoCommand(*(arv->region().get()), &before, &arv->region()->get_state())); } commit_reversible_command (); @@ -3464,17 +3459,17 @@ Editor::apply_filter (AudioFilter& filter, string command) if (!arv) continue; - Playlist* playlist = arv->region().playlist(); + Playlist* playlist = arv->region()->playlist(); RegionSelection::iterator tmp; tmp = r; ++tmp; - if (arv->audio_region().apply (filter) == 0) { + if (arv->audio_region()->apply (filter) == 0) { XMLNode &before = playlist->get_state(); - playlist->replace_region (arv->region(), *(filter.results.front()), arv->region().position()); + playlist->replace_region (arv->region(), filter.results.front(), arv->region()->position()); XMLNode &after = playlist->get_state(); session->add_command(new MementoCommand(*playlist, &before, &after)); } else { @@ -3495,7 +3490,8 @@ void Editor::region_selection_op (void (Region::*pmf)(void)) { for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - ((*i)->region().*pmf)(); + Region* region = (*i)->region().get(); + (region->*pmf)(); } } @@ -3504,7 +3500,8 @@ void Editor::region_selection_op (void (Region::*pmf)(void*), void *arg) { for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - ((*i)->region().*pmf)(arg); + Region* region = (*i)->region().get(); + (region->*pmf)(arg); } } @@ -3512,7 +3509,8 @@ void Editor::region_selection_op (void (Region::*pmf)(bool), bool yn) { for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { - ((*i)->region().*pmf)(yn); + Region* region = (*i)->region().get(); + (region->*pmf)(yn); } } @@ -3563,6 +3561,6 @@ Editor::toggle_gain_envelope_active () for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { AudioRegionView* const arv = dynamic_cast(*i); if (arv) - arv->audio_region().set_envelope_active (true); + arv->audio_region()->set_envelope_active (true); } } diff --git a/gtk2_ardour/editor_region_list.cc b/gtk2_ardour/editor_region_list.cc index 7df91cfa4f..ccfa1c378a 100644 --- a/gtk2_ardour/editor_region_list.cc +++ b/gtk2_ardour/editor_region_list.cc @@ -48,14 +48,14 @@ using namespace Glib; using namespace Editing; void -Editor::handle_region_removed (Region* region) +Editor::handle_region_removed (boost::shared_ptr region) { ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_region_removed), region)); redisplay_regions (); } void -Editor::handle_new_region (Region *region) +Editor::handle_new_region (boost::shared_ptr region) { ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_new_region), region)); @@ -67,7 +67,7 @@ Editor::handle_new_region (Region *region) } void -Editor::region_hidden (Region* r) +Editor::region_hidden (boost::shared_ptr r) { ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::region_hidden), r)); @@ -75,7 +75,7 @@ Editor::region_hidden (Region* r) } void -Editor::add_region_to_region_display (Region *region) +Editor::add_region_to_region_display (boost::shared_ptr region) { string str; TreeModel::Row row; @@ -96,7 +96,7 @@ Editor::add_region_to_region_display (Region *region) parent = *(region_list_model->append()); parent[region_list_columns.name] = _("Hidden"); - parent[region_list_columns.region] = 0; + /// XXX FIX ME parent[region_list_columns.region]->reset (); } else { @@ -104,7 +104,7 @@ Editor::add_region_to_region_display (Region *region) parent = *(region_list_model->insert(iter)); parent[region_list_columns.name] = _("Hidden"); - parent[region_list_columns.region] = 0; + /// XXX FIX ME parent[region_list_columns.region]->reset (); } else { parent = *iter; @@ -120,11 +120,11 @@ Editor::add_region_to_region_display (Region *region) set_color(c, rgba_from_style ("RegionListWholeFile", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false )); row[region_list_columns.color_] = c; - if (region->source().name()[0] == '/') { // external file + if (region->source()->name()[0] == '/') { // external file if (region->whole_file()) { str = ".../"; - str += PBD::basename_nosuffix (region->source().name()); + str += PBD::basename_nosuffix (region->source()->name()); } else { str = region->name(); @@ -151,11 +151,11 @@ Editor::add_region_to_region_display (Region *region) for (i = rows.begin(); i != rows.end(); ++i) { - Region* rr = (*i)[region_list_columns.region]; - AudioRegion* r = dynamic_cast(rr); + boost::shared_ptr rr = (*i)[region_list_columns.region]; + boost::shared_ptr r = boost::dynamic_pointer_cast(rr); if (r && r->whole_file()) { - if (region->source_equivalent (*r)) { + if (region->source_equivalent (r)) { row = *(region_list_model->append ((*i).children())); found_parent = true; break; @@ -200,13 +200,13 @@ Editor::region_list_selection_changed() */ if ((iter = region_list_model->get_iter (*i))) { - set_selected_regionview_from_region_list (*((*iter)[region_list_columns.region]), Selection::Set); + set_selected_regionview_from_region_list (((*iter)[region_list_columns.region]), Selection::Set); } } } void -Editor::insert_into_tmp_regionlist(Region* region) +Editor::insert_into_tmp_regionlist(boost::shared_ptr region) { /* keep all whole files at the beginning */ @@ -232,7 +232,7 @@ Editor::redisplay_regions () tmp_region_list.clear(); session->foreach_region (this, &Editor::insert_into_tmp_regionlist); - for (list::iterator r = tmp_region_list.begin(); r != tmp_region_list.end(); ++r) { + for (list >::iterator r = tmp_region_list.begin(); r != tmp_region_list.end(); ++r) { add_region_to_region_display (*r); } @@ -323,7 +323,7 @@ Editor::region_list_display_key_release (GdkEventKey* ev) bool Editor::region_list_display_button_press (GdkEventButton *ev) { - Region* region; + boost::shared_ptr region; TreeIter iter; TreeModel::Path path; TreeViewColumn* column; @@ -341,7 +341,7 @@ Editor::region_list_display_button_press (GdkEventButton *ev) } if (Keyboard::is_delete_event (ev)) { - session->remove_region_from_region_list (*region); + session->remove_region_from_region_list (region); return true; } @@ -354,7 +354,7 @@ Editor::region_list_display_button_press (GdkEventButton *ev) case 1: /* audition on double click */ if (ev->type == GDK_2BUTTON_PRESS) { - consider_auditioning (*region); + consider_auditioning (region); return true; } return false; @@ -362,7 +362,7 @@ Editor::region_list_display_button_press (GdkEventButton *ev) case 2: if (!Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) { - consider_auditioning (*region); + consider_auditioning (region); } return true; break; @@ -382,7 +382,7 @@ Editor::region_list_display_button_release (GdkEventButton *ev) TreeViewColumn* column; int cellx; int celly; - Region* region = 0; + boost::shared_ptr region; if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) { if ((iter = region_list_model->get_iter (path))) { @@ -391,7 +391,7 @@ Editor::region_list_display_button_release (GdkEventButton *ev) } if (region && Keyboard::is_delete_event (ev)) { - session->remove_region_from_region_list (*region); + session->remove_region_from_region_list (region); return true; } @@ -399,9 +399,9 @@ Editor::region_list_display_button_release (GdkEventButton *ev) } void -Editor::consider_auditioning (Region& region) +Editor::consider_auditioning (boost::shared_ptr region) { - AudioRegion* r = dynamic_cast (®ion); + boost::shared_ptr r = boost::dynamic_pointer_cast (region); if (r == 0) { session->cancel_audition (); @@ -415,7 +415,7 @@ Editor::consider_auditioning (Region& region) } } - session->audition_region (*r); + session->audition_region (r); last_audition_region = r; } @@ -424,8 +424,8 @@ Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b) { int cmp = 0; - Region* r1 = (*a)[region_list_columns.region]; - Region* r2 = (*b)[region_list_columns.region]; + boost::shared_ptr r1 = (*a)[region_list_columns.region]; + boost::shared_ptr r2 = (*b)[region_list_columns.region]; /* handle rows without regions, like "Hidden" */ @@ -437,8 +437,8 @@ Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b) return 1; } - AudioRegion* region1 = dynamic_cast (r1); - AudioRegion* region2 = dynamic_cast (r2); + boost::shared_ptr region1 = boost::dynamic_pointer_cast (r1); + boost::shared_ptr region2 = boost::dynamic_pointer_cast (r2); if (region1 == 0 || region2 == 0) { Glib::ustring s1; @@ -467,7 +467,7 @@ Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b) break; case ByTimestamp: - cmp = region1->source().timestamp() - region2->source().timestamp(); + cmp = region1->source()->timestamp() - region2->source()->timestamp(); break; case ByStartInFile: @@ -479,22 +479,22 @@ Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b) break; case BySourceFileName: - cmp = strcasecmp (region1->source().name().c_str(), region2->source().name().c_str()); + cmp = strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str()); break; case BySourceFileLength: - cmp = region1->source().length() - region2->source().length(); + cmp = region1->source()->length() - region2->source()->length(); break; case BySourceFileCreationDate: - cmp = region1->source().timestamp() - region2->source().timestamp(); + cmp = region1->source()->timestamp() - region2->source()->timestamp(); break; case BySourceFileFS: - if (region1->source().name() == region2->source().name()) { + if (region1->source()->name() == region2->source()->name()) { cmp = strcasecmp (region1->name().c_str(), region2->name().c_str()); } else { - cmp = strcasecmp (region1->source().name().c_str(), region2->source().name().c_str()); + cmp = strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str()); } break; } @@ -524,7 +524,7 @@ Editor::reset_region_list_sort_direction (bool up) } void -Editor::region_list_selection_mapover (slot sl) +Editor::region_list_selection_mapover (slot > sl) { Glib::RefPtr selection = region_list_display.get_selection(); TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows (); @@ -538,19 +538,19 @@ Editor::region_list_selection_mapover (slot sl) TreeIter iter; if ((iter = region_list_model->get_iter (*i))) { - sl (*((*iter)[region_list_columns.region])); + sl (((*iter)[region_list_columns.region])); } } } void -Editor::hide_a_region (Region& r) +Editor::hide_a_region (boost::shared_ptr r) { - r.set_hidden (true); + r->set_hidden (true); } void -Editor::remove_a_region (Region& r) +Editor::remove_a_region (boost::shared_ptr r) { session->remove_region_from_region_list (r); } @@ -593,5 +593,7 @@ Editor::region_list_selection_filter (const RefPtr& model, const Tree { /* not possible to select rows that do not represent regions, like "Hidden" */ - return (*(model->get_iter (path)))[region_list_columns.region] != 0; + /// XXXX FIXME boost::shared_ptr r = ((model->get_iter (path)))[region_list_columns.region]; + /// return r != 0; + return true; } diff --git a/gtk2_ardour/editor_timefx.cc b/gtk2_ardour/editor_timefx.cc index caa9698b8c..188960c962 100644 --- a/gtk2_ardour/editor_timefx.cc +++ b/gtk2_ardour/editor_timefx.cc @@ -160,21 +160,18 @@ Editor::do_timestretch (TimeStretchDialog& dialog) { Track* t; Playlist* playlist; - Region* new_region; - + boost::shared_ptr new_region; for (RegionSelection::iterator i = dialog.regions.begin(); i != dialog.regions.end(); ) { AudioRegionView* arv = dynamic_cast(*i); if (!arv) continue; - AudioRegion& region (arv->audio_region()); + boost::shared_ptr region (arv->audio_region()); TimeAxisView* tv = &(arv->get_time_axis_view()); RouteTimeAxisView* rtv; RegionSelection::iterator tmp; - cerr << "stretch " << region.name() << endl; - tmp = i; ++tmp; @@ -193,7 +190,7 @@ Editor::do_timestretch (TimeStretchDialog& dialog) continue; } - dialog.request.region = ®ion; + dialog.request.region = region; if (!dialog.request.running) { /* we were cancelled */ @@ -208,7 +205,7 @@ Editor::do_timestretch (TimeStretchDialog& dialog) } XMLNode &before = playlist->get_state(); - playlist->replace_region (region, *new_region, region.position()); + playlist->replace_region (region, new_region, region->position()); XMLNode &after = playlist->get_state(); session->add_command (new MementoCommand(*playlist, &before, &after)); @@ -217,6 +214,7 @@ Editor::do_timestretch (TimeStretchDialog& dialog) dialog.status = 0; dialog.request.running = false; + dialog.request.region.reset (); } void* diff --git a/gtk2_ardour/export_dialog.cc b/gtk2_ardour/export_dialog.cc index bf7873914d..730da46673 100644 --- a/gtk2_ardour/export_dialog.cc +++ b/gtk2_ardour/export_dialog.cc @@ -392,7 +392,7 @@ void ExportDialog::connect_to_session (Session *s) { session = s; - session->going_away.connect (mem_fun(*this, &Window::hide_all)); + session->GoingAway.connect (mem_fun(*this, &Window::hide_all)); switch (session->frame_rate()) { case 22050: diff --git a/gtk2_ardour/export_region_dialog.cc b/gtk2_ardour/export_region_dialog.cc index 1964fabbfe..3ed282761d 100644 --- a/gtk2_ardour/export_region_dialog.cc +++ b/gtk2_ardour/export_region_dialog.cc @@ -28,11 +28,10 @@ #include "i18n.h" -ExportRegionDialog::ExportRegionDialog (PublicEditor& editor, ARDOUR::Region* region) +ExportRegionDialog::ExportRegionDialog (PublicEditor& editor, boost::shared_ptr region) : ExportDialog(editor) { - // FIXME - ARDOUR::AudioRegion* audio_region = dynamic_cast(region); + boost::shared_ptr audio_region = boost::dynamic_pointer_cast(region); assert(audio_region); do_not_allow_track_and_master_selection(); diff --git a/gtk2_ardour/export_region_dialog.h b/gtk2_ardour/export_region_dialog.h index e8afe97d6b..a0457b7331 100644 --- a/gtk2_ardour/export_region_dialog.h +++ b/gtk2_ardour/export_region_dialog.h @@ -27,7 +27,7 @@ class ExportRegionDialog : public ExportDialog { public: - ExportRegionDialog (PublicEditor&, ARDOUR::Region*); + ExportRegionDialog (PublicEditor&, boost::shared_ptr); static void* _export_region_thread (void *); void export_region (); @@ -36,7 +36,7 @@ class ExportRegionDialog : public ExportDialog void export_audio_data(); private: - ARDOUR::AudioRegion* audio_region; + boost::shared_ptr audio_region; }; diff --git a/gtk2_ardour/io_selector.cc b/gtk2_ardour/io_selector.cc index f9082c3ef0..e53bd2fb02 100644 --- a/gtk2_ardour/io_selector.cc +++ b/gtk2_ardour/io_selector.cc @@ -21,6 +21,8 @@ #include #include +#include + #include #include @@ -839,9 +841,9 @@ PortInsertWindow::PortInsertWindow (Session& sess, boost::shared_ptr } void -PortInsertWindow::plugin_going_away (ARDOUR::Redirect* ignored) +PortInsertWindow::plugin_going_away () { - ENSURE_GUI_THREAD(bind (mem_fun(*this, &PortInsertWindow::plugin_going_away), ignored)); + ENSURE_GUI_THREAD(mem_fun(*this, &PortInsertWindow::plugin_going_away)); delete_when_idle (this); } diff --git a/gtk2_ardour/io_selector.h b/gtk2_ardour/io_selector.h index 993d4aa1ad..b0175644a4 100644 --- a/gtk2_ardour/io_selector.h +++ b/gtk2_ardour/io_selector.h @@ -198,7 +198,7 @@ class PortInsertWindow : public ArdourDialog void cancel (); void accept (); - void plugin_going_away (ARDOUR::Redirect*); + void plugin_going_away (); }; diff --git a/gtk2_ardour/location_ui.cc b/gtk2_ardour/location_ui.cc index 12e7079de2..125ed8df5d 100644 --- a/gtk2_ardour/location_ui.cc +++ b/gtk2_ardour/location_ui.cc @@ -836,7 +836,7 @@ LocationUI::set_session(ARDOUR::Session* sess) session->locations()->StateChanged.connect (mem_fun(*this, &LocationUI::refresh_location_list_s)); session->locations()->added.connect (mem_fun(*this, &LocationUI::location_added)); session->locations()->removed.connect (mem_fun(*this, &LocationUI::location_removed)); - session->going_away.connect (mem_fun(*this, &LocationUI::session_gone)); + session->GoingAway.connect (mem_fun(*this, &LocationUI::session_gone)); } refresh_location_list (); } diff --git a/gtk2_ardour/meter_bridge.cc b/gtk2_ardour/meter_bridge.cc index 65434d5e82..b871561563 100644 --- a/gtk2_ardour/meter_bridge.cc +++ b/gtk2_ardour/meter_bridge.cc @@ -101,7 +101,7 @@ MeterBridge::set_session (Session *s) // (refs vs. ptrs) // session->foreach_route (this, &MeterBridge::add_route); session->RouteAdded.connect (mem_fun(*this, &MeterBridge::add_route)); - session->going_away.connect (mem_fun(*this, &MeterBridge::session_gone)); + session->GoingAway.connect (mem_fun(*this, &MeterBridge::session_gone)); start_metering (); } } @@ -171,7 +171,7 @@ MeterBridge::add_route (ARDOUR::Route* route) meter->set_meter_on(true); - session->going_away.connect (mem_fun(*this, &MeterBridge::session_gone)); + session->GoingAway.connect (mem_fun(*this, &MeterBridge::session_gone)); } void diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 2e102b4f70..c225295f13 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -50,13 +50,13 @@ using namespace PBD; using namespace Editing; using namespace ArdourCanvas; -MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, MidiRegion& r, double spu, +MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr r, double spu, Gdk::Color& basic_color) : RegionView (parent, tv, r, spu, basic_color) { } -MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, MidiRegion& r, double spu, +MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr r, double spu, Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility) : RegionView (parent, tv, r, spu, basic_color, visibility) { @@ -73,7 +73,7 @@ MidiRegionView::init (Gdk::Color& basic_color, bool wfd) compute_colors (basic_color); - reset_width_dependent_items ((double) _region.length() / samples_per_unit); + reset_width_dependent_items ((double) _region->length() / samples_per_unit); set_height (trackview.height); @@ -81,7 +81,7 @@ MidiRegionView::init (Gdk::Color& basic_color, bool wfd) region_resized (BoundsChanged); region_locked (); - _region.StateChanged.connect (mem_fun(*this, &MidiRegionView::region_changed)); + _region->StateChanged.connect (mem_fun(*this, &MidiRegionView::region_changed)); set_colors (); } @@ -93,11 +93,11 @@ MidiRegionView::~MidiRegionView () RegionViewGoingAway (this); /* EMIT_SIGNAL */ } -ARDOUR::MidiRegion& +boost::shared_ptr MidiRegionView::midi_region() const { // "Guaranteed" to succeed... - return dynamic_cast(_region); + return boost::dynamic_pointer_cast(_region); } void diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index 3161d0eb05..03bd0b1cf7 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -46,16 +46,16 @@ class MidiRegionView : public RegionView { public: MidiRegionView (ArdourCanvas::Group *, - RouteTimeAxisView&, - ARDOUR::MidiRegion&, - double initial_samples_per_unit, - Gdk::Color& basic_color); + RouteTimeAxisView&, + boost::shared_ptr, + double initial_samples_per_unit, + Gdk::Color& basic_color); ~MidiRegionView (); virtual void init (Gdk::Color& base_color, bool wait_for_data = false); - ARDOUR::MidiRegion& midi_region() const; + boost::shared_ptr midi_region() const; void show_region_editor (); @@ -69,11 +69,11 @@ class MidiRegionView : public RegionView */ MidiRegionView (ArdourCanvas::Group *, - RouteTimeAxisView&, - ARDOUR::MidiRegion&, - double samples_per_unit, - Gdk::Color& basic_color, - TimeAxisViewItem::Visibility); + RouteTimeAxisView&, + boost::shared_ptr, + double samples_per_unit, + Gdk::Color& basic_color, + TimeAxisViewItem::Visibility); void region_moved (void *); diff --git a/gtk2_ardour/midi_streamview.cc b/gtk2_ardour/midi_streamview.cc index 47148446eb..94d2a397cf 100644 --- a/gtk2_ardour/midi_streamview.cc +++ b/gtk2_ardour/midi_streamview.cc @@ -28,8 +28,8 @@ #include #include #include -//#include -#include +#include +#include #include "midi_streamview.h" #include "region_view.h" @@ -70,11 +70,11 @@ MidiStreamView::~MidiStreamView () void -MidiStreamView::add_region_view_internal (Region *r, bool wait_for_waves) +MidiStreamView::add_region_view_internal (boost::shared_ptr r, bool wait_for_waves) { ENSURE_GUI_THREAD (bind (mem_fun (*this, &MidiStreamView::add_region_view), r)); - MidiRegion* region = dynamic_cast (r); + boost::shared_ptr region = boost::dynamic_pointer_cast (r); if (region == 0) { return; @@ -84,7 +84,7 @@ MidiStreamView::add_region_view_internal (Region *r, bool wait_for_waves) list::iterator i; for (i = region_views.begin(); i != region_views.end(); ++i) { - if (&(*i)->region() == r) { + if ((*i)->region() == r) { /* great. we already have a MidiRegionView for this Region. use it again. */ @@ -96,7 +96,7 @@ MidiStreamView::add_region_view_internal (Region *r, bool wait_for_waves) // can't we all just get along? assert(_trackview.midi_track()->mode() != Destructive); - region_view = new MidiRegionView (canvas_group, _trackview, *region, + region_view = new MidiRegionView (canvas_group, _trackview, region, _samples_per_unit, region_color); region_view->init (region_color, wait_for_waves); @@ -109,7 +109,7 @@ MidiStreamView::add_region_view_internal (Region *r, bool wait_for_waves) /* catch regionview going away */ - region->GoingAway.connect (mem_fun (*this, &MidiStreamView::remove_region_view)); + region->GoingAway.connect (bind (mem_fun (*this, &MidiStreamView::remove_region_view), region)); RegionViewAdded (region_view); } @@ -167,7 +167,7 @@ MidiStreamView::setup_rec_box () boost::shared_ptr mds = boost::dynamic_pointer_cast(_trackview.get_diskstream()); assert(mds); - sources.push_back((Source*)mds->write_source()); + 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), mds->write_source()))); @@ -178,11 +178,13 @@ MidiStreamView::setup_rec_box () start = rec_regions.back()->start() + _trackview.get_diskstream()->get_captured_frames(rec_regions.size()-1); } - MidiRegion * region = new MidiRegion(sources, start, 1 , "", 0, (Region::Flag)(Region::DefaultFlags | Region::DoNotSaveState), false); + boost::shared_ptr region (boost::dynamic_pointer_cast + (RegionFactory::create (sources, start, 1 , "", 0, (Region::Flag)(Region::DefaultFlags | Region::DoNotSaveState), false))); + assert(region); region->set_position (_trackview.session().transport_frame(), this); rec_regions.push_back (region); /* catch it if it goes away */ - region->GoingAway.connect (mem_fun (*this, &MidiStreamView::remove_rec_region)); + region->GoingAway.connect (bind (mem_fun (*this, &MidiStreamView::remove_rec_region), region)); /* we add the region later */ } @@ -250,23 +252,9 @@ MidiStreamView::setup_rec_box () last_rec_data_frame = 0; /* remove temp regions */ - for (list::iterator iter=rec_regions.begin(); iter != rec_regions.end(); ) - { - list::iterator tmp; - - tmp = iter; - ++tmp; - - /* this will trigger the remove_region_view */ - delete *iter; - - iter = tmp; - } - rec_regions.clear(); // cerr << "\tclear " << rec_rects.size() << " rec rects\n"; - /* transport stopped, clear boxes */ for (vector::iterator iter=rec_rects.begin(); iter != rec_rects.end(); ++iter) { @@ -288,9 +276,9 @@ MidiStreamView::update_rec_regions () uint32_t n = 0; - for (list::iterator iter = rec_regions.begin(); iter != rec_regions.end(); n++) { + for (list >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); n++) { - list::iterator tmp; + list >::iterator tmp; tmp = iter; ++tmp; @@ -301,8 +289,7 @@ MidiStreamView::update_rec_regions () continue; } - // FIXME? - MidiRegion * region = dynamic_cast(*iter); + boost::shared_ptr region = boost::dynamic_pointer_cast(*iter); assert(region); jack_nframes_t origlen = region->length(); @@ -338,7 +325,7 @@ MidiStreamView::update_rec_regions () if (nlen != region->length()) { - if (region->source(0).length() >= region->start() + nlen) { + if (region->source(0)->length() >= region->start() + nlen) { region->freeze (); region->set_position (_trackview.get_diskstream()->get_capture_start_frame(n), this); @@ -364,7 +351,7 @@ MidiStreamView::update_rec_regions () } void -MidiStreamView::rec_data_range_ready (jack_nframes_t start, jack_nframes_t cnt, Source * src) +MidiStreamView::rec_data_range_ready (jack_nframes_t start, jack_nframes_t cnt, boost::shared_ptr src) { // this is called from the butler thread for now // yeah we need a "peak" building thread or something, though there's not really any diff --git a/gtk2_ardour/midi_streamview.h b/gtk2_ardour/midi_streamview.h index 107a804db8..39ae510ed8 100644 --- a/gtk2_ardour/midi_streamview.h +++ b/gtk2_ardour/midi_streamview.h @@ -62,12 +62,10 @@ class MidiStreamView : public StreamView private: void setup_rec_box (); - void rec_data_range_ready (jack_nframes_t start, jack_nframes_t cnt, ARDOUR::Source* src); + void rec_data_range_ready (jack_nframes_t start, jack_nframes_t cnt, boost::shared_ptr src); void update_rec_regions (); - void add_region_view_internal (ARDOUR::Region*, bool wait_for_waves); - void remove_midi_region_view (ARDOUR::MidiRegion* ); - void remove_midi_rec_region (ARDOUR::MidiRegion*); + void add_region_view_internal (boost::shared_ptr, bool wait_for_waves); void redisplay_diskstream (); diff --git a/gtk2_ardour/mixer_ui.cc b/gtk2_ardour/mixer_ui.cc index 84fade5472..9bc5f3d1a0 100644 --- a/gtk2_ardour/mixer_ui.cc +++ b/gtk2_ardour/mixer_ui.cc @@ -353,7 +353,7 @@ Mixer_UI::connect_to_session (Session* sess) initial_track_display (); - session->going_away.connect (mem_fun(*this, &Mixer_UI::disconnect_from_session)); + session->GoingAway.connect (mem_fun(*this, &Mixer_UI::disconnect_from_session)); session->RouteAdded.connect (mem_fun(*this, &Mixer_UI::add_strip)); session->mix_group_added.connect (mem_fun(*this, &Mixer_UI::add_mix_group)); session->mix_group_removed.connect (mem_fun(*this, &Mixer_UI::mix_groups_changed)); diff --git a/gtk2_ardour/playlist_selector.cc b/gtk2_ardour/playlist_selector.cc index 68227d193c..ffeaf8f5e9 100644 --- a/gtk2_ardour/playlist_selector.cc +++ b/gtk2_ardour/playlist_selector.cc @@ -205,7 +205,7 @@ PlaylistSelector::set_session (Session* s) session = s; if (session) { - session->going_away.connect (bind (mem_fun(*this, &PlaylistSelector::set_session), static_cast (0))); + session->GoingAway.connect (bind (mem_fun(*this, &PlaylistSelector::set_session), static_cast (0))); } } diff --git a/gtk2_ardour/plugin_selector.cc b/gtk2_ardour/plugin_selector.cc index 6c72767b11..69f6f56690 100644 --- a/gtk2_ardour/plugin_selector.cc +++ b/gtk2_ardour/plugin_selector.cc @@ -244,7 +244,7 @@ PluginSelector::set_session (Session* s) session = s; if (session) { - session->going_away.connect (bind (mem_fun(*this, &PluginSelector::set_session), static_cast (0))); + session->GoingAway.connect (bind (mem_fun(*this, &PluginSelector::set_session), static_cast (0))); } } diff --git a/gtk2_ardour/plugin_ui.cc b/gtk2_ardour/plugin_ui.cc index 4619d50359..b19a9f74eb 100644 --- a/gtk2_ardour/plugin_ui.cc +++ b/gtk2_ardour/plugin_ui.cc @@ -131,9 +131,9 @@ PluginUIWindow::on_key_release_event (GdkEventKey* event) } void -PluginUIWindow::plugin_going_away (ARDOUR::Redirect* ignored) +PluginUIWindow::plugin_going_away () { - ENSURE_GUI_THREAD(bind (mem_fun(*this, &PluginUIWindow::plugin_going_away), ignored)); + ENSURE_GUI_THREAD(mem_fun(*this, &PluginUIWindow::plugin_going_away)); _pluginui->stop_updating(0); delete_when_idle (this); diff --git a/gtk2_ardour/plugin_ui.h b/gtk2_ardour/plugin_ui.h index fd5516cee1..c1d538b3d1 100644 --- a/gtk2_ardour/plugin_ui.h +++ b/gtk2_ardour/plugin_ui.h @@ -207,7 +207,7 @@ class PluginUIWindow : public ArdourDialog private: PlugUIBase* _pluginui; - void plugin_going_away (ARDOUR::Redirect*); + void plugin_going_away (); }; #ifdef VST_SUPPORT diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index cb3d62f625..a37e33bede 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -11,6 +11,8 @@ #include #include +#include + #include "editing.h" #include "keyboard_target.h" #include "canvas.h" @@ -52,7 +54,7 @@ class ImageFrameView; class ImageFrameTimeAxis; class MarkerView; -class PublicEditor : public Gtk::Window, public Stateful { +class PublicEditor : public Gtk::Window, public PBD::StatefulDestructible { public: PublicEditor(); virtual ~PublicEditor(); @@ -76,7 +78,7 @@ class PublicEditor : public Gtk::Window, public Stateful { virtual void connect_to_image_compositor() = 0; virtual void scroll_timeaxis_to_imageframe_item(const TimeAxisViewItem* item) = 0; virtual TimeAxisView* get_named_time_axis(const string & name) = 0; - virtual void consider_auditioning (ARDOUR::Region&) = 0; + virtual void consider_auditioning (boost::shared_ptr) = 0; virtual void set_show_waveforms (bool yn) = 0; virtual bool show_waveforms() const = 0; virtual void set_show_waveforms_recording (bool yn) = 0; diff --git a/gtk2_ardour/region_gain_line.cc b/gtk2_ardour/region_gain_line.cc index e2b1d6c826..467f24bd94 100644 --- a/gtk2_ardour/region_gain_line.cc +++ b/gtk2_ardour/region_gain_line.cc @@ -47,9 +47,9 @@ void AudioRegionGainLine::start_drag (ControlPoint* cp, float fraction) { AutomationLine::start_drag(cp,fraction); - if (!rv.audio_region().envelope_active()) { - trackview.session().add_command(new MementoCommand(rv.audio_region(), &rv.audio_region().get_state(), 0)); - rv.audio_region().set_envelope_active(false); + if (!rv.audio_region()->envelope_active()) { + trackview.session().add_command(new MementoCommand(*(rv.audio_region().get()), &rv.audio_region()->get_state(), 0)); + rv.audio_region()->set_envelope_active(false); } } @@ -64,11 +64,11 @@ AudioRegionGainLine::remove_point (ControlPoint& cp) trackview.editor.current_session()->begin_reversible_command (_("remove control point")); XMLNode &before = get_state(); - if (!rv.audio_region().envelope_active()) { - XMLNode &before = rv.audio_region().get_state(); - rv.audio_region().set_envelope_active(true); - XMLNode &after = rv.audio_region().get_state(); - trackview.session().add_command(new MementoCommand(rv.audio_region(), &before, &after)); + if (!rv.audio_region()->envelope_active()) { + XMLNode &before = rv.audio_region()->get_state(); + rv.audio_region()->set_envelope_active(true); + XMLNode &after = rv.audio_region()->get_state(); + trackview.session().add_command(new MementoCommand(*(rv.audio_region().get()), &before, &after)); } alist.erase (mr.start, mr.end); @@ -81,9 +81,9 @@ AudioRegionGainLine::remove_point (ControlPoint& cp) void AudioRegionGainLine::end_drag (ControlPoint* cp) { - if (!rv.audio_region().envelope_active()) { - rv.audio_region().set_envelope_active(true); - trackview.session().add_command(new MementoCommand(rv.audio_region(), 0, &rv.audio_region().get_state())); + if (!rv.audio_region()->envelope_active()) { + rv.audio_region()->set_envelope_active(true); + trackview.session().add_command(new MementoCommand(*(rv.audio_region().get()), 0, &rv.audio_region()->get_state())); } AutomationLine::end_drag(cp); } diff --git a/gtk2_ardour/region_selection.cc b/gtk2_ardour/region_selection.cc index f8c9f384a9..7f7148d2b1 100644 --- a/gtk2_ardour/region_selection.cc +++ b/gtk2_ardour/region_selection.cc @@ -102,12 +102,12 @@ RegionSelection::add (RegionView* rv, bool dosort) rv->RegionViewGoingAway.connect (mem_fun(*this, &RegionSelection::remove_it)); - if (rv->region().first_frame() < _current_start || empty()) { - _current_start = rv->region().first_frame(); + if (rv->region()->first_frame() < _current_start || empty()) { + _current_start = rv->region()->first_frame(); } - if (rv->region().last_frame() > _current_end || empty()) { - _current_end = rv->region().last_frame(); + if (rv->region()->last_frame() > _current_end || empty()) { + _current_end = rv->region()->last_frame(); } insert (rv); @@ -142,17 +142,17 @@ RegionSelection::remove (RegionView* rv) } else { - Region& region ((*i)->region()); + boost::shared_ptr region ((*i)->region()); - if (region.first_frame() == _current_start) { + if (region->first_frame() == _current_start) { /* reset current start */ jack_nframes_t ref = max_frames; for (i = begin (); i != end(); ++i) { - if (region.first_frame() < ref) { - ref = region.first_frame(); + if (region->first_frame() < ref) { + ref = region->first_frame(); } } @@ -160,15 +160,15 @@ RegionSelection::remove (RegionView* rv) } - if (region.last_frame() == _current_end) { + if (region->last_frame() == _current_end) { /* reset current end */ jack_nframes_t ref = 0; for (i = begin (); i != end(); ++i) { - if (region.first_frame() > ref) { - ref = region.first_frame(); + if (region->first_frame() > ref) { + ref = region->first_frame(); } } @@ -191,7 +191,7 @@ RegionSelection::add_to_layer (RegionView * rv) for (i = _bylayer.begin(); i != _bylayer.end(); ++i) { - if (rv->region().layer() < (*i)->region().layer()) { + if (rv->region()->layer() < (*i)->region()->layer()) { _bylayer.insert(i, rv); return; } @@ -203,7 +203,7 @@ RegionSelection::add_to_layer (RegionView * rv) struct RegionSortByTime { bool operator() (const RegionView* a, const RegionView* b) { - return a->region().position() < b->region().position(); + return a->region()->position() < b->region()->position(); } }; diff --git a/gtk2_ardour/region_view.cc b/gtk2_ardour/region_view.cc index 68676fe85c..702c328ecd 100644 --- a/gtk2_ardour/region_view.cc +++ b/gtk2_ardour/region_view.cc @@ -59,33 +59,33 @@ sigc::signal RegionView::RegionViewGoingAway; RegionView::RegionView (ArdourCanvas::Group* parent, TimeAxisView& tv, - ARDOUR::Region& r, + boost::shared_ptr r, double spu, Gdk::Color& basic_color) - : TimeAxisViewItem (r.name(), *parent, tv, spu, basic_color, r.position(), r.length(), - TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText| - TimeAxisViewItem::ShowNameHighlight| - TimeAxisViewItem::ShowFrame)) - , _region (r) - , sync_mark(0) - , no_wave_msg(0) - , editor(0) - , current_visible_sync_position(0.0) - , valid(false) - , _pixel_width(1.0) - , _height(1.0) - , in_destructor(false) - , wait_for_data(false) + : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), + TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowNameText| + TimeAxisViewItem::ShowNameHighlight| + TimeAxisViewItem::ShowFrame)) + , _region (r) + , sync_mark(0) + , no_wave_msg(0) + , editor(0) + , current_visible_sync_position(0.0) + , valid(false) + , _pixel_width(1.0) + , _height(1.0) + , in_destructor(false) + , wait_for_data(false) { } RegionView::RegionView (ArdourCanvas::Group* parent, TimeAxisView& tv, - ARDOUR::Region& r, + boost::shared_ptr r, double spu, Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility) - : TimeAxisViewItem (r.name(), *parent, tv, spu, basic_color, r.position(), r.length(), visibility) + : TimeAxisViewItem (r->name(), *parent, tv, spu, basic_color, r->position(), r->length(), visibility) , _region (r) , sync_mark(0) , no_wave_msg(0) @@ -129,7 +129,7 @@ RegionView::init (Gdk::Color& basic_color, bool wfd) sync_mark->property_fill_color_rgba() = fill_color; sync_mark->hide(); - reset_width_dependent_items ((double) _region.length() / samples_per_unit); + reset_width_dependent_items ((double) _region->length() / samples_per_unit); set_height (trackview.height); @@ -138,7 +138,7 @@ RegionView::init (Gdk::Color& basic_color, bool wfd) region_resized (BoundsChanged); region_locked (); - _region.StateChanged.connect (mem_fun(*this, &RegionView::region_changed)); + _region->StateChanged.connect (mem_fun(*this, &RegionView::region_changed)); group->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_event), group, this)); name_highlight->signal_event().connect (bind (mem_fun (PublicEditor::instance(), &PublicEditor::canvas_region_view_name_highlight_event), name_highlight, this)); @@ -182,7 +182,7 @@ RegionView::_lock_toggle (ArdourCanvas::Item* item, GdkEvent* ev, void* arg) void RegionView::lock_toggle () { - _region.set_locked (!_region.locked()); + _region->set_locked (!_region->locked()); } void @@ -227,14 +227,14 @@ RegionView::region_resized (Change what_changed) double unit_length; if (what_changed & ARDOUR::PositionChanged) { - set_position (_region.position(), 0); + set_position (_region->position(), 0); } if (what_changed & Change (StartChanged|LengthChanged)) { - set_duration (_region.length(), 0); + set_duration (_region->length(), 0); - unit_length = _region.length() / samples_per_unit; + unit_length = _region->length() / samples_per_unit; reset_width_dependent_items (unit_length); @@ -285,25 +285,25 @@ RegionView::region_opacity () void RegionView::raise () { - _region.raise (); + _region->raise (); } void RegionView::raise_to_top () { - _region.raise_to_top (); + _region->raise_to_top (); } void RegionView::lower () { - _region.lower (); + _region->lower (); } void RegionView::lower_to_bottom () { - _region.lower_to_bottom (); + _region->lower_to_bottom (); } bool @@ -336,7 +336,7 @@ RegionView::set_samples_per_unit (gdouble spu) for (vector::iterator i = ghosts.begin(); i != ghosts.end(); ++i) { (*i)->set_samples_per_unit (spu); - (*i)->set_duration (_region.length() / samples_per_unit); + (*i)->set_duration (_region->length() / samples_per_unit); } region_sync_changed (); @@ -350,7 +350,7 @@ RegionView::set_duration (jack_nframes_t frames, void *src) } for (vector::iterator i = ghosts.begin(); i != ghosts.end(); ++i) { - (*i)->set_duration (_region.length() / samples_per_unit); + (*i)->set_duration (_region->length() / samples_per_unit); } return true; @@ -375,7 +375,7 @@ RegionView::set_colors () void RegionView::set_frame_color () { - if (_region.opaque()) { + if (_region->opaque()) { fill_opacity = 180; } else { fill_opacity = 100; @@ -397,15 +397,18 @@ RegionView::region_renamed () { string str; - if (_region.locked()) { + if (_region->locked()) { str += '>'; - str += _region.name(); + str += _region->name(); str += '<'; } else { - str = _region.name(); + str = _region->name(); } - if (_region.muted()) { + // speed mismatch handled in audio_region_view.cc + // FIXME: come up with more elegant solution for this + + if (_region->muted()) { str = string ("!") + str; } @@ -423,10 +426,10 @@ RegionView::region_sync_changed () int sync_dir; jack_nframes_t sync_offset; - sync_offset = _region.sync_offset (sync_dir); + sync_offset = _region->sync_offset (sync_dir); /* this has to handle both a genuine change of position, a change of samples_per_unit, - and a change in the bounds of the _region. + and a change in the bounds of the _region-> */ if (sync_offset == 0) { @@ -437,7 +440,7 @@ RegionView::region_sync_changed () } else { - if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region.length()))) { + if ((sync_dir < 0) || ((sync_dir > 0) && (sync_offset > _region->length()))) { /* no sync mark - its out of the bounds of the region */ @@ -466,7 +469,7 @@ RegionView::region_sync_changed () void RegionView::move (double x_delta, double y_delta) { - if (_region.locked() || (x_delta == 0 && y_delta == 0)) { + if (_region->locked() || (x_delta == 0 && y_delta == 0)) { return; } diff --git a/gtk2_ardour/region_view.h b/gtk2_ardour/region_view.h index beb4f10d54..c7d113d17d 100644 --- a/gtk2_ardour/region_view.h +++ b/gtk2_ardour/region_view.h @@ -43,7 +43,7 @@ class RegionView : public TimeAxisViewItem public: RegionView (ArdourCanvas::Group* parent, TimeAxisView& time_view, - ARDOUR::Region& region, + boost::shared_ptr region, double samples_per_unit, Gdk::Color& basic_color); @@ -51,7 +51,7 @@ class RegionView : public TimeAxisViewItem virtual void init (Gdk::Color& base_color, bool wait_for_data); - ARDOUR::Region& region() const { return _region; } + boost::shared_ptr region() const { return _region; } bool is_valid() const { return valid; } void set_valid (bool yn) { valid = yn; } @@ -91,30 +91,12 @@ class RegionView : public TimeAxisViewItem * to the TimeAxisViewItem parent class */ RegionView (ArdourCanvas::Group *, - TimeAxisView&, - ARDOUR::Region&, - double samples_per_unit, - Gdk::Color& basic_color, - TimeAxisViewItem::Visibility); + TimeAxisView&, + boost::shared_ptr, + double samples_per_unit, + Gdk::Color& basic_color, + TimeAxisViewItem::Visibility); - ARDOUR::Region& _region; - - ArdourCanvas::Polygon* sync_mark; ///< polgyon for sync position - ArdourCanvas::Text* no_wave_msg; - - RegionEditor *editor; - - vector control_points; - double current_visible_sync_position; - - bool valid; ///< see StreamView::redisplay_diskstream() - double _pixel_width; - double _height; - bool in_destructor; - - bool wait_for_data; - sigc::connection data_ready_connection; - virtual void region_resized (ARDOUR::Change); void region_moved (void *); virtual void region_muted (); @@ -132,9 +114,27 @@ class RegionView : public TimeAxisViewItem virtual void set_frame_color (); virtual void reset_width_dependent_items (double pixel_width); - vector ghosts; - virtual void color_handler (ColorID, uint32_t) {} + + boost::shared_ptr _region; + + ArdourCanvas::Polygon* sync_mark; ///< polgyon for sync position + ArdourCanvas::Text* no_wave_msg; + + RegionEditor* editor; + + vector control_points; + double current_visible_sync_position; + + bool valid; ///< see StreamView::redisplay_diskstream() + double _pixel_width; + double _height; + bool in_destructor; + + bool wait_for_data; + sigc::connection data_ready_connection; + + vector ghosts; }; #endif /* __gtk_ardour_region_view_h__ */ diff --git a/gtk2_ardour/route_params_ui.cc b/gtk2_ardour/route_params_ui.cc index c23ed272e1..5f61b0528c 100644 --- a/gtk2_ardour/route_params_ui.cc +++ b/gtk2_ardour/route_params_ui.cc @@ -361,7 +361,7 @@ RouteParams_UI::set_session (Session *sess) if (session) { boost::shared_ptr r = session->get_routes(); add_routes (*r); - session->going_away.connect (mem_fun(*this, &ArdourDialog::session_gone)); + session->GoingAway.connect (mem_fun(*this, &ArdourDialog::session_gone)); session->RouteAdded.connect (mem_fun(*this, &RouteParams_UI::add_routes)); start_updating (); } else { @@ -537,7 +537,7 @@ RouteParams_UI::redirect_selected (boost::shared_ptr redirect, if (place == PreFader) { cleanup_pre_view(); - _pre_plugin_conn = send->GoingAway.connect (mem_fun(*this, &RouteParams_UI::redirect_going_away)); + _pre_plugin_conn = send->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away), redirect)); _active_pre_view = send_ui; pre_redir_hpane.add2 (*_active_pre_view); @@ -545,7 +545,7 @@ RouteParams_UI::redirect_selected (boost::shared_ptr redirect, } else { cleanup_post_view(); - _post_plugin_conn = send->GoingAway.connect (mem_fun(*this, &RouteParams_UI::redirect_going_away)); + _post_plugin_conn = send->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away), redirect)); _active_post_view = send_ui; post_redir_hpane.add2 (*_active_post_view); @@ -586,7 +586,7 @@ RouteParams_UI::redirect_selected (boost::shared_ptr redirect, if (place == PreFader) { cleanup_pre_view(); - _pre_plugin_conn = port_insert->GoingAway.connect (mem_fun(*this, &RouteParams_UI::redirect_going_away)); + _pre_plugin_conn = port_insert->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away), redirect)); _active_pre_view = portinsert_ui; pre_redir_hpane.pack2 (*_active_pre_view); portinsert_ui->redisplay(); @@ -594,7 +594,7 @@ RouteParams_UI::redirect_selected (boost::shared_ptr redirect, } else { cleanup_post_view(); - _post_plugin_conn = port_insert->GoingAway.connect (mem_fun(*this, &RouteParams_UI::redirect_going_away)); + _post_plugin_conn = port_insert->GoingAway.connect (bind (mem_fun(*this, &RouteParams_UI::redirect_going_away), redirect)); _active_post_view = portinsert_ui; post_redir_hpane.pack2 (*_active_post_view); portinsert_ui->redisplay(); @@ -615,9 +615,9 @@ RouteParams_UI::redirect_selected (boost::shared_ptr redirect, } void -RouteParams_UI::plugin_going_away (Plugin *plugin, Placement place) +RouteParams_UI::plugin_going_away (Placement place) { - ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::plugin_going_away), plugin, place)); + ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::plugin_going_away), place)); // delete the current view without calling finish @@ -632,18 +632,17 @@ RouteParams_UI::plugin_going_away (Plugin *plugin, Placement place) } void -RouteParams_UI::redirect_going_away (ARDOUR::Redirect *plugin) +RouteParams_UI::redirect_going_away (boost::shared_ptr redirect) { - ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::redirect_going_away), plugin)); + ENSURE_GUI_THREAD(bind (mem_fun(*this, &RouteParams_UI::redirect_going_away), redirect)); printf ("redirect going away\n"); // delete the current view without calling finish - if (plugin == _pre_redirect.get()) { + if (redirect == _pre_redirect) { cleanup_pre_view (false); _pre_redirect.reset ((Redirect*) 0); - } - else if (plugin == _post_redirect.get()) { + } else if (redirect == _post_redirect) { cleanup_post_view (false); _post_redirect.reset ((Redirect*) 0); } diff --git a/gtk2_ardour/route_params_ui.h b/gtk2_ardour/route_params_ui.h index eff31023f7..394383de6b 100644 --- a/gtk2_ardour/route_params_ui.h +++ b/gtk2_ardour/route_params_ui.h @@ -182,8 +182,8 @@ class RouteParams_UI : public ArdourDialog void redirect_selected (boost::shared_ptr, ARDOUR::Placement); - void plugin_going_away (ARDOUR::Plugin *foo, ARDOUR::Placement); - void redirect_going_away (ARDOUR::Redirect *foo); + void plugin_going_away (ARDOUR::Placement); + void redirect_going_away (boost::shared_ptr); gint edit_input_configuration (GdkEventButton *ev); gint edit_output_configuration (GdkEventButton *ev); diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index e7a6df2f27..27d1739fd4 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -1010,7 +1010,7 @@ RouteTimeAxisView::hide_click () editor.hide_track_in_display (*this); } -Region* +boost::shared_ptr RouteTimeAxisView::find_next_region (jack_nframes_t pos, RegionPoint point, int32_t dir) { boost::shared_ptr stream; @@ -1020,7 +1020,7 @@ RouteTimeAxisView::find_next_region (jack_nframes_t pos, RegionPoint point, int3 return playlist->find_next_region (pos, point, dir); } - return 0; + return boost::shared_ptr (); } bool diff --git a/gtk2_ardour/route_time_axis.h b/gtk2_ardour/route_time_axis.h index d305fd390c..f3643de68b 100644 --- a/gtk2_ardour/route_time_axis.h +++ b/gtk2_ardour/route_time_axis.h @@ -81,7 +81,7 @@ public: void get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list&); void get_inverted_selectables (Selection&, list&); - ARDOUR::Region* find_next_region (jack_nframes_t pos, ARDOUR::RegionPoint, int32_t dir); + boost::shared_ptr find_next_region (jack_nframes_t pos, ARDOUR::RegionPoint, int32_t dir); /* Editing operations */ bool cut_copy_clear (Selection&, Editing::CutCopyOp); diff --git a/gtk2_ardour/selection.cc b/gtk2_ardour/selection.cc index aa7fdbe30f..9d171e484d 100644 --- a/gtk2_ardour/selection.cc +++ b/gtk2_ardour/selection.cc @@ -84,7 +84,7 @@ Selection::dump_region_layers() { cerr << "region selection layer dump" << endl; for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) { - cerr << "layer: " << (int)(*i)->region().layer() << endl; + cerr << "layer: " << (int)(*i)->region()->layer() << endl; } } diff --git a/gtk2_ardour/selection_templates.h b/gtk2_ardour/selection_templates.h index 9511db7d61..5440112ad6 100644 --- a/gtk2_ardour/selection_templates.h +++ b/gtk2_ardour/selection_templates.h @@ -34,33 +34,17 @@ inline void Selection::foreach_region (void (ARDOUR::Region::*method)(void)) { for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) { - ((*i)->region().*(method))(); + ARDOUR::Region* region = (*i)->region().get(); + (region->*(method))(); } } template inline void Selection::foreach_region (void (ARDOUR::Region::*method)(A), A arg) { for (RegionSelection::iterator i = regions.begin(); i != regions.end(); ++i) { - ((*i)->region().*(method))(arg); + ARDOUR::Region* region = (*i)->region().get(); + (region->*(method))(arg); } } -#if 0 - -template inline void -Selection::foreach_route (void (ARDOUR::Route::*method)(A), A arg) { - for (list::iterator i = routes.begin(); i != routes.end(); ++i) { - ((*i)->region().*(method))(arg); - } -} - -template inline void -Selection::foreach_route (void (ARDOUR::Route::*method)(A1,A2), A1 arg1, A2 arg2) { - for (list::iterator i = routes.begin(); i != routes.end(); ++i) { - ((*i)->region().*(method))(arg1, arg2); - } -} - -#endif - #endif /* __ardour_gtk_selection_templates_h__ */ diff --git a/gtk2_ardour/send_ui.cc b/gtk2_ardour/send_ui.cc index 9925ff51d4..897f5f3847 100644 --- a/gtk2_ardour/send_ui.cc +++ b/gtk2_ardour/send_ui.cc @@ -98,9 +98,9 @@ SendUI::outs_changed (IOChange change, void* ignored) } void -SendUI::send_going_away (Redirect *ignored) +SendUI::send_going_away () { - ENSURE_GUI_THREAD (bind (mem_fun (*this, &SendUI::send_going_away), ignored)); + ENSURE_GUI_THREAD (mem_fun (*this, &SendUI::send_going_away)) delete this; } @@ -143,9 +143,9 @@ SendUIWindow::~SendUIWindow () } void -SendUIWindow::send_going_away (Redirect *ignored) +SendUIWindow::send_going_away () { - ENSURE_GUI_THREAD(bind (mem_fun (*this, &SendUIWindow::send_going_away), ignored)); + ENSURE_GUI_THREAD (mem_fun (*this, &SendUIWindow::send_going_away)); delete this; } diff --git a/gtk2_ardour/send_ui.h b/gtk2_ardour/send_ui.h index 1d5a74e102..c8576cab9e 100644 --- a/gtk2_ardour/send_ui.h +++ b/gtk2_ardour/send_ui.h @@ -54,7 +54,7 @@ class SendUI : public Gtk::HBox sigc::connection screen_update_connection; sigc::connection fast_screen_update_connection; - void send_going_away (ARDOUR::Redirect*); + void send_going_away (); void ins_changed (ARDOUR::IOChange, void*); void outs_changed (ARDOUR::IOChange, void*); }; @@ -71,7 +71,7 @@ class SendUIWindow : public Gtk::Window Gtk::VBox vpacker; Gtk::HBox hpacker; - void send_going_away (ARDOUR::Redirect*); + void send_going_away (); }; #endif /* __ardour_gtk_send_ui_h__ */ diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc index d9ded04d2b..6858b8442d 100644 --- a/gtk2_ardour/sfdb_ui.cc +++ b/gtk2_ardour/sfdb_ui.cc @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include "ardour_ui.h" #include "gui_thread.h" @@ -187,15 +189,15 @@ SoundFileBox::play_btn_clicked () return; } - static std::map region_cache; + static std::map > region_cache; if (region_cache.find (path) == region_cache.end()) { - AudioRegion::SourceList srclist; - AudioFileSource* afs; - + SourceList srclist; + boost::shared_ptr afs; + for (int n = 0; n < sf_info.channels; ++n) { try { - afs = AudioFileSource::create (path+":"+string_compose("%1", n)); + afs = boost::dynamic_pointer_cast (SourceFactory::createReadable (DataType::AUDIO, path+":"+string_compose("%1", n), AudioFileSource::Flag (0))); srclist.push_back(afs); } catch (failed_constructor& err) { @@ -208,16 +210,18 @@ SoundFileBox::play_btn_clicked () return; } - string result; - _session->region_name (result, Glib::path_get_basename(srclist[0]->name()), false); - AudioRegion* a_region = new AudioRegion(srclist, 0, srclist[0]->length(), result, 0, Region::DefaultFlags, false); - region_cache[path] = a_region; + pair > newpair; + + _session->region_name (newpair.first, Glib::path_get_basename(srclist[0]->name()), false); + newpair.second = boost::dynamic_pointer_cast (RegionFactory::create (srclist, 0, srclist[0]->length(), newpair.first, 0, Region::DefaultFlags, false)); + + region_cache.insert (newpair); } play_btn.hide(); stop_btn.show(); - _session->audition_region(*region_cache[path]); + _session->audition_region(region_cache[path]); } void diff --git a/gtk2_ardour/streamview.cc b/gtk2_ardour/streamview.cc index ff51ca4b9f..3a1237f882 100644 --- a/gtk2_ardour/streamview.cc +++ b/gtk2_ardour/streamview.cc @@ -159,18 +159,18 @@ StreamView::set_samples_per_unit (gdouble spp) } void -StreamView::add_region_view (Region *r) +StreamView::add_region_view (boost::shared_ptr r) { add_region_view_internal (r, true); } void -StreamView::remove_region_view (Region *r) +StreamView::remove_region_view (boost::shared_ptr r) { ENSURE_GUI_THREAD (bind (mem_fun (*this, &StreamView::remove_region_view), r)); for (list::iterator i = region_views.begin(); i != region_views.end(); ++i) { - if (&((*i)->region()) == r) { + if (((*i)->region()) == r) { delete *i; region_views.erase (i); break; @@ -179,7 +179,7 @@ StreamView::remove_region_view (Region *r) } void -StreamView::remove_rec_region (Region *r) +StreamView::remove_rec_region (boost::shared_ptr r) { ENSURE_GUI_THREAD(bind (mem_fun (*this, &StreamView::remove_rec_region), r)); @@ -188,7 +188,7 @@ StreamView::remove_rec_region (Region *r) /*NOTREACHED*/ } - for (list::iterator i = rec_regions.begin(); i != rec_regions.end(); ++i) { + for (list >::iterator i = rec_regions.begin(); i != rec_regions.end(); ++i) { if (*i == r) { rec_regions.erase (i); break; @@ -304,7 +304,7 @@ StreamView::region_layered (RegionView* rv) /* this used to be + 1, but regions to the left ended up below ..something.. and couldn't receive events. why? good question. */ - rv->get_canvas_group()->raise (rv->region().layer() + 2); + rv->get_canvas_group()->raise (rv->region()->layer() + 2); } void @@ -355,11 +355,11 @@ StreamView::update_rec_box () } RegionView* -StreamView::find_view (const Region& region) +StreamView::find_view (boost::shared_ptr region) { for (list::iterator i = region_views.begin(); i != region_views.end(); ++i) { - if (&(*i)->region() == ®ion) { + if ((*i)->region() == region) { return *i; } } @@ -399,7 +399,7 @@ void StreamView::get_selectables (jack_nframes_t start, jack_nframes_t end, list& results) { for (list::iterator i = region_views.begin(); i != region_views.end(); ++i) { - if ((*i)->region().coverage(start, end) != OverlapNone) { + if ((*i)->region()->coverage(start, end) != OverlapNone) { results.push_back (*i); } } diff --git a/gtk2_ardour/streamview.h b/gtk2_ardour/streamview.h index fb49433cce..6f5e37869a 100644 --- a/gtk2_ardour/streamview.h +++ b/gtk2_ardour/streamview.h @@ -83,14 +83,14 @@ public: Gdk::Color get_region_color () const { return region_color; } void apply_color (Gdk::Color&, ColorTarget t); - RegionView* find_view (const ARDOUR::Region&); + RegionView* find_view (boost::shared_ptr); void foreach_regionview (sigc::slot slot); void set_selected_regionviews (RegionSelection&); void get_selectables (jack_nframes_t start, jack_nframes_t end, list&); void get_inverted_selectables (Selection&, list& results); - void add_region_view (ARDOUR::Region*); + void add_region_view (boost::shared_ptr); void region_layered (RegionView*); sigc::signal RegionViewAdded; @@ -107,9 +107,9 @@ protected: void update_rec_box (); virtual void update_rec_regions () = 0; - virtual void add_region_view_internal (ARDOUR::Region*, bool wait_for_waves) = 0; - virtual void remove_region_view (ARDOUR::Region* ); - void remove_rec_region (ARDOUR::Region*); + virtual void add_region_view_internal (boost::shared_ptr, bool wait_for_waves) = 0; + virtual void remove_region_view (boost::shared_ptr ); + void remove_rec_region (boost::shared_ptr); void display_diskstream (boost::shared_ptr); virtual void undisplay_diskstream (); @@ -134,7 +134,7 @@ protected: sigc::connection screen_update_connection; vector rec_rects; - list rec_regions; + list > rec_regions; bool rec_updating; bool rec_active; bool use_rec_regions; @@ -145,9 +145,9 @@ protected: vector playlist_connections; sigc::connection playlist_change_connection; - list rec_data_ready_connections; - jack_nframes_t last_rec_data_frame; - map rec_data_ready_map; + list rec_data_ready_connections; + jack_nframes_t last_rec_data_frame; + map, bool> rec_data_ready_map; }; #endif /* __ardour_streamview_h__ */ diff --git a/gtk2_ardour/tape_region_view.cc b/gtk2_ardour/tape_region_view.cc index 4110ad7d98..e697afddb9 100644 --- a/gtk2_ardour/tape_region_view.cc +++ b/gtk2_ardour/tape_region_view.cc @@ -50,12 +50,12 @@ const TimeAxisViewItem::Visibility TapeAudioRegionView::default_tape_visibility TimeAxisViewItem::FullWidthNameHighlight); TapeAudioRegionView::TapeAudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, - AudioRegion& r, + boost::shared_ptr r, double spu, Gdk::Color& basic_color) : AudioRegionView (parent, tv, r, spu, basic_color, - TimeAxisViewItem::Visibility ((r.position() != 0) ? default_tape_visibility : + TimeAxisViewItem::Visibility ((r->position() != 0) ? default_tape_visibility : TimeAxisViewItem::Visibility (default_tape_visibility|TimeAxisViewItem::HideFrameLeft))) { } @@ -67,8 +67,8 @@ TapeAudioRegionView::init (Gdk::Color& basic_color, bool wfw) /* every time the wave data changes and peaks are ready, redraw */ - for (uint32_t n = 0; n < audio_region().n_channels(); ++n) { - audio_region().audio_source(n).PeaksReady.connect (bind (mem_fun(*this, &TapeAudioRegionView::update), n)); + for (uint32_t n = 0; n < audio_region()->n_channels(); ++n) { + audio_region()->audio_source(n)->PeaksReady.connect (bind (mem_fun(*this, &TapeAudioRegionView::update), n)); } } @@ -90,7 +90,7 @@ TapeAudioRegionView::update (uint32_t n) /* this triggers a cache invalidation and redraw in the waveview */ - waves[n]->property_data_src() = &_region; + waves[n]->property_data_src() = _region.get(); } void diff --git a/gtk2_ardour/tape_region_view.h b/gtk2_ardour/tape_region_view.h index ed3852e3a9..fbedf19ebc 100644 --- a/gtk2_ardour/tape_region_view.h +++ b/gtk2_ardour/tape_region_view.h @@ -30,7 +30,7 @@ class TapeAudioRegionView : public AudioRegionView public: TapeAudioRegionView (ArdourCanvas::Group *, RouteTimeAxisView&, - ARDOUR::AudioRegion&, + boost::shared_ptr, double initial_samples_per_unit, Gdk::Color& base_color); ~TapeAudioRegionView (); diff --git a/gtk2_ardour/time_axis_view.h b/gtk2_ardour/time_axis_view.h index 3eae76a802..eff2e5fb6a 100644 --- a/gtk2_ardour/time_axis_view.h +++ b/gtk2_ardour/time_axis_view.h @@ -180,8 +180,8 @@ class TimeAxisView : public virtual AxisView virtual void set_selected_regionviews (RegionSelection&) {} virtual void set_selected_points (PointSelection&) {} - virtual ARDOUR::Region* find_next_region (jack_nframes_t pos, ARDOUR::RegionPoint, int32_t dir) { - return 0; + virtual boost::shared_ptr find_next_region (jack_nframes_t pos, ARDOUR::RegionPoint, int32_t dir) { + return boost::shared_ptr (); } void order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top); diff --git a/libs/ardour/SConscript b/libs/ardour/SConscript index 1128ecfde9..254f5a0560 100644 --- a/libs/ardour/SConscript +++ b/libs/ardour/SConscript @@ -84,6 +84,7 @@ plugin_manager.cc recent_sessions.cc redirect.cc region.cc +region_factory.cc reverse.cc route.cc route_group.cc @@ -103,6 +104,7 @@ session_transport.cc sndfile_helpers.cc sndfilesource.cc source.cc +source_factory.cc state_manager.cc tempo.cc utils.cc diff --git a/libs/ardour/ardour/audio_diskstream.h b/libs/ardour/ardour/audio_diskstream.h index 18f8328cfd..8588c9660d 100644 --- a/libs/ardour/ardour/audio_diskstream.h +++ b/libs/ardour/ardour/audio_diskstream.h @@ -108,10 +108,10 @@ class AudioDiskstream : public Diskstream return 0; } - AudioFileSource *write_source (uint32_t n=0) { + boost::shared_ptr write_source (uint32_t n=0) { if (n < channels.size()) return channels[n].write_source; - return 0; + return boost::shared_ptr(); } int add_channel (); @@ -141,8 +141,6 @@ class AudioDiskstream : public Diskstream } } - std::list& last_capture_regions () { return _last_capture_regions; } - XMLNode* deprecated_io_node; protected: @@ -181,9 +179,9 @@ class AudioDiskstream : public Diskstream Sample *speed_buffer; float peak_power; - - AudioFileSource *fades_source; - AudioFileSource *write_source; + + boost::shared_ptr fades_source; + boost::shared_ptr write_source; Port *source; Sample *current_capture_buffer; @@ -251,7 +249,7 @@ class AudioDiskstream : public Diskstream int _do_refill (Sample *mixdown_buffer, float *gain_buffer); - std::vector capturing_sources; + std::vector > capturing_sources; typedef vector ChannelList; ChannelList channels; diff --git a/libs/ardour/ardour/audiofilesource.h b/libs/ardour/ardour/audiofilesource.h index 3e0d4c45ae..b1ffab0944 100644 --- a/libs/ardour/ardour/audiofilesource.h +++ b/libs/ardour/ardour/audiofilesource.h @@ -56,16 +56,6 @@ class AudioFileSource : public AudioSource { static void set_peak_dir (string dir) { peak_dir = dir; } - /* factory for an existing but not-used-in-session audio file. this exists - because there maybe multiple back-end derivations of AudioFileSource, - some of which can handle formats that cannot be handled by others. - For example, CoreAudioFileSource can handle MP3 files, which SndFileSource - cannot. - */ - - static AudioFileSource* create (const string& path_plus_channel, Flag flags = Flag (0)); - static AudioFileSource* create (const XMLNode&); - static bool get_soundfile_info (string path, SoundFileInfo& _info, string& error); void set_allow_remove_if_empty (bool yn); diff --git a/libs/ardour/ardour/audiofilter.h b/libs/ardour/ardour/audiofilter.h index 02e5e6f061..c8762dbf69 100644 --- a/libs/ardour/ardour/audiofilter.h +++ b/libs/ardour/ardour/audiofilter.h @@ -36,14 +36,14 @@ class AudioFilter { : session (s){} virtual ~AudioFilter() {} - virtual int run (ARDOUR::AudioRegion&) = 0; - std::vector results; + virtual int run (boost::shared_ptr) = 0; + std::vector > results; protected: ARDOUR::Session& session; - int make_new_sources (ARDOUR::AudioRegion&, ARDOUR::AudioRegion::SourceList&); - int finish (ARDOUR::AudioRegion&, ARDOUR::AudioRegion::SourceList&); + int make_new_sources (boost::shared_ptr, ARDOUR::SourceList&); + int finish (boost::shared_ptr, ARDOUR::SourceList&); }; } /* namespace */ diff --git a/libs/ardour/ardour/audioplaylist.h b/libs/ardour/ardour/audioplaylist.h index bd76c30289..0426208ba1 100644 --- a/libs/ardour/ardour/audioplaylist.h +++ b/libs/ardour/ardour/audioplaylist.h @@ -58,7 +58,7 @@ class AudioPlaylist : public ARDOUR::Playlist AudioPlaylist (const AudioPlaylist&, string name, bool hidden = false); AudioPlaylist (const AudioPlaylist&, jack_nframes_t start, jack_nframes_t cnt, string name, bool hidden = false); - void clear (bool with_delete = false, bool with_save = true); + void clear (bool with_save = true); jack_nframes_t read (Sample *dst, Sample *mixdown, float *gain_buffer, jack_nframes_t start, jack_nframes_t cnt, uint32_t chan_n=0); @@ -75,7 +75,7 @@ class AudioPlaylist : public ARDOUR::Playlist (obj.*method) (states, _current_state_id); } - bool destroy_region (Region*); + bool destroy_region (boost::shared_ptr); void drop_all_states (); @@ -91,11 +91,11 @@ class AudioPlaylist : public ARDOUR::Playlist void notify_crossfade_added (Crossfade *); void flush_notifications (); - void finalize_split_region (Region *orig, Region *left, Region *right); + void finalize_split_region (boost::shared_ptr orig, boost::shared_ptr left, boost::shared_ptr right); - void refresh_dependents (Region& region); - void check_dependents (Region& region, bool norefresh); - void remove_dependents (Region& region); + void refresh_dependents (boost::shared_ptr region); + void check_dependents (boost::shared_ptr region, bool norefresh); + void remove_dependents (boost::shared_ptr region); protected: ~AudioPlaylist (); /* public should use unref() */ @@ -108,7 +108,7 @@ class AudioPlaylist : public ARDOUR::Playlist XMLNode& state (bool full_state); void dump () const; - bool region_changed (Change, Region*); + bool region_changed (Change, boost::shared_ptr); void crossfade_changed (Change); void add_crossfade (Crossfade&); }; diff --git a/libs/ardour/ardour/audioregion.h b/libs/ardour/ardour/audioregion.h index fd2cc8d2f1..9b97a88bc0 100644 --- a/libs/ardour/ardour/audioregion.h +++ b/libs/ardour/ardour/audioregion.h @@ -65,18 +65,11 @@ class AudioRegion : public Region static Change ScaleAmplitudeChanged; static Change EnvelopeChanged; - AudioRegion (AudioSource&, jack_nframes_t start, jack_nframes_t length, bool announce = true); - AudioRegion (AudioSource&, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true); - AudioRegion (SourceList &, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true); - AudioRegion (const AudioRegion&, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true); - AudioRegion (const AudioRegion&); - AudioRegion (AudioSource&, const XMLNode&); - AudioRegion (SourceList &, const XMLNode&); ~AudioRegion(); bool speed_mismatch (float) const; - AudioSource& audio_source (uint32_t n=0) const; + boost::shared_ptr audio_source (uint32_t n=0) const; void set_scale_amplitude (gain_t); gain_t scale_amplitude() const { return _scale_amplitude; } @@ -149,7 +142,15 @@ class AudioRegion : public Region void resume_fade_out (); private: - friend class Playlist; + friend class RegionFactory; + + AudioRegion (boost::shared_ptr, jack_nframes_t start, jack_nframes_t length); + AudioRegion (boost::shared_ptr, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags); + AudioRegion (SourceList &, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags); + AudioRegion (boost::shared_ptr, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags); + AudioRegion (boost::shared_ptr); + AudioRegion (boost::shared_ptr, const XMLNode&); + AudioRegion (SourceList &, const XMLNode&); private: void set_default_fades (); @@ -174,7 +175,6 @@ class AudioRegion : public Region void envelope_changed (Change); - mutable Curve _fade_in; FadeShape _fade_in_shape; mutable Curve _fade_out; diff --git a/libs/ardour/ardour/audiosource.h b/libs/ardour/ardour/audiosource.h index c3c2f9bb9a..751213ee8e 100644 --- a/libs/ardour/ardour/audiosource.h +++ b/libs/ardour/ardour/audiosource.h @@ -70,7 +70,7 @@ class AudioSource : public Source int read_peaks (PeakData *peaks, jack_nframes_t npeaks, jack_nframes_t start, jack_nframes_t cnt, double samples_per_unit) const; int build_peaks (); bool peaks_ready (sigc::slot, sigc::connection&) const; - + mutable sigc::signal PeaksReady; mutable sigc::signal PeakRangeReady; @@ -129,7 +129,7 @@ class AudioSource : public Source static vector pending_peak_sources; static Glib::Mutex* pending_peak_sources_lock; - static void queue_for_peaks (AudioSource&); + static void queue_for_peaks (AudioSource*); static void clear_queue_for_peaks (); struct PeakBuildRecord { diff --git a/libs/ardour/ardour/auditioner.h b/libs/ardour/ardour/auditioner.h index 434ec32f97..424ede0009 100644 --- a/libs/ardour/ardour/auditioner.h +++ b/libs/ardour/ardour/auditioner.h @@ -40,7 +40,7 @@ class Auditioner : public AudioTrack Auditioner (Session&); ~Auditioner (); - void audition_region (AudioRegion&); + void audition_region (boost::shared_ptr); ARDOUR::AudioPlaylist& prepare_playlist (); void audition_current_playlist (); @@ -54,7 +54,7 @@ class Auditioner : public AudioTrack bool active() const { return g_atomic_int_get (&_active); } private: - AudioRegion *the_region; + boost::shared_ptr the_region; jack_nframes_t current_frame; mutable gint _active; Glib::Mutex lock; diff --git a/libs/ardour/ardour/automation_event.h b/libs/ardour/ardour/automation_event.h index dad94161d0..a3b84289c1 100644 --- a/libs/ardour/ardour/automation_event.h +++ b/libs/ardour/ardour/automation_event.h @@ -27,8 +27,11 @@ #include #include + #include #include +#include + #include #include @@ -51,7 +54,7 @@ struct ControlEvent { }; -class AutomationList : public StateManager, public Stateful + class AutomationList : public StateManager, public PBD::StatefulDestructible { public: typedef std::list AutomationEventList; diff --git a/libs/ardour/ardour/crossfade.h b/libs/ardour/ardour/crossfade.h index aea7b31852..ded41bbfda 100644 --- a/libs/ardour/ardour/crossfade.h +++ b/libs/ardour/ardour/crossfade.h @@ -23,10 +23,12 @@ #include #include +#include #include #include +#include #include #include @@ -51,7 +53,7 @@ struct CrossfadeState : public StateManager::State { bool active; }; -class Crossfade : public Stateful, public StateManager +class Crossfade : public PBD::StatefulDestructible, public StateManager { public: @@ -62,7 +64,7 @@ class Crossfade : public Stateful, public StateManager /* constructor for "fixed" xfades at each end of an internal overlap */ - Crossfade (ARDOUR::AudioRegion& in, ARDOUR::AudioRegion& out, + Crossfade (boost::shared_ptr in, boost::shared_ptr out, jack_nframes_t position, jack_nframes_t initial_length, AnchorPoint); @@ -71,12 +73,12 @@ class Crossfade : public Stateful, public StateManager except the "internal" case. */ - Crossfade (ARDOUR::AudioRegion& in, ARDOUR::AudioRegion& out, CrossfadeModel, bool active); + Crossfade (boost::shared_ptr in, boost::shared_ptr out, CrossfadeModel, bool active); /* copy constructor to copy a crossfade with new regions. used (for example) when a playlist copy is made */ - Crossfade (const Crossfade &, ARDOUR::AudioRegion *, ARDOUR::AudioRegion *); + Crossfade (const Crossfade &, boost::shared_ptr, boost::shared_ptr); /* the usual XML constructor */ @@ -88,8 +90,8 @@ class Crossfade : public Stateful, public StateManager XMLNode& get_state (void); int set_state (const XMLNode&); - ARDOUR::AudioRegion& in() const { return *_in; } - ARDOUR::AudioRegion& out() const { return *_out; } + boost::shared_ptr in() const { return _in; } + boost::shared_ptr out() const { return _out; } jack_nframes_t read_at (Sample *buf, Sample *mixdown_buffer, float *gain_buffer, jack_nframes_t position, jack_nframes_t cnt, @@ -107,12 +109,12 @@ class Crossfade : public Stateful, public StateManager return std::min (_in->layer(), _out->layer()); } - bool involves (ARDOUR::AudioRegion& region) const { - return _in == ®ion || _out == ®ion; + bool involves (boost::shared_ptr region) const { + return _in == region || _out == region; } - bool involves (ARDOUR::AudioRegion& a, ARDOUR::AudioRegion& b) const { - return (_in == &a && _out == &b) || (_in == &b && _out == &a); + bool involves (boost::shared_ptr a, boost::shared_ptr b) const { + return (_in == a && _out == b) || (_in == b && _out == a); } jack_nframes_t length() const { return _length; } @@ -120,7 +122,6 @@ class Crossfade : public Stateful, public StateManager jack_nframes_t position() const { return _position; } sigc::signal Invalidated; - sigc::signal GoingAway; bool covers (jack_nframes_t frame) const { return _position <= frame && frame < _position + _length; @@ -155,8 +156,8 @@ class Crossfade : public Stateful, public StateManager static jack_nframes_t _short_xfade_length; - ARDOUR::AudioRegion* _in; - ARDOUR::AudioRegion* _out; + boost::shared_ptr _in; + boost::shared_ptr _out; bool _active; bool _in_update; OverlapType overlap_type; @@ -172,7 +173,7 @@ class Crossfade : public Stateful, public StateManager static Sample* crossfade_buffer_in; void initialize (bool savestate=true); - int compute (ARDOUR::AudioRegion&, ARDOUR::AudioRegion&, CrossfadeModel); + int compute (boost::shared_ptr, boost::shared_ptr, CrossfadeModel); bool update (bool force); StateManager::State* state_factory (std::string why) const; diff --git a/libs/ardour/ardour/diskstream.h b/libs/ardour/ardour/diskstream.h index 858ed1af6f..2bce6a424f 100644 --- a/libs/ardour/ardour/diskstream.h +++ b/libs/ardour/ardour/diskstream.h @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include @@ -54,7 +54,7 @@ class Session; class Playlist; class IO; - class Diskstream : public Stateful, public sigc::trackable, public PBD::Destructible + class Diskstream : public sigc::trackable, public PBD::StatefulDestructible { public: enum Flag { @@ -134,7 +134,7 @@ class IO; int set_loop (Location *loc); - std::list& last_capture_regions () { return _last_capture_regions; } + std::list >& last_capture_regions () { return _last_capture_regions; } void handle_input_change (IOChange, void *src); @@ -147,7 +147,7 @@ class IO; static sigc::signal DiskOverrun; static sigc::signal DiskUnderrun; - static sigc::signal*> DeleteSources; + static sigc::signal >*> DeleteSources; protected: friend class Session; @@ -224,7 +224,7 @@ class IO; virtual bool realtime_set_speed (double, bool global_change); - std::list _last_capture_regions; + std::list > _last_capture_regions; virtual int use_pending_capture_data (XMLNode& node) = 0; virtual void get_input_sources () = 0; diff --git a/libs/ardour/ardour/io.h b/libs/ardour/ardour/io.h index 7b5e72742d..ec29c6f843 100644 --- a/libs/ardour/ardour/io.h +++ b/libs/ardour/ardour/io.h @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -65,7 +65,7 @@ class BufferSet; * An IO can contain ports of varying types, making routes/inserts/etc with * varied combinations of types (eg MIDI and audio) possible. */ -class IO : public Stateful, public ARDOUR::StateManager +class IO : public PBD::StatefulDestructible, public ARDOUR::StateManager { public: @@ -76,7 +76,7 @@ class IO : public Stateful, public ARDOUR::StateManager int output_min = -1, int output_max = -1, DataType default_type = DataType::AUDIO); - virtual ~IO(); +virtual ~IO(); ChanCount input_minimum() const { return _input_minimum; } ChanCount input_maximum() const { return _input_maximum; } diff --git a/libs/ardour/ardour/location.h b/libs/ardour/ardour/location.h index beae4a6e07..1052b74bd4 100644 --- a/libs/ardour/ardour/location.h +++ b/libs/ardour/ardour/location.h @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -41,7 +42,7 @@ using std::string; namespace ARDOUR { -class Location : public Stateful, public sigc::trackable +class Location : public sigc::trackable, public PBD::StatefulDestructible { public: enum Flags { @@ -72,6 +73,7 @@ class Location : public Stateful, public sigc::trackable } Location (const Location& other); + Location (const XMLNode&); Location* operator= (const Location& other); jack_nframes_t start() { return _start; } @@ -132,7 +134,7 @@ class Location : public Stateful, public sigc::trackable bool set_flag_internal (bool yn, Flags flag); }; -class Locations : public Stateful, public StateManager +class Locations : public StateManager, public PBD::StatefulDestructible { public: typedef std::list LocationList; diff --git a/libs/ardour/ardour/midi_diskstream.h b/libs/ardour/ardour/midi_diskstream.h index bf64cedd08..e62121672f 100644 --- a/libs/ardour/ardour/midi_diskstream.h +++ b/libs/ardour/ardour/midi_diskstream.h @@ -85,7 +85,7 @@ class MidiDiskstream : public Diskstream void monitor_input (bool); - MidiSource* write_source() { return (MidiSource*)_write_source; } + boost::shared_ptr write_source () { return _write_source; } void set_destructive (bool yn); // doom! @@ -153,7 +153,7 @@ class MidiDiskstream : public Diskstream //RawMidi* _playback_wrap_buffer; //RawMidi* _capture_wrap_buffer; MidiPort* _source_port; - SMFSource* _write_source; ///< aka capturing source + boost::shared_ptr _write_source; RingBufferNPT* _capture_transition_buf; //RingBufferNPT::rw_vector _playback_vector; //RingBufferNPT::rw_vector _capture_vector; diff --git a/libs/ardour/ardour/midi_playlist.h b/libs/ardour/ardour/midi_playlist.h index 11627b5a07..36793b70ea 100644 --- a/libs/ardour/ardour/midi_playlist.h +++ b/libs/ardour/ardour/midi_playlist.h @@ -69,10 +69,7 @@ public: (obj.*method) (states, _current_state_id); } - bool destroy_region (Region*); - - void get_equivalent_regions (const MidiRegion&, std::vector&); - void get_region_list_equivalent_regions (const MidiRegion&, std::vector&); + bool destroy_region (boost::shared_ptr); void drop_all_states (); @@ -87,11 +84,11 @@ protected: /* playlist "callbacks" */ void flush_notifications (); - void finalize_split_region (Region *orig, Region *left, Region *right); - - void refresh_dependents (Region& region); - void check_dependents (Region& region, bool norefresh); - void remove_dependents (Region& region); + void finalize_split_region (boost::shared_ptr original, boost::shared_ptr left, boost::shared_ptr right); + + void check_dependents (boost::shared_ptr region, bool norefresh); + void refresh_dependents (boost::shared_ptr region); + void remove_dependents (boost::shared_ptr region); protected: ~MidiPlaylist (); /* public should use unref() */ @@ -100,7 +97,7 @@ private: XMLNode& state (bool full_state); void dump () const; - bool region_changed (Change, Region*); + bool region_changed (Change, boost::shared_ptr); }; } /* namespace ARDOUR */ diff --git a/libs/ardour/ardour/midi_region.h b/libs/ardour/ardour/midi_region.h index 745d3fa4a8..a5c578b7cd 100644 --- a/libs/ardour/ardour/midi_region.h +++ b/libs/ardour/ardour/midi_region.h @@ -46,16 +46,9 @@ class MidiRingBuffer; class MidiRegion : public Region { public: - MidiRegion (MidiSource&, jack_nframes_t start, jack_nframes_t length, bool announce = true); - MidiRegion (MidiSource&, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true); - MidiRegion (SourceList &, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true); - MidiRegion (const MidiRegion&, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true); - MidiRegion (const MidiRegion&); - MidiRegion (MidiSource&, const XMLNode&); - MidiRegion (SourceList &, const XMLNode&); ~MidiRegion(); - MidiSource& midi_source (uint32_t n=0) const; + boost::shared_ptr midi_source (uint32_t n=0) const; jack_nframes_t read_at (MidiRingBuffer& dst, jack_nframes_t position, @@ -76,6 +69,17 @@ class MidiRegion : public Region UndoAction get_memento() const; + private: + friend class RegionFactory; + + MidiRegion (boost::shared_ptr, jack_nframes_t start, jack_nframes_t length); + MidiRegion (boost::shared_ptr, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags); + MidiRegion (SourceList &, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags); + MidiRegion (boost::shared_ptr, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags); + MidiRegion (boost::shared_ptr); + MidiRegion (boost::shared_ptr, const XMLNode&); + MidiRegion (SourceList &, const XMLNode&); + private: friend class Playlist; diff --git a/libs/ardour/ardour/playlist.h b/libs/ardour/ardour/playlist.h index 59fd0f8bc5..c04b59286f 100644 --- a/libs/ardour/ardour/playlist.h +++ b/libs/ardour/ardour/playlist.h @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -34,6 +35,7 @@ #include #include +#include #include #include @@ -46,16 +48,16 @@ namespace ARDOUR { class Session; class Region; -class Playlist : public Stateful, public StateManager { +class Playlist : public StateManager, public PBD::StatefulDestructible { public: - typedef list RegionList; + typedef list > RegionList; Playlist (Session&, const XMLNode&, DataType type, bool hidden = false); Playlist (Session&, string name, DataType type, bool hidden = false); Playlist (const Playlist&, string name, bool hidden = false); Playlist (const Playlist&, jack_nframes_t start, jack_nframes_t cnt, string name, bool hidden = false); - virtual void clear (bool with_delete = false, bool with_save = true); + virtual void clear (bool with_save = true); virtual void dump () const; virtual UndoAction get_memento() const = 0; @@ -82,17 +84,17 @@ class Playlist : public Stateful, public StateManager { PBD::ID id() { return _id; } /* Editing operations */ - void add_region (const Region&, jack_nframes_t position, float times = 1, bool with_save = true); - void remove_region (Region *); - void get_equivalent_regions (const Region&, std::vector&); - void get_region_list_equivalent_regions (const Region&, std::vector&); - void replace_region (Region& old, Region& newr, jack_nframes_t pos); - void split_region (Region&, jack_nframes_t position); + void add_region (boost::shared_ptr, jack_nframes_t position, float times = 1, bool with_save = true); + void remove_region (boost::shared_ptr); + void get_equivalent_regions (boost::shared_ptr, std::vector >&); + void get_region_list_equivalent_regions (boost::shared_ptr, std::vector >&); + void replace_region (boost::shared_ptr old, boost::shared_ptr newr, jack_nframes_t pos); + void split_region (boost::shared_ptr, jack_nframes_t position); void partition (jack_nframes_t start, jack_nframes_t end, bool just_top_level); - void duplicate (Region&, jack_nframes_t position, float times); + void duplicate (boost::shared_ptr, jack_nframes_t position, float times); void nudge_after (jack_nframes_t start, jack_nframes_t distance, bool forwards); - Region* find_region (const PBD::ID&) const; + boost::shared_ptr find_region (const PBD::ID&) const; Playlist* cut (list&, bool result_is_hidden = true); Playlist* copy (list&, bool result_is_hidden = true); @@ -102,25 +104,24 @@ class Playlist : public Stateful, public StateManager { RegionList* regions_at (jack_nframes_t frame); RegionList* regions_touched (jack_nframes_t start, jack_nframes_t end); - Region* top_region_at (jack_nframes_t frame); + boost::shared_ptr top_region_at (jack_nframes_t frame); - Region* find_next_region (jack_nframes_t frame, RegionPoint point, int dir); + boost::shared_ptr find_next_region (jack_nframes_t frame, RegionPoint point, int dir); - template void foreach_region (T *t, void (T::*func)(Region *, void *), void *arg); - template void foreach_region (T *t, void (T::*func)(Region *)); + template void foreach_region (T *t, void (T::*func)(boost::shared_ptr, void *), void *arg); + template void foreach_region (T *t, void (T::*func)(boost::shared_ptr)); XMLNode& get_state (); int set_state (const XMLNode&); XMLNode& get_template (); - sigc::signal RegionAdded; - sigc::signal RegionRemoved; + sigc::signal > RegionAdded; + sigc::signal > RegionRemoved; sigc::signal InUse; sigc::signal Modified; sigc::signal NameChanged; sigc::signal LengthChanged; sigc::signal LayeringChanged; - sigc::signal GoingAway; sigc::signal StatePushed; static sigc::signal PlaylistCreated; @@ -131,10 +132,10 @@ class Playlist : public Stateful, public StateManager { void freeze (); void thaw (); - void raise_region (Region&); - void lower_region (Region&); - void raise_region_to_top (Region&); - void lower_region_to_bottom (Region&); + void raise_region (boost::shared_ptr); + void lower_region (boost::shared_ptr); + void raise_region_to_top (boost::shared_ptr); + void lower_region_to_bottom (boost::shared_ptr); uint32_t read_data_count() const { return _read_data_count; } @@ -145,7 +146,7 @@ class Playlist : public Stateful, public StateManager { /* destructive editing */ - virtual bool destroy_region (Region *) = 0; + virtual bool destroy_region (boost::shared_ptr) = 0; protected: friend class Session; @@ -216,8 +217,8 @@ class Playlist : public Stateful, public StateManager { void release_notifications (); virtual void flush_notifications (); - void notify_region_removed (Region *); - void notify_region_added (Region *); + void notify_region_removed (boost::shared_ptr); + void notify_region_added (boost::shared_ptr); void notify_length_changed (); void notify_layering_changed (); void notify_modified (); @@ -225,11 +226,11 @@ class Playlist : public Stateful, public StateManager { void mark_session_dirty(); - void region_changed_proxy (Change, Region*); - virtual bool region_changed (Change, Region*); + void region_changed_proxy (Change, boost::shared_ptr); + virtual bool region_changed (Change, boost::shared_ptr); - void region_bounds_changed (Change, Region *); - void region_deleted (Region *); + void region_bounds_changed (Change, boost::shared_ptr); + void region_deleted (boost::shared_ptr); void sort_regions (); @@ -240,11 +241,11 @@ class Playlist : public Stateful, public StateManager { void splice_unlocked (); - virtual void finalize_split_region (Region *original, Region *left, Region *right) {} + virtual void finalize_split_region (boost::shared_ptr original, boost::shared_ptr left, boost::shared_ptr right) {} - virtual void check_dependents (Region& region, bool norefresh) {} - virtual void refresh_dependents (Region& region) {} - virtual void remove_dependents (Region& region) {} + virtual void check_dependents (boost::shared_ptr region, bool norefresh) {} + virtual void refresh_dependents (boost::shared_ptr region) {} + virtual void remove_dependents (boost::shared_ptr region) {} virtual XMLNode& state (bool); @@ -253,9 +254,9 @@ class Playlist : public Stateful, public StateManager { void save_state (std::string why); void maybe_save_state (std::string why); - void add_region_internal (Region *, jack_nframes_t position, bool delay_sort = false); + void add_region_internal (boost::shared_ptr, jack_nframes_t position, bool delay_sort = false); - int remove_region_internal (Region *, bool delay_sort = false); + int remove_region_internal (boost::shared_ptr, bool delay_sort = false); RegionList *find_regions_at (jack_nframes_t frame); void copy_regions (RegionList&) const; void partition_internal (jack_nframes_t start, jack_nframes_t end, bool cutting, RegionList& thawlist); @@ -268,7 +269,7 @@ class Playlist : public Stateful, public StateManager { Playlist *copy (jack_nframes_t start, jack_nframes_t cnt, bool result_is_hidden); - int move_region_to_layer (layer_t, Region& r, int dir); + int move_region_to_layer (layer_t, boost::shared_ptr r, int dir); void relayer (); static Playlist* copyPlaylist (const Playlist&, jack_nframes_t start, jack_nframes_t length, @@ -277,7 +278,7 @@ class Playlist : public Stateful, public StateManager { void unset_freeze_parent (Playlist*); void unset_freeze_child (Playlist*); - void timestamp_layer_op (Region&); + void timestamp_layer_op (boost::shared_ptr); PBD::ID _id; }; diff --git a/libs/ardour/ardour/playlist_templates.h b/libs/ardour/ardour/playlist_templates.h index d3d682b8c5..7ce6c1818c 100644 --- a/libs/ardour/ardour/playlist_templates.h +++ b/libs/ardour/ardour/playlist_templates.h @@ -30,14 +30,14 @@ template void AudioPlaylist::foreach_crossfade (T *t, void (T::*func)(C } } -template void Playlist::foreach_region (T *t, void (T::*func)(Region *, void *), void *arg) { +template void Playlist::foreach_region (T *t, void (T::*func)(boost::shared_ptr, void *), void *arg) { RegionLock rlock (this, false); for (RegionList::iterator i = regions.begin(); i != regions.end(); i++) { (t->*func) ((*i), arg); } } -template void Playlist::foreach_region (T *t, void (T::*func)(Region *)) { +template void Playlist::foreach_region (T *t, void (T::*func)(boost::shared_ptr)) { RegionLock rlock (this, false); for (RegionList::const_iterator i = regions.begin(); i != regions.end(); i++) { (t->*func) (*i); diff --git a/libs/ardour/ardour/plugin.h b/libs/ardour/ardour/plugin.h index a199e99933..2117a9d58a 100644 --- a/libs/ardour/ardour/plugin.h +++ b/libs/ardour/ardour/plugin.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -78,8 +78,7 @@ class PluginInfo { typedef boost::shared_ptr PluginInfoPtr; typedef std::list PluginInfoList; -class Plugin : public Stateful, public sigc::trackable - +class Plugin : public PBD::StatefulDestructible, public sigc::trackable { public: Plugin (ARDOUR::AudioEngine&, ARDOUR::Session&); @@ -141,7 +140,6 @@ class Plugin : public Stateful, public sigc::trackable virtual bool has_editor() const = 0; sigc::signal ParameterChanged; - sigc::signal GoingAway; PBD::Controllable *get_nth_control (uint32_t); diff --git a/libs/ardour/ardour/redirect.h b/libs/ardour/ardour/redirect.h index b9e91e1cfd..4015c708de 100644 --- a/libs/ardour/ardour/redirect.h +++ b/libs/ardour/ardour/redirect.h @@ -92,7 +92,6 @@ class Redirect : public IO sigc::signal placement_changed; sigc::signal AutomationPlaybackChanged; sigc::signal AutomationChanged; - sigc::signal GoingAway; static sigc::signal RedirectCreated; diff --git a/libs/ardour/ardour/region.h b/libs/ardour/ardour/region.h index 80504ce044..1abba574f1 100644 --- a/libs/ardour/ardour/region.h +++ b/libs/ardour/ardour/region.h @@ -22,8 +22,10 @@ #define __ardour_region_h__ #include +#include #include +#include #include #include @@ -56,10 +58,10 @@ struct RegionState : public StateManager::State mutable RegionEditState _first_edit; }; -class Region : public Stateful, public StateManager +class Region : public PBD::StatefulDestructible, public StateManager { public: - typedef std::vector SourceList; + typedef std::vector > SourceList; enum Flag { Muted = 0x1, @@ -94,15 +96,6 @@ class Region : public Stateful, public StateManager static Change LayerChanged; static Change HiddenChanged; - Region (Source& src, jack_nframes_t start, jack_nframes_t length, - const string& name, DataType type, layer_t = 0, Flag flags = DefaultFlags); - Region (SourceList& srcs, jack_nframes_t start, jack_nframes_t length, - const string& name, DataType type, layer_t = 0, Flag flags = DefaultFlags); - Region (const Region&, jack_nframes_t start, jack_nframes_t length, - const string& name, layer_t = 0, Flag flags = DefaultFlags); - Region (const Region&); - Region (SourceList& srcs, const XMLNode&); - Region (Source& src, const XMLNode&); virtual ~Region(); const PBD::ID& id() const { return _id; } @@ -151,11 +144,11 @@ class Region : public Stateful, public StateManager return ARDOUR::coverage (_position, _position + _length - 1, start, end); } - bool equivalent (const Region&) const; - bool size_equivalent (const Region&) const; - bool overlap_equivalent (const Region&) const; - bool region_list_equivalent (const Region&) const; - bool source_equivalent (const Region&) const; + bool equivalent (boost::shared_ptr) const; + bool size_equivalent (boost::shared_ptr) const; + bool overlap_equivalent (boost::shared_ptr) const; + bool region_list_equivalent (boost::shared_ptr) const; + bool source_equivalent (boost::shared_ptr) const; /* EDITING OPERATIONS */ @@ -194,12 +187,10 @@ class Region : public Stateful, public StateManager void set_playlist (ARDOUR::Playlist*); - void lock_sources (); - void unlock_sources (); - void source_deleted (Source*); + void source_deleted (boost::shared_ptr); - Source& source (uint32_t n=0) const { return *_sources[ (n < _sources.size()) ? n : 0 ]; } - uint32_t n_channels() const { return _sources.size(); } + boost::shared_ptr source (uint32_t n=0) const { return _sources[ (n < _sources.size()) ? n : 0 ]; } + uint32_t n_channels() const { return _sources.size(); } std::vector master_source_names(); @@ -210,23 +201,23 @@ class Region : public Stateful, public StateManager virtual XMLNode& state (bool); virtual int set_state (const XMLNode&); - sigc::signal GoingAway; - - /* This is emitted only when a new id is assigned. Therefore, - in a pure Region copy, it will not be emitted. - - It must be emitted by derived classes, not Region - itself, to permit dynamic_cast<> to be used to - infer the type of Region. - */ - - static sigc::signal CheckNewRegion; - - Region* get_parent(); + boost::shared_ptr get_parent(); uint64_t last_layer_op() const { return _last_layer_op; } void set_last_layer_op (uint64_t when); + protected: + friend class RegionFactory; + + Region (boost::shared_ptr src, jack_nframes_t start, jack_nframes_t length, + const string& name, DataType type, layer_t = 0, Flag flags = DefaultFlags); + Region (SourceList& srcs, jack_nframes_t start, jack_nframes_t length, + const string& name, DataType type, layer_t = 0, Flag flags = DefaultFlags); + Region (boost::shared_ptr, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Flag flags = DefaultFlags); + Region (boost::shared_ptr); + Region (boost::shared_ptr src, const XMLNode&); + Region (SourceList& srcs, const XMLNode&); + protected: XMLNode& get_short_state (); /* used only by Session */ diff --git a/libs/ardour/ardour/region_factory.h b/libs/ardour/ardour/region_factory.h index f72c0a52d8..bd5089f512 100644 --- a/libs/ardour/ardour/region_factory.h +++ b/libs/ardour/ardour/region_factory.h @@ -10,12 +10,30 @@ namespace ARDOUR { class Session; -Region* createRegion (const Region&, jack_nframes_t start, - jack_nframes_t length, std::string name, - layer_t = 0, Region::Flag flags = Region::DefaultFlags); -// Region* createRegion (const Region&, std::string name); -Region* createRegion (const Region&); -Region* createRegion (Session&, XMLNode&, bool); +class RegionFactory { + + public: + /** This is emitted only when a new id is assigned. Therefore, + in a pure Region copy, it will not be emitted. + + It must be emitted by derived classes, not Region + itself, to permit dynamic_cast<> to be used to + infer the type of Region. + */ + static sigc::signal > CheckNewRegion; + + static boost::shared_ptr create (boost::shared_ptr, jack_nframes_t start, + jack_nframes_t length, std::string name, + layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true); + static boost::shared_ptr create (boost::shared_ptr, jack_nframes_t start, + jack_nframes_t length, std::string name, + layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true); + static boost::shared_ptr create (boost::shared_ptr, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true); + static boost::shared_ptr create (SourceList &, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t = 0, Region::Flag flags = Region::DefaultFlags, bool announce = true); + static boost::shared_ptr create (boost::shared_ptr); + static boost::shared_ptr create (Session&, XMLNode&, bool); + static boost::shared_ptr create (SourceList &, const XMLNode&); +}; } diff --git a/libs/ardour/ardour/reverse.h b/libs/ardour/ardour/reverse.h index 05ea8a1353..c60df990f2 100644 --- a/libs/ardour/ardour/reverse.h +++ b/libs/ardour/ardour/reverse.h @@ -30,7 +30,7 @@ class Reverse : public AudioFilter { Reverse (ARDOUR::Session&); ~Reverse (); - int run (ARDOUR::AudioRegion&); + int run (boost::shared_ptr); }; } /* namespace */ diff --git a/libs/ardour/ardour/route.h b/libs/ardour/ardour/route.h index 5b9c92dc71..7abc69f059 100644 --- a/libs/ardour/ardour/route.h +++ b/libs/ardour/ardour/route.h @@ -56,7 +56,7 @@ enum mute_type { MAIN_OUTS = 0x8 }; - class Route : public IO, public PBD::Destructible +class Route : public IO { protected: diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index eeb905a301..ee87848dcb 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -1,22 +1,22 @@ -/* - Copyright (C) 2000 Paul Davis + /* + Copyright (C) 2000 Paul Davis - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ -*/ + $Id$ + */ #ifndef __ardour_session_h__ #define __ardour_session_h__ @@ -27,6 +27,9 @@ #include #include #include + +#include + #include #include @@ -37,11 +40,13 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -108,12 +113,10 @@ struct RouteGroup; using std::vector; using std::string; -using std::list; using std::map; using std::set; -class Session : public sigc::trackable, public Stateful - +class Session : public sigc::trackable, public PBD::StatefulDestructible { private: typedef std::pair,bool> RouteBooleanState; @@ -133,7 +136,7 @@ class Session : public sigc::trackable, public Stateful MTC, JACK }; - + enum AutoConnectOption { AutoConnectPhysical = 0x1, AutoConnectMaster = 0x2 @@ -185,6 +188,8 @@ class Session : public sigc::trackable, public Stateful Route* route; }; + boost::shared_ptr region; + list audio_range; list music_range; @@ -339,11 +344,9 @@ class Session : public sigc::trackable, public Stateful void disable_record (bool rt_context, bool force = false); void step_back_from_record (); - sigc::signal going_away; - /* Proxy signal for region hidden changes */ - sigc::signal RegionHiddenChange; + sigc::signal > RegionHiddenChange; /* Emitted when all i/o connections are complete */ @@ -382,7 +385,7 @@ class Session : public sigc::trackable, public Stateful int wipe (); //int wipe_diskstream (AudioDiskstream *); - int remove_region_from_region_list (Region&); + int remove_region_from_region_list (boost::shared_ptr); jack_nframes_t get_maximum_extent () const; jack_nframes_t current_end_frame() const { return end_location->start(); } @@ -633,21 +636,21 @@ class Session : public sigc::trackable, public Stateful /* region info */ - sigc::signal RegionAdded; - sigc::signal RegionRemoved; + sigc::signal > RegionAdded; + sigc::signal > RegionRemoved; int region_name (string& result, string base = string(""), bool newlevel = false) const; string new_region_name (string); string path_from_region_name (string name, string identifier); - Region* find_whole_file_parent (Region& child); - void find_equivalent_playlist_regions (Region&, std::vector& result); + boost::shared_ptr find_whole_file_parent (Region&); + void find_equivalent_playlist_regions (boost::shared_ptr, std::vector >& result); - Region* XMLRegionFactory (const XMLNode&, bool full); - AudioRegion* XMLAudioRegionFactory (const XMLNode&, bool full); - MidiRegion* XMLMidiRegionFactory (const XMLNode&, bool full); + boost::shared_ptr XMLRegionFactory (const XMLNode&, bool full); + boost::shared_ptr XMLAudioRegionFactory (const XMLNode&, bool full); + boost::shared_ptr XMLMidiRegionFactory (const XMLNode&, bool full); - template void foreach_region (T *obj, void (T::*func)(Region *)); + template void foreach_region (T *obj, void (T::*func)(boost::shared_ptr)); /* source management */ @@ -661,8 +664,7 @@ class Session : public sigc::trackable, public Stateful string pathname; /* result */ - std::vector new_regions; - + std::vector > new_regions; }; int import_audiofile (import_status&); @@ -675,9 +677,9 @@ class Session : public sigc::trackable, public Stateful int start_audio_export (ARDOUR::AudioExportSpecification&); int stop_audio_export (ARDOUR::AudioExportSpecification&); - void add_source (Source *); - void remove_source (Source *); - int cleanup_audio_file_source (AudioFileSource&); + void add_source (boost::shared_ptr); + void remove_source (boost::weak_ptr); + int cleanup_audio_file_source (boost::shared_ptr); struct cleanup_report { vector paths; @@ -687,8 +689,8 @@ class Session : public sigc::trackable, public Stateful int cleanup_sources (cleanup_report&); int cleanup_trash_sources (cleanup_report&); - int destroy_region (Region*); - int destroy_regions (list); + int destroy_region (boost::shared_ptr); + int destroy_regions (std::list >); int remove_last_capture (); @@ -706,14 +708,14 @@ class Session : public sigc::trackable, public Stateful static sigc::signal AskAboutPendingState; - sigc::signal SourceAdded; - sigc::signal SourceRemoved; + sigc::signal > SourceAdded; + sigc::signal > SourceRemoved; - AudioFileSource *create_audio_source_for_session (ARDOUR::AudioDiskstream&, uint32_t which_channel, bool destructive); + boost::shared_ptr create_audio_source_for_session (ARDOUR::AudioDiskstream&, uint32_t which_channel, bool destructive); - MidiSource *create_midi_source_for_session (ARDOUR::MidiDiskstream&); + boost::shared_ptr create_midi_source_for_session (ARDOUR::MidiDiskstream&); - Source *source_by_id (const PBD::ID&); + boost::shared_ptr source_by_id (const PBD::ID&); /* playlist management */ @@ -750,7 +752,7 @@ class Session : public sigc::trackable, public Stateful boost::shared_ptr the_auditioner() { return auditioner; } void audition_playlist (); - void audition_region (Region&); + void audition_region (boost::shared_ptr); void cancel_audition (); bool is_auditioning () const; @@ -758,7 +760,8 @@ class Session : public sigc::trackable, public Stateful /* flattening stuff */ - int write_one_audio_track (AudioTrack&, jack_nframes_t start, jack_nframes_t cnt, bool overwrite, vector&, InterThreadInfo& wot); + int write_one_audio_track (AudioTrack&, jack_nframes_t start, jack_nframes_t cnt, bool overwrite, vector >&, + InterThreadInfo& wot); int freeze (InterThreadInfo&); /* session-wide solo/mute/rec-enable */ @@ -861,12 +864,15 @@ class Session : public sigc::trackable, public Stateful void commit_reversible_command (Command* cmd = 0); void add_command (Command *const cmd) { - current_trans.add_command (cmd); + current_trans->add_command (cmd); } + std::map registry; + // these commands are implemented in libs/ardour/session_command.cc Command *memento_command_factory(XMLNode *n); - void register_with_memento_command_factory(PBD::ID, Stateful *); + void register_with_memento_command_factory(PBD::ID, PBD::StatefulDestructible *); + class GlobalSoloStateCommand : public Command { GlobalRouteBooleanState before, after; @@ -936,17 +942,17 @@ class Session : public sigc::trackable, public Stateful /* tempo FX */ struct TimeStretchRequest { - ARDOUR::AudioRegion* region; + boost::shared_ptr region; float fraction; /* session: read ; GUI: write */ float progress; /* session: write ; GUI: read */ bool running; /* read/write */ bool quick_seek; /* GUI: write */ bool antialias; /* GUI: write */ - TimeStretchRequest () : region (0) {} + TimeStretchRequest () {} }; - AudioRegion* tempoize_region (TimeStretchRequest&); + boost::shared_ptr tempoize_region (TimeStretchRequest&); string raid_path() const; void set_raid_path(string); @@ -1558,27 +1564,27 @@ class Session : public sigc::trackable, public Stateful /* REGION MANAGEMENT */ mutable Glib::Mutex region_lock; - typedef map RegionList; + typedef map > RegionList; RegionList regions; - void region_renamed (Region *); - void region_changed (Change, Region *); - void add_region (Region *); - void remove_region (Region *); + void region_renamed (boost::shared_ptr); + void region_changed (Change, boost::shared_ptr); + void add_region (boost::shared_ptr); + void remove_region (boost::shared_ptr); int load_regions (const XMLNode& node); /* SOURCES */ mutable Glib::Mutex source_lock; - typedef std::map SourceList; + typedef std::map > SourceMap; - SourceList sources; + SourceMap sources; int load_sources (const XMLNode& node); XMLNode& get_sources_as_xml (); - Source *XMLSourceFactory (const XMLNode&); + boost::shared_ptr XMLSourceFactory (const XMLNode&); /* PLAYLISTS */ @@ -1609,9 +1615,9 @@ class Session : public sigc::trackable, public Stateful NamedSelection *named_selection_factory (string name); NamedSelection *XMLNamedSelectionFactory (const XMLNode&); - /* CURVES and AUTOMATION LISTS */ - std::map curves; - std::map automation_lists; + /* CURVES and AUTOMATION LISTS */ + std::map curves; + std::map automation_lists; /* DEFAULT FADE CURVES */ @@ -1621,9 +1627,9 @@ class Session : public sigc::trackable, public Stateful /* AUDITIONING */ boost::shared_ptr auditioner; - void set_audition (AudioRegion*); + void set_audition (boost::shared_ptr); void non_realtime_set_audition (); - AudioRegion *pending_audition_region; + boost::shared_ptr pending_audition_region; /* EXPORT */ @@ -1692,7 +1698,7 @@ class Session : public sigc::trackable, public Stateful void reverse_diskstream_buffers (); UndoHistory history; - UndoTransaction current_trans; + UndoTransaction* current_trans; GlobalRouteBooleanState get_global_route_boolean (bool (Route::*method)(void) const); GlobalRouteMeterState get_global_route_metering (); diff --git a/libs/ardour/ardour/session_region.h b/libs/ardour/ardour/session_region.h index fae950baa6..bce025adbe 100644 --- a/libs/ardour/ardour/session_region.h +++ b/libs/ardour/ardour/session_region.h @@ -6,7 +6,7 @@ namespace ARDOUR { -template void Session::foreach_region (T *obj, void (T::*func)(Region *)) +template void Session::foreach_region (T *obj, void (T::*func)(boost::shared_ptr)) { Glib::Mutex::Lock lm (region_lock); for (RegionList::iterator i = regions.begin(); i != regions.end(); i++) { @@ -14,6 +14,6 @@ template void Session::foreach_region (T *obj, void (T::*func)(Region * } } -} +} // namespace ARDOUR #endif /* __ardour_session_region_h__ */ diff --git a/libs/ardour/ardour/source.h b/libs/ardour/ardour/source.h index a8d0fed20b..1728cdb477 100644 --- a/libs/ardour/ardour/source.h +++ b/libs/ardour/ardour/source.h @@ -24,15 +24,16 @@ #include #include +#include -#include +#include #include #include namespace ARDOUR { -class Source : public Stateful, public sigc::trackable +class Source : public PBD::StatefulDestructible, public sigc::trackable, public boost::enable_shared_from_this { public: Source (std::string name, DataType type); @@ -42,13 +43,9 @@ class Source : public Stateful, public sigc::trackable std::string name() const { return _name; } int set_name (std::string str, bool destructive); - const PBD::ID& id() const { return _id; } + DataType type() { return _type; } - uint32_t use_cnt() const { return _use_cnt; } - void use (); - void release (); - - virtual void mark_for_remove() = 0; + const PBD::ID& id() const { return _id; } time_t timestamp() const { return _timestamp; } void stamp (time_t when) { _timestamp = when; } @@ -58,18 +55,19 @@ class Source : public Stateful, public sigc::trackable virtual jack_nframes_t natural_position() const { return 0; } + virtual void mark_for_remove() = 0; + virtual void mark_streaming_write_completed () = 0; + XMLNode& get_state (); int set_state (const XMLNode&); - + static sigc::signal SourceCreated; - sigc::signal GoingAway; protected: void update_length (jack_nframes_t pos, jack_nframes_t cnt); string _name; DataType _type; - uint32_t _use_cnt; time_t _timestamp; jack_nframes_t _length; diff --git a/libs/ardour/ardour/source_factory.h b/libs/ardour/ardour/source_factory.h new file mode 100644 index 0000000000..2b25752a0d --- /dev/null +++ b/libs/ardour/ardour/source_factory.h @@ -0,0 +1,28 @@ +#ifndef __ardour_source_factory_h__ +#define __ardour_source_factory_h__ + +#include +#include +#include +#include + +#include +#include + +class XMLNode; + +namespace ARDOUR { + +class SourceFactory { + public: + static sigc::signal > SourceCreated; + + static boost::shared_ptr create (const XMLNode& node); + + static boost::shared_ptr createReadable (DataType type, std::string idstr, AudioFileSource::Flag flags, bool announce = true); + static boost::shared_ptr createWritable (DataType type, std::string name, bool destructive, jack_nframes_t rate, bool announce = true); +}; + +} + +#endif /* __ardour_source_factory_h__ */ diff --git a/libs/ardour/ardour/tempo.h b/libs/ardour/ardour/tempo.h index bfd3e429c3..a365717417 100644 --- a/libs/ardour/ardour/tempo.h +++ b/libs/ardour/ardour/tempo.h @@ -26,8 +26,11 @@ #include #include #include + #include #include +#include + #include #include @@ -169,7 +172,8 @@ class TempoMapState : public StateManager::State { Metrics *metrics; }; -class TempoMap : public Stateful, public StateManager { +class TempoMap : public StateManager, public PBD::StatefulDestructible +{ public: TempoMap (jack_nframes_t frame_rate); diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index d5bfded460..c0975be922 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -26,6 +26,8 @@ #endif #include +#include +#include #include #include @@ -43,6 +45,7 @@ typedef int intptr_t; namespace ARDOUR { class Source; + class AudioSource; typedef jack_default_audio_sample_t Sample; typedef float pan_t; @@ -254,6 +257,7 @@ namespace ARDOUR { VST }; + typedef std::vector > SourceList; } // namespace ARDOUR std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf); diff --git a/libs/ardour/audio_diskstream.cc b/libs/ardour/audio_diskstream.cc index dceaea3f7e..5daaae5d51 100644 --- a/libs/ardour/audio_diskstream.cc +++ b/libs/ardour/audio_diskstream.cc @@ -44,10 +44,12 @@ #include #include #include +#include #include #include #include #include +#include #include "i18n.h" #include @@ -100,7 +102,6 @@ AudioDiskstream::init_channel (ChannelInfo &chan) chan.capture_wrap_buffer = 0; chan.speed_buffer = 0; chan.peak_power = 0.0f; - chan.write_source = 0; chan.source = 0; chan.current_capture_buffer = 0; chan.current_playback_buffer = 0; @@ -143,8 +144,7 @@ void AudioDiskstream::destroy_channel (ChannelInfo &chan) { if (chan.write_source) { - chan.write_source->release (); - chan.write_source = 0; + chan.write_source.reset (); } if (chan.speed_buffer) { @@ -189,8 +189,8 @@ AudioDiskstream::allocate_working_buffers() void AudioDiskstream::free_working_buffers() { - delete _mixdown_buffer; - delete _gain_buffer; + delete [] _mixdown_buffer; + delete [] _gain_buffer; _working_buffers_size = 0; _mixdown_buffer = 0; _gain_buffer = 0; @@ -369,7 +369,7 @@ AudioDiskstream::use_copy_playlist () void AudioDiskstream::setup_destructive_playlist () { - AudioRegion::SourceList srcs; + SourceList srcs; for (ChannelList::iterator chan = channels.begin(); chan != channels.end(); ++chan) { srcs.push_back ((*chan).write_source); @@ -379,8 +379,8 @@ AudioDiskstream::setup_destructive_playlist () cerr << "setup DS using " << srcs.front()->natural_position () << endl; - AudioRegion* region = new AudioRegion (srcs, 0, max_frames, _name); - _playlist->add_region (*region, srcs.front()->natural_position()); + boost::shared_ptr region (RegionFactory::create (srcs, 0, max_frames, _name)); + _playlist->add_region (region, srcs.front()->natural_position()); } void @@ -395,7 +395,7 @@ AudioDiskstream::use_destructive_playlist () return; } - AudioRegion* region = dynamic_cast (rl->front()); + boost::shared_ptr region = boost::dynamic_pointer_cast (rl->front()); if (region == 0) { throw failed_constructor(); @@ -407,7 +407,7 @@ AudioDiskstream::use_destructive_playlist () ChannelList::iterator chan; for (n = 0, chan = channels.begin(); chan != channels.end(); ++chan, ++n) { - (*chan).write_source = dynamic_cast(®ion->source (n)); + (*chan).write_source = boost::dynamic_pointer_cast(region->source (n)); assert((*chan).write_source); (*chan).write_source->set_allow_remove_if_empty (false); } @@ -1458,10 +1458,10 @@ AudioDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_ca uint32_t buffer_position; bool more_work = true; int err = 0; - AudioRegion* region = 0; + boost::shared_ptr region; jack_nframes_t total_capture; - AudioRegion::SourceList srcs; - AudioRegion::SourceList::iterator src; + SourceList srcs; + SourceList::iterator src; ChannelList::iterator chan; vector::iterator ci; uint32_t n = 0; @@ -1497,18 +1497,17 @@ AudioDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_ca ChannelList::iterator chan; - list* deletion_list = new list; + list >* deletion_list = new list >; for ( chan = channels.begin(); chan != channels.end(); ++chan) { if ((*chan).write_source) { (*chan).write_source->mark_for_remove (); - (*chan).write_source->release (); deletion_list->push_back ((*chan).write_source); - (*chan).write_source = 0; + (*chan).write_source.reset (); } /* new source set up in "out" below */ @@ -1531,19 +1530,11 @@ AudioDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_ca for (n = 0, chan = channels.begin(); chan != channels.end(); ++chan, ++n) { - AudioFileSource* s = (*chan).write_source; + boost::shared_ptr s = (*chan).write_source; if (s) { - - AudioFileSource* fsrc; - srcs.push_back (s); - - if ((fsrc = dynamic_cast(s)) != 0) { - cerr << "updating source after capture\n"; - fsrc->update_header (capture_info.front()->start, when, twhen); - } - + s->update_header (capture_info.front()->start, when, twhen); s->set_captured_for (_name); } @@ -1570,10 +1561,11 @@ AudioDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_ca */ try { - region = new AudioRegion (srcs, channels[0].write_source->last_capture_start_frame(), total_capture, - region_name_from_path (channels[0].write_source->name()), - 0, AudioRegion::Flag (AudioRegion::DefaultFlags|AudioRegion::Automatic|AudioRegion::WholeFile)); - + boost::shared_ptr rx (RegionFactory::create (srcs, channels[0].write_source->last_capture_start_frame(), total_capture, + region_name_from_path (channels[0].write_source->name()), + 0, AudioRegion::Flag (AudioRegion::DefaultFlags|AudioRegion::Automatic|AudioRegion::WholeFile))); + + region = boost::dynamic_pointer_cast (rx); region->special_set_position (capture_info.front()->start); } @@ -1595,10 +1587,11 @@ AudioDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_ca string region_name; _session.region_name (region_name, channels[0].write_source->name(), false); - // cerr << _name << ": based on ci of " << (*ci)->start << " for " << (*ci)->frames << " add a region\n"; + cerr << _name << ": based on ci of " << (*ci)->start << " for " << (*ci)->frames << " add region " << region_name << endl; try { - region = new AudioRegion (srcs, buffer_position, (*ci)->frames, region_name); + boost::shared_ptr rx (RegionFactory::create (srcs, buffer_position, (*ci)->frames, region_name)); + region = boost::dynamic_pointer_cast (rx); } catch (failed_constructor& err) { @@ -1611,7 +1604,7 @@ AudioDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_ca // cerr << "add new region, buffer position = " << buffer_position << " @ " << (*ci)->start << endl; i_am_the_modifier++; - _playlist->add_region (*region, (*ci)->start); + _playlist->add_region (region, (*ci)->start); i_am_the_modifier--; buffer_position += (*ci)->frames; @@ -1785,7 +1778,7 @@ AudioDiskstream::get_state () XMLNode* cs_child = new XMLNode (X_("CapturingSources")); XMLNode* cs_grandchild; - for (vector::iterator i = capturing_sources.begin(); i != capturing_sources.end(); ++i) { + for (vector >::iterator i = capturing_sources.begin(); i != capturing_sources.end(); ++i) { cs_grandchild = new XMLNode (X_("file")); cs_grandchild->add_property (X_("path"), (*i)->path()); cs_child->add_child_nocopy (*cs_grandchild); @@ -1954,11 +1947,9 @@ AudioDiskstream::use_new_write_source (uint32_t n) if (AudioFileSource::is_empty (chan.write_source->path())) { chan.write_source->mark_for_remove (); - chan.write_source->release(); - delete chan.write_source; + chan.write_source.reset (); } else { - chan.write_source->release(); - chan.write_source = 0; + chan.write_source.reset (); } } @@ -1970,12 +1961,10 @@ AudioDiskstream::use_new_write_source (uint32_t n) catch (failed_constructor &err) { error << string_compose (_("%1:%2 new capture file not initialized correctly"), _name, n) << endmsg; - chan.write_source = 0; + chan.write_source.reset (); return -1; } - chan.write_source->use (); - /* do not remove destructive files even if they are empty */ chan.write_source->set_allow_remove_if_empty (!destructive()); @@ -2172,9 +2161,9 @@ AudioDiskstream::use_pending_capture_data (XMLNode& node) const XMLProperty* prop; XMLNodeList nlist = node.children(); XMLNodeIterator niter; - AudioFileSource* fs; - AudioFileSource* first_fs = 0; - AudioRegion::SourceList pending_sources; + boost::shared_ptr fs; + boost::shared_ptr first_fs; + SourceList pending_sources; jack_nframes_t position; if ((prop = node.property (X_("at"))) == 0) { @@ -2193,10 +2182,7 @@ AudioDiskstream::use_pending_capture_data (XMLNode& node) } try { - fs = new SndFileSource (prop->value(), - Config->get_native_file_data_format(), - Config->get_native_file_header_format(), - _session.frame_rate()); + fs = boost::dynamic_pointer_cast (SourceFactory::createWritable (DataType::AUDIO, prop->value(), false, _session.frame_rate())); } catch (failed_constructor& err) { @@ -2227,13 +2213,12 @@ AudioDiskstream::use_pending_capture_data (XMLNode& node) return -1; } - AudioRegion* region; + boost::shared_ptr region; try { - region = new AudioRegion (pending_sources, 0, first_fs->length(), - region_name_from_path (first_fs->name()), - 0, AudioRegion::Flag (AudioRegion::DefaultFlags|AudioRegion::Automatic|AudioRegion::WholeFile)); - + region = boost::dynamic_pointer_cast (RegionFactory::create (pending_sources, 0, first_fs->length(), + region_name_from_path (first_fs->name()), + 0, AudioRegion::Flag (AudioRegion::DefaultFlags|AudioRegion::Automatic|AudioRegion::WholeFile))); region->special_set_position (0); } @@ -2246,7 +2231,7 @@ AudioDiskstream::use_pending_capture_data (XMLNode& node) } try { - region = new AudioRegion (pending_sources, 0, first_fs->length(), region_name_from_path (first_fs->name())); + region = boost::dynamic_pointer_cast (RegionFactory::create (pending_sources, 0, first_fs->length(), region_name_from_path (first_fs->name()))); } catch (failed_constructor& err) { @@ -2257,7 +2242,7 @@ AudioDiskstream::use_pending_capture_data (XMLNode& node) return -1; } - _playlist->add_region (*region, position); + _playlist->add_region (region, position); return 0; } diff --git a/libs/ardour/audio_playlist.cc b/libs/ardour/audio_playlist.cc index b621e587e9..7fc29f84b8 100644 --- a/libs/ardour/audio_playlist.cc +++ b/libs/ardour/audio_playlist.cc @@ -76,28 +76,28 @@ AudioPlaylist::AudioPlaylist (const AudioPlaylist& other, string name, bool hidd { save_state (_("initial state")); - list::const_iterator in_o = other.regions.begin(); - list::iterator in_n = regions.begin(); + RegionList::const_iterator in_o = other.regions.begin(); + RegionList::iterator in_n = regions.begin(); while (in_o != other.regions.end()) { - AudioRegion *ar = dynamic_cast( (*in_o) ); + boost::shared_ptr ar = boost::dynamic_pointer_cast(*in_o); // We look only for crossfades which begin with the current region, so we don't get doubles for (list::const_iterator xfades = other._crossfades.begin(); xfades != other._crossfades.end(); ++xfades) { - if ( &(*xfades)->in() == ar) { + if ((*xfades)->in() == ar) { // We found one! Now copy it! - list::const_iterator out_o = other.regions.begin(); - list::const_iterator out_n = regions.begin(); + RegionList::const_iterator out_o = other.regions.begin(); + RegionList::const_iterator out_n = regions.begin(); while (out_o != other.regions.end()) { - AudioRegion *ar2 = dynamic_cast( (*out_o) ); + boost::shared_ptrar2 = boost::dynamic_pointer_cast(*out_o); - if ( &(*xfades)->out() == ar2) { - AudioRegion *in = dynamic_cast( (*in_n) ); - AudioRegion *out = dynamic_cast( (*out_n) ); - Crossfade *new_fade = new Crossfade( *(*xfades), in, out); + if ((*xfades)->out() == ar2) { + boost::shared_ptrin = boost::dynamic_pointer_cast(*in_n); + boost::shared_ptrout = boost::dynamic_pointer_cast(*out_n); + Crossfade *new_fade = new Crossfade (*(*xfades), in, out); add_crossfade(*new_fade); break; } @@ -129,29 +129,21 @@ AudioPlaylist::AudioPlaylist (const AudioPlaylist& other, jack_nframes_t start, AudioPlaylist::~AudioPlaylist () { set all_xfades; - set all_regions; - GoingAway (this); + GoingAway (); /* EMIT SIGNAL */ - /* find every region we've ever used, and add it to the set of - all regions. same for xfades; - */ + /* drop connections to signals */ - for (RegionList::iterator x = regions.begin(); x != regions.end(); ++x) { - all_regions.insert (*x); - } + notify_callbacks (); for (Crossfades::iterator x = _crossfades.begin(); x != _crossfades.end(); ++x) { all_xfades.insert (*x); } for (StateMap::iterator i = states.begin(); i != states.end(); ++i) { - + AudioPlaylist::State* apstate = dynamic_cast (*i); - for (RegionList::iterator r = apstate->regions.begin(); r != apstate->regions.end(); ++r) { - all_regions.insert (*r); - } for (Crossfades::iterator xf = apstate->crossfades.begin(); xf != apstate->crossfades.end(); ++xf) { all_xfades.insert (*xf); } @@ -159,13 +151,6 @@ AudioPlaylist::~AudioPlaylist () delete apstate; } - /* delete every region */ - - for (set::iterator ar = all_regions.begin(); ar != all_regions.end(); ++ar) { - (*ar)->unlock_sources (); - delete *ar; - } - /* delete every crossfade */ for (set::iterator axf = all_xfades.begin(); axf != all_xfades.end(); ++axf) { @@ -174,7 +159,7 @@ AudioPlaylist::~AudioPlaylist () } struct RegionSortByLayer { - bool operator() (Region *a, Region *b) { + bool operator() (boost::shared_ptr a, boost::shared_ptr b) { return a->layer() < b->layer(); } }; @@ -215,7 +200,7 @@ AudioPlaylist::read (Sample *buf, Sample *mixdown_buffer, float *gain_buffer, ja skip_frames = 0; _read_data_count = 0; - map > relevant_regions; + map > > relevant_regions; map > relevant_xfades; vector relevant_layers; @@ -246,12 +231,11 @@ AudioPlaylist::read (Sample *buf, Sample *mixdown_buffer, float *gain_buffer, ja for (vector::iterator l = relevant_layers.begin(); l != relevant_layers.end(); ++l) { - // FIXME: Should be vector - vector& r (relevant_regions[*l]); + vector > r (relevant_regions[*l]); vector& x (relevant_xfades[*l]); - for (vector::iterator i = r.begin(); i != r.end(); ++i) { - AudioRegion* const ar = dynamic_cast(*i); + for (vector >::iterator i = r.begin(); i != r.end(); ++i) { + boost::shared_ptr ar = boost::dynamic_pointer_cast(*i); assert(ar); ar->read_at (buf, mixdown_buffer, gain_buffer, start, cnt, chan_n, read_frames, skip_frames); _read_data_count += ar->read_data_count(); @@ -271,10 +255,10 @@ AudioPlaylist::read (Sample *buf, Sample *mixdown_buffer, float *gain_buffer, ja void -AudioPlaylist::remove_dependents (Region& region) +AudioPlaylist::remove_dependents (boost::shared_ptr region) { Crossfades::iterator i, tmp; - AudioRegion* r = dynamic_cast (®ion); + boost::shared_ptr r = boost::dynamic_pointer_cast (region); if (r == 0) { fatal << _("programming error: non-audio Region passed to remove_overlap in audio playlist") @@ -286,7 +270,7 @@ AudioPlaylist::remove_dependents (Region& region) tmp = i; tmp++; - if ((*i)->involves (*r)) { + if ((*i)->involves (r)) { /* do not delete crossfades */ _crossfades.erase (i); } @@ -318,9 +302,9 @@ AudioPlaylist::flush_notifications () } void -AudioPlaylist::refresh_dependents (Region& r) +AudioPlaylist::refresh_dependents (boost::shared_ptr r) { - AudioRegion* ar = dynamic_cast(&r); + boost::shared_ptr ar = boost::dynamic_pointer_cast(r); set updated; if (ar == 0) { @@ -336,7 +320,7 @@ AudioPlaylist::refresh_dependents (Region& r) /* only update them once */ - if ((*x)->involves (*ar)) { + if ((*x)->involves (ar)) { if (find (updated.begin(), updated.end(), *x) == updated.end()) { if ((*x)->refresh ()) { @@ -351,11 +335,11 @@ AudioPlaylist::refresh_dependents (Region& r) } void -AudioPlaylist::finalize_split_region (Region *o, Region *l, Region *r) +AudioPlaylist::finalize_split_region (boost::shared_ptr o, boost::shared_ptr l, boost::shared_ptr r) { - AudioRegion *orig = dynamic_cast(o); - AudioRegion *left = dynamic_cast(l); - AudioRegion *right = dynamic_cast(r); + boost::shared_ptr orig = boost::dynamic_pointer_cast(o); + boost::shared_ptr left = boost::dynamic_pointer_cast(l); + boost::shared_ptr right = boost::dynamic_pointer_cast(r); for (Crossfades::iterator x = _crossfades.begin(); x != _crossfades.end();) { Crossfades::iterator tmp; @@ -366,24 +350,24 @@ AudioPlaylist::finalize_split_region (Region *o, Region *l, Region *r) if ((*x)->_in == orig) { if (! (*x)->covers(right->position())) { - fade = new Crossfade( *(*x), left, (*x)->_out); + fade = new Crossfade (**x, left, (*x)->_out); } else { // Overlap, the crossfade is copied on the left side of the right region instead - fade = new Crossfade( *(*x), right, (*x)->_out); + fade = new Crossfade (**x, right, (*x)->_out); } } if ((*x)->_out == orig) { if (! (*x)->covers(right->position())) { - fade = new Crossfade( *(*x), (*x)->_in, right); + fade = new Crossfade (**x, (*x)->_in, right); } else { // Overlap, the crossfade is copied on the right side of the left region instead - fade = new Crossfade( *(*x), (*x)->_in, left); + fade = new Crossfade (**x, (*x)->_in, left); } } if (fade) { - _crossfades.remove( (*x) ); + _crossfades.remove (*x); add_crossfade (*fade); } x = tmp; @@ -391,19 +375,19 @@ AudioPlaylist::finalize_split_region (Region *o, Region *l, Region *r) } void -AudioPlaylist::check_dependents (Region& r, bool norefresh) +AudioPlaylist::check_dependents (boost::shared_ptr r, bool norefresh) { - AudioRegion* other; - AudioRegion* region; - AudioRegion* top; - AudioRegion* bottom; + boost::shared_ptr other; + boost::shared_ptr region; + boost::shared_ptr top; + boost::shared_ptr bottom; Crossfade* xfade; if (in_set_state || in_partition) { return; } - if ((region = dynamic_cast (&r)) == 0) { + if ((region = boost::dynamic_pointer_cast (r)) == 0) { fatal << _("programming error: non-audio Region tested for overlap in audio playlist") << endmsg; return; @@ -419,7 +403,7 @@ AudioPlaylist::check_dependents (Region& r, bool norefresh) for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) { - other = dynamic_cast (*i); + other = boost::dynamic_pointer_cast (*i); if (other == region) { continue; @@ -461,14 +445,14 @@ AudioPlaylist::check_dependents (Region& r, bool norefresh) jack_nframes_t xfade_length = min ((jack_nframes_t) 720, top->length()); /* in, out */ - xfade = new Crossfade (*top, *bottom, xfade_length, top->first_frame(), StartOfIn); + xfade = new Crossfade (top, bottom, xfade_length, top->first_frame(), StartOfIn); add_crossfade (*xfade); - xfade = new Crossfade (*bottom, *top, xfade_length, top->last_frame() - xfade_length, EndOfOut); + xfade = new Crossfade (bottom, top, xfade_length, top->last_frame() - xfade_length, EndOfOut); add_crossfade (*xfade); } else { - xfade = new Crossfade (*other, *region, _session.get_xfade_model(), _session.get_crossfades_active()); + xfade = new Crossfade (other, region, _session.get_xfade_model(), _session.get_crossfades_active()); add_crossfade (*xfade); } } @@ -522,8 +506,8 @@ AudioPlaylist::crossfade_invalidated (Crossfade* xfade) { Crossfades::iterator i; - xfade->in().resume_fade_in (); - xfade->out().resume_fade_out (); + xfade->in()->resume_fade_in (); + xfade->out()->resume_fade_out (); if ((i = find (_crossfades.begin(), _crossfades.end(), xfade)) != _crossfades.end()) { _crossfades.erase (i); @@ -589,7 +573,7 @@ void AudioPlaylist::drop_all_states () { set all_xfades; - set all_regions; + set > all_regions; /* find every region we've ever used, and add it to the set of all regions. same for xfades; @@ -602,6 +586,7 @@ AudioPlaylist::drop_all_states () for (RegionList::iterator r = apstate->regions.begin(); r != apstate->regions.end(); ++r) { all_regions.insert (*r); } + for (Crossfades::iterator xf = apstate->crossfades.begin(); xf != apstate->crossfades.end(); ++xf) { all_xfades.insert (*xf); } @@ -609,8 +594,8 @@ AudioPlaylist::drop_all_states () /* now remove from the "all" lists every region that is in the current list. */ - for (list::iterator i = regions.begin(); i != regions.end(); ++i) { - set::iterator x = all_regions.find (*i); + for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) { + set >::iterator x = all_regions.find (*i); if (x != all_regions.end()) { all_regions.erase (x); } @@ -625,13 +610,6 @@ AudioPlaylist::drop_all_states () } } - /* delete every region that is left - these are all things that are part of our "history" */ - - for (set::iterator ar = all_regions.begin(); ar != all_regions.end(); ++ar) { - (*ar)->unlock_sources (); - delete *ar; - } - /* delete every crossfade that is left (ditto as per regions) */ for (set::iterator axf = all_xfades.begin(); axf != all_xfades.end(); ++axf) { @@ -697,17 +675,11 @@ AudioPlaylist::get_memento () const } void -AudioPlaylist::clear (bool with_delete, bool with_save) +AudioPlaylist::clear (bool with_save) { - if (with_delete) { - for (Crossfades::iterator i = _crossfades.begin(); i != _crossfades.end(); ++i) { - delete *i; - } - } - _crossfades.clear (); - Playlist::clear (with_delete, with_save); + Playlist::clear (with_save); } XMLNode& @@ -727,7 +699,7 @@ AudioPlaylist::state (bool full_state) void AudioPlaylist::dump () const { - Region *r; + boost::shared_ptrr; Crossfade *x; cerr << "Playlist \"" << _name << "\" " << endl @@ -749,9 +721,9 @@ AudioPlaylist::dump () const for (Crossfades::const_iterator i = _crossfades.begin(); i != _crossfades.end(); ++i) { x = *i; cerr << " xfade [" - << x->out().name() + << x->out()->name() << ',' - << x->in().name() + << x->in()->name() << " @ " << x->position() << " length = " @@ -763,9 +735,9 @@ AudioPlaylist::dump () const } bool -AudioPlaylist::destroy_region (Region* region) +AudioPlaylist::destroy_region (boost::shared_ptr region) { - AudioRegion* r = dynamic_cast (region); + boost::shared_ptr r = boost::dynamic_pointer_cast (region); bool changed = false; Crossfades::iterator c, ctmp; set unique_xfades; @@ -788,7 +760,6 @@ AudioPlaylist::destroy_region (Region* region) ++tmp; if ((*i) == region) { - (*i)->unlock_sources (); regions.erase (i); changed = true; } @@ -801,7 +772,7 @@ AudioPlaylist::destroy_region (Region* region) ctmp = c; ++ctmp; - if ((*c)->involves (*r)) { + if ((*c)->involves (r)) { unique_xfades.insert (*c); _crossfades.erase (c); } @@ -822,7 +793,7 @@ AudioPlaylist::destroy_region (Region* region) ctmp = c; ++ctmp; - if ((*c)->involves (*r)) { + if ((*c)->involves (r)) { unique_xfades.insert (*c); _crossfades.erase (c); } @@ -886,7 +857,7 @@ AudioPlaylist::crossfade_changed (Change ignored) } bool -AudioPlaylist::region_changed (Change what_changed, Region* region) +AudioPlaylist::region_changed (Change what_changed, boost::shared_ptr region) { if (in_flush || in_set_state) { return false; diff --git a/libs/ardour/audio_track.cc b/libs/ardour/audio_track.cc index 7a44be9b54..2762418f19 100644 --- a/libs/ardour/audio_track.cc +++ b/libs/ardour/audio_track.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -719,7 +720,7 @@ AudioTrack::export_stuff (BufferSet& buffers, jack_nframes_t start, jack_nframes void AudioTrack::bounce (InterThreadInfo& itt) { - vector srcs; + vector > srcs; _session.write_one_audio_track (*this, 0, _session.current_end_frame(), false, srcs, itt); } @@ -727,18 +728,17 @@ AudioTrack::bounce (InterThreadInfo& itt) void AudioTrack::bounce_range (jack_nframes_t start, jack_nframes_t end, InterThreadInfo& itt) { - vector srcs; + vector > srcs; _session.write_one_audio_track (*this, start, end, false, srcs, itt); } void AudioTrack::freeze (InterThreadInfo& itt) { - vector srcs; + vector > srcs; string new_playlist_name; Playlist* new_playlist; string dir; - AudioRegion* region; string region_name; boost::shared_ptr diskstream = audio_diskstream(); @@ -805,13 +805,13 @@ AudioTrack::freeze (InterThreadInfo& itt) /* create a new region from all filesources, keep it private */ - region = new AudioRegion (srcs, 0, srcs[0]->length(), - region_name, 0, - (AudioRegion::Flag) (AudioRegion::WholeFile|AudioRegion::DefaultFlags), - false); + boost::shared_ptr region (RegionFactory::create (srcs, 0, srcs[0]->length(), + region_name, 0, + (Region::Flag) (Region::WholeFile|Region::DefaultFlags), + false)); new_playlist->set_orig_diskstream_id (diskstream->id()); - new_playlist->add_region (*region, 0); + new_playlist->add_region (region, 0); new_playlist->set_frozen (true); region->set_locked (true); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index 15ad6e442c..fe29037cb7 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -63,16 +63,16 @@ AudioEngine::AudioEngine (string client_name) _buffer_size = 0; _freewheeling = false; _freewheel_thread_registered = false; - - m_meter_thread = 0; - m_meter_exit = false; - start_metering_thread(); - + m_meter_thread = 0; + m_meter_exit = false; + if (connect_to_jack (client_name)) { throw NoBackendAvailable (); } + start_metering_thread(); + } AudioEngine::~AudioEngine () @@ -81,9 +81,9 @@ AudioEngine::~AudioEngine () jack_client_close (_jack); } - if(m_meter_thread) { - g_atomic_int_inc(&m_meter_exit); - } + if(m_meter_thread) { + g_atomic_int_inc(&m_meter_exit); + } } void @@ -207,7 +207,7 @@ AudioEngine::_xrun_callback (void *arg) int AudioEngine::_graph_order_callback (void *arg) { - static_cast(arg)->GraphReordered (); /* EMIT SIGNAL */ + static_cast(arg)->GraphReordered (); /* EMIT SIGNAL */ return 0; } @@ -359,9 +359,9 @@ AudioEngine::jack_bufsize_callback (jack_nframes_t nframes) void AudioEngine::start_metering_thread () { - if(m_meter_thread == 0) { - m_meter_thread = Glib::Thread::create (sigc::mem_fun(this, &AudioEngine::meter_thread), false); - } + if(m_meter_thread == 0) { + m_meter_thread = Glib::Thread::create (sigc::mem_fun(this, &AudioEngine::meter_thread), false); + } } void diff --git a/libs/ardour/audiofilesource.cc b/libs/ardour/audiofilesource.cc index 46079ef9a5..963a2274df 100644 --- a/libs/ardour/audiofilesource.cc +++ b/libs/ardour/audiofilesource.cc @@ -38,6 +38,7 @@ #include #include #include +#include // if these headers come before sigc++ is included // the parser throws ObjC++ errors. (nil is a keyword) @@ -108,8 +109,7 @@ AudioFileSource::~AudioFileSource () bool AudioFileSource::removable () const { - return (_flags & Removable) && ((_flags & RemoveAtDestroy) || - ((_flags & RemovableIfEmpty) && is_empty (_path))); + return (_flags & Removable) && ((_flags & RemoveAtDestroy) || ((_flags & RemovableIfEmpty) && is_empty (_path))); } int @@ -164,80 +164,6 @@ AudioFileSource::old_peak_path (string audio_path) return res; } -#ifdef HAVE_COREAUDIO - -AudioFileSource* -AudioFileSource::create (const XMLNode& node) -{ - AudioFileSource* es = 0; - - if (node.property (X_("destructive")) != 0) { - - es = new DestructiveFileSource (node); - - } else { - - try { - es = new CoreAudioSource (node); - } - - - catch (failed_constructor& err) { - es = new SndFileSource (node); - } - } - - return es; -} - -#else - -AudioFileSource* -AudioFileSource::create (const XMLNode& node) -{ - if (node.property (X_("destructive")) != 0) { - - return new DestructiveFileSource (node); - - } else { - - return new SndFileSource (node); - } -} - -#endif // HAVE_COREAUDIO - -#ifdef HAVE_COREAUDIO -AudioFileSource* -AudioFileSource::create (const string& idstr, Flag flags) -{ - AudioFileSource* es = 0; - - if (flags & Destructive) { - return new DestructiveFileSource (idstr, flags); - } - - try { - es = new CoreAudioSource (idstr, flags); - } - - catch (failed_constructor& err) { - es = new SndFileSource (idstr, flags); - } - - return es; -} - -#else - -AudioFileSource* -AudioFileSource::create (const string& idstr, Flag flags) -{ - return new SndFileSource (idstr, flags); -} - -#endif // HAVE_COREAUDIO - bool AudioFileSource::get_soundfile_info (string path, SoundFileInfo& _info, string& error_msg) { @@ -579,7 +505,6 @@ void AudioFileSource::set_header_position_offset (jack_nframes_t offset) { header_position_offset = offset; - cerr << "hpo set to " << offset << endl; HeaderPositionOffsetChanged (); } @@ -639,11 +564,11 @@ bool AudioFileSource::is_empty (string path) { bool ret = false; - AudioFileSource* afs = create (path, NoPeakFile); + boost::shared_ptr afs = boost::dynamic_pointer_cast ( + SourceFactory::createReadable (DataType::AUDIO, path, NoPeakFile, false)); if (afs) { ret = (afs->length() == 0); - delete afs; } return ret; diff --git a/libs/ardour/audiofilter.cc b/libs/ardour/audiofilter.cc index a26d9674bd..0a630f1e25 100644 --- a/libs/ardour/audiofilter.cc +++ b/libs/ardour/audiofilter.cc @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include "i18n.h" @@ -33,25 +35,23 @@ using namespace ARDOUR; using namespace PBD; int -AudioFilter::make_new_sources (AudioRegion& region, AudioRegion::SourceList& nsrcs) +AudioFilter::make_new_sources (boost::shared_ptr region, SourceList& nsrcs) { - vector names = region.master_source_names(); + vector names = region->master_source_names(); - for (uint32_t i = 0; i < region.n_channels(); ++i) { + for (uint32_t i = 0; i < region->n_channels(); ++i) { string path = session.path_from_region_name (PBD::basename_nosuffix (names[i]), string ("")); if (path.length() == 0) { - error << string_compose (_("audiofilter: error creating name for new audio file based on %1"), region.name()) + error << string_compose (_("audiofilter: error creating name for new audio file based on %1"), region->name()) << endmsg; return -1; } try { - nsrcs.push_back (new SndFileSource (path, - Config->get_native_file_data_format(), - Config->get_native_file_header_format(), - session.frame_rate())); + nsrcs.push_back (boost::dynamic_pointer_cast ( + SourceFactory::createWritable (DataType::AUDIO, path, false, session.frame_rate()))); } catch (failed_constructor& err) { @@ -64,7 +64,7 @@ AudioFilter::make_new_sources (AudioRegion& region, AudioRegion::SourceList& nsr } int -AudioFilter::finish (AudioRegion& region, AudioRegion::SourceList& nsrcs) +AudioFilter::finish (boost::shared_ptr region, SourceList& nsrcs) { string region_name; @@ -76,19 +76,19 @@ AudioFilter::finish (AudioRegion& region, AudioRegion::SourceList& nsrcs) time (&xnow); now = localtime (&xnow); - for (AudioRegion::SourceList::iterator si = nsrcs.begin(); si != nsrcs.end(); ++si) { - AudioFileSource* afs = dynamic_cast(*si); + for (SourceList::iterator si = nsrcs.begin(); si != nsrcs.end(); ++si) { + boost::shared_ptr afs = boost::dynamic_pointer_cast(*si); if (afs) { - afs->update_header (region.position(), *now, xnow); + afs->update_header (region->position(), *now, xnow); } } /* create a new region */ - region_name = session.new_region_name (region.name()); + region_name = session.new_region_name (region->name()); results.clear (); - results.push_back (new AudioRegion (nsrcs, 0, region.length(), region_name, 0, - Region::Flag (Region::WholeFile|Region::DefaultFlags))); - + results.push_back (boost::dynamic_pointer_cast (RegionFactory::create (nsrcs, 0, region->length(), region_name, 0, + Region::Flag (Region::WholeFile|Region::DefaultFlags)))); + return 0; } diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index 052049cda7..07127b78c1 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -65,11 +65,11 @@ AudioRegionState::AudioRegionState (string why) } /** Basic AudioRegion constructor (one channel) */ -AudioRegion::AudioRegion (AudioSource& src, jack_nframes_t start, jack_nframes_t length, bool announce) - : Region (src, start, length, PBD::basename_nosuffix(src.name()), DataType::AUDIO, 0, Region::Flag(Region::DefaultFlags|Region::External)) - , _fade_in (0.0, 2.0, 1.0, false) - , _fade_out (0.0, 2.0, 1.0, false) - , _envelope (0.0, 2.0, 1.0, false) +AudioRegion::AudioRegion (boost::shared_ptr src, jack_nframes_t start, jack_nframes_t length) + : Region (src, start, length, PBD::basename_nosuffix(src->name()), DataType::AUDIO, 0, Region::Flag(Region::DefaultFlags|Region::External)), + _fade_in (0.0, 2.0, 1.0, false), + _fade_out (0.0, 2.0, 1.0, false), + _envelope (0.0, 2.0, 1.0, false) { _scale_amplitude = 1.0; @@ -79,14 +79,10 @@ AudioRegion::AudioRegion (AudioSource& src, jack_nframes_t start, jack_nframes_t save_state ("initial state"); _envelope.StateChanged.connect (mem_fun (*this, &AudioRegion::envelope_changed)); - - if (announce) { - CheckNewRegion (this); /* EMIT SIGNAL */ - } } /* Basic AudioRegion constructor (one channel) */ -AudioRegion::AudioRegion (AudioSource& src, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t layer, Flag flags, bool announce) +AudioRegion::AudioRegion (boost::shared_ptr src, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t layer, Flag flags) : Region (src, start, length, name, DataType::AUDIO, layer, flags) , _fade_in (0.0, 2.0, 1.0, false) , _fade_out (0.0, 2.0, 1.0, false) @@ -99,14 +95,10 @@ AudioRegion::AudioRegion (AudioSource& src, jack_nframes_t start, jack_nframes_t save_state ("initial state"); _envelope.StateChanged.connect (mem_fun (*this, &AudioRegion::envelope_changed)); - - if (announce) { - CheckNewRegion (this); /* EMIT SIGNAL */ - } } /* Basic AudioRegion constructor (many channels) */ -AudioRegion::AudioRegion (SourceList& srcs, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t layer, Flag flags, bool announce) +AudioRegion::AudioRegion (SourceList& srcs, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t layer, Flag flags) : Region (srcs, start, length, name, DataType::AUDIO, layer, flags) , _fade_in (0.0, 2.0, 1.0, false) , _fade_out (0.0, 2.0, 1.0, false) @@ -119,19 +111,15 @@ AudioRegion::AudioRegion (SourceList& srcs, jack_nframes_t start, jack_nframes_t save_state ("initial state"); _envelope.StateChanged.connect (mem_fun (*this, &AudioRegion::envelope_changed)); - - if (announce) { - CheckNewRegion (this); /* EMIT SIGNAL */ - } } /** Create a new AudioRegion, that is part of an existing one */ -AudioRegion::AudioRegion (const AudioRegion& other, jack_nframes_t offset, jack_nframes_t length, const string& name, layer_t layer, Flag flags, bool announce) - : Region (other, offset, length, name, layer, flags) - , _fade_in (other._fade_in) - , _fade_out (other._fade_out) - , _envelope (other._envelope, (double) offset, (double) offset + length) +AudioRegion::AudioRegion (boost::shared_ptr other, jack_nframes_t offset, jack_nframes_t length, const string& name, layer_t layer, Flag flags) + : Region (other, offset, length, name, layer, flags), + _fade_in (other->_fade_in), + _fade_out (other->_fade_out), + _envelope (other->_envelope, (double) offset, (double) offset + length) { /* return to default fades if the existing ones are too long */ _fade_in_disabled = 0; @@ -142,7 +130,7 @@ AudioRegion::AudioRegion (const AudioRegion& other, jack_nframes_t offset, jack_ if (_fade_in.back()->when >= _length) { set_default_fade_in (); } else { - _fade_in_disabled = other._fade_in_disabled; + _fade_in_disabled = other->_fade_in_disabled; } set_default_fade_out (); _flags = Flag (_flags & ~Region::LeftOfSplit); @@ -152,31 +140,29 @@ AudioRegion::AudioRegion (const AudioRegion& other, jack_nframes_t offset, jack_ if (_fade_out.back()->when >= _length) { set_default_fade_out (); } else { - _fade_out_disabled = other._fade_out_disabled; + _fade_out_disabled = other->_fade_out_disabled; } set_default_fade_in (); _flags = Flag (_flags & ~Region::RightOfSplit); } - _scale_amplitude = other._scale_amplitude; + _scale_amplitude = other->_scale_amplitude; save_state ("initial state"); _envelope.StateChanged.connect (mem_fun (*this, &AudioRegion::envelope_changed)); - - if (announce) { - CheckNewRegion (this); /* EMIT SIGNAL */ - } + + assert(_type == DataType::AUDIO); } -AudioRegion::AudioRegion (const AudioRegion &other) - : Region (other) - , _fade_in (other._fade_in) - , _fade_out (other._fade_out) - , _envelope (other._envelope) +AudioRegion::AudioRegion (boost::shared_ptr other) + : Region (other), + _fade_in (other->_fade_in), + _fade_out (other->_fade_out), + _envelope (other->_envelope) { - _scale_amplitude = other._scale_amplitude; - _envelope = other._envelope; + _scale_amplitude = other->_scale_amplitude; + _envelope = other->_envelope; _fade_in_disabled = 0; _fade_out_disabled = 0; @@ -185,10 +171,10 @@ AudioRegion::AudioRegion (const AudioRegion &other) _envelope.StateChanged.connect (mem_fun (*this, &AudioRegion::envelope_changed)); - /* NOTE: no CheckNewRegion signal emitted here. This is the copy constructor */ + assert(_type == DataType::AUDIO); } -AudioRegion::AudioRegion (AudioSource& src, const XMLNode& node) +AudioRegion::AudioRegion (boost::shared_ptr src, const XMLNode& node) : Region (src, node) , _fade_in (0.0, 2.0, 1.0, false) , _fade_out (0.0, 2.0, 1.0, false) @@ -205,8 +191,6 @@ AudioRegion::AudioRegion (AudioSource& src, const XMLNode& node) _envelope.StateChanged.connect (mem_fun (*this, &AudioRegion::envelope_changed)); assert(_type == DataType::AUDIO); - - CheckNewRegion (this); /* EMIT SIGNAL */ } AudioRegion::AudioRegion (SourceList& srcs, const XMLNode& node) @@ -227,13 +211,11 @@ AudioRegion::AudioRegion (SourceList& srcs, const XMLNode& node) _envelope.StateChanged.connect (mem_fun (*this, &AudioRegion::envelope_changed)); assert(_type == DataType::AUDIO); - - CheckNewRegion (this); /* EMIT SIGNAL */ } AudioRegion::~AudioRegion () { - GoingAway (this); + GoingAway (); /* EMIT SIGNAL */ } StateManager::State* @@ -345,7 +327,7 @@ AudioRegion::read_peaks (PeakData *buf, jack_nframes_t npeaks, jack_nframes_t of return 0; } - if (audio_source(chan_n).read_peaks (buf, npeaks, offset, cnt, samples_per_unit)) { + if (audio_source(chan_n)->read_peaks (buf, npeaks, offset, cnt, samples_per_unit)) { return 0; } else { if (_scale_amplitude != 1.0) { @@ -419,12 +401,12 @@ AudioRegion::_read_at (const SourceList& srcs, Sample *buf, Sample *mixdown_buff _read_data_count = 0; - AudioSource& src = audio_source(chan_n); - if (src.read (mixdown_buffer, _start + internal_offset, to_read) != to_read) { + boost::shared_ptr src = audio_source(chan_n); + if (src->read (mixdown_buffer, _start + internal_offset, to_read) != to_read) { return 0; /* "read nothing" */ } - _read_data_count += src.read_data_count(); + _read_data_count += src->read_data_count(); /* fade in */ @@ -974,7 +956,7 @@ AudioRegion::separate_by_channel (Session& session, vector& v) con int AudioRegion::apply (AudioFilter& filter) { - return filter.run (*this); + return filter.run (boost::shared_ptr (this)); } int @@ -1002,7 +984,7 @@ AudioRegion::exportme (Session& session, AudioExportSpecification& spec) if (spec.channels == 1) { - if (audio_source().read (spec.dataF, _start + spec.pos, to_read) != to_read) { + if (audio_source()->read (spec.dataF, _start + spec.pos, to_read) != to_read) { goto out; } @@ -1012,7 +994,7 @@ AudioRegion::exportme (Session& session, AudioExportSpecification& spec) for (uint32_t chan = 0; chan < spec.channels; ++chan) { - if (audio_source(chan).read (buf, _start + spec.pos, to_read) != to_read) { + if (audio_source(chan)->read (buf, _start + spec.pos, to_read) != to_read) { goto out; } @@ -1090,7 +1072,7 @@ AudioRegion::normalize_to (float target_dB) /* read it in */ - if (audio_source (n).read (buf, fpos, to_read) != to_read) { + if (audio_source (n)->read (buf, fpos, to_read) != to_read) { return; } @@ -1178,16 +1160,16 @@ AudioRegion::speed_mismatch (float sr) const return false; } - float fsr = audio_source().sample_rate(); + float fsr = audio_source()->sample_rate(); return fsr != sr; } -AudioSource& +boost::shared_ptr AudioRegion::audio_source (uint32_t n) const { // Guaranteed to succeed (use a static cast?) - return dynamic_cast(source(n)); + return boost::dynamic_pointer_cast(source(n)); } extern "C" { @@ -1205,7 +1187,7 @@ uint32_t region_length_from_c (void *arg) uint32_t sourcefile_length_from_c (void *arg, double zoom_factor) { - return ( (AudioRegion *) arg)->audio_source().available_peaks (zoom_factor) ; + return ( (AudioRegion *) arg)->audio_source()->available_peaks (zoom_factor) ; } } /* extern "C" */ diff --git a/libs/ardour/audiosource.cc b/libs/ardour/audiosource.cc index 9620565ae2..b9d21223e3 100644 --- a/libs/ardour/audiosource.cc +++ b/libs/ardour/audiosource.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -65,6 +66,7 @@ AudioSource::AudioSource (string name) AudioSource::AudioSource (const XMLNode& node) : Source (node) { + cerr << "audiosource from XML\n"; if (pending_peak_sources_lock == 0) { pending_peak_sources_lock = new Glib::Mutex; } @@ -249,18 +251,18 @@ AudioSource::stop_peak_thread () } void -AudioSource::queue_for_peaks (AudioSource& source) +AudioSource::queue_for_peaks (AudioSource* source) { if (have_peak_thread) { - + Glib::Mutex::Lock lm (*pending_peak_sources_lock); - source.next_peak_clear_should_notify = true; + source->next_peak_clear_should_notify = true; if (find (pending_peak_sources.begin(), pending_peak_sources.end(), - &source) == pending_peak_sources.end()) { - pending_peak_sources.push_back (&source); + source) == pending_peak_sources.end()) { + pending_peak_sources.push_back (source); } char c = (char) PeakRequest::Build; @@ -829,7 +831,7 @@ AudioSource::build_peaks_from_scratch () next_peak_clear_should_notify = true; pending_peak_builds.push_back (new PeakBuildRecord (0, _length)); - queue_for_peaks (*this); + queue_for_peaks (this); } bool diff --git a/libs/ardour/auditioner.cc b/libs/ardour/auditioner.cc index 3109323acd..29ae3b4d2b 100644 --- a/libs/ardour/auditioner.cc +++ b/libs/ardour/auditioner.cc @@ -20,6 +20,8 @@ #include +#include + #include #include #include @@ -28,9 +30,13 @@ #include #include #include +#include using namespace std; using namespace ARDOUR; +using namespace PBD; + +#include "i18n.h" Auditioner::Auditioner (Session& s) : AudioTrack (s, "auditioner", Route::Hidden) @@ -59,7 +65,7 @@ Auditioner::Auditioner (Session& s) IO::output_changed.connect (mem_fun (*this, &Auditioner::output_changed)); - the_region = 0; + the_region.reset ((AudioRegion*) 0); g_atomic_int_set (&_active, 0); } @@ -74,7 +80,7 @@ Auditioner::prepare_playlist () AudioPlaylist* const apl = dynamic_cast(_diskstream->playlist()); assert(apl); - apl->clear (false, false); + apl->clear (false); return *apl; } @@ -101,7 +107,7 @@ Auditioner::audition_current_playlist () } void -Auditioner::audition_region (AudioRegion& region) +Auditioner::audition_region (boost::shared_ptr region) { if (g_atomic_int_get (&_active)) { /* don't go via session for this, because we are going @@ -110,13 +116,20 @@ Auditioner::audition_region (AudioRegion& region) cancel_audition (); } + if (boost::dynamic_pointer_cast(region) == 0) { + error << _("Auditioning of non-audio regions not yet supported") << endmsg; + return; + } + Glib::Mutex::Lock lm (lock); - the_region = new AudioRegion (region); + /* copy it */ + + boost::shared_ptr the_region (boost::dynamic_pointer_cast (RegionFactory::create (region))); the_region->set_position (0, this); - _diskstream->playlist()->clear (true, false); - _diskstream->playlist()->add_region (*the_region, 0, 1, false); + _diskstream->playlist()->clear (false); + _diskstream->playlist()->add_region (the_region, 0, 1, false); while (_diskstream->n_channels().get(DataType::AUDIO) < the_region->n_channels()) { audio_diskstream()->add_channel (); diff --git a/libs/ardour/automation_event.cc b/libs/ardour/automation_event.cc index ccfcef28f4..afdeecbbfe 100644 --- a/libs/ardour/automation_event.cc +++ b/libs/ardour/automation_event.cc @@ -136,6 +136,8 @@ AutomationList::~AutomationList() std::set all_events; AutomationList::State* asp; + GoingAway (); + for (AutomationEventList::iterator x = events.begin(); x != events.end(); ++x) { all_events.insert (*x); } diff --git a/libs/ardour/control_protocol_manager.cc b/libs/ardour/control_protocol_manager.cc index 0370886a35..5c02936ba0 100644 --- a/libs/ardour/control_protocol_manager.cc +++ b/libs/ardour/control_protocol_manager.cc @@ -43,7 +43,7 @@ void ControlProtocolManager::set_session (Session& s) { _session = &s; - _session->going_away.connect (mem_fun (*this, &ControlProtocolManager::drop_session)); + _session->GoingAway.connect (mem_fun (*this, &ControlProtocolManager::drop_session)); for (list::iterator i = control_protocol_info.begin(); i != control_protocol_info.end(); ++i) { if ((*i)->requested || (*i)->mandatory) { diff --git a/libs/ardour/coreaudiosource.cc b/libs/ardour/coreaudiosource.cc index d2a9a8c8e6..652ca1e4f2 100644 --- a/libs/ardour/coreaudiosource.cc +++ b/libs/ardour/coreaudiosource.cc @@ -141,7 +141,7 @@ CoreAudioSource::init (const string& idstr) CoreAudioSource::~CoreAudioSource () { - GoingAway (this); /* EMIT SIGNAL */ + GoingAway (); /* EMIT SIGNAL */ if (af) { ExtAudioFileDispose (af); diff --git a/libs/ardour/crossfade.cc b/libs/ardour/crossfade.cc index 379c9333b0..fcd2158fd8 100644 --- a/libs/ardour/crossfade.cc +++ b/libs/ardour/crossfade.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2003 Paul Davis + Copyright (C) 2003-2006 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -36,7 +36,7 @@ using namespace ARDOUR; using namespace PBD; jack_nframes_t Crossfade::_short_xfade_length = 0; -Change Crossfade::ActiveChanged = ARDOUR::new_change(); +Change Crossfade::ActiveChanged = new_change(); /* XXX if and when we ever implement parallel processing of the process() callback, these will need to be handled on a per-thread basis. @@ -70,15 +70,15 @@ Crossfade::operator== (const Crossfade& other) return (_in == other._in) && (_out == other._out); } -Crossfade::Crossfade (ARDOUR::AudioRegion& in, ARDOUR::AudioRegion& out, +Crossfade::Crossfade (boost::shared_ptr in, boost::shared_ptr out, jack_nframes_t length, jack_nframes_t position, AnchorPoint ap) : _fade_in (0.0, 2.0, 1.0), // linear (gain coefficient) => -inf..+6dB _fade_out (0.0, 2.0, 1.0) // linear (gain coefficient) => -inf..+6dB { - _in = ∈ - _out = &out; + _in = in; + _out = out; _length = length; _position = position; _anchor_point = ap; @@ -89,7 +89,7 @@ Crossfade::Crossfade (ARDOUR::AudioRegion& in, ARDOUR::AudioRegion& out, initialize (); } -Crossfade::Crossfade (ARDOUR::AudioRegion& a, ARDOUR::AudioRegion& b, CrossfadeModel model, bool act) +Crossfade::Crossfade (boost::shared_ptr a, boost::shared_ptr b, CrossfadeModel model, bool act) : _fade_in (0.0, 2.0, 1.0), // linear (gain coefficient) => -inf..+6dB _fade_out (0.0, 2.0, 1.0) // linear (gain coefficient) => -inf..+6dB { @@ -110,7 +110,7 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode& node) : _fade_in (0.0, 2.0, 1.0), // linear (gain coefficient) => -inf..+6dB _fade_out (0.0, 2.0, 1.0) // linear (gain coefficient) => -inf..+6dB { - Region* r; + boost::shared_ptr r; XMLProperty* prop; LocaleGuard lg (X_("POSIX")); @@ -129,7 +129,7 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode& node) throw failed_constructor(); } - if ((_in = dynamic_cast (r)) == 0) { + if ((_in = boost::dynamic_pointer_cast (r)) == 0) { throw failed_constructor(); } @@ -146,7 +146,7 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode& node) throw failed_constructor(); } - if ((_out = dynamic_cast (r)) == 0) { + if ((_out = boost::dynamic_pointer_cast (r)) == 0) { throw failed_constructor(); } @@ -160,7 +160,7 @@ Crossfade::Crossfade (const Playlist& playlist, XMLNode& node) save_state ("initial"); } -Crossfade::Crossfade (const Crossfade &orig, ARDOUR::AudioRegion *newin, ARDOUR::AudioRegion *newout) +Crossfade::Crossfade (const Crossfade &orig, boost::shared_ptr newin, boost::shared_ptr newout) : _fade_in(orig._fade_in), _fade_out(orig._fade_out) { @@ -236,20 +236,20 @@ Crossfade::initialize (bool savestate) } int -Crossfade::compute (AudioRegion& a, AudioRegion& b, CrossfadeModel model) +Crossfade::compute (boost::shared_ptr a, boost::shared_ptr b, CrossfadeModel model) { - AudioRegion* top; - AudioRegion* bottom; + boost::shared_ptr top; + boost::shared_ptr bottom; jack_nframes_t short_xfade_length; short_xfade_length = _short_xfade_length; - if (a.layer() < b.layer()) { - top = &b; - bottom = &a; + if (a->layer() < b->layer()) { + top = b; + bottom = a; } else { - top = &a; - bottom = &b; + top = a; + bottom = b; } /* first check for matching ends */ @@ -605,7 +605,7 @@ Crossfade::member_changed (Change what_changed) { Change what_we_care_about = Change (Region::MuteChanged| Region::LayerChanged| - ARDOUR::BoundsChanged); + BoundsChanged); if (what_changed & what_we_care_about) { refresh (); diff --git a/libs/ardour/destructive_filesource.cc b/libs/ardour/destructive_filesource.cc index 65ca8dae67..7bf47e84a0 100644 --- a/libs/ardour/destructive_filesource.cc +++ b/libs/ardour/destructive_filesource.cc @@ -376,7 +376,7 @@ DestructiveFileSource::write_unlocked (Sample* data, jack_nframes_t cnt) } if (_build_peakfiles) { - queue_for_peaks (*this); + queue_for_peaks (this); } return cnt; diff --git a/libs/ardour/diskstream.cc b/libs/ardour/diskstream.cc index 9a80f3e70f..a5c4d769b1 100644 --- a/libs/ardour/diskstream.cc +++ b/libs/ardour/diskstream.cc @@ -32,6 +32,8 @@ #include #include +#include + #include #include #include @@ -63,7 +65,7 @@ using namespace PBD; */ jack_nframes_t Diskstream::disk_io_chunk_frames = 1024 * 256; -sigc::signal*> Diskstream::DeleteSources; +sigc::signal >*> Diskstream::DeleteSources; sigc::signal Diskstream::DiskOverrun; sigc::signal Diskstream::DiskUnderrun; @@ -330,7 +332,7 @@ Diskstream::use_playlist (Playlist* playlist) plstate_connection = _playlist->StateChanged.connect (mem_fun (*this, &Diskstream::playlist_changed)); plmod_connection = _playlist->Modified.connect (mem_fun (*this, &Diskstream::playlist_modified)); - plgone_connection = _playlist->GoingAway.connect (mem_fun (*this, &Diskstream::playlist_deleted)); + plgone_connection = _playlist->GoingAway.connect (bind (mem_fun (*this, &Diskstream::playlist_deleted), _playlist)); } if (!overwrite_queued) { diff --git a/libs/ardour/import.cc b/libs/ardour/import.cc index 6d98388941..14f67245fd 100644 --- a/libs/ardour/import.cc +++ b/libs/ardour/import.cc @@ -35,11 +35,15 @@ #include #include +#include #include #include #include #include #include +#include +#include + #include "i18n.h" @@ -52,8 +56,8 @@ int Session::import_audiofile (import_status& status) { SNDFILE *in; - AudioFileSource **newfiles = 0; - AudioRegion::SourceList sources; + vector > newfiles; + SourceList sources; SF_INFO info; float *data = 0; Sample **channel_data = 0; @@ -94,11 +98,10 @@ Session::import_audiofile (import_status& status) } } - newfiles = new AudioFileSource *[info.channels]; for (n = 0; n < info.channels; ++n) { - newfiles[n] = 0; + newfiles.push_back (boost::shared_ptr()); } - + sounds_dir = discover_best_sound_dir (); basepath = PBD::basename_nosuffix (status.pathname); @@ -135,12 +138,9 @@ Session::import_audiofile (import_status& status) } while ( !goodfile); - try { - newfiles[n] = new SndFileSource (buf, - Config->get_native_file_data_format(), - Config->get_native_file_header_format(), - frame_rate ()); + newfiles[n] = boost::dynamic_pointer_cast ( + SourceFactory::createWritable (DataType::AUDIO, buf, false, frame_rate())); } catch (failed_constructor& err) { @@ -217,8 +217,8 @@ Session::import_audiofile (import_status& status) sources.push_back(newfiles[n]); } - AudioRegion *r = new AudioRegion (sources, 0, newfiles[0]->length(), region_name_from_path (Glib::path_get_basename (basepath)), - 0, AudioRegion::Flag (AudioRegion::DefaultFlags | AudioRegion::WholeFile)); + boost::shared_ptr r (boost::dynamic_pointer_cast (RegionFactory::create (sources, 0, newfiles[0]->length(), region_name_from_path (Glib::path_get_basename (basepath)), + 0, AudioRegion::Flag (AudioRegion::DefaultFlags | AudioRegion::WholeFile)))); status.new_regions.push_back (r); @@ -233,10 +233,10 @@ Session::import_audiofile (import_status& status) did not bother to create whole-file AudioRegions for them. Do it now. */ - AudioRegion *r = new AudioRegion (*newfiles[n], 0, newfiles[n]->length(), region_name_from_path (Glib::path_get_basename (newfiles[n]->name())), - 0, AudioRegion::Flag (AudioRegion::DefaultFlags | AudioRegion::WholeFile | AudioRegion::Import)); - - status.new_regions.push_back (r); + status.new_regions.push_back (boost::dynamic_pointer_cast + (RegionFactory::create (boost::static_pointer_cast (newfiles[n]), 0, newfiles[n]->length(), + region_name_from_path (Glib::path_get_basename (newfiles[n]->name())), + 0, AudioRegion::Flag (AudioRegion::DefaultFlags | AudioRegion::WholeFile | AudioRegion::Import)))); } } @@ -262,19 +262,13 @@ Session::import_audiofile (import_status& status) } if (status.cancel) { - for (vector::iterator i = status.new_regions.begin(); i != status.new_regions.end(); ++i) { - delete *i; - } + status.new_regions.clear (); for (vector::iterator i = new_paths.begin(); i != new_paths.end(); ++i) { unlink ((*i).c_str()); } } - if (newfiles) { - delete [] newfiles; - } - if (tmp_convert_file.length()) { unlink(tmp_convert_file.c_str()); } diff --git a/libs/ardour/insert.cc b/libs/ardour/insert.cc index f4263099eb..2fe40424fd 100644 --- a/libs/ardour/insert.cc +++ b/libs/ardour/insert.cc @@ -176,7 +176,7 @@ PluginInsert::init () PluginInsert::~PluginInsert () { - GoingAway (this); /* EMIT SIGNAL */ + GoingAway (); /* EMIT SIGNAL */ } void @@ -907,7 +907,7 @@ PortInsert::PortInsert (Session& s, const XMLNode& node) PortInsert::~PortInsert () { - GoingAway (this); + GoingAway (); } void diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc index 430801310d..0abc10648e 100644 --- a/libs/ardour/io.cc +++ b/libs/ardour/io.cc @@ -129,13 +129,13 @@ IO::IO (Session& s, string name, _gain_automation_state = Off; _gain_automation_style = Absolute; - - { - // IO::Meter is emitted from another thread so the - // Meter signal must be protected. - Glib::Mutex::Lock guard (m_meter_signal_lock); - m_meter_connection = Meter.connect (mem_fun (*this, &IO::meter)); - } + + { + // IO::Meter is emitted from another thread so the + // Meter signal must be protected. + Glib::Mutex::Lock guard (m_meter_signal_lock); + m_meter_connection = Meter.connect (mem_fun (*this, &IO::meter)); + } // Connect to our own MoreChannels signal to connect output buffers IO::MoreChannels.connect (mem_fun (*this, &IO::attach_buffers)); @@ -143,7 +143,8 @@ IO::IO (Session& s, string name, IO::~IO () { - Glib::Mutex::Lock guard (m_meter_signal_lock); + Glib::Mutex::Lock guard (m_meter_signal_lock); + Glib::Mutex::Lock lm (io_lock); for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) { @@ -154,7 +155,7 @@ IO::~IO () _session.engine().unregister_port (*i); } - m_meter_connection.disconnect(); + m_meter_connection.disconnect(); delete _meter; delete _panner; diff --git a/libs/ardour/ladspa_plugin.cc b/libs/ardour/ladspa_plugin.cc index 803cbd74a0..82cc4e6202 100644 --- a/libs/ardour/ladspa_plugin.cc +++ b/libs/ardour/ladspa_plugin.cc @@ -144,7 +144,7 @@ LadspaPlugin::~LadspaPlugin () deactivate (); cleanup (); - GoingAway (this); /* EMIT SIGNAL */ + GoingAway (); /* EMIT SIGNAL */ /* XXX who should close a plugin? */ diff --git a/libs/ardour/location.cc b/libs/ardour/location.cc index ca88a2851b..58ef812d2e 100644 --- a/libs/ardour/location.cc +++ b/libs/ardour/location.cc @@ -51,6 +51,13 @@ Location::Location (const Location& other) _flags = Flags (_flags & ~IsEnd); } +Location::Location (const XMLNode& node) +{ + if (set_state (node)) { + throw failed_constructor (); + } +} + Location* Location::operator= (const Location& other) { @@ -241,13 +248,16 @@ XMLNode& Location::get_state (void) { XMLNode *node = new XMLNode ("Location"); - char buf[32]; + char buf[64]; typedef map::const_iterator CI; + for(CI m = cd_info.begin(); m != cd_info.end(); ++m){ node->add_child_nocopy(cd_info_node(m->first, m->second)); } + id().print (buf); + node->add_property("id", buf); node->add_property ("name", name()); snprintf (buf, sizeof (buf), "%u", start()); node->add_property ("start", buf); @@ -262,7 +272,6 @@ Location::get_state (void) int Location::set_state (const XMLNode& node) { - XMLPropertyList plist; const XMLProperty *prop; XMLNodeList cd_list = node.children(); @@ -272,14 +281,17 @@ Location::set_state (const XMLNode& node) string cd_name; string cd_value; - if (node.name() != "Location") { error << _("incorrect XML node passed to Location::set_state") << endmsg; return -1; } - plist = node.properties(); - + if ((prop = node.property ("id")) == 0) { + warning << _("XML node for Location has no ID information") << endmsg; + } else { + _id = prop->value (); + } + if ((prop = node.property ("name")) == 0) { error << _("XML node for Location has no name information") << endmsg; return -1; @@ -582,16 +594,20 @@ Locations::set_state (const XMLNode& node) Glib::Mutex::Lock lm (lock); for (niter = nlist.begin(); niter != nlist.end(); ++niter) { - Location *loc = new Location; - if (loc->set_state (**niter)) { - delete loc; - } else { + try { + + Location *loc = new Location (**niter); locations.push_back (loc); } + + catch (failed_constructor& err) { + error << _("could not load location from session file - ignored") << endmsg; + } } if (locations.size()) { + current_location = locations.front(); } else { current_location = 0; diff --git a/libs/ardour/midi_diskstream.cc b/libs/ardour/midi_diskstream.cc index e42e455df0..6435655689 100644 --- a/libs/ardour/midi_diskstream.cc +++ b/libs/ardour/midi_diskstream.cc @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -66,7 +67,6 @@ MidiDiskstream::MidiDiskstream (Session &sess, const string &name, Diskstream::F //, _playback_wrap_buffer(0) //, _capture_wrap_buffer(0) , _source_port(0) - , _write_source(0) , _capture_transition_buf(0) , _last_flush_frame(0) { @@ -91,7 +91,6 @@ MidiDiskstream::MidiDiskstream (Session& sess, const XMLNode& node) //, _playback_wrap_buffer(0) //, _capture_wrap_buffer(0) , _source_port(0) - , _write_source(0) , _capture_transition_buf(0) , _last_flush_frame(0) { @@ -972,7 +971,7 @@ MidiDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_cap uint32_t buffer_position; bool more_work = true; int err = 0; - MidiRegion* region = 0; + boost::shared_ptr region; jack_nframes_t total_capture; MidiRegion::SourceList srcs; MidiRegion::SourceList::iterator src; @@ -1007,15 +1006,15 @@ MidiDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_cap if (abort_capture) { - list* deletion_list = new list; + list >* deletion_list = new list >; if (_write_source) { + _write_source->mark_for_remove (); - _write_source->release (); deletion_list->push_back (_write_source); - _write_source = 0; + _write_source.reset(); } /* new source set up in "out" below */ @@ -1036,7 +1035,7 @@ MidiDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_cap /* figure out the name for this take */ - SMFSource* s = _write_source; + boost::shared_ptr s = _write_source; if (s) { @@ -1056,10 +1055,12 @@ MidiDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_cap */ try { assert(_write_source); - region = new MidiRegion (srcs, _write_source->last_capture_start_frame(), total_capture, - region_name_from_path (_write_source->name()), - 0, Region::Flag (Region::DefaultFlags|Region::Automatic|Region::WholeFile)); + + boost::shared_ptr rx (RegionFactory::create (srcs, _write_source->last_capture_start_frame(), total_capture, + region_name_from_path (_write_source->name()), + 0, Region::Flag (Region::DefaultFlags|Region::Automatic|Region::WholeFile))); + region = boost::dynamic_pointer_cast (rx); region->special_set_position (capture_info.front()->start); } @@ -1084,11 +1085,12 @@ MidiDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_cap // cerr << _name << ": based on ci of " << (*ci)->start << " for " << (*ci)->frames << " add a region\n"; try { - region = new MidiRegion (srcs, buffer_position, (*ci)->frames, region_name); + boost::shared_ptr rx (RegionFactory::create (srcs, buffer_position, (*ci)->frames, region_name)); + region = boost::dynamic_pointer_cast (rx); } catch (failed_constructor& err) { - error << _("MidiDiskstream: could not create region for captured audio!") << endmsg; + error << _("MidiDiskstream: could not create region for captured midi!") << endmsg; continue; /* XXX is this OK? */ } @@ -1097,7 +1099,7 @@ MidiDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_cap // cerr << "add new region, buffer position = " << buffer_position << " @ " << (*ci)->start << endl; i_am_the_modifier++; - _playlist->add_region (*region, (*ci)->start); + _playlist->add_region (region, (*ci)->start); i_am_the_modifier--; buffer_position += (*ci)->frames; @@ -1361,16 +1363,14 @@ MidiDiskstream::use_new_write_source (uint32_t n) if (SMFSource::is_empty (_write_source->path())) { _write_source->mark_for_remove (); - _write_source->release(); - delete _write_source; + _write_source.reset(); } else { - _write_source->release(); - _write_source = 0; + _write_source.reset(); } } try { - _write_source = dynamic_cast(_session.create_midi_source_for_session (*this)); + _write_source = boost::dynamic_pointer_cast(_session.create_midi_source_for_session (*this)); if (!_write_source) { throw failed_constructor(); } @@ -1378,11 +1378,10 @@ MidiDiskstream::use_new_write_source (uint32_t n) catch (failed_constructor &err) { error << string_compose (_("%1:%2 new capture file not initialized correctly"), _name, n) << endmsg; - _write_source = 0; + _write_source.reset(); return -1; } - _write_source->use (); _write_source->set_allow_remove_if_empty (true); return 0; diff --git a/libs/ardour/midi_playlist.cc b/libs/ardour/midi_playlist.cc index 051203e55e..7f2781d707 100644 --- a/libs/ardour/midi_playlist.cc +++ b/libs/ardour/midi_playlist.cc @@ -129,44 +129,19 @@ MidiPlaylist::MidiPlaylist (const MidiPlaylist& other, jack_nframes_t start, jac MidiPlaylist::~MidiPlaylist () { - set all_regions; - - GoingAway (this); - - /* find every region we've ever used, and add it to the set of - all regions. - */ - - for (RegionList::iterator x = regions.begin(); x != regions.end(); ++x) { - all_regions.insert (*x); - } + GoingAway (); /* EMIT SIGNAL */ for (StateMap::iterator i = states.begin(); i != states.end(); ++i) { MidiPlaylist::State* apstate = dynamic_cast (*i); - - for (RegionList::iterator r = apstate->regions.begin(); r != apstate->regions.end(); ++r) { - all_regions.insert (*r); - } - delete apstate; } - - /* delete every region */ - - for (set::iterator ar = all_regions.begin(); ar != all_regions.end(); ++ar) { - (*ar)->unlock_sources (); - delete *ar; - } - } -struct RegionSortByLayer -{ - bool operator() (Region *a, Region *b) - { - return a->layer() < b->layer(); - } +struct RegionSortByLayer { + bool operator() (boost::shared_ptr a, boost::shared_ptr b) { + return a->layer() < b->layer(); + } }; /** Returns the number of frames in time duration read (eg could be large when 0 events are read) */ @@ -187,22 +162,24 @@ MidiPlaylist::read (MidiRingBuffer& dst, jack_nframes_t start, //_read_data_count = 0; - vector regs; // relevent regions overlapping start <--> end + // relevent regions overlapping start <--> end + vector > regs; for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) { - MidiRegion* const mr = dynamic_cast(*i); - if (mr && mr->coverage (start, end) != OverlapNone) { - regs.push_back(mr); + + if ((*i)->coverage (start, end) != OverlapNone) { + regs.push_back(*i); } } RegionSortByLayer layer_cmp; sort(regs.begin(), regs.end(), layer_cmp); - for (vector::iterator i = regs.begin(); i != regs.end(); ++i) { + for (vector >::iterator i = regs.begin(); i != regs.end(); ++i) { // FIXME: ensure time is monotonic here - (*i)->read_at (dst, start, dur, chan_n, 0, 0);// FIXME read_frames, skip_frames); - ret += (*i)->read_data_count(); + boost::shared_ptr mr = boost::dynamic_pointer_cast(*i); + mr->read_at (dst, start, dur, chan_n, 0, 0);// FIXME read_frames, skip_frames); + ret += mr->read_data_count(); } _read_data_count += ret; @@ -213,16 +190,8 @@ MidiPlaylist::read (MidiRingBuffer& dst, jack_nframes_t start, void -MidiPlaylist::remove_dependents (Region& region) +MidiPlaylist::remove_dependents (boost::shared_ptr region) { - MidiRegion* r = dynamic_cast (®ion); - - if (r == 0) { - PBD::fatal << _("programming error: non-midi Region passed to remove_overlap in midi playlist") - << endmsg; - return; - } - } @@ -241,17 +210,12 @@ MidiPlaylist::flush_notifications () } void -MidiPlaylist::refresh_dependents (Region& r) +MidiPlaylist::refresh_dependents (boost::shared_ptr r) { - MidiRegion* ar = dynamic_cast(&r); - - if (ar == 0) { - return; - } } void -MidiPlaylist::finalize_split_region (Region *o, Region *l, Region *r) +MidiPlaylist::finalize_split_region (boost::shared_ptr original, boost::shared_ptr left, boost::shared_ptr right) { throw; // I don't wanna /* @@ -293,48 +257,8 @@ MidiPlaylist::finalize_split_region (Region *o, Region *l, Region *r) } void -MidiPlaylist::check_dependents (Region& r, bool norefresh) +MidiPlaylist::check_dependents (boost::shared_ptr r, bool norefresh) { - MidiRegion* other; - MidiRegion* region; - MidiRegion* top; - MidiRegion* bottom; - - if (in_set_state || in_partition) { - return; - } - - if ((region = dynamic_cast (&r)) == 0) { - PBD::fatal << _("programming error: non-midi Region tested for overlap in midi playlist") - << endmsg; - return; - } - - if (!norefresh) { - refresh_dependents (r); - } - - for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) { - - other = dynamic_cast (*i); - - if (other == region) { - continue; - } - - if (other->muted() || region->muted()) { - continue; - } - - if (other->layer() < region->layer()) { - top = region; - bottom = other; - } else { - top = other; - bottom = region; - } - - } } @@ -362,14 +286,14 @@ MidiPlaylist::set_state (const XMLNode& node) void MidiPlaylist::drop_all_states () { - set all_regions; + set > all_regions; - /* find every region we've ever used, and add it to the set of + /* find every region we've ever used, and add it to the set of all regions. same for xfades; */ for (StateMap::iterator i = states.begin(); i != states.end(); ++i) { - + MidiPlaylist::State* apstate = dynamic_cast (*i); for (RegionList::iterator r = apstate->regions.begin(); r != apstate->regions.end(); ++r) { @@ -379,21 +303,13 @@ MidiPlaylist::drop_all_states () /* now remove from the "all" lists every region that is in the current list. */ - for (list::iterator i = regions.begin(); i != regions.end(); ++i) { - set - ::iterator x = all_regions.find (*i); + for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) { + set >::iterator x = all_regions.find (*i); if (x != all_regions.end()) { all_regions.erase (x); } } - - /* delete every region that is left - these are all things that are part of our "history" */ - - for (set::iterator ar = all_regions.begin(); ar != all_regions.end(); ++ar) { - (*ar)->unlock_sources (); - delete *ar; - } - + /* Now do the generic thing ... */ StateManager::drop_all_states (); @@ -456,7 +372,7 @@ MidiPlaylist::state (bool full_state) void MidiPlaylist::dump () const { - Region *r; + boost::shared_ptr r; cerr << "Playlist \"" << _name << "\" " << endl << regions.size() << " regions " @@ -475,9 +391,9 @@ MidiPlaylist::dump () const } bool -MidiPlaylist::destroy_region (Region* region) +MidiPlaylist::destroy_region (boost::shared_ptr region) { - MidiRegion* r = dynamic_cast (region); + boost::shared_ptr r = boost::dynamic_pointer_cast (region); bool changed = false; if (r == 0) { @@ -498,7 +414,6 @@ MidiPlaylist::destroy_region (Region* region) ++tmp; if ((*i) == region) { - (*i)->unlock_sources (); regions.erase (i); changed = true; } @@ -549,41 +464,8 @@ MidiPlaylist::destroy_region (Region* region) return changed; } - -void -MidiPlaylist::get_equivalent_regions (const MidiRegion& other, vector& results) -{ - for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) { - - MidiRegion* ar = dynamic_cast (*i); - - if (ar) { - if (Config->get_use_overlap_equivalency()) { - if (ar->overlap_equivalent (other)) { - results.push_back (ar); - } else if (ar->equivalent (other)) { - results.push_back (ar); - } - } - } - } -} - -void -MidiPlaylist::get_region_list_equivalent_regions (const MidiRegion& other, vector& results) -{ - for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) { - - MidiRegion* ar = dynamic_cast (*i); - - if (ar && ar->region_list_equivalent (other)) { - results.push_back (ar); - } - } -} - bool -MidiPlaylist::region_changed (Change what_changed, Region* region) +MidiPlaylist::region_changed (Change what_changed, boost::shared_ptr region) { if (in_flush || in_set_state) { return false; diff --git a/libs/ardour/midi_region.cc b/libs/ardour/midi_region.cc index 136b2bfc38..c4816d8121 100644 --- a/libs/ardour/midi_region.cc +++ b/libs/ardour/midi_region.cc @@ -48,68 +48,51 @@ using namespace std; using namespace ARDOUR; /** Basic MidiRegion constructor (one channel) */ -MidiRegion::MidiRegion (MidiSource& src, jack_nframes_t start, jack_nframes_t length, bool announce) - : Region (src, start, length, PBD::basename_nosuffix(src.name()), DataType::MIDI, 0, Region::Flag(Region::DefaultFlags|Region::External)) +MidiRegion::MidiRegion (boost::shared_ptr src, jack_nframes_t start, jack_nframes_t length) + : Region (src, start, length, PBD::basename_nosuffix(src->name()), DataType::MIDI, 0, Region::Flag(Region::DefaultFlags|Region::External)) { save_state ("initial state"); - if (announce) { - CheckNewRegion (this); /* EMIT SIGNAL */ - } - assert(_name.find("/") == string::npos); } /* Basic MidiRegion constructor (one channel) */ -MidiRegion::MidiRegion (MidiSource& src, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t layer, Flag flags, bool announce) +MidiRegion::MidiRegion (boost::shared_ptr src, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t layer, Flag flags) : Region (src, start, length, name, DataType::MIDI, layer, flags) { save_state ("initial state"); - if (announce) { - CheckNewRegion (this); /* EMIT SIGNAL */ - } - assert(_name.find("/") == string::npos); } /* Basic MidiRegion constructor (many channels) */ -MidiRegion::MidiRegion (SourceList& srcs, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t layer, Flag flags, bool announce) +MidiRegion::MidiRegion (SourceList& srcs, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t layer, Flag flags) : Region (srcs, start, length, name, DataType::MIDI, layer, flags) { save_state ("initial state"); - if (announce) { - CheckNewRegion (this); /* EMIT SIGNAL */ - } - assert(_name.find("/") == string::npos); } /** Create a new MidiRegion, that is part of an existing one */ -MidiRegion::MidiRegion (const MidiRegion& other, jack_nframes_t offset, jack_nframes_t length, const string& name, layer_t layer, Flag flags, bool announce) +MidiRegion::MidiRegion (boost::shared_ptr other, jack_nframes_t offset, jack_nframes_t length, const string& name, layer_t layer, Flag flags) : Region (other, offset, length, name, layer, flags) { save_state ("initial state"); - if (announce) { - CheckNewRegion (this); /* EMIT SIGNAL */ - } - assert(_name.find("/") == string::npos); } -MidiRegion::MidiRegion (const MidiRegion &other) +MidiRegion::MidiRegion (boost::shared_ptr other) : Region (other) { save_state ("initial state"); - /* NOTE: no CheckNewRegion signal emitted here. This is the copy constructor */ assert(_name.find("/") == string::npos); } -MidiRegion::MidiRegion (MidiSource& src, const XMLNode& node) +MidiRegion::MidiRegion (boost::shared_ptr src, const XMLNode& node) : Region (src, node) { if (set_state (node)) { @@ -120,8 +103,6 @@ MidiRegion::MidiRegion (MidiSource& src, const XMLNode& node) assert(_name.find("/") == string::npos); assert(_type == DataType::MIDI); - - CheckNewRegion (this); /* EMIT SIGNAL */ } MidiRegion::MidiRegion (SourceList& srcs, const XMLNode& node) @@ -135,13 +116,11 @@ MidiRegion::MidiRegion (SourceList& srcs, const XMLNode& node) assert(_name.find("/") == string::npos); assert(_type == DataType::MIDI); - - CheckNewRegion (this); /* EMIT SIGNAL */ } MidiRegion::~MidiRegion () { - GoingAway (this); + GoingAway (); /* EMIT SIGNAL */ } StateManager::State* @@ -260,12 +239,12 @@ MidiRegion::_read_at (const SourceList& srcs, MidiRingBuffer& dst, _read_data_count = 0; - MidiSource& src = midi_source(chan_n); - if (src.read (dst, _start + internal_offset, to_read, _position) != to_read) { + boost::shared_ptr src = midi_source(chan_n); + if (src->read (dst, _start + internal_offset, to_read, _position) != to_read) { return 0; /* "read nothing" */ } - _read_data_count += src.read_data_count(); // FIXME: semantics? + _read_data_count += src->read_data_count(); // FIXME: semantics? return to_read; } @@ -380,10 +359,10 @@ MidiRegion::separate_by_channel (Session& session, vector& v) const return -1; } -MidiSource& +boost::shared_ptr MidiRegion::midi_source (uint32_t n) const { // Guaranteed to succeed (use a static cast?) - return dynamic_cast(source(n)); + return boost::dynamic_pointer_cast(source(n)); } diff --git a/libs/ardour/osc.cc b/libs/ardour/osc.cc index 5aaf9d5591..c43f254f6f 100644 --- a/libs/ardour/osc.cc +++ b/libs/ardour/osc.cc @@ -365,7 +365,7 @@ void OSC::set_session (Session& s) { session = &s; - session->going_away.connect (mem_fun (*this, &OSC::session_going_away)); + session->GoingAway.connect (mem_fun (*this, &OSC::session_going_away)); } void diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index 61aa5c587a..f778175e9e 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -55,19 +55,19 @@ struct ShowMeTheList { }; struct RegionSortByLayer { - bool operator() (Region *a, Region *b) { + bool operator() (boost::shared_ptr a, boost::shared_ptr b) { return a->layer() < b->layer(); } }; struct RegionSortByPosition { - bool operator() (Region *a, Region *b) { + bool operator() (boost::shared_ptr a, boost::shared_ptr b) { return a->position() < b->position(); } }; struct RegionSortByLastLayerOp { - bool operator() (Region *a, Region *b) { + bool operator() (boost::shared_ptr a, boost::shared_ptr b) { return a->last_layer_op() < b->last_layer_op(); } }; @@ -106,7 +106,7 @@ Playlist::Playlist (const Playlist& other, string namestr, bool hide) in_set_state = true; - for (list::iterator x = tmp.begin(); x != tmp.end(); ++x) { + for (list >::iterator x = tmp.begin(); x != tmp.end(); ++x) { add_region_internal( (*x), (*x)->position() ); } @@ -140,8 +140,8 @@ Playlist::Playlist (const Playlist& other, jack_nframes_t start, jack_nframes_t for (RegionList::const_iterator i = other.regions.begin(); i != other.regions.end(); i++) { - Region *region; - Region *new_region; + boost::shared_ptr region; + boost::shared_ptr new_region; jack_nframes_t offset = 0; jack_nframes_t position = 0; jack_nframes_t len = 0; @@ -183,7 +183,7 @@ Playlist::Playlist (const Playlist& other, jack_nframes_t start, jack_nframes_t _session.region_name (new_name, region->name(), false); - new_region = createRegion (*region, offset, len, new_name, region->layer(), region->flags()); + new_region = RegionFactory::RegionFactory::create (region, offset, len, new_name, region->layer(), region->flags()); add_region_internal (new_region, position, true); } @@ -221,7 +221,7 @@ Playlist::copy_regions (RegionList& newlist) const RegionLock rlock (const_cast (this)); for (RegionList::const_iterator i = regions.begin(); i != regions.end(); ++i) { - newlist.push_back (createRegion (**i)); + newlist.push_back (RegionFactory::RegionFactory::create (*i)); } } @@ -266,6 +266,7 @@ Playlist::Playlist (Playlist& pl) Playlist::~Playlist () { + /* GoingAway must be emitted by derived classes */ } void @@ -336,7 +337,7 @@ Playlist::notify_modified () } void -Playlist::notify_region_removed (Region *r) +Playlist::notify_region_removed (boost::shared_ptr r) { if (holding_state ()) { pending_removals.insert (pending_removals.end(), r); @@ -351,7 +352,7 @@ Playlist::notify_region_removed (Region *r) } void -Playlist::notify_region_added (Region *r) +Playlist::notify_region_added (boost::shared_ptr r) { if (holding_state()) { pending_adds.insert (pending_adds.end(), r); @@ -381,7 +382,7 @@ Playlist::flush_notifications () { RegionList::iterator r; RegionList::iterator a; - set dependent_checks_needed; + set > dependent_checks_needed; uint32_t n = 0; if (in_flush) { @@ -401,7 +402,7 @@ Playlist::flush_notifications () for (RegionList::iterator r = pending_bounds.begin(); r != pending_bounds.end(); ++r) { if (_session.get_layer_model() == Session::MoveAddHigher) { - timestamp_layer_op (**r); + timestamp_layer_op (*r); } pending_length = true; n++; @@ -418,12 +419,12 @@ Playlist::flush_notifications () n++; } - for (set::iterator x = dependent_checks_needed.begin(); x != dependent_checks_needed.end(); ++x) { - check_dependents (**x, false); + for (set >::iterator x = dependent_checks_needed.begin(); x != dependent_checks_needed.end(); ++x) { + check_dependents (*x, false); } for (r = pending_removals.begin(); r != pending_removals.end(); ++r) { - remove_dependents (**r); + remove_dependents (*r); RegionRemoved (*r); /* EMIT SIGNAL */ n++; } @@ -460,7 +461,7 @@ Playlist::flush_notifications () *************************************************************/ void -Playlist::add_region (const Region& region, jack_nframes_t position, float times, bool with_save) +Playlist::add_region (boost::shared_ptr region, jack_nframes_t position, float times, bool with_save) { RegionLock rlock (this); @@ -471,8 +472,8 @@ Playlist::add_region (const Region& region, jack_nframes_t position, float times jack_nframes_t pos = position; if (itimes >= 1) { - add_region_internal (const_cast(®ion), pos, true); - pos += region.length(); + add_region_internal (region, pos, true); + pos += region->length(); --itimes; } @@ -487,16 +488,16 @@ Playlist::add_region (const Region& region, jack_nframes_t position, float times */ for (int i = 0; i < itimes; ++i) { - Region *copy = createRegion (region); + boost::shared_ptr copy = RegionFactory::create (region); add_region_internal (copy, pos, true); - pos += region.length(); + pos += region->length(); } if (floor (times) != times) { - jack_nframes_t length = (jack_nframes_t) floor (region.length() * (times - floor (times))); + jack_nframes_t length = (jack_nframes_t) floor (region->length() * (times - floor (times))); string name; - _session.region_name (name, region.name(), false); - Region *sub = createRegion (region, 0, length, name, region.layer(), region.flags()); + _session.region_name (name, region->name(), false); + boost::shared_ptr sub = RegionFactory::create (region, 0, length, name, region->layer(), region->flags()); add_region_internal (sub, pos, true); } @@ -506,22 +507,19 @@ Playlist::add_region (const Region& region, jack_nframes_t position, float times } void -Playlist::add_region_internal (Region *region, jack_nframes_t position, bool delay_sort) +Playlist::add_region_internal (boost::shared_ptr region, jack_nframes_t position, bool delay_sort) { RegionSortByPosition cmp; jack_nframes_t old_length = 0; - // cerr << "adding region " << region->name() << " at " << position << endl; - if (!holding_state()) { old_length = _get_maximum_extent(); } region->set_playlist (this); region->set_position (position, this); - region->lock_sources (); - timestamp_layer_op (*region); + timestamp_layer_op (region); regions.insert (upper_bound (regions.begin(), regions.end(), region, cmp), region); @@ -535,7 +533,7 @@ Playlist::add_region_internal (Region *region, jack_nframes_t position, bool del notify_region_added (region); if (!holding_state ()) { - check_dependents (*region, false); + check_dependents (region, false); if (old_length != _get_maximum_extent()) { notify_length_changed (); } @@ -545,12 +543,12 @@ Playlist::add_region_internal (Region *region, jack_nframes_t position, bool del } void -Playlist::replace_region (Region& old, Region& newr, jack_nframes_t pos) +Playlist::replace_region (boost::shared_ptr old, boost::shared_ptr newr, jack_nframes_t pos) { RegionLock rlock (this); - remove_region_internal (&old); - add_region_internal (&newr, pos); + remove_region_internal (old); + add_region_internal (newr, pos); if (!holding_state ()) { possibly_splice_unlocked (); @@ -560,7 +558,7 @@ Playlist::replace_region (Region& old, Region& newr, jack_nframes_t pos) } void -Playlist::remove_region (Region *region) +Playlist::remove_region (boost::shared_ptr region) { RegionLock rlock (this); remove_region_internal (region); @@ -573,7 +571,7 @@ Playlist::remove_region (Region *region) } int -Playlist::remove_region_internal (Region *region, bool delay_sort) +Playlist::remove_region_internal (boost::shared_ptrregion, bool delay_sort) { RegionList::iterator i; jack_nframes_t old_length = 0; @@ -591,7 +589,7 @@ Playlist::remove_region_internal (Region *region, bool delay_sort) if (!holding_state ()) { relayer (); - remove_dependents (*region); + remove_dependents (region); if (old_length != _get_maximum_extent()) { notify_length_changed (); @@ -606,7 +604,7 @@ Playlist::remove_region_internal (Region *region, bool delay_sort) } void -Playlist::get_equivalent_regions (const Region& other, vector& results) +Playlist::get_equivalent_regions (boost::shared_ptr other, vector >& results) { for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) { if (Config->get_use_overlap_equivalency()) { @@ -620,7 +618,7 @@ Playlist::get_equivalent_regions (const Region& other, vector& results) } void -Playlist::get_region_list_equivalent_regions (const Region& other, vector& results) +Playlist::get_region_list_equivalent_regions (boost::shared_ptr other, vector >& results) { for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) { @@ -648,8 +646,8 @@ void Playlist::partition_internal (jack_nframes_t start, jack_nframes_t end, bool cutting, RegionList& thawlist) { RegionLock rlock (this); - Region *region; - Region *current; + boost::shared_ptr region; + boost::shared_ptr current; string new_name; RegionList::iterator tmp; OverlapType overlap; @@ -709,7 +707,7 @@ Playlist::partition_internal (jack_nframes_t start, jack_nframes_t end, bool cut /* "middle" ++++++ */ _session.region_name (new_name, current->name(), false); - region = createRegion (*current, pos2 - pos1, pos3 - pos2, new_name, + region = RegionFactory::create (current, pos2 - pos1, pos3 - pos2, new_name, regions.size(), Region::Flag(current->flags()|Region::Automatic|Region::LeftOfSplit|Region::RightOfSplit)); add_region_internal (region, start, true); new_regions.push_back (region); @@ -718,7 +716,7 @@ Playlist::partition_internal (jack_nframes_t start, jack_nframes_t end, bool cut /* "end" ====== */ _session.region_name (new_name, current->name(), false); - region = createRegion (*current, pos3 - pos1, pos4 - pos3, new_name, + region = RegionFactory::create (current, pos3 - pos1, pos4 - pos3, new_name, regions.size(), Region::Flag(current->flags()|Region::Automatic|Region::RightOfSplit)); add_region_internal (region, end, true); @@ -748,7 +746,7 @@ Playlist::partition_internal (jack_nframes_t start, jack_nframes_t end, bool cut /* end +++++ */ _session.region_name (new_name, current->name(), false); - region = createRegion (*current, pos2 - pos1, pos4 - pos2, new_name, (layer_t) regions.size(), + region = RegionFactory::create (current, pos2 - pos1, pos4 - pos2, new_name, (layer_t) regions.size(), Region::Flag(current->flags()|Region::Automatic|Region::LeftOfSplit)); add_region_internal (region, start, true); new_regions.push_back (region); @@ -782,7 +780,7 @@ Playlist::partition_internal (jack_nframes_t start, jack_nframes_t end, bool cut /* front **** */ _session.region_name (new_name, current->name(), false); - region = createRegion (*current, 0, pos3 - pos1, new_name, + region = RegionFactory::create (current, 0, pos3 - pos1, new_name, regions.size(), Region::Flag(current->flags()|Region::Automatic|Region::RightOfSplit)); add_region_internal (region, pos1, true); new_regions.push_back (region); @@ -822,7 +820,7 @@ Playlist::partition_internal (jack_nframes_t start, jack_nframes_t end, bool cut in_partition = false; for (RegionList::iterator i = new_regions.begin(); i != new_regions.end(); ++i) { - check_dependents (**i, false); + check_dependents (*i, false); } } @@ -943,7 +941,7 @@ Playlist::paste (Playlist& other, jack_nframes_t position, float times) while (itimes--) { for (RegionList::iterator i = other.regions.begin(); i != other.regions.end(); ++i) { - Region *copy_of_region = createRegion (**i); + boost::shared_ptr copy_of_region = RegionFactory::create (*i); /* put these new regions on top of all existing ones, but preserve the ordering they had in the original playlist. @@ -973,7 +971,7 @@ Playlist::paste (Playlist& other, jack_nframes_t position, float times) void -Playlist::duplicate (Region& region, jack_nframes_t position, float times) +Playlist::duplicate (boost::shared_ptr region, jack_nframes_t position, float times) { times = fabs (times); @@ -982,16 +980,16 @@ Playlist::duplicate (Region& region, jack_nframes_t position, float times) jack_nframes_t pos = position; while (itimes--) { - Region *copy = createRegion (region); + boost::shared_ptr copy = RegionFactory::create (region); add_region_internal (copy, pos, true); - pos += region.length(); + pos += region->length(); } if (floor (times) != times) { - jack_nframes_t length = (jack_nframes_t) floor (region.length() * (times - floor (times))); + jack_nframes_t length = (jack_nframes_t) floor (region->length() * (times - floor (times))); string name; - _session.region_name (name, region.name(), false); - Region *sub = createRegion (region, 0, length, name, region.layer(), region.flags()); + _session.region_name (name, region->name(), false); + boost::shared_ptr sub = RegionFactory::create (region, 0, length, name, region->layer(), region->flags()); add_region_internal (sub, pos, true); } @@ -999,40 +997,40 @@ Playlist::duplicate (Region& region, jack_nframes_t position, float times) } void -Playlist::split_region (Region& region, jack_nframes_t playlist_position) +Playlist::split_region (boost::shared_ptr region, jack_nframes_t playlist_position) { RegionLock rl (this); - if (!region.covers (playlist_position)) { + if (!region->covers (playlist_position)) { return; } - if (region.position() == playlist_position || - region.last_frame() == playlist_position) { + if (region->position() == playlist_position || + region->last_frame() == playlist_position) { return; } - Region *left; - Region *right; + boost::shared_ptr left; + boost::shared_ptr right; jack_nframes_t before; jack_nframes_t after; string before_name; string after_name; - before = playlist_position - region.position(); - after = region.length() - before; + before = playlist_position - region->position(); + after = region->length() - before; - _session.region_name (before_name, region.name(), false); - left = createRegion (region, 0, before, before_name, region.layer(), Region::Flag (region.flags()|Region::LeftOfSplit)); + _session.region_name (before_name, region->name(), false); + left = RegionFactory::create (region, 0, before, before_name, region->layer(), Region::Flag (region->flags()|Region::LeftOfSplit)); - _session.region_name (after_name, region.name(), false); - right = createRegion (region, before, after, after_name, region.layer(), Region::Flag (region.flags()|Region::RightOfSplit)); + _session.region_name (after_name, region->name(), false); + right = RegionFactory::create (region, before, after, after_name, region->layer(), Region::Flag (region->flags()|Region::RightOfSplit)); - add_region_internal (left, region.position(), true); - add_region_internal (right, region.position() + before); + add_region_internal (left, region->position(), true); + add_region_internal (right, region->position() + before); - uint64_t orig_layer_op = region.last_layer_op(); + uint64_t orig_layer_op = region->last_layer_op(); for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) { if ((*i)->last_layer_op() > orig_layer_op) { (*i)->set_last_layer_op( (*i)->last_layer_op() + 1 ); @@ -1044,9 +1042,9 @@ Playlist::split_region (Region& region, jack_nframes_t playlist_position) layer_op_counter++; - finalize_split_region (®ion, left, right); + finalize_split_region (region, left, right); - if (remove_region_internal (®ion, true)) { + if (remove_region_internal (region, true)) { return; } @@ -1110,7 +1108,7 @@ Playlist::core_splice () } void -Playlist::region_bounds_changed (Change what_changed, Region *region) +Playlist::region_bounds_changed (Change what_changed, boost::shared_ptr region) { if (in_set_state || _splicing || _nudging) { return; @@ -1134,8 +1132,7 @@ Playlist::region_bounds_changed (Change what_changed, Region *region) } regions.erase (i); - regions.insert (upper_bound (regions.begin(), regions.end(), region, cmp), - region); + regions.insert (upper_bound (regions.begin(), regions.end(), region, cmp), region); } @@ -1146,11 +1143,11 @@ Playlist::region_bounds_changed (Change what_changed, Region *region) } else { if (_session.get_layer_model() == Session::MoveAddHigher) { /* it moved or changed length, so change the timestamp */ - timestamp_layer_op (*region); + timestamp_layer_op (region); } possibly_splice (); - check_dependents (*region, false); + check_dependents (region, false); notify_length_changed (); relayer (); } @@ -1158,7 +1155,7 @@ Playlist::region_bounds_changed (Change what_changed, Region *region) } void -Playlist::region_changed_proxy (Change what_changed, Region* region) +Playlist::region_changed_proxy (Change what_changed, boost::shared_ptr region) { /* this makes a virtual call to the right kind of playlist ... */ @@ -1166,7 +1163,7 @@ Playlist::region_changed_proxy (Change what_changed, Region* region) } bool -Playlist::region_changed (Change what_changed, Region* region) +Playlist::region_changed (Change what_changed, boost::shared_ptr region) { Change our_interests = Change (Region::MuteChanged|Region::LayerChanged|Region::OpacityChanged); bool save = false; @@ -1183,7 +1180,7 @@ Playlist::region_changed (Change what_changed, Region* region) if ((what_changed & Region::MuteChanged) && !(what_changed & Change (ARDOUR::PositionChanged|ARDOUR::LengthChanged))) { - check_dependents (*region, false); + check_dependents (region, false); } if (what_changed & our_interests) { @@ -1195,7 +1192,7 @@ Playlist::region_changed (Change what_changed, Region* region) } void -Playlist::clear (bool with_delete, bool with_save) +Playlist::clear (bool with_save) { RegionList::iterator i; RegionList tmp; @@ -1208,9 +1205,6 @@ Playlist::clear (bool with_delete, bool with_save) for (i = tmp.begin(); i != tmp.end(); ++i) { notify_region_removed (*i); - if (with_delete) { - delete *i; - } } if (with_save) { @@ -1230,14 +1224,14 @@ Playlist::regions_at (jack_nframes_t frame) return find_regions_at (frame); } -Region * +boost::shared_ptr Playlist::top_region_at (jack_nframes_t frame) { RegionLock rlock (this); RegionList *rlist = find_regions_at (frame); - Region *region = 0; - + boost::shared_ptr region; + if (rlist->size()) { RegionSortByLayer cmp; rlist->sort (cmp); @@ -1278,18 +1272,17 @@ Playlist::regions_touched (jack_nframes_t start, jack_nframes_t end) } -Region* - +boost::shared_ptr Playlist::find_next_region (jack_nframes_t frame, RegionPoint point, int dir) { RegionLock rlock (this); - Region* ret = 0; + boost::shared_ptr ret; jack_nframes_t closest = max_frames; for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) { jack_nframes_t distance; - Region* r = (*i); + boost::shared_ptr r = (*i); jack_nframes_t pos = 0; switch (point) { @@ -1354,10 +1347,10 @@ Playlist::set_state (const XMLNode& node) XMLPropertyList plist; XMLPropertyConstIterator piter; XMLProperty *prop; - Region *region; + boost::shared_ptr region; string region_name; - clear (false, false); + clear (false); if (node.name() != "Playlist") { in_set_state = false; @@ -1387,12 +1380,12 @@ Playlist::set_state (const XMLNode& node) if (child->name() == "Region") { - if ((region = createRegion (_session, *child, true)) == 0) { + if ((region = RegionFactory::create (_session, *child, true)) == 0) { error << _("Playlist: cannot create region from state file") << endmsg; continue; } - add_region (*region, region->position(), 1.0, false); + add_region (region, region->position(), 1.0, false); // So that layer_op ordering doesn't get screwed up region->set_last_layer_op( region->layer()); @@ -1406,7 +1399,7 @@ Playlist::set_state (const XMLNode& node) */ for (RegionList::iterator r = regions.begin(); r != regions.end(); ++r) { - check_dependents (**r, false); + check_dependents (*r, false); } in_set_state = false; @@ -1589,10 +1582,10 @@ Playlist::relayer () /* XXX these layer functions are all deprecated */ void -Playlist::raise_region (Region& region) +Playlist::raise_region (boost::shared_ptr region) { uint32_t rsz = regions.size(); - layer_t target = region.layer() + 1U; + layer_t target = region->layer() + 1U; if (target >= rsz) { /* its already at the effective top */ @@ -1603,20 +1596,20 @@ Playlist::raise_region (Region& region) } void -Playlist::lower_region (Region& region) +Playlist::lower_region (boost::shared_ptr region) { - if (region.layer() == 0) { + if (region->layer() == 0) { /* its already at the bottom */ return; } - layer_t target = region.layer() - 1U; + layer_t target = region->layer() - 1U; move_region_to_layer (target, region, -1); } void -Playlist::raise_region_to_top (Region& region) +Playlist::raise_region_to_top (boost::shared_ptr region) { /* does nothing useful if layering mode is later=higher */ if ((_session.get_layer_model() == Session::MoveAddHigher) || @@ -1627,21 +1620,21 @@ Playlist::raise_region_to_top (Region& region) } void -Playlist::lower_region_to_bottom (Region& region) +Playlist::lower_region_to_bottom (boost::shared_ptr region) { /* does nothing useful if layering mode is later=higher */ if ((_session.get_layer_model() == Session::MoveAddHigher) || (_session.get_layer_model() == Session::AddHigher)) { - region.set_last_layer_op (0); + region->set_last_layer_op (0); relayer (); } } int -Playlist::move_region_to_layer (layer_t target_layer, Region& region, int dir) +Playlist::move_region_to_layer (layer_t target_layer, boost::shared_ptr region, int dir) { RegionList::iterator i; - typedef pair LayerInfo; + typedef pair,layer_t> LayerInfo; list layerinfo; layer_t dest; @@ -1650,7 +1643,7 @@ Playlist::move_region_to_layer (layer_t target_layer, Region& region, int dir) for (i = regions.begin(); i != regions.end(); ++i) { - if (®ion == *i) { + if (region == *i) { continue; } @@ -1660,7 +1653,7 @@ Playlist::move_region_to_layer (layer_t target_layer, Region& region, int dir) down 1 */ - if ((*i)->layer() > region.layer() && (*i)->layer() <= target_layer) { + if ((*i)->layer() > region->layer() && (*i)->layer() <= target_layer) { dest = (*i)->layer() - 1; } else { /* not affected */ @@ -1672,7 +1665,7 @@ Playlist::move_region_to_layer (layer_t target_layer, Region& region, int dir) up 1 */ - if ((*i)->layer() < region.layer() && (*i)->layer() >= target_layer) { + if ((*i)->layer() < region->layer() && (*i)->layer() >= target_layer) { dest = (*i)->layer() + 1; } else { /* not affected */ @@ -1695,12 +1688,12 @@ Playlist::move_region_to_layer (layer_t target_layer, Region& region, int dir) x->first->set_layer (x->second); } - region.set_layer (target_layer); + region->set_layer (target_layer); /* now check all dependents */ for (list::iterator x = layerinfo.begin(); x != layerinfo.end(); ++x) { - check_dependents (*(x->first), false); + check_dependents (x->first, false); } check_dependents (region, false); @@ -1755,19 +1748,20 @@ Playlist::nudge_after (jack_nframes_t start, jack_nframes_t distance, bool forwa } -Region* +boost::shared_ptr Playlist::find_region (const ID& id) const { RegionLock rlock (const_cast (this)); RegionList::const_iterator i; - + boost::shared_ptr ret; + for (i = regions.begin(); i != regions.end(); ++i) { if ((*i)->id() == id) { - return (*i); + ret = *i; } } - return 0; + return ret; } void @@ -1781,7 +1775,7 @@ Playlist::save_state (std::string why) void Playlist::dump () const { - Region *r; + boost::shared_ptr r; cerr << "Playlist \"" << _name << "\" " << endl << regions.size() << " regions " @@ -1806,11 +1800,11 @@ Playlist::set_frozen (bool yn) } void -Playlist::timestamp_layer_op (Region& region) +Playlist::timestamp_layer_op (boost::shared_ptr region) { // struct timeval tv; // gettimeofday (&tv, 0); - region.set_last_layer_op (++layer_op_counter); + region->set_last_layer_op (++layer_op_counter); } void diff --git a/libs/ardour/playlist_factory.cc b/libs/ardour/playlist_factory.cc index 7c7060dae8..05d9c76f7a 100644 --- a/libs/ardour/playlist_factory.cc +++ b/libs/ardour/playlist_factory.cc @@ -20,60 +20,14 @@ #include -#include - #include #include -#include -#include -#include - #include "i18n.h" using namespace ARDOUR; using namespace PBD; -Region* -ARDOUR::createRegion (const Region& region, jack_nframes_t start, - jack_nframes_t length, std::string name, - layer_t layer, Region::Flag flags) -{ - const AudioRegion* ar; - - if ((ar = dynamic_cast(®ion)) != 0) { - AudioRegion* ret; - ret = new AudioRegion (*ar, start, length, name, layer, flags); - return ret; - } else { - fatal << _("programming error: Playlist::createRegion called with unknown Region type") - << endmsg; - /*NOTREACHED*/ - return 0; - } -} - -Region* -ARDOUR::createRegion (const Region& region) -{ - const AudioRegion* ar; - - if ((ar = dynamic_cast(®ion)) != 0) { - return new AudioRegion (*ar); - } else { - fatal << _("programming error: Playlist::createRegion called with unknown Region type") - << endmsg; - /*NOTREACHED*/ - return 0; - } -} - -Region* -ARDOUR::createRegion (Session& session, XMLNode& node, bool yn) -{ - return session.XMLRegionFactory (node, yn); -} - Playlist* Playlist::copyPlaylist (const Playlist& playlist, jack_nframes_t start, jack_nframes_t length, string name, bool result_is_hidden) diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc index 3481ee3eea..48431087ae 100644 --- a/libs/ardour/region.cc +++ b/libs/ardour/region.cc @@ -48,10 +48,8 @@ Change Region::LockChanged = ARDOUR::new_change (); Change Region::LayerChanged = ARDOUR::new_change (); Change Region::HiddenChanged = ARDOUR::new_change (); -sigc::signal Region::CheckNewRegion; - /** Basic Region constructor (single source) */ -Region::Region (Source& src, jack_nframes_t start, jack_nframes_t length, const string& name, DataType type, layer_t layer, Region::Flag flags) +Region::Region (boost::shared_ptr src, jack_nframes_t start, jack_nframes_t length, const string& name, DataType type, layer_t layer, Region::Flag flags) : _name(name) , _type(type) , _flags(flags) @@ -69,9 +67,9 @@ Region::Region (Source& src, jack_nframes_t start, jack_nframes_t length, const { _current_state_id = 0; - _sources.push_back (&src); - _master_sources.push_back (&src); - src.GoingAway.connect (mem_fun (*this, &Region::source_deleted)); + _sources.push_back (src); + _master_sources.push_back (src); + src->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), src)); assert(_sources.size() > 0); } @@ -95,18 +93,18 @@ Region::Region (SourceList& srcs, jack_nframes_t start, jack_nframes_t length, c { _current_state_id = 0; - set unique_srcs; + set > unique_srcs; for (SourceList::iterator i=srcs.begin(); i != srcs.end(); ++i) { _sources.push_back (*i); - (*i)->GoingAway.connect (mem_fun (*this, &Region::source_deleted)); + (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i))); unique_srcs.insert (*i); } for (SourceList::iterator i = srcs.begin(); i != srcs.end(); ++i) { _master_sources.push_back (*i); if (unique_srcs.find (*i) == unique_srcs.end()) { - (*i)->GoingAway.connect (mem_fun (*this, &Region::source_deleted)); + (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i))); } } @@ -114,11 +112,11 @@ Region::Region (SourceList& srcs, jack_nframes_t start, jack_nframes_t length, c } /** Create a new Region from part of an existing one */ -Region::Region (const Region& other, jack_nframes_t offset, jack_nframes_t length, const string& name, layer_t layer, Flag flags) +Region::Region (boost::shared_ptr other, jack_nframes_t offset, jack_nframes_t length, const string& name, layer_t layer, Flag flags) : _name(name) - , _type(other.data_type()) + , _type(other->data_type()) , _flags(Flag(flags & ~(Locked|WholeFile|Hidden))) - , _start(other._start + offset) + , _start(other->_start + offset) , _length(length) , _position(0) , _sync_position(_start) @@ -132,20 +130,24 @@ Region::Region (const Region& other, jack_nframes_t offset, jack_nframes_t lengt { _current_state_id = 0; - if (other._sync_position < offset) - _sync_position = other._sync_position; + if (other->_sync_position < offset) + _sync_position = other->_sync_position; - set unique_srcs; + set > unique_srcs; - for (SourceList::const_iterator i= other._sources.begin(); i != other._sources.end(); ++i) { + for (SourceList::const_iterator i= other->_sources.begin(); i != other->_sources.end(); ++i) { _sources.push_back (*i); - (*i)->GoingAway.connect (mem_fun (*this, &Region::source_deleted)); + (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i))); unique_srcs.insert (*i); } + + if (other->_sync_position < offset) { + _sync_position = other->_sync_position; + } - for (SourceList::const_iterator i = other._master_sources.begin(); i != other._master_sources.end(); ++i) { + for (SourceList::const_iterator i = other->_master_sources.begin(); i != other->_master_sources.end(); ++i) { if (unique_srcs.find (*i) == unique_srcs.end()) { - (*i)->GoingAway.connect (mem_fun (*this, &Region::source_deleted)); + (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i))); } _master_sources.push_back (*i); } @@ -154,44 +156,44 @@ Region::Region (const Region& other, jack_nframes_t offset, jack_nframes_t lengt } /** Pure copy constructor */ -Region::Region (const Region &other) - : _name(other._name) - , _type(other.data_type()) - , _flags(Flag(other._flags & ~Locked)) - , _start(other._start) - , _length(other._length) - , _position(other._position) - , _sync_position(other._sync_position) - , _layer(other._layer) +Region::Region (boost::shared_ptr other) + : _name(other->_name) + , _type(other->data_type()) + , _flags(Flag(other->_flags & ~Locked)) + , _start(other->_start) + , _length(other->_length) + , _position(other->_position) + , _sync_position(other->_sync_position) + , _layer(other->_layer) , _first_edit(EditChangesID) , _frozen(0) , _read_data_count(0) , _pending_changed(Change(0)) - , _last_layer_op(other._last_layer_op) + , _last_layer_op(other->_last_layer_op) , _playlist(0) { _current_state_id = 0; - other._first_edit = EditChangesName; + other->_first_edit = EditChangesName; - if (other._extra_xml) { - _extra_xml = new XMLNode (*other._extra_xml); + if (other->_extra_xml) { + _extra_xml = new XMLNode (*other->_extra_xml); } else { _extra_xml = 0; } - set unique_srcs; + set > unique_srcs; - for (SourceList::const_iterator i = other._sources.begin(); i != other._sources.end(); ++i) { + for (SourceList::const_iterator i = other->_sources.begin(); i != other->_sources.end(); ++i) { _sources.push_back (*i); - (*i)->GoingAway.connect (mem_fun (*this, &Region::source_deleted)); + (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i))); unique_srcs.insert (*i); } - for (SourceList::const_iterator i = other._master_sources.begin(); i != other._master_sources.end(); ++i) { + for (SourceList::const_iterator i = other->_master_sources.begin(); i != other->_master_sources.end(); ++i) { _master_sources.push_back (*i); if (unique_srcs.find (*i) == unique_srcs.end()) { - (*i)->GoingAway.connect (mem_fun (*this, &Region::source_deleted)); + (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i))); } } @@ -215,23 +217,23 @@ Region::Region (SourceList& srcs, const XMLNode& node) , _playlist(0) { - set unique_srcs; + _current_state_id = 0; + + set > unique_srcs; for (SourceList::iterator i=srcs.begin(); i != srcs.end(); ++i) { _sources.push_back (*i); - (*i)->GoingAway.connect (mem_fun (*this, &Region::source_deleted)); + (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i))); unique_srcs.insert (*i); } for (SourceList::iterator i = srcs.begin(); i != srcs.end(); ++i) { _master_sources.push_back (*i); if (unique_srcs.find (*i) == unique_srcs.end()) { - (*i)->GoingAway.connect (mem_fun (*this, &Region::source_deleted)); + (*i)->GoingAway.connect (bind (mem_fun (*this, &Region::source_deleted), (*i))); } } - _current_state_id = 0; - if (set_state (node)) { throw failed_constructor(); } @@ -240,7 +242,7 @@ Region::Region (SourceList& srcs, const XMLNode& node) assert(_sources.size() > 0); } -Region::Region (Source& src, const XMLNode& node) +Region::Region (boost::shared_ptr src, const XMLNode& node) : _name(X_("error: XML did not reset this")) , _type(DataType::NIL) , _flags(Flag(0)) @@ -256,7 +258,7 @@ Region::Region (Source& src, const XMLNode& node) , _last_layer_op(0) , _playlist(0) { - _sources.push_back (&src); + _sources.push_back (src); _current_state_id = 0; @@ -270,6 +272,9 @@ Region::Region (Source& src, const XMLNode& node) Region::~Region () { + notify_callbacks (); + + /* derived classes must emit GoingAway */ } void @@ -395,7 +400,7 @@ Region::first_edit () _first_edit = EditChangesNothing; send_change (NameChanged); - CheckNewRegion (this); + /// XXX CheckNewRegion (boost::shared_ptr(this)); } } @@ -406,7 +411,7 @@ Region::move_to_natural_position (void *src) return; } - Region* whole_file_region = get_parent(); + boost::shared_ptr whole_file_region = get_parent(); if (whole_file_region) { set_position (whole_file_region->position() + _start, src); @@ -464,7 +469,7 @@ Region::set_position_on_top (jack_nframes_t pos, void *src) } } - _playlist->raise_region_to_top (*this); + _playlist->raise_region_to_top (boost::shared_ptr(this)); /* do this even if the position is the same. this helps out a GUI that has moved its representation already. @@ -906,7 +911,7 @@ Region::raise () return; } - _playlist->raise_region (*this); + _playlist->raise_region (boost::shared_ptr(this)); } void @@ -916,7 +921,7 @@ Region::lower () return; } - _playlist->lower_region (*this); + _playlist->lower_region (boost::shared_ptr(this)); } void @@ -927,7 +932,7 @@ Region::raise_to_top () return; } - _playlist->raise_region_to_top (*this); + _playlist->raise_region_to_top (boost::shared_ptr(this)); } void @@ -937,7 +942,7 @@ Region::lower_to_bottom () return; } - _playlist->lower_region_to_bottom (*this); + _playlist->lower_region_to_bottom (boost::shared_ptr(this)); } void @@ -1121,74 +1126,38 @@ Region::set_last_layer_op (uint64_t when) } bool -Region::overlap_equivalent (const Region& other) const +Region::overlap_equivalent (boost::shared_ptr other) const { - return coverage (other.first_frame(), other.last_frame()) != OverlapNone; + return coverage (other->first_frame(), other->last_frame()) != OverlapNone; } bool -Region::equivalent (const Region& other) const +Region::equivalent (boost::shared_ptr other) const { - return _start == other._start && - _position == other._position && - _length == other._length; + return _start == other->_start && + _position == other->_position && + _length == other->_length; } bool -Region::size_equivalent (const Region& other) const +Region::size_equivalent (boost::shared_ptr other) const { - return _start == other._start && - _length == other._length; + return _start == other->_start && + _length == other->_length; } bool -Region::region_list_equivalent (const Region& other) const +Region::region_list_equivalent (boost::shared_ptr other) const { - return size_equivalent (other) && source_equivalent (other) && _name == other._name; + return size_equivalent (other) && source_equivalent (other) && _name == other->_name; } void -Region::source_deleted (Source* ignored) +Region::source_deleted (boost::shared_ptr) { delete this; } -void -Region::lock_sources () -{ - SourceList::iterator i; - set unique_srcs; - - for (i = _sources.begin(); i != _sources.end(); ++i) { - unique_srcs.insert (*i); - (*i)->use (); - } - - for (i = _master_sources.begin(); i != _master_sources.end(); ++i) { - if (unique_srcs.find (*i) == unique_srcs.end()) { - (*i)->use (); - } - } -} - -void -Region::unlock_sources () -{ - SourceList::iterator i; - set unique_srcs; - - for (i = _sources.begin(); i != _sources.end(); ++i) { - unique_srcs.insert (*i); - (*i)->release (); - } - - for (i = _master_sources.begin(); i != _master_sources.end(); ++i) { - if (unique_srcs.find (*i) == unique_srcs.end()) { - (*i)->release (); - } - } -} - vector Region::master_source_names () { @@ -1203,18 +1172,21 @@ Region::master_source_names () } bool -Region::source_equivalent (const Region& other) const +Region::source_equivalent (boost::shared_ptr other) const { + if (!other) + return false; + SourceList::const_iterator i; SourceList::const_iterator io; - for (i = _sources.begin(), io = other._sources.begin(); i != _sources.end() && io != other._sources.end(); ++i, ++io) { + for (i = _sources.begin(), io = other->_sources.begin(); i != _sources.end() && io != other->_sources.end(); ++i, ++io) { if ((*i)->id() != (*io)->id()) { return false; } } - for (i = _master_sources.begin(), io = other._master_sources.begin(); i != _master_sources.end() && io != other._master_sources.end(); ++i, ++io) { + for (i = _master_sources.begin(), io = other->_master_sources.begin(); i != _master_sources.end() && io != other->_master_sources.end(); ++i, ++io) { if ((*i)->id() != (*io)->id()) { return false; } @@ -1266,10 +1238,10 @@ Region::verify_start_mutable (jack_nframes_t& new_start) return true; } -Region* +boost::shared_ptr Region::get_parent() { - Region* r = 0; + boost::shared_ptr r; if (_playlist) { r = _playlist->session().find_whole_file_parent (*this); diff --git a/libs/ardour/region_factory.cc b/libs/ardour/region_factory.cc new file mode 100644 index 0000000000..492a25a08f --- /dev/null +++ b/libs/ardour/region_factory.cc @@ -0,0 +1,182 @@ +/* + Copyright (C) 2000-2006 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id: playlist_factory.cc 629 2006-06-21 23:01:03Z paul $ +*/ + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "i18n.h" + +using namespace ARDOUR; +using namespace PBD; + +sigc::signal > RegionFactory::CheckNewRegion; + +boost::shared_ptr +RegionFactory::create (boost::shared_ptr region, jack_nframes_t start, + jack_nframes_t length, std::string name, + layer_t layer, Region::Flag flags, bool announce) +{ + boost::shared_ptr other_a; + boost::shared_ptr other_m; + + if ((other_a = boost::dynamic_pointer_cast(region)) != 0) { + AudioRegion* ar = new AudioRegion (other_a, start, length, name, layer, flags); + boost::shared_ptr arp (ar); + boost::shared_ptr ret (boost::static_pointer_cast (arp)); + if (announce) { + CheckNewRegion (ret); + } + return ret; + } else if ((other_m = boost::dynamic_pointer_cast(region)) != 0) { + MidiRegion* ar = new MidiRegion (other_m, start, length, name, layer, flags); + boost::shared_ptr arp (ar); + boost::shared_ptr ret (boost::static_pointer_cast (arp)); + if (announce) { + CheckNewRegion (ret); + } + return ret; + } else { + fatal << _("programming error: RegionFactory::create() called with unknown Region type") + << endmsg; + /*NOTREACHED*/ + return boost::shared_ptr(); + } +} + +boost::shared_ptr +RegionFactory::create (boost::shared_ptr region) +{ + boost::shared_ptr ar; + boost::shared_ptr mr; + + if ((ar = boost::dynamic_pointer_cast(region)) != 0) { + boost::shared_ptr ret (new AudioRegion (ar)); + /* pure copy constructor - no CheckNewRegion emitted */ + return ret; + } else if ((mr = boost::dynamic_pointer_cast(region)) != 0) { + boost::shared_ptr ret (new MidiRegion (mr)); + /* pure copy constructor - no CheckNewRegion emitted */ + return ret; + } else { + fatal << _("programming error: RegionFactory::create() called with unknown Region type") + << endmsg; + /*NOTREACHED*/ + return boost::shared_ptr(); + } +} + +boost::shared_ptr +RegionFactory::create (boost::shared_ptr region, jack_nframes_t start, + jack_nframes_t length, std::string name, + layer_t layer, Region::Flag flags, bool announce) +{ + return create (boost::static_pointer_cast (region), start, length, name, layer, flags, announce); +} + +boost::shared_ptr +RegionFactory::create (Session& session, XMLNode& node, bool yn) +{ + boost::shared_ptr r = session.XMLRegionFactory (node, yn); + CheckNewRegion (r); + return r; +} + +boost::shared_ptr +RegionFactory::create (SourceList& srcs, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t layer, Region::Flag flags, bool announce) +{ + if (srcs.empty()) { + return boost::shared_ptr(); + } + + if (srcs[0]->type() == DataType::AUDIO) { + + AudioRegion* ar = new AudioRegion (srcs, start, length, name, layer, flags); + boost::shared_ptr arp (ar); + boost::shared_ptr ret (boost::static_pointer_cast (arp)); + if (announce) { + CheckNewRegion (ret); + } + return ret; + + } else if (srcs[0]->type() == DataType::MIDI) { + + MidiRegion* ar = new MidiRegion (srcs, start, length, name, layer, flags); + boost::shared_ptr mrp (ar); + boost::shared_ptr ret (boost::static_pointer_cast (mrp)); + if (announce) { + CheckNewRegion (ret); + } + return ret; + + } + + return boost::shared_ptr (); +} + +boost::shared_ptr +RegionFactory::create (SourceList& srcs, const XMLNode& node) +{ + if (srcs.empty()) { + return boost::shared_ptr(); + } + + if (srcs[0]->type() == DataType::AUDIO) { + boost::shared_ptr ret (new AudioRegion (srcs, node)); + CheckNewRegion (ret); + return ret; + } else if (srcs[0]->type() == DataType::MIDI) { + boost::shared_ptr ret (new MidiRegion (srcs, node)); + CheckNewRegion (ret); + return ret; + } + + return boost::shared_ptr (); +} + +boost::shared_ptr +RegionFactory::create (boost::shared_ptr src, jack_nframes_t start, jack_nframes_t length, const string& name, layer_t layer, Region::Flag flags, bool announce) +{ + boost::shared_ptr as; + boost::shared_ptr ms; + + if ((as = boost::dynamic_pointer_cast(src)) != 0) { + boost::shared_ptr ret (new AudioRegion (as, start, length, name, layer, flags)); + if (announce) { + CheckNewRegion (ret); + } + return ret; + } else if ((ms = boost::dynamic_pointer_cast(src)) != 0) { + boost::shared_ptr ret (new MidiRegion (ms, start, length, name, layer, flags)); + if (announce) { + CheckNewRegion (ret); + } + return ret; + } + + return boost::shared_ptr(); +} diff --git a/libs/ardour/reverse.cc b/libs/ardour/reverse.cc index b981ff0722..15f90fec45 100644 --- a/libs/ardour/reverse.cc +++ b/libs/ardour/reverse.cc @@ -43,10 +43,10 @@ Reverse::~Reverse () } int -Reverse::run (AudioRegion& region) +Reverse::run (boost::shared_ptr region) { - AudioRegion::SourceList nsrcs; - AudioRegion::SourceList::iterator si; + SourceList nsrcs; + SourceList::iterator si; const jack_nframes_t blocksize = 256 * 1048; Sample buf[blocksize]; jack_nframes_t fpos; @@ -61,8 +61,8 @@ Reverse::run (AudioRegion& region) goto out; } - fend = region.start() + region.length(); - fstart = region.start(); + fend = region->start() + region->length(); + fstart = region->start(); if (blocksize < fend) { fpos =max(fstart, fend - blocksize); @@ -70,7 +70,7 @@ Reverse::run (AudioRegion& region) fpos = fstart; } - to_read = min (region.length(), blocksize); + to_read = min (region->length(), blocksize); /* now read it backwards */ @@ -78,12 +78,11 @@ Reverse::run (AudioRegion& region) uint32_t n; - for (n = 0, si = nsrcs.begin(); n < region.n_channels(); ++n, ++si) { - AudioSource* const asrc = dynamic_cast(*si); + for (n = 0, si = nsrcs.begin(); n < region->n_channels(); ++n, ++si) { /* read it in */ - if (region.audio_source (n).read (buf, fpos, to_read) != to_read) { + if (region->audio_source (n)->read (buf, fpos, to_read) != to_read) { goto out; } @@ -95,7 +94,9 @@ Reverse::run (AudioRegion& region) /* write it out */ - if (asrc->write (buf, to_read) != to_read) { + boost::shared_ptr asrc(boost::dynamic_pointer_cast(*si)); + + if (asrc && asrc->write (buf, to_read) != to_read) { goto out; } } @@ -117,8 +118,8 @@ Reverse::run (AudioRegion& region) if (ret) { for (si = nsrcs.begin(); si != nsrcs.end(); ++si) { - (*si)->mark_for_remove (); - delete *si; + boost::shared_ptr asrc(boost::dynamic_pointer_cast(*si)); + asrc->mark_for_remove (); } } diff --git a/libs/ardour/send.cc b/libs/ardour/send.cc index c67e0fcdbe..9161b0492d 100644 --- a/libs/ardour/send.cc +++ b/libs/ardour/send.cc @@ -64,7 +64,7 @@ Send::Send (const Send& other) Send::~Send () { - GoingAway (this); + GoingAway (); } XMLNode& diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 7d5f838499..0a85c47cb9 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -71,6 +71,7 @@ #include #include #include +#include #ifdef HAVE_LIBLO #include @@ -282,10 +283,12 @@ Session::Session (AudioEngine &eng, first_stage_init (fullpath, snapshot_name); if (create (new_session, mix_template, _engine.frame_rate() * 60 * 5)) { + cerr << "create failed\n"; throw failed_constructor (); } if (second_stage_init (new_session)) { + cerr << "2nd state failed\n"; throw failed_constructor (); } @@ -386,9 +389,23 @@ Session::~Session () _state_of_the_state = StateOfTheState (CannotSave|Deletion); _engine.remove_session (); + + GoingAway (); /* EMIT SIGNAL */ - going_away (); /* EMIT SIGNAL */ + /* do this */ + + notify_callbacks (); + + /* clear history so that no references to objects are held any more */ + + history.clear (); + + /* clear state tree so that no references to objects are held any more */ + if (state_tree) { + delete state_tree; + } + terminate_butler_thread (); //terminate_midi_thread (); @@ -439,16 +456,12 @@ Session::~Session () #ifdef TRACK_DESTRUCTION cerr << "delete regions\n"; #endif /* TRACK_DESTRUCTION */ - for (RegionList::iterator i = regions.begin(); i != regions.end(); ) { - RegionList::iterator tmp; - - tmp =i; - ++tmp; - - delete i->second; - - i = tmp; + + for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) { + i->second->drop_references (); } + + regions.clear (); #ifdef TRACK_DESTRUCTION cerr << "delete routes\n"; @@ -456,12 +469,8 @@ Session::~Session () { RCUWriter writer (routes); boost::shared_ptr r = writer.get_copy (); - for (RouteList::iterator i = r->begin(); i != r->end(); ) { - RouteList::iterator tmp; - tmp = i; - ++tmp; + for (RouteList::iterator i = r->begin(); i != r->end(); ++i) { (*i)->drop_references (); - i = tmp; } r->clear (); /* writer goes out of scope and updates master */ @@ -475,15 +484,8 @@ Session::~Session () { RCUWriter dwriter (diskstreams); boost::shared_ptr dsl = dwriter.get_copy(); - for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ) { - DiskstreamList::iterator tmp; - - tmp = i; - ++tmp; - + for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) { (*i)->drop_references (); - - i = tmp; } dsl->clear (); } @@ -492,17 +494,19 @@ Session::~Session () #ifdef TRACK_DESTRUCTION cerr << "delete audio sources\n"; #endif /* TRACK_DESTRUCTION */ - for (SourceList::iterator i = sources.begin(); i != sources.end(); ) { - SourceList::iterator tmp; + for (SourceMap::iterator i = sources.begin(); i != sources.end(); ) { + SourceMap::iterator tmp; tmp = i; ++tmp; - delete i->second; + i->second->drop_references (); i = tmp; } + sources.clear (); + #ifdef TRACK_DESTRUCTION cerr << "delete mix groups\n"; #endif /* TRACK_DESTRUCTION */ @@ -558,10 +562,6 @@ Session::~Session () if (mmc) { delete mmc; } - - if (state_tree) { - delete state_tree; - } } void @@ -2712,8 +2712,9 @@ Session::region_name (string& result, string base, bool newlevel) const } void -Session::add_region (Region* region) +Session::add_region (boost::shared_ptr region) { + boost::shared_ptr other; bool added = false; { @@ -2723,7 +2724,9 @@ Session::add_region (Region* region) for (x = regions.begin(); x != regions.end(); ++x) { - if (region->region_list_equivalent (*x->second)) { + other = x->second; + + if (region->region_list_equivalent (other)) { break; } } @@ -2737,6 +2740,7 @@ Session::add_region (Region* region) pair x = regions.insert (entry); + if (!x.second) { return; } @@ -2748,19 +2752,19 @@ Session::add_region (Region* region) /* mark dirty because something has changed even if we didn't add the region to the region list. - */ - + */ + set_dirty(); - + if (added) { - region->GoingAway.connect (mem_fun (*this, &Session::remove_region)); + region->GoingAway.connect (sigc::bind (mem_fun (*this, &Session::remove_region), region)); region->StateChanged.connect (sigc::bind (mem_fun (*this, &Session::region_changed), region)); RegionAdded (region); /* EMIT SIGNAL */ } } void -Session::region_changed (Change what_changed, Region* region) +Session::region_changed (Change what_changed, boost::shared_ptr region) { if (what_changed & Region::HiddenChanged) { /* relay hidden changes */ @@ -2769,17 +2773,17 @@ Session::region_changed (Change what_changed, Region* region) } void -Session::region_renamed (Region* region) +Session::region_renamed (boost::shared_ptr region) { add_region (region); } void -Session::remove_region (Region* region) +Session::remove_region (boost::shared_ptr region) { RegionList::iterator i; bool removed = false; - + { Glib::Mutex::Lock lm (region_lock); @@ -2787,25 +2791,25 @@ Session::remove_region (Region* region) regions.erase (i); removed = true; } - } /* mark dirty because something has changed even if we didn't remove the region from the region list. - */ + */ set_dirty(); if (removed) { - RegionRemoved(region); /* EMIT SIGNAL */ + RegionRemoved(region); /* EMIT SIGNAL */ } } -Region* +boost::shared_ptr Session::find_whole_file_parent (Region& child) { RegionList::iterator i; - Region* region; + boost::shared_ptr region; + Glib::Mutex::Lock lm (region_lock); for (i = regions.begin(); i != regions.end(); ++i) { @@ -2814,49 +2818,51 @@ Session::find_whole_file_parent (Region& child) if (region->whole_file()) { - if (child.source_equivalent (*region)) { + if (child.source_equivalent (region)) { return region; } } } - return 0; + return boost::shared_ptr ((AudioRegion*) 0); } void -Session::find_equivalent_playlist_regions (Region& region, vector& result) +Session::find_equivalent_playlist_regions (boost::shared_ptr region, vector >& result) { for (PlaylistList::iterator i = playlists.begin(); i != playlists.end(); ++i) (*i)->get_region_list_equivalent_regions (region, result); } int -Session::destroy_region (Region* region) +Session::destroy_region (boost::shared_ptr region) { - AudioRegion* aregion; + boost::shared_ptr aregion; - if ((aregion = dynamic_cast (region)) == 0) { + if ((aregion = boost::dynamic_pointer_cast (region)) == 0) { return 0; } - + if (aregion->playlist()) { aregion->playlist()->destroy_region (region); } - vector srcs; + vector > srcs; for (uint32_t n = 0; n < aregion->n_channels(); ++n) { - srcs.push_back (&aregion->source (n)); + srcs.push_back (aregion->source (n)); } - for (vector::iterator i = srcs.begin(); i != srcs.end(); ++i) { + for (vector >::iterator i = srcs.begin(); i != srcs.end(); ++i) { - if ((*i)->use_cnt() == 0) { - AudioFileSource* afs = dynamic_cast(*i); + if ((*i).use_count() == 1) { + boost::shared_ptr afs = boost::dynamic_pointer_cast(*i); + if (afs) { (afs)->mark_for_remove (); } - delete *i; + + (*i)->drop_references (); } } @@ -2864,9 +2870,9 @@ Session::destroy_region (Region* region) } int -Session::destroy_regions (list regions) +Session::destroy_regions (list > regions) { - for (list::iterator i = regions.begin(); i != regions.end(); ++i) { + for (list >::iterator i = regions.begin(); i != regions.end(); ++i) { destroy_region (*i); } return 0; @@ -2875,12 +2881,12 @@ Session::destroy_regions (list regions) int Session::remove_last_capture () { - list r; + list > r; boost::shared_ptr dsl = diskstreams.reader(); for (DiskstreamList::iterator i = dsl->begin(); i != dsl->end(); ++i) { - list& l = (*i)->last_capture_regions(); + list >& l = (*i)->last_capture_regions(); if (!l.empty()) { r.insert (r.end(), l.begin(), l.end()); @@ -2893,62 +2899,77 @@ Session::remove_last_capture () } int -Session::remove_region_from_region_list (Region& r) +Session::remove_region_from_region_list (boost::shared_ptr r) { - remove_region (&r); + remove_region (r); return 0; } /* Source Management */ void -Session::add_source (Source* source) +Session::add_source (boost::shared_ptr source) { - pair entry; + cerr << "add new source " << source->name() << endl; + + pair entry; + pair result; - { - Glib::Mutex::Lock lm (source_lock); - entry.first = source->id(); - entry.second = source; - sources.insert (entry); - } + entry.first = source->id(); + entry.second = source; - source->GoingAway.connect (mem_fun (this, &Session::remove_source)); + { + Glib::Mutex::Lock lm (source_lock); + result = sources.insert (entry); + } + + if (!result.second) { + cerr << "\tNOT inserted ? " << result.second << endl; + } + + source->GoingAway.connect (sigc::bind (mem_fun (this, &Session::remove_source), boost::weak_ptr (source))); set_dirty(); SourceAdded (source); /* EMIT SIGNAL */ } void -Session::remove_source (Source* source) +Session::remove_source (boost::weak_ptr src) { - SourceList::iterator i; + SourceMap::iterator i; + boost::shared_ptr source = src.lock(); - { - Glib::Mutex::Lock lm (source_lock); - - if ((i = sources.find (source->id())) != sources.end()) { - sources.erase (i); - } - } - - if (!_state_of_the_state & InCleanup) { - - /* save state so we don't end up with a session file - referring to non-existent sources. - */ + if (!source) { + cerr << "removing a source DEAD\n"; + } else { + cerr << "removing a source " << source->name () << endl; - save_state (_current_snapshot_name); + { + Glib::Mutex::Lock lm (source_lock); + + if ((i = sources.find (source->id())) != sources.end()) { + sources.erase (i); + } + } + + if (!_state_of_the_state & InCleanup) { + + /* save state so we don't end up with a session file + referring to non-existent sources. + */ + + save_state (_current_snapshot_name); + } + + SourceRemoved(source); /* EMIT SIGNAL */ } - - SourceRemoved(source); /* EMIT SIGNAL */ } -Source * +boost::shared_ptr Session::source_by_id (const PBD::ID& id) { Glib::Mutex::Lock lm (source_lock); - SourceList::iterator i; - Source* source = 0; + SourceMap::iterator i; + boost::shared_ptr source; if ((i = sources.find (id)) != sources.end()) { source = i->second; @@ -3194,24 +3215,11 @@ Session::audio_path_from_name (string name, uint32_t nchan, uint32_t chan, bool return spath; } -AudioFileSource * +boost::shared_ptr Session::create_audio_source_for_session (AudioDiskstream& ds, uint32_t chan, bool destructive) { string spath = audio_path_from_name (ds.name(), ds.n_channels().get(DataType::AUDIO), chan, destructive); - - /* this might throw failed_constructor(), which is OK */ - - if (destructive) { - return new DestructiveFileSource (spath, - Config->get_native_file_data_format(), - Config->get_native_file_header_format(), - frame_rate()); - } else { - return new SndFileSource (spath, - Config->get_native_file_data_format(), - Config->get_native_file_header_format(), - frame_rate()); - } + return boost::dynamic_pointer_cast (SourceFactory::createWritable (DataType::AUDIO, spath, destructive, frame_rate())); } string @@ -3277,13 +3285,12 @@ Session::midi_path_from_name (string name) return spath; } -MidiSource * +boost::shared_ptr Session::create_midi_source_for_session (MidiDiskstream& ds) { string spath = midi_path_from_name (ds.name()); - - /* this might throw failed_constructor(), which is OK */ - return new SMFSource (spath); + + return boost::dynamic_pointer_cast (SourceFactory::createWritable (DataType::MIDI, spath, false, frame_rate())); } @@ -3319,7 +3326,7 @@ Session::add_playlist (Playlist* playlist) playlists.insert (playlists.begin(), playlist); // playlist->ref(); playlist->InUse.connect (mem_fun (*this, &Session::track_playlist)); - playlist->GoingAway.connect (mem_fun (*this, &Session::remove_playlist)); + playlist->GoingAway.connect (sigc::bind (mem_fun (*this, &Session::remove_playlist), playlist)); } } @@ -3390,50 +3397,47 @@ Session::remove_playlist (Playlist* playlist) } void -Session::set_audition (AudioRegion* r) +Session::set_audition (boost::shared_ptr r) { pending_audition_region = r; post_transport_work = PostTransportWork (post_transport_work | PostTransportAudition); schedule_butler_transport_work (); } +void +Session::audition_playlist () +{ + Event* ev = new Event (Event::Audition, Event::Add, Event::Immediate, 0, 0.0); + ev->region.reset (); + queue_event (ev); +} + void Session::non_realtime_set_audition () { - if (pending_audition_region == (AudioRegion*) 0xfeedface) { + if (!pending_audition_region) { auditioner->audition_current_playlist (); - } else if (pending_audition_region) { - auditioner->audition_region (*pending_audition_region); + } else { + auditioner->audition_region (pending_audition_region); + pending_audition_region.reset (); } - pending_audition_region = 0; AuditionActive (true); /* EMIT SIGNAL */ } void -Session::audition_playlist () +Session::audition_region (boost::shared_ptr r) { Event* ev = new Event (Event::Audition, Event::Add, Event::Immediate, 0, 0.0); - ev->set_ptr ((void*) 0xfeedface); + ev->region = r; queue_event (ev); } -void -Session::audition_region (Region& r) -{ - AudioRegion* ar = dynamic_cast(&r); - if (ar) { - Event* ev = new Event (Event::Audition, Event::Add, Event::Immediate, 0, 0.0); - ev->set_ptr (ar); - queue_event (ev); - } -} - void Session::cancel_audition () { if (auditioner->active()) { auditioner->cancel_audition (); - AuditionActive (false); /* EMIT SIGNAL */ + AuditionActive (false); /* EMIT SIGNAL */ } } @@ -3600,7 +3604,7 @@ Session::add_redirect (Redirect* redirect) /*NOTREACHED*/ } - redirect->GoingAway.connect (mem_fun (*this, &Session::remove_redirect)); + redirect->GoingAway.connect (sigc::bind (mem_fun (*this, &Session::remove_redirect), redirect)); set_dirty(); } @@ -3822,9 +3826,9 @@ Session::route_name_unique (string n) const } int -Session::cleanup_audio_file_source (AudioFileSource& fs) +Session::cleanup_audio_file_source (boost::shared_ptr fs) { - return fs.move_to_trash (dead_sound_dir_name); + return fs->move_to_trash (dead_sound_dir_name); } uint32_t @@ -3891,11 +3895,12 @@ Session::freeze (InterThreadInfo& itt) int Session::write_one_audio_track (AudioTrack& track, jack_nframes_t start, jack_nframes_t len, - bool overwrite, vector& srcs, InterThreadInfo& itt) + bool overwrite, vector >& srcs, InterThreadInfo& itt) { + boost::shared_ptr fsource; + int ret = -1; Playlist* playlist = 0; - AudioFileSource* fsource = 0; uint32_t x; char buf[PATH_MAX+1]; string dir; @@ -3939,11 +3944,7 @@ Session::write_one_audio_track (AudioTrack& track, jack_nframes_t start, jack_nf } try { - fsource = new SndFileSource (buf, - Config->get_native_file_data_format(), - Config->get_native_file_header_format(), - frame_rate()); - + fsource = boost::dynamic_pointer_cast (SourceFactory::createWritable (DataType::AUDIO, buf, false, frame_rate())); } catch (failed_constructor& err) { @@ -3951,7 +3952,7 @@ Session::write_one_audio_track (AudioTrack& track, jack_nframes_t start, jack_nf goto out; } - srcs.push_back(fsource); + srcs.push_back (fsource); } /* XXX need to flush all redirects */ @@ -3972,9 +3973,9 @@ Session::write_one_audio_track (AudioTrack& track, jack_nframes_t start, jack_nf } uint32_t n = 0; - for (vector::iterator src=srcs.begin(); src != srcs.end(); ++src, ++n) { - AudioFileSource* afs = dynamic_cast(*src); - + for (vector >::iterator src=srcs.begin(); src != srcs.end(); ++src, ++n) { + boost::shared_ptr afs = boost::dynamic_pointer_cast(*src); + if (afs) { if (afs->write (buffers.get_audio(n).data(this_chunk), this_chunk) != this_chunk) { goto out; @@ -3996,8 +3997,9 @@ Session::write_one_audio_track (AudioTrack& track, jack_nframes_t start, jack_nf time (&now); xnow = localtime (&now); - for (vector::iterator src=srcs.begin(); src != srcs.end(); ++src) { - AudioFileSource* afs = dynamic_cast(*src); + for (vector >::iterator src=srcs.begin(); src != srcs.end(); ++src) { + boost::shared_ptr afs = boost::dynamic_pointer_cast(*src); + if (afs) { afs->update_header (position, *xnow, now); } @@ -4005,8 +4007,8 @@ Session::write_one_audio_track (AudioTrack& track, jack_nframes_t start, jack_nf /* build peakfile for new source */ - for (vector::iterator src=srcs.begin(); src != srcs.end(); ++src) { - AudioFileSource* afs = dynamic_cast(*src); + for (vector >::iterator src=srcs.begin(); src != srcs.end(); ++src) { + boost::shared_ptr afs = boost::dynamic_pointer_cast(*src); if (afs) { afs->build_peaks (); } @@ -4017,12 +4019,14 @@ Session::write_one_audio_track (AudioTrack& track, jack_nframes_t start, jack_nf out: if (ret) { - for (vector::iterator src=srcs.begin(); src != srcs.end(); ++src) { - AudioFileSource* afs = dynamic_cast(*src); + for (vector >::iterator src = srcs.begin(); src != srcs.end(); ++src) { + boost::shared_ptr afs = boost::dynamic_pointer_cast(*src); + if (afs) { afs->mark_for_remove (); } - delete *src; + + (*src)->drop_references (); } } diff --git a/libs/ardour/session_butler.cc b/libs/ardour/session_butler.cc index 5d691a7425..832284901c 100644 --- a/libs/ardour/session_butler.cc +++ b/libs/ardour/session_butler.cc @@ -187,7 +187,7 @@ Session::butler_thread_work () } if (pfd[0].revents & ~POLLIN) { - error << _("Error on butler thread request pipe") << endmsg; + error << string_compose (_("Error on butler thread request pipe: fd=%1 err=%2"), pfd[0].fd, pfd[0].revents) << endmsg; break; } diff --git a/libs/ardour/session_command.cc b/libs/ardour/session_command.cc index 4e7c4151b7..fb15304e9f 100644 --- a/libs/ardour/session_command.cc +++ b/libs/ardour/session_command.cc @@ -13,9 +13,7 @@ using namespace PBD; namespace ARDOUR { -static map registry; - -void Session::register_with_memento_command_factory(PBD::ID id, Stateful *ptr) +void Session::register_with_memento_command_factory(PBD::ID id, StatefulDestructible *ptr) { registry[id] = ptr; } @@ -90,7 +88,8 @@ Command *Session::memento_command_factory(XMLNode *n) } // For Editor and AutomationLine which are off-limits here else if (registry.count(id)) - return new MementoCommand(*registry[id], before, after); + return new MementoCommand(*registry[id], before, after); + /* we failed */ error << _("could not reconstitute MementoCommand from XMLNode. id=") << id.to_s() << endmsg; diff --git a/libs/ardour/session_events.cc b/libs/ardour/session_events.cc index 79d20c8c39..9b6313fff3 100644 --- a/libs/ardour/session_events.cc +++ b/libs/ardour/session_events.cc @@ -405,7 +405,7 @@ Session::process_event (Event* ev) break; case Event::Audition: - set_audition (static_cast (ev->ptr)); + set_audition (ev->region); break; case Event::InputConfigurationChange: diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 5553127b90..6351b64cfe 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -88,6 +88,8 @@ #include #include #include +#include +#include #include "i18n.h" #include @@ -182,7 +184,6 @@ Session::first_stage_init (string fullpath, string snapshot_name) g_atomic_int_set (&_capture_load, 100); g_atomic_int_set (&_playback_load_min, 100); g_atomic_int_set (&_capture_load_min, 100); - pending_audition_region = 0; _edit_mode = Slide; pending_edit_mode = _edit_mode; _play_range = false; @@ -197,6 +198,7 @@ Session::first_stage_init (string fullpath, string snapshot_name) layer_model = MoveAddHigher; xfade_model = ShortCrossfade; destructive_index = 0; + current_trans = 0; AudioDiskstream::allocate_working_buffers(); @@ -267,13 +269,13 @@ Session::first_stage_init (string fullpath, string snapshot_name) /* These are all static "per-class" signals */ - Region::CheckNewRegion.connect (mem_fun (*this, &Session::add_region)); - Source::SourceCreated.connect (mem_fun (*this, &Session::add_source)); + RegionFactory::CheckNewRegion.connect (mem_fun (*this, &Session::add_region)); + SourceFactory::SourceCreated.connect (mem_fun (*this, &Session::add_source)); Playlist::PlaylistCreated.connect (mem_fun (*this, &Session::add_playlist)); Redirect::RedirectCreated.connect (mem_fun (*this, &Session::add_redirect)); NamedSelection::NamedSelectionCreated.connect (mem_fun (*this, &Session::add_named_selection)); - Curve::CurveCreated.connect (mem_fun (*this, &Session::add_curve)); - AutomationList::AutomationListCreated.connect (mem_fun (*this, &Session::add_automation_list)); + Curve::CurveCreated.connect (mem_fun (*this, &Session::add_curve)); + AutomationList::AutomationListCreated.connect (mem_fun (*this, &Session::add_automation_list)); Controllable::Created.connect (mem_fun (*this, &Session::add_controllable)); Controllable::GoingAway.connect (mem_fun (*this, &Session::remove_controllable)); @@ -294,6 +296,7 @@ Session::second_stage_init (bool new_session) if (!new_session) { if (load_state (_current_snapshot_name)) { + cerr << "load state failed\n"; return -1; } remove_empty_sounds (); @@ -1360,17 +1363,21 @@ Session::state(bool full_state) if (full_state) { Glib::Mutex::Lock sl (source_lock); - for (SourceList::iterator siter = sources.begin(); siter != sources.end(); ++siter) { + for (SourceMap::iterator siter = sources.begin(); siter != sources.end(); ++siter) { + /* Don't save information about AudioFileSources that are empty */ + + boost::shared_ptr fs; - DestructiveFileSource* const dfs = dynamic_cast (siter->second); - - /* Don't save sources that are empty, unless they're destructive (which are OK - if they are empty, because we will re-use them every time.) - */ + if ((fs = boost::dynamic_pointer_cast (siter->second)) != 0) { + boost::shared_ptr dfs = boost::dynamic_pointer_cast (fs); - if ( ! dfs && siter->second->length() == 0) { - continue; + /* Don't save sources that are empty, unless they're destructive (which are OK + if they are empty, because we will re-use them every time.) + */ + if ( ! dfs && siter->second->length() == 0) { + continue; + } } child->add_child_nocopy (siter->second->get_state()); @@ -1774,7 +1781,7 @@ Session::load_regions (const XMLNode& node) { XMLNodeList nlist; XMLNodeConstIterator niter; - Region* region; + boost::shared_ptr region; nlist = node.children(); @@ -1785,10 +1792,11 @@ Session::load_regions (const XMLNode& node) error << _("Session: cannot create Region from XML description.") << endmsg; } } + return 0; } -Region * +boost::shared_ptr Session::XMLRegionFactory (const XMLNode& node, bool full) { const XMLProperty* type = node.property("type"); @@ -1797,33 +1805,33 @@ Session::XMLRegionFactory (const XMLNode& node, bool full) if ( !type || type->value() == "audio" ) { - return XMLAudioRegionFactory (node, full); + return boost::shared_ptr(XMLAudioRegionFactory (node, full)); } else if (type->value() == "midi") { - return XMLMidiRegionFactory (node, full); + return boost::shared_ptr(XMLMidiRegionFactory (node, full)); } } catch (failed_constructor& err) { - return 0; + return boost::shared_ptr (); } - return 0; + return boost::shared_ptr (); } -AudioRegion * +boost::shared_ptr Session::XMLAudioRegionFactory (const XMLNode& node, bool full) { const XMLProperty* prop; - Source* source; - AudioSource* as; - AudioRegion::SourceList sources; + boost::shared_ptr source; + boost::shared_ptr as; + SourceList sources; uint32_t nchans = 1; char buf[128]; if (node.name() != X_("Region")) { - return 0; + return boost::shared_ptr(); } if ((prop = node.property (X_("channels"))) != 0) { @@ -1834,7 +1842,7 @@ Session::XMLAudioRegionFactory (const XMLNode& node, bool full) if ((prop = node.property (X_("source-0"))) == 0) { if ((prop = node.property ("source")) == 0) { error << _("Session: XMLNode describing a AudioRegion is incomplete (no source)") << endmsg; - return 0; + return boost::shared_ptr(); } } @@ -1842,13 +1850,13 @@ Session::XMLAudioRegionFactory (const XMLNode& node, bool full) if ((source = source_by_id (s_id)) == 0) { error << string_compose(_("Session: XMLNode describing a AudioRegion references an unknown source id =%1"), s_id) << endmsg; - return 0; + return boost::shared_ptr(); } - - as = dynamic_cast(source); + + as = boost::dynamic_pointer_cast(source); if (!as) { error << string_compose(_("Session: XMLNode describing a AudioRegion references a non-audio source id =%1"), s_id) << endmsg; - return 0; + return boost::shared_ptr(); } sources.push_back (as); @@ -1863,38 +1871,40 @@ Session::XMLAudioRegionFactory (const XMLNode& node, bool full) if ((source = source_by_id (id2)) == 0) { error << string_compose(_("Session: XMLNode describing a AudioRegion references an unknown source id =%1"), id2) << endmsg; - return 0; + return boost::shared_ptr(); } - as = dynamic_cast(source); + as = boost::dynamic_pointer_cast(source); if (!as) { error << string_compose(_("Session: XMLNode describing a AudioRegion references a non-audio source id =%1"), id2) << endmsg; - return 0; + return boost::shared_ptr(); } sources.push_back (as); } } try { - return new AudioRegion (sources, node); + boost::shared_ptr region (boost::dynamic_pointer_cast (RegionFactory::create (sources, node))); + return region; + } catch (failed_constructor& err) { - return 0; + return boost::shared_ptr(); } } -MidiRegion * +boost::shared_ptr Session::XMLMidiRegionFactory (const XMLNode& node, bool full) { const XMLProperty* prop; - Source* source; - MidiSource* ms; + boost::shared_ptr source; + boost::shared_ptr ms; MidiRegion::SourceList sources; uint32_t nchans = 1; if (node.name() != X_("Region")) { - return 0; + return boost::shared_ptr(); } if ((prop = node.property (X_("channels"))) != 0) { @@ -1907,7 +1917,7 @@ Session::XMLMidiRegionFactory (const XMLNode& node, bool full) if ((prop = node.property (X_("source-0"))) == 0) { if ((prop = node.property ("source")) == 0) { error << _("Session: XMLNode describing a MidiRegion is incomplete (no source)") << endmsg; - return 0; + return boost::shared_ptr(); } } @@ -1915,23 +1925,24 @@ Session::XMLMidiRegionFactory (const XMLNode& node, bool full) if ((source = source_by_id (s_id)) == 0) { error << string_compose(_("Session: XMLNode describing a MidiRegion references an unknown source id =%1"), s_id) << endmsg; - return 0; + return boost::shared_ptr(); } - ms = dynamic_cast(source); + ms = boost::dynamic_pointer_cast(source); if (!ms) { - error << string_compose(_("Session: XMLNode describing a MidiRegion references a non-audio source id =%1"), s_id) << endmsg; - return 0; + error << string_compose(_("Session: XMLNode describing a MidiRegion references a non-midi source id =%1"), s_id) << endmsg; + return boost::shared_ptr(); } sources.push_back (ms); try { - return new MidiRegion (sources, node); + boost::shared_ptr region (boost::dynamic_pointer_cast (RegionFactory::create (sources, node))); + return region; } catch (failed_constructor& err) { - return 0; + return boost::shared_ptr(); } } @@ -1942,7 +1953,7 @@ Session::get_sources_as_xml () XMLNode* node = new XMLNode (X_("Sources")); Glib::Mutex::Lock lm (source_lock); - for (SourceList::iterator i = sources.begin(); i != sources.end(); ++i) { + for (SourceMap::iterator i = sources.begin(); i != sources.end(); ++i) { node->add_child_nocopy (i->second->get_state()); } @@ -1979,7 +1990,7 @@ Session::load_sources (const XMLNode& node) { XMLNodeList nlist; XMLNodeConstIterator niter; - Source* source; + boost::shared_ptr source; nlist = node.children(); @@ -1995,41 +2006,22 @@ Session::load_sources (const XMLNode& node) return 0; } -Source * +boost::shared_ptr Session::XMLSourceFactory (const XMLNode& node) { - Source *src = 0; if (node.name() != "Source") { - return 0; - } - - DataType type = DataType::AUDIO; - const XMLProperty* prop = node.property("type"); - if (prop) { - type = DataType(prop->value()); + return boost::shared_ptr(); } try { - - - if (type == DataType::AUDIO) { - - src = AudioFileSource::create (node); - - } else if (type == DataType::MIDI) { - - src = new SMFSource (node); - + return SourceFactory::create (node); } - - } catch (failed_constructor& err) { - error << _("Found a file that cannot be read by Ardour. Talk to the progammers.") << endmsg; - return 0; + catch (failed_constructor& err) { + error << _("Found a sound file that cannot be used by Ardour. Talk to the progammers.") << endmsg; + return boost::shared_ptr(); } - - return src; } int @@ -2699,8 +2691,8 @@ Session::set_meter_falloff (float val) void Session::begin_reversible_command (string name) { - current_trans.clear (); - current_trans.set_name (name); + current_trans = new UndoTransaction; + current_trans->set_name (name); } void @@ -2709,11 +2701,11 @@ Session::commit_reversible_command (Command *cmd) struct timeval now; if (cmd) { - current_trans.add_command (cmd); + current_trans->add_command (cmd); } gettimeofday (&now, 0); - current_trans.set_timestamp (now); + current_trans->set_timestamp (now); history.add (current_trans); } @@ -3007,7 +2999,7 @@ Session::find_all_sources_across_snapshots (set& result, bool exclude_th int Session::cleanup_sources (Session::cleanup_report& rep) { - vector dead_sources; + vector > dead_sources; vector playlists_tbd; PathScanner scanner; string sound_path; @@ -3067,9 +3059,9 @@ Session::cleanup_sources (Session::cleanup_report& rep) rep.paths.clear (); rep.space = 0; - for (SourceList::iterator i = sources.begin(); i != sources.end(); ) { + for (SourceMap::iterator i = sources.begin(); i != sources.end(); ) { - SourceList::iterator tmp; + SourceMap::iterator tmp; tmp = i; ++tmp; @@ -3079,7 +3071,7 @@ Session::cleanup_sources (Session::cleanup_report& rep) capture files. */ - if (i->second->use_cnt() == 0 && i->second->length() > 0) { + if (i->second.use_count() == 1 && i->second->length() > 0) { dead_sources.push_back (i->second); /* remove this source from our own list to avoid us @@ -3097,7 +3089,7 @@ Session::cleanup_sources (Session::cleanup_report& rep) other snapshots). */ - for (vector::iterator i = dead_sources.begin(); i != dead_sources.end();++i) { + for (vector >::iterator i = dead_sources.begin(); i != dead_sources.end();++i) { for (RegionList::iterator r = regions.begin(); r != regions.end(); ) { RegionList::iterator tmp; @@ -3105,10 +3097,10 @@ Session::cleanup_sources (Session::cleanup_report& rep) tmp = r; ++tmp; - Region* const reg = r->second; + boost::shared_ptr reg = r->second; for (uint32_t n = 0; n < reg->n_channels(); ++n) { - if (®->source (n) == (*i)) { + if (reg->source (n) == (*i)) { /* this region is dead */ remove_region (reg); } @@ -3155,10 +3147,10 @@ Session::cleanup_sources (Session::cleanup_report& rep) /* add our current source list */ - for (SourceList::iterator i = sources.begin(); i != sources.end(); ++i) { - AudioFileSource* fs; + for (SourceMap::iterator i = sources.begin(); i != sources.end(); ++i) { + boost::shared_ptr fs; - if ((fs = dynamic_cast (i->second)) != 0) { + if ((fs = boost::dynamic_pointer_cast (i->second)) != 0) { all_sources.insert (fs->path()); } } @@ -3484,15 +3476,15 @@ Session::restore_history (string snapshot_name) it++) { XMLNode *t = *it; - UndoTransaction ut; + UndoTransaction* ut = new UndoTransaction (); struct timeval tv; - ut.set_name(t->property("name")->value()); + ut->set_name(t->property("name")->value()); stringstream ss(t->property("tv_sec")->value()); ss >> tv.tv_sec; ss.str(t->property("tv_usec")->value()); ss >> tv.tv_usec; - ut.set_timestamp(tv); + ut->set_timestamp(tv); for (XMLNodeConstIterator child_it = t->children().begin(); child_it != t->children().end(); @@ -3506,7 +3498,7 @@ Session::restore_history (string snapshot_name) { c = memento_command_factory(n); if (c) - ut.add_command(c); + ut->add_command(c); } else { diff --git a/libs/ardour/session_timefx.cc b/libs/ardour/session_timefx.cc index 82fd25ddb2..4ba8d42d9e 100644 --- a/libs/ardour/session_timefx.cc +++ b/libs/ardour/session_timefx.cc @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include "i18n.h" @@ -36,12 +38,12 @@ using namespace ARDOUR; using namespace PBD; using namespace soundtouch; -AudioRegion* +boost::shared_ptr Session::tempoize_region (TimeStretchRequest& tsr) { - AudioRegion::SourceList sources; - AudioRegion::SourceList::iterator it; - AudioRegion* r = 0; + SourceList sources; + SourceList::iterator it; + boost::shared_ptr r; SoundTouch st; string region_name; string ident = X_("-TIMEFX-"); @@ -80,10 +82,9 @@ Session::tempoize_region (TimeStretchRequest& tsr) } try { - sources.push_back (new SndFileSource (path, - Config->get_native_file_data_format(), - Config->get_native_file_header_format(), - frame_rate())); + sources.push_back (boost::dynamic_pointer_cast ( + SourceFactory::createWritable (DataType::AUDIO, path, false, frame_rate()))); + } catch (failed_constructor& err) { error << string_compose (_("tempoize: error creating new audio file %1 (%2)"), path, strerror (errno)) << endmsg; goto out; @@ -99,7 +100,7 @@ Session::tempoize_region (TimeStretchRequest& tsr) jack_nframes_t pos = 0; jack_nframes_t this_read = 0; - AudioSource* const asrc = dynamic_cast(sources[i]); + boost::shared_ptr asrc = boost::dynamic_pointer_cast(sources[i]); if (!asrc) { cerr << "FIXME: TimeFX for non-audio" << endl; continue; @@ -158,7 +159,7 @@ Session::tempoize_region (TimeStretchRequest& tsr) xnow = localtime (&now); for (it = sources.begin(); it != sources.end(); ++it) { - AudioFileSource* afs = dynamic_cast(*it); + boost::shared_ptr afs = boost::dynamic_pointer_cast(*it); if (afs) { afs->update_header (tsr.region->position(), *xnow, now); } @@ -166,10 +167,9 @@ Session::tempoize_region (TimeStretchRequest& tsr) region_name = tsr.region->name() + X_(".t"); - r = new AudioRegion (sources, 0, sources.front()->length(), region_name, - 0, AudioRegion::Flag (AudioRegion::DefaultFlags | AudioRegion::WholeFile)); - - + r = (boost::dynamic_pointer_cast (RegionFactory::create (sources, 0, sources.front()->length(), region_name, + 0, AudioRegion::Flag (AudioRegion::DefaultFlags | AudioRegion::WholeFile)))); + out: if (sources.size()) { @@ -178,21 +178,19 @@ Session::tempoize_region (TimeStretchRequest& tsr) for deletion. */ - if ((r == 0 || !tsr.running)) { + if ((!r || !tsr.running)) { for (it = sources.begin(); it != sources.end(); ++it) { (*it)->mark_for_remove (); - delete *it; } } + + sources.clear (); } /* if the process was cancelled, delete the region */ if (!tsr.running) { - if (r) { - delete r; - r = 0; - } + r.reset (); } return r; diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 5a5bafb6ca..44186ef86f 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -70,8 +70,6 @@ SMFSource::SMFSource (std::string path, Flag flags) } assert(_name.find("/") == string::npos); - - SourceCreated (this); /* EMIT SIGNAL */ } SMFSource::SMFSource (const XMLNode& node) @@ -100,8 +98,6 @@ SMFSource::SMFSource (const XMLNode& node) } assert(_name.find("/") == string::npos); - - SourceCreated (this); /* EMIT SIGNAL */ } SMFSource::~SMFSource () diff --git a/libs/ardour/sndfilesource.cc b/libs/ardour/sndfilesource.cc index 83c3c982b0..2bdcdc5a02 100644 --- a/libs/ardour/sndfilesource.cc +++ b/libs/ardour/sndfilesource.cc @@ -50,8 +50,6 @@ SndFileSource::SndFileSource (const XMLNode& node) throw failed_constructor (); } } - - SourceCreated (this); /* EMIT SIGNAL */ } SndFileSource::SndFileSource (string idstr, Flag flags) @@ -71,9 +69,6 @@ SndFileSource::SndFileSource (string idstr, Flag flags) throw failed_constructor (); } } - - - SourceCreated (this); /* EMIT SIGNAL */ } SndFileSource::SndFileSource (string idstr, SampleFormat sfmt, HeaderFormat hf, jack_nframes_t rate, Flag flags) @@ -183,9 +178,6 @@ SndFileSource::SndFileSource (string idstr, SampleFormat sfmt, HeaderFormat hf, throw failed_constructor (); } } - - SourceCreated (this); /* EMIT SIGNAL */ - } void @@ -235,7 +227,8 @@ SndFileSource::open () _length = _info.frames; - _broadcast_info = (SF_BROADCAST_INFO*) calloc (1, sizeof (SF_BROADCAST_INFO)); + _broadcast_info = new SF_BROADCAST_INFO; + memset (_broadcast_info, 0, sizeof (*_broadcast_info)); /* lookup broadcast info */ @@ -244,7 +237,7 @@ SndFileSource::open () /* if the file has data but no broadcast info, then clearly, there is no broadcast info */ if (_length) { - free (_broadcast_info); + delete _broadcast_info; _broadcast_info = 0; _flags = Flag (_flags & ~Broadcast); } @@ -269,7 +262,7 @@ SndFileSource::open () SndFileSource::~SndFileSource () { - GoingAway (this); /* EMIT SIGNAL */ + GoingAway (); /* EMIT SIGNAL */ if (sf) { sf_close (sf); @@ -412,7 +405,7 @@ SndFileSource::write_unlocked (Sample *data, jack_nframes_t cnt) if (_build_peakfiles) { - queue_for_peaks (*this); + queue_for_peaks (this); } _write_data_count = cnt; @@ -485,7 +478,7 @@ SndFileSource::setup_broadcast_info (jack_nframes_t when, struct tm& now, time_t if (sf_command (sf, SFC_SET_BROADCAST_INFO, _broadcast_info, sizeof (*_broadcast_info)) != SF_TRUE) { error << string_compose (_("cannot set broadcast info for audio file %1; Dropping broadcast info for this file"), _path) << endmsg; _flags = Flag (_flags & ~Broadcast); - free (_broadcast_info); + delete _broadcast_info; _broadcast_info = 0; return -1; } @@ -506,7 +499,7 @@ SndFileSource::set_header_timeline_position () if (sf_command (sf, SFC_SET_BROADCAST_INFO, _broadcast_info, sizeof (*_broadcast_info)) != SF_TRUE) { error << string_compose (_("cannot set broadcast info for audio file %1; Dropping broadcast info for this file"), _path) << endmsg; _flags = Flag (_flags & ~Broadcast); - free (_broadcast_info); + delete _broadcast_info; _broadcast_info = 0; } } diff --git a/libs/ardour/source.cc b/libs/ardour/source.cc index 0b15a8b5b8..d218e2cf94 100644 --- a/libs/ardour/source.cc +++ b/libs/ardour/source.cc @@ -51,7 +51,6 @@ Source::Source (string name, DataType type) assert(_name.find("/") == string::npos); _name = name; - _use_cnt = 0; _timestamp = 0; _length = 0; } @@ -59,7 +58,6 @@ Source::Source (string name, DataType type) Source::Source (const XMLNode& node) : _type(DataType::AUDIO) { - _use_cnt = 0; _timestamp = 0; _length = 0; @@ -71,6 +69,7 @@ Source::Source (const XMLNode& node) Source::~Source () { + notify_callbacks (); } XMLNode& @@ -121,18 +120,6 @@ Source::set_state (const XMLNode& node) return 0; } -void -Source::use () -{ - _use_cnt++; -} - -void -Source::release () -{ - if (_use_cnt) --_use_cnt; -} - void Source::update_length (jack_nframes_t pos, jack_nframes_t cnt) { diff --git a/libs/ardour/source_factory.cc b/libs/ardour/source_factory.cc new file mode 100644 index 0000000000..2fcdd29033 --- /dev/null +++ b/libs/ardour/source_factory.cc @@ -0,0 +1,219 @@ +/* + Copyright (C) 2000-2006 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + $Id$ +*/ + +#include +#include +#include +#include +#include + +#include "i18n.h" + +using namespace ARDOUR; +using namespace std; + +sigc::signal > SourceFactory::SourceCreated; + +#ifdef HAVE_COREAUDIO + + +boost::shared_ptr +SourceFactory::create (const XMLNode& node) +{ + DataType type = DataType::AUDIO; + const XMLProperty* prop = node.property("type"); + if (prop) { + type = DataType(prop->value()); + } + + if (type == DataType::AUDIO) { + + if (node.property (X_("destructive")) != 0) { + + boost::shared_ptr ret (new DestructiveFileSource (node)); + SourceCreated (ret); + return ret; + + } else { + + try { + boost::shared_ptr ret (new CoreAudioSource (node)); + SourceCreated (ret); + return ret; + } + + + catch (failed_constructor& err) { + boost::shared_ptr ret (new SndFileSource (node)); + SourceCreated (ret); + return ret; + } + } + + } else if (type == DataType::MIDI) { + + boost::shared_ptr ret (new SMFSource (node)); + SourceCreated (ret); + return ret; + + } + + return boost::shared_ptr(); +} + +#else + +boost::shared_ptr +SourceFactory::create (const XMLNode& node) +{ + DataType type = DataType::AUDIO; + const XMLProperty* prop = node.property("type"); + if (prop) { + type = DataType(prop->value()); + } + + if (type == DataType::AUDIO) { + + if (node.property (X_("destructive")) != 0) { + + boost::shared_ptr ret (new DestructiveFileSource (node)); + SourceCreated (ret); + return ret; + + } else { + + boost::shared_ptr ret (new SndFileSource (node)); + SourceCreated (ret); + return ret; + } + + } else if (type == DataType::MIDI) { + + boost::shared_ptr ret (new SMFSource (node)); + SourceCreated (ret); + return ret; + + } + + return boost::shared_ptr (); +} + +#endif // HAVE_COREAUDIO + +#ifdef HAVE_COREAUDIO +boost::shared_ptr +SourceFactory::createReadable (string idstr, AudioFileSource::Flag flags, bool announce) +{ + if (type == DataType::AUDIO) { + if (flags & Destructive) { + boost::shared_ptr ret (new DestructiveFileSource (idstr, flags)); + if (announce) { + SourceCreated (ret); + } + return ret; + } + + try { + boost::shared_ptr ret (new CoreAudioSource (idstr, flags)); + if (announce) { + SourceCreated (ret); + } + return ret; + } + + catch (failed_constructor& err) { + boost::shared_ptr ret (new SndFileSource (idstr, flags)); + if (announce) { + SourceCreated (ret); + } + return ret; + } + } else if (type == DataType::MIDI) { + + boost::shared_ptr ret (new SMFSource (node)); + SourceCreated (ret); + return ret; + + } + + return boost::shared_ptr(); +} + +#else + +boost::shared_ptr +SourceFactory::createReadable (DataType type, string idstr, AudioFileSource::Flag flags, bool announce) +{ + if (type == DataType::AUDIO) { + boost::shared_ptr ret (new SndFileSource (idstr, flags)); + if (announce) { + SourceCreated (ret); + } + return ret; + + } else if (type == DataType::MIDI) { + + boost::shared_ptr ret (new SMFSource (idstr, SMFSource::Flag(0))); // FIXME: flags? + SourceCreated (ret); + return ret; + + } + + return boost::shared_ptr (); +} + +#endif // HAVE_COREAUDIO + +boost::shared_ptr +SourceFactory::createWritable (DataType type, std::string path, bool destructive, jack_nframes_t rate, bool announce) +{ + /* this might throw failed_constructor(), which is OK */ + + if (type == DataType::AUDIO) { + if (destructive) { + boost::shared_ptr ret (new DestructiveFileSource (path, + Config->get_native_file_data_format(), + Config->get_native_file_header_format(), + rate)); + if (announce) { + SourceCreated (ret); + } + return ret; + + } else { + boost::shared_ptr ret (new SndFileSource (path, + Config->get_native_file_data_format(), + Config->get_native_file_header_format(), + rate)); + if (announce) { + SourceCreated (ret); + } + return ret; + } + } else if (type == DataType::MIDI) { + + boost::shared_ptr ret (new SMFSource (path)); + SourceCreated (ret); + return ret; + + } + + return boost::shared_ptr (); +} diff --git a/libs/ardour/vst_plugin.cc b/libs/ardour/vst_plugin.cc index 4c09ba3440..dbb7547052 100644 --- a/libs/ardour/vst_plugin.cc +++ b/libs/ardour/vst_plugin.cc @@ -98,7 +98,7 @@ VSTPlugin::VSTPlugin (const VSTPlugin &other) VSTPlugin::~VSTPlugin () { deactivate (); - GoingAway (this); /* EMIT SIGNAL */ + GoingAway (); /* EMIT SIGNAL */ fst_close (_fst); } diff --git a/libs/pbd/pbd/command.h b/libs/pbd/pbd/command.h index cd9bf0e08a..7c367e7462 100644 --- a/libs/pbd/pbd/command.h +++ b/libs/pbd/pbd/command.h @@ -22,8 +22,9 @@ #define __lib_pbd_command_h__ #include +#include -class Command : public Stateful +class Command : public Stateful, public PBD::Destructible { public: virtual ~Command() {} diff --git a/libs/pbd/pbd/memento_command.h b/libs/pbd/pbd/memento_command.h index 3a72fc9841..f257e63233 100644 --- a/libs/pbd/pbd/memento_command.h +++ b/libs/pbd/pbd/memento_command.h @@ -21,6 +21,10 @@ #ifndef __lib_pbd_memento_command_h__ #define __lib_pbd_memento_command_h__ +#include +using std::cerr; +using std::endl; + #include #include #include @@ -34,12 +38,22 @@ template class MementoCommand : public Command { public: - MementoCommand(XMLNode &state); - MementoCommand(obj_T &obj, + MementoCommand(obj_T &object, XMLNode *before, XMLNode *after ) - : obj(obj), before(before), after(after) {} + : obj(object), before(before), after(after) { + obj.GoingAway.connect (sigc::mem_fun (*this, &MementoCommand::object_death)); + } + ~MementoCommand () { + GoingAway(); + if (before) { + delete before; + } + if (after) { + delete after; + } + } void operator() () { if (after) @@ -60,20 +74,27 @@ class MementoCommand : public Command else name = "MementoRedoCommand"; + XMLNode *node = new XMLNode(name); - node->add_property("obj_id", obj.id().to_s()); - node->add_property("type_name", typeid(obj).name()); - if (before) - node->add_child_copy(*before); - if (after) - node->add_child_copy(*after); + node->add_property("obj_id", obj.id().to_s()); + node->add_property("type_name", typeid(obj).name()); + + if (before) + node->add_child_copy(*before); + if (after) + node->add_child_copy(*after); return *node; } + protected: obj_T &obj; XMLNode *before, *after; + + void object_death () { + delete this; + } }; #endif // __lib_pbd_memento_h__ diff --git a/libs/pbd/pbd/statefuldestructible.h b/libs/pbd/pbd/statefuldestructible.h new file mode 100644 index 0000000000..e78cc4bdaa --- /dev/null +++ b/libs/pbd/pbd/statefuldestructible.h @@ -0,0 +1,13 @@ +#ifndef __pbd_stateful_destructible_h__ +#define __pbd_stateful_destructible_h__ + +#include +#include + +namespace PBD { +class StatefulDestructible : public Stateful, public Destructible +{ +}; +} + +#endif /* __pbd_stateful_destructible_h__ */ diff --git a/libs/pbd/pbd/undo.h b/libs/pbd/pbd/undo.h index 724e86aaa0..eecd8ae49d 100644 --- a/libs/pbd/pbd/undo.h +++ b/libs/pbd/pbd/undo.h @@ -29,9 +29,6 @@ #include #include -using std::string; -using std::list; - typedef sigc::slot UndoAction; class UndoTransaction : public Command @@ -40,10 +37,11 @@ class UndoTransaction : public Command UndoTransaction (); UndoTransaction (const UndoTransaction&); UndoTransaction& operator= (const UndoTransaction&); + ~UndoTransaction (); void clear (); - void add_command (Command *const); + void add_command (Command* const); void operator() (); void undo(); @@ -51,10 +49,10 @@ class UndoTransaction : public Command XMLNode &get_state(); - void set_name (const string& str) { + void set_name (const std::string& str) { _name = str; } - const string& name() const { return _name; } + const std::string& name() const { return _name; } void set_timestamp (struct timeval &t) { _timestamp = t; @@ -65,26 +63,28 @@ class UndoTransaction : public Command } private: - list actions; - struct timeval _timestamp; - string _name; + std::list actions; + struct timeval _timestamp; + std::string _name; + bool clearing; + void remove_command (Command* const); }; class UndoHistory { public: - UndoHistory() {} + UndoHistory(); ~UndoHistory() {} - void add (UndoTransaction ut); + void add (UndoTransaction* ut); void undo (unsigned int n); void redo (unsigned int n); unsigned long undo_depth() const { return UndoList.size(); } unsigned long redo_depth() const { return RedoList.size(); } - string next_undo() const { return (UndoList.empty() ? string("") : UndoList.back().name()); } - string next_redo() const { return (RedoList.empty() ? string("") : RedoList.back().name()); } + std::string next_undo() const { return (UndoList.empty() ? std::string("") : UndoList.back()->name()); } + std::string next_redo() const { return (RedoList.empty() ? std::string("") : RedoList.back()->name()); } void clear (); void clear_undo (); @@ -92,9 +92,13 @@ class UndoHistory XMLNode &get_state(); void save_state(); + private: - list UndoList; - list RedoList; + bool clearing; + std::list UndoList; + std::list RedoList; + + void remove (UndoTransaction*); }; diff --git a/libs/pbd/undo.cc b/libs/pbd/undo.cc index 6f421de84e..717c355bae 100644 --- a/libs/pbd/undo.cc +++ b/libs/pbd/undo.cc @@ -19,26 +19,36 @@ */ #include +#include +#include #include #include -#include -#include + +#include using namespace std; using namespace sigc; UndoTransaction::UndoTransaction () { + clearing = false; } UndoTransaction::UndoTransaction (const UndoTransaction& rhs) { _name = rhs._name; + clearing = false; clear (); actions.insert(actions.end(),rhs.actions.begin(),rhs.actions.end()); } +UndoTransaction::~UndoTransaction () +{ + GoingAway (); + clear (); +} + UndoTransaction& UndoTransaction::operator= (const UndoTransaction& rhs) { @@ -52,13 +62,31 @@ UndoTransaction::operator= (const UndoTransaction& rhs) void UndoTransaction::add_command (Command *const action) { + action->GoingAway.connect (bind (mem_fun (*this, &UndoTransaction::remove_command), action)); actions.push_back (action); } +void +UndoTransaction::remove_command (Command* const action) +{ + if (clearing) { + return; + } + actions.remove (action); + if (actions.empty()) { + delete this; + } +} + void UndoTransaction::clear () { + clearing = true; + for (list::iterator i = actions.begin(); i != actions.end(); ++i) { + delete *i; + } actions.clear (); + clearing = false; } void @@ -72,7 +100,6 @@ UndoTransaction::operator() () void UndoTransaction::undo () { - cerr << "Undo " << _name << endl; for (list::reverse_iterator i = actions.rbegin(); i != actions.rend(); ++i) { (*i)->undo(); } @@ -81,7 +108,6 @@ UndoTransaction::undo () void UndoTransaction::redo () { - cerr << "Redo " << _name << endl; (*this)(); } @@ -103,10 +129,29 @@ XMLNode &UndoTransaction::get_state() return *node; } +UndoHistory::UndoHistory () +{ + clearing = false; +} + void -UndoHistory::add (UndoTransaction ut) +UndoHistory::add (UndoTransaction* const ut) { + ut->GoingAway.connect (bind (mem_fun (*this, &UndoHistory::remove), ut)); UndoList.push_back (ut); + + /* we are now owners of the transaction */ +} + +void +UndoHistory::remove (UndoTransaction* const ut) +{ + if (clearing) { + return; + } + + UndoList.remove (ut); + RedoList.remove (ut); } void @@ -116,9 +161,9 @@ UndoHistory::undo (unsigned int n) if (UndoList.size() == 0) { return; } - UndoTransaction ut = UndoList.back (); + UndoTransaction* ut = UndoList.back (); UndoList.pop_back (); - ut.undo (); + ut->undo (); RedoList.push_back (ut); } } @@ -130,9 +175,9 @@ UndoHistory::redo (unsigned int n) if (RedoList.size() == 0) { return; } - UndoTransaction ut = RedoList.back (); + UndoTransaction* ut = RedoList.back (); RedoList.pop_back (); - ut.redo (); + ut->redo (); UndoList.push_back (ut); } } @@ -140,29 +185,34 @@ UndoHistory::redo (unsigned int n) void UndoHistory::clear_redo () { + clearing = true; RedoList.clear (); + clearing = false; } void UndoHistory::clear_undo () { + clearing = true; UndoList.clear (); + clearing = false; } void UndoHistory::clear () { - RedoList.clear (); - UndoList.clear (); + clear_undo (); + clear_redo (); } XMLNode & UndoHistory::get_state() { XMLNode *node = new XMLNode ("UndoHistory"); - list::iterator it; - for (it=UndoList.begin(); it != UndoList.end(); it++) - node->add_child_nocopy(it->get_state()); + list::iterator it; + for (it = UndoList.begin(); it != UndoList.end(); it++) { + node->add_child_nocopy((*it)->get_state()); + } return *node; } -- cgit v1.2.3