From f995ac37860140c513e29c3bc58701474a7ed336 Mon Sep 17 00:00:00 2001 From: Hans Fugal Date: Sat, 12 Aug 2006 01:36:34 +0000 Subject: [PATCH 1/2] merge from trunk git-svn-id: svn://localhost/ardour2/branches/undo@794 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/SConscript | 16 +- gtk2_ardour/analysis_window.cc | 6 +- au_pluginui.cc => gtk2_ardour/au_pluginui.cc | 31 +- gtk2_ardour/editor_export_audio.cc | 12 +- gtk2_ardour/ladspa_pluginui.cc | 757 +++++++++++++++++++ gtk2_ardour/new_session_dialog.cc | 23 +- gtk2_ardour/pan_automation_time_axis.cc | 2 +- gtk2_ardour/plugin_selector.cc | 53 +- gtk2_ardour/plugin_selector.h | 4 +- gtk2_ardour/plugin_ui.cc | 711 +---------------- gtk2_ardour/plugin_ui.h | 22 +- gtk2_ardour/public_editor.h | 3 + gtk2_ardour/redirect_box.cc | 79 +- gtk2_ardour/route_params_ui.cc | 2 +- libs/ardour/ardour/audio_diskstream.h | 9 +- libs/ardour/ardour/audio_track.h | 2 +- libs/ardour/ardour/audio_unit.h | 2 + libs/ardour/ardour/audioplaylist.h | 2 +- libs/ardour/ardour/audioregion.h | 6 +- libs/ardour/ardour/audiosource.h | 8 +- libs/ardour/ardour/coreaudiosource.h | 4 +- libs/ardour/ardour/crossfade.h | 2 +- libs/ardour/ardour/destructive_filesource.h | 4 +- libs/ardour/ardour/diskstream.h | 4 +- libs/ardour/ardour/insert.h | 5 +- libs/ardour/ardour/plugin.h | 13 +- libs/ardour/ardour/session.h | 3 - libs/ardour/ardour/sndfilesource.h | 4 +- libs/ardour/ardour/types.h | 10 +- libs/ardour/ardour/vst_plugin.h | 2 + libs/ardour/audio_diskstream.cc | 33 +- libs/ardour/audio_playlist.cc | 6 +- libs/ardour/audio_track.cc | 6 +- libs/ardour/audio_unit.cc | 2 +- libs/ardour/audioregion.cc | 19 +- libs/ardour/audiosource.cc | 27 +- libs/ardour/configuration.cc | 2 +- libs/ardour/coreaudiosource.cc | 2 +- libs/ardour/crossfade.cc | 6 +- libs/ardour/destructive_filesource.cc | 12 +- libs/ardour/diskstream.cc | 8 +- libs/ardour/import.cc | 7 +- libs/ardour/insert.cc | 52 +- libs/ardour/panner.cc | 4 +- libs/ardour/plugin.cc | 8 +- libs/ardour/plugin_manager.cc | 4 +- libs/ardour/reverse.cc | 10 +- libs/ardour/session.cc | 15 +- libs/ardour/session_state.cc | 3 - libs/ardour/session_timefx.cc | 7 +- libs/ardour/sndfilesource.cc | 4 +- libs/ardour/track.cc | 2 +- 52 files changed, 1097 insertions(+), 943 deletions(-) rename au_pluginui.cc => gtk2_ardour/au_pluginui.cc (56%) create mode 100644 gtk2_ardour/ladspa_pluginui.cc diff --git a/gtk2_ardour/SConscript b/gtk2_ardour/SConscript index d004c9c4c6..2a7250eaa4 100644 --- a/gtk2_ardour/SConscript +++ b/gtk2_ardour/SConscript @@ -57,14 +57,13 @@ if gtkardour['FFT_ANALYSIS']: gtkardour.Merge ([libraries['fftw3f']]) gtkardour.Append(CCFLAGS='-DFFT_ANALYSIS') -if gtkardour['COREAUDIO']: - gtkardour.Append(CCFLAGS='-DHAVE_COREAUDIO') - gtkardour.Merge([libraries['appleutility']]) - skipped_files=Split(""" connection_editor.cc """) +coreaudio_files=Split(""" +au_pluginui.cc +""") gtkardour_files=Split(""" about.cc @@ -140,6 +139,7 @@ imageframe_time_axis_view.cc imageframe_view.cc io_selector.cc keyboard.cc +ladspa_pluginui.cc location_ui.cc main.cc marker.cc @@ -186,7 +186,6 @@ visual_time_axis.cc waveview.cc """) - fft_analysis_files=Split(""" analysis_window.cc fft_graph.cc @@ -212,7 +211,12 @@ vst_files = [ 'vst_pluginui.cc' ] if env['VST']: extra_sources += vst_files gtkardour.Append (CCFLAGS="-DVST_SUPPORT", CPPPATH="#libs/fst") - + +if gtkardour['COREAUDIO']: + extra_sources += coreaudio_files + gtkardour.Append(CCFLAGS='-DHAVE_COREAUDIO') + gtkardour.Merge([libraries['appleutility']]) + if env['FFT_ANALYSIS']: extra_sources += fft_analysis_files diff --git a/gtk2_ardour/analysis_window.cc b/gtk2_ardour/analysis_window.cc index f742afd727..24c6cc4fb8 100644 --- a/gtk2_ardour/analysis_window.cc +++ b/gtk2_ardour/analysis_window.cc @@ -221,7 +221,6 @@ AnalysisWindow::analyze_data (Gtk::Button *button) Sample *buf = (Sample *) malloc(sizeof(Sample) * fft_graph.windowSize()); Sample *mixbuf = (Sample *) malloc(sizeof(Sample) * fft_graph.windowSize()); float *gain = (float *) malloc(sizeof(float) * fft_graph.windowSize()); - char *work = (char *) malloc(sizeof(char) * fft_graph.windowSize()); Selection s = PublicEditor::instance().get_selection(); TimeSelection ts = s.time; @@ -261,7 +260,7 @@ AnalysisWindow::analyze_data (Gtk::Button *button) n = (*j).length() - i; } - n = pl->read(buf, mixbuf, gain, work, (*j).start + i, n); + n = pl->read(buf, mixbuf, gain, (*j).start + i, n); if ( n < fft_graph.windowSize()) { for (int j = n; j < fft_graph.windowSize(); j++) { @@ -301,7 +300,7 @@ AnalysisWindow::analyze_data (Gtk::Button *button) n = arv->region().length() - i; } - n = arv->audio_region().read_at(buf, mixbuf, gain, work, 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++) { @@ -331,7 +330,6 @@ AnalysisWindow::analyze_data (Gtk::Button *button) free(buf); free(mixbuf); - free(work); track_list_ready = true; } /* end lock */ diff --git a/au_pluginui.cc b/gtk2_ardour/au_pluginui.cc similarity index 56% rename from au_pluginui.cc rename to gtk2_ardour/au_pluginui.cc index cbf493a629..e4a5c73fe9 100644 --- a/au_pluginui.cc +++ b/gtk2_ardour/au_pluginui.cc @@ -23,13 +23,32 @@ #include "plugin_ui.h" +#include "i18n.h" + using namespace ARDOUR; using namespace PBD; -AUPluginUI::AUPluginUI (boost::shared_ptr pi, boost::shared_ptr ap) - : PlugUIBase (pi), - au (ap) +AUPluginUI::AUPluginUI (boost::shared_ptr ap) { + if ((au = boost::dynamic_pointer_cast (ap->plugin())) == 0) { + error << _("unknown type of editor-supplying plugin (note: no AudioUnit support in this version of ardour)") << endmsg; + throw failed_constructor (); + } + +#if 0 + set_position (Gtk::WIN_POS_MOUSE); + set_name ("PluginEditor"); + add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK); + + signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast (this))); + insert->GoingAway.connect (mem_fun(*this, &PluginUIWindow::plugin_going_away)); + + if (scrollable) { + gint h = _pluginui->get_preferred_height (); + if (h > 600) h = 600; + set_default_size (450, h); + } +#endif info << "AUPluginUI created" << endmsg; } @@ -37,9 +56,3 @@ AUPluginUI::~AUPluginUI () { // nothing to do here - plugin destructor destroys the GUI } - -int -AUPluginUI::get_preferred_height () -{ - return -1; -} diff --git a/gtk2_ardour/editor_export_audio.cc b/gtk2_ardour/editor_export_audio.cc index 46a704b435..865796a1ed 100644 --- a/gtk2_ardour/editor_export_audio.cc +++ b/gtk2_ardour/editor_export_audio.cc @@ -162,7 +162,6 @@ Editor::write_region (string path, AudioRegion& region) jack_nframes_t to_read; Sample buf[chunk_size]; gain_t gain_buffer[chunk_size]; - char workbuf[chunk_size *4]; jack_nframes_t pos; char s[PATH_MAX+1]; uint32_t cnt; @@ -234,11 +233,11 @@ Editor::write_region (string path, AudioRegion& region) fs = (*src); - if (region.read_at (buf, buf, gain_buffer, workbuf, pos, this_time) != this_time) { + if (region.read_at (buf, buf, gain_buffer, pos, this_time) != this_time) { break; } - if (fs->write (buf, this_time, workbuf) != this_time) { + if (fs->write (buf, this_time) != this_time) { error << "" << endmsg; goto error_out; } @@ -309,7 +308,6 @@ Editor::write_audio_range (AudioPlaylist& playlist, uint32_t channels, listwrite (buf, this_time, workbuf) != this_time) { + if (fs->write (buf, this_time) != this_time) { goto error_out; } } @@ -397,7 +395,7 @@ Editor::write_audio_range (AudioPlaylist& playlist, uint32_t channels, listwrite (buf, this_time, workbuf) != this_time) { + if (fs->write (buf, this_time) != this_time) { goto error_out; } } diff --git a/gtk2_ardour/ladspa_pluginui.cc b/gtk2_ardour/ladspa_pluginui.cc new file mode 100644 index 0000000000..b1f193b862 --- /dev/null +++ b/gtk2_ardour/ladspa_pluginui.cc @@ -0,0 +1,757 @@ +/* + 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 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. + +*/ + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include + +#include "ardour_ui.h" +#include "prompter.h" +#include "plugin_ui.h" +#include "utils.h" +#include "gui_thread.h" + +#include "i18n.h" + +using namespace std; +using namespace ARDOUR; +using namespace PBD; +using namespace Gtkmm2ext; +using namespace Gtk; +using namespace sigc; + +LadspaPluginUI::LadspaPluginUI (boost::shared_ptr pi, bool scrollable) + : PlugUIBase (pi), + button_table (initial_button_rows, initial_button_cols), + output_table (initial_output_rows, initial_output_cols), + hAdjustment(0.0, 0.0, 0.0), + vAdjustment(0.0, 0.0, 0.0), + scroller_view(hAdjustment, vAdjustment), + automation_menu (0), + is_scrollable(scrollable) +{ + set_name ("PluginEditor"); + set_border_width (10); + set_homogeneous (false); + + settings_box.set_homogeneous (false); + + HBox* constraint_hbox = manage (new HBox); + HBox* smaller_hbox = manage (new HBox); + Label* combo_label = manage (new Label (_("Presets"))); + combo_label->set_use_markup (true); + + smaller_hbox->pack_start (*combo_label, false, false, 10); + smaller_hbox->pack_start (combo, false, false); + smaller_hbox->pack_start (save_button, false, false); + + constraint_hbox->set_spacing (5); + constraint_hbox->pack_start (*smaller_hbox, true, false); + constraint_hbox->pack_end (bypass_button, false, false); + + settings_box.pack_end (*constraint_hbox, false, false); + + pack_start (settings_box, false, false); + + if ( is_scrollable ) { + scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); + scroller.set_name ("PluginEditor"); + scroller_view.set_name("PluginEditor"); + scroller_view.add (hpacker); + scroller.add (scroller_view); + + pack_start (scroller, true, true); + + } + else { + pack_start (hpacker, false, false); + } + + insert->active_changed.connect (mem_fun(*this, &LadspaPluginUI::redirect_active_changed)); + bypass_button.set_active (!insert->active()); + + build (); +} + +LadspaPluginUI::~LadspaPluginUI () +{ + if (output_controls.size() > 0) { + screen_update_connection.disconnect(); + } +} + +void +LadspaPluginUI::build () + +{ + guint32 i = 0; + guint32 x = 0; + Frame* frame; + Frame* bt_frame; + VBox* box; + int output_row, output_col; + int button_row, button_col; + int output_rows, output_cols; + int button_rows, button_cols; + guint32 n_ins=0, n_outs = 0; + + prefheight = 30; + hpacker.set_spacing (10); + + output_rows = initial_output_rows; + output_cols = initial_output_cols; + button_rows = initial_button_rows; + button_cols = initial_button_cols; + output_row = 0; + button_row = 0; + output_col = 0; + button_col = 0; + + button_table.set_homogeneous (false); + button_table.set_row_spacings (2); + button_table.set_col_spacings (2); + output_table.set_homogeneous (true); + output_table.set_row_spacings (2); + output_table.set_col_spacings (2); + button_table.set_border_width (5); + output_table.set_border_width (5); + + hpacker.set_border_width (10); + + bt_frame = manage (new Frame); + bt_frame->set_name ("BaseFrame"); + bt_frame->add (button_table); + hpacker.pack_start(*bt_frame, true, true); + + box = manage (new VBox); + box->set_border_width (5); + box->set_spacing (1); + + frame = manage (new Frame); + frame->set_name ("BaseFrame"); + frame->set_label (_("Controls")); + frame->add (*box); + hpacker.pack_start(*frame, true, true); + + /* find all ports. build control elements for all appropriate control ports */ + + for (i = 0; i < plugin->parameter_count(); ++i) { + + if (plugin->parameter_is_control (i)) { + + /* Don't show latency control ports */ + + if (plugin->describe_parameter (i) == X_("latency")) { + continue; + } + + ControlUI* cui; + + /* if we are scrollable, just use one long column */ + + if (!is_scrollable) { + if (x++ > 7){ + frame = manage (new Frame); + frame->set_name ("BaseFrame"); + box = manage (new VBox); + + box->set_border_width (5); + box->set_spacing (1); + + frame->add (*box); + hpacker.pack_start(*frame,true,true); + + x = 0; + } + } + + if ((cui = build_control_ui (i, plugin->get_nth_control (i))) == 0) { + error << string_compose(_("Plugin Editor: could not build control element for port %1"), i) << endmsg; + continue; + } + + if (cui->control || cui->clickbox || cui->combo) { + + box->pack_start (*cui, false, false); + + } else if (cui->button) { + + if (button_row == button_rows) { + button_row = 0; + if (++button_col == button_cols) { + button_cols += 2; + button_table.resize (button_rows, button_cols); + } + } + + button_table.attach (*cui, button_col, button_col + 1, button_row, button_row+1, + FILL|EXPAND, FILL); + button_row++; + + } else if (cui->display) { + + output_table.attach (*cui, output_col, output_col + 1, output_row, output_row+1, + FILL|EXPAND, FILL); + + // TODO: The meters should be divided into multiple rows + + if (++output_col == output_cols) { + output_cols ++; + output_table.resize (output_rows, output_cols); + } + + /* old code, which divides meters into + * columns first, rows later. New code divides into one row + + if (output_row == output_rows) { + output_row = 0; + if (++output_col == output_cols) { + output_cols += 2; + output_table.resize (output_rows, output_cols); + } + } + + output_table.attach (*cui, output_col, output_col + 1, output_row, output_row+1, + FILL|EXPAND, FILL); + + output_row++; + */ + } + + /* HACK: ideally the preferred height would be queried from + the complete hpacker, but I can't seem to get that + information in time, so this is an estimation + */ + + prefheight += 30; + + } + } + + n_ins = plugin->get_info()->n_inputs; + n_outs = plugin->get_info()->n_outputs; + + if (box->children().empty()) { + hpacker.remove (*frame); + } + + if (button_table.children().empty()) { + hpacker.remove (*bt_frame); + } + + if (!output_table.children().empty()) { + frame = manage (new Frame); + frame->set_name ("BaseFrame"); + frame->add (output_table); + hpacker.pack_end (*frame, true, true); + } + + output_update (); + + output_table.show_all (); + button_table.show_all (); +} + +LadspaPluginUI::ControlUI::ControlUI () + : automate_button (X_("")) // force creation of a label +{ + automate_button.set_name ("PluginAutomateButton"); + ARDOUR_UI::instance()->tooltips().set_tip (automate_button, + _("Automation control")); + + /* don't fix the height, it messes up the bar controllers */ + + set_size_request_to_display_given_text (automate_button, X_("lngnuf"), 2, 2); + + ignore_change = 0; + display = 0; + button = 0; + control = 0; + clickbox = 0; + adjustment = 0; + meterinfo = 0; +} + +LadspaPluginUI::ControlUI::~ControlUI() +{ + if (adjustment) { + delete adjustment; + } + + if (meterinfo) { + delete meterinfo->meter; + delete meterinfo; + } +} + +void +LadspaPluginUI::automation_state_changed (ControlUI* cui) +{ + /* update button label */ + + switch (insert->get_port_automation_state (cui->port_index) & (Off|Play|Touch|Write)) { + case Off: + cui->automate_button.set_label (_("Off")); + break; + case Play: + cui->automate_button.set_label (_("Play")); + break; + case Write: + cui->automate_button.set_label (_("Write")); + break; + case Touch: + cui->automate_button.set_label (_("Touch")); + break; + default: + cui->automate_button.set_label (_("???")); + break; + } +} + + +static void integer_printer (char buf[32], Adjustment &adj, void *arg) +{ + snprintf (buf, 32, "%.0f", adj.get_value()); +} + +void +LadspaPluginUI::print_parameter (char *buf, uint32_t len, uint32_t param) +{ + plugin->print_parameter (param, buf, len); +} + +LadspaPluginUI::ControlUI* +LadspaPluginUI::build_control_ui (guint32 port_index, PBD::Controllable* mcontrol) + +{ + ControlUI* control_ui; + Plugin::ParameterDescriptor desc; + + plugin->get_parameter_descriptor (port_index, desc); + + control_ui = manage (new ControlUI ()); + control_ui->adjustment = 0; + control_ui->combo = 0; + control_ui->combo_map = 0; + control_ui->port_index = port_index; + control_ui->update_pending = false; + control_ui->label.set_text (desc.label); + control_ui->label.set_alignment (0.0, 0.5); + control_ui->label.set_name ("PluginParameterLabel"); + + control_ui->set_spacing (5); + + if (plugin->parameter_is_input (port_index)) { + + boost::shared_ptr lp; + + if ((lp = boost::dynamic_pointer_cast(plugin)) != 0) { + + lrdf_defaults* defaults = lrdf_get_scale_values(lp->unique_id(), port_index); + + if (defaults && defaults->count > 0) { + + control_ui->combo = new Gtk::ComboBoxText; + //control_ui->combo->set_value_in_list(true, false); + set_popdown_strings (*control_ui->combo, setup_scale_values(port_index, control_ui)); + control_ui->combo->signal_changed().connect (bind (mem_fun(*this, &LadspaPluginUI::control_combo_changed), control_ui)); + plugin->ParameterChanged.connect (bind (mem_fun (*this, &LadspaPluginUI::parameter_changed), control_ui)); + control_ui->pack_start(control_ui->label, true, true); + control_ui->pack_start(*control_ui->combo, false, true); + + update_control_display(control_ui); + + lrdf_free_setting_values(defaults); + return control_ui; + } + } + + if (desc.toggled) { + + /* Build a button */ + + control_ui->button = manage (new ToggleButton ()); + control_ui->button->set_name ("PluginEditorButton"); + control_ui->button->set_size_request (20, 20); + + control_ui->pack_start (control_ui->label, true, true); + control_ui->pack_start (*control_ui->button, false, true); + control_ui->pack_start (control_ui->automate_button, false, false); + + control_ui->button->signal_clicked().connect (bind (mem_fun(*this, &LadspaPluginUI::control_port_toggled), control_ui)); + + if(plugin->get_parameter (port_index) == 1){ + control_ui->button->set_active(true); + } + + return control_ui; + } + + control_ui->adjustment = new Adjustment (0, 0, 0, 0, 0); + + /* XXX this code is not right yet, because it doesn't handle + the absence of bounds in any sensible fashion. + */ + + control_ui->adjustment->set_lower (desc.lower); + control_ui->adjustment->set_upper (desc.upper); + + control_ui->logarithmic = desc.logarithmic; + if (control_ui->logarithmic) { + if (control_ui->adjustment->get_lower() == 0.0) { + control_ui->adjustment->set_lower (control_ui->adjustment->get_upper()/10000); + } + control_ui->adjustment->set_upper (log(control_ui->adjustment->get_upper())); + control_ui->adjustment->set_lower (log(control_ui->adjustment->get_lower())); + } + + float delta = desc.upper - desc.lower; + + control_ui->adjustment->set_page_size (delta/100.0); + control_ui->adjustment->set_step_increment (desc.step); + control_ui->adjustment->set_page_increment (desc.largestep); + + if (desc.integer_step) { + control_ui->clickbox = new ClickBox (control_ui->adjustment, "PluginUIClickBox"); + Gtkmm2ext::set_size_request_to_display_given_text (*control_ui->clickbox, "g9999999", 2, 2); + control_ui->clickbox->set_print_func (integer_printer, 0); + } else { + sigc::slot pslot = sigc::bind (mem_fun(*this, &LadspaPluginUI::print_parameter), (uint32_t) port_index); + + control_ui->control = new BarController (*control_ui->adjustment, *mcontrol, pslot); + // should really match the height of the text in the automation button+label + control_ui->control->set_size_request (200, 22); + control_ui->control->set_name (X_("PluginSlider")); + control_ui->control->set_style (BarController::LeftToRight); + control_ui->control->set_use_parent (true); + + control_ui->control->StartGesture.connect (bind (mem_fun(*this, &LadspaPluginUI::start_touch), control_ui)); + control_ui->control->StopGesture.connect (bind (mem_fun(*this, &LadspaPluginUI::stop_touch), control_ui)); + + } + + if (control_ui->logarithmic) { + control_ui->adjustment->set_value(log(plugin->get_parameter(port_index))); + } else{ + control_ui->adjustment->set_value(plugin->get_parameter(port_index)); + } + + /* XXX memory leak: SliderController not destroyed by ControlUI + destructor, and manage() reports object hierarchy + ambiguity. + */ + + control_ui->pack_start (control_ui->label, true, true); + if (desc.integer_step) { + control_ui->pack_start (*control_ui->clickbox, false, false); + } else { + control_ui->pack_start (*control_ui->control, false, false); + } + + control_ui->pack_start (control_ui->automate_button, false, false); + control_ui->adjustment->signal_value_changed().connect (bind (mem_fun(*this, &LadspaPluginUI::control_adjustment_changed), control_ui)); + control_ui->automate_button.signal_clicked().connect (bind (mem_fun(*this, &LadspaPluginUI::astate_clicked), control_ui, (uint32_t) port_index)); + + automation_state_changed (control_ui); + + plugin->ParameterChanged.connect (bind (mem_fun(*this, &LadspaPluginUI::parameter_changed), control_ui)); + insert->automation_list (port_index).automation_state_changed.connect + (bind (mem_fun(*this, &LadspaPluginUI::automation_state_changed), control_ui)); + + } else if (plugin->parameter_is_output (port_index)) { + + control_ui->display = manage (new EventBox); + control_ui->display->set_name ("ParameterValueDisplay"); + + control_ui->display_label = manage (new Label); + + control_ui->display_label->set_name ("ParameterValueDisplay"); + + control_ui->display->add (*control_ui->display_label); + Gtkmm2ext::set_size_request_to_display_given_text (*control_ui->display, "-99,99", 2, 2); + + control_ui->display->show_all (); + + /* set up a meter */ + /* TODO: only make a meter if the port is Hinted for it */ + + MeterInfo * info = new MeterInfo(port_index); + control_ui->meterinfo = info; + + info->meter = new FastMeter (5, 100, FastMeter::Vertical); + + info->min_unbound = desc.min_unbound; + info->max_unbound = desc.max_unbound; + + info->min = desc.lower; + info->max = desc.upper; + + control_ui->vbox = manage (new VBox); + control_ui->hbox = manage (new HBox); + + control_ui->label.set_angle(90); + control_ui->hbox->pack_start (control_ui->label, false, false); + control_ui->hbox->pack_start (*info->meter, false, false); + + control_ui->vbox->pack_start (*control_ui->hbox, false, false); + + control_ui->vbox->pack_start (*control_ui->display, false, false); + + control_ui->pack_start (*control_ui->vbox); + + control_ui->meterinfo->meter->show_all(); + control_ui->meterinfo->packed = true; + + output_controls.push_back (control_ui); + } + + plugin->ParameterChanged.connect (bind (mem_fun(*this, &LadspaPluginUI::parameter_changed), control_ui)); + return control_ui; +} + +void +LadspaPluginUI::start_touch (LadspaPluginUI::ControlUI* cui) +{ + insert->automation_list (cui->port_index).start_touch (); +} + +void +LadspaPluginUI::stop_touch (LadspaPluginUI::ControlUI* cui) +{ + insert->automation_list (cui->port_index).stop_touch (); +} + +void +LadspaPluginUI::astate_clicked (ControlUI* cui, uint32_t port) +{ + using namespace Menu_Helpers; + + if (automation_menu == 0) { + automation_menu = manage (new Menu); + automation_menu->set_name ("ArdourContextMenu"); + } + + MenuList& items (automation_menu->items()); + + items.clear (); + items.push_back (MenuElem (_("Off"), + bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Off, cui))); + items.push_back (MenuElem (_("Play"), + bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Play, cui))); + items.push_back (MenuElem (_("Write"), + bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Write, cui))); + items.push_back (MenuElem (_("Touch"), + bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Touch, cui))); + + automation_menu->popup (1, 0); +} + +void +LadspaPluginUI::set_automation_state (AutoState state, ControlUI* cui) +{ + insert->set_port_automation_state (cui->port_index, state); +} + +void +LadspaPluginUI::control_adjustment_changed (ControlUI* cui) +{ + if (cui->ignore_change) { + return; + } + + double value = cui->adjustment->get_value(); + + if (cui->logarithmic) { + value = exp(value); + } + + insert->set_parameter (cui->port_index, (float) value); +} + +void +LadspaPluginUI::parameter_changed (uint32_t abs_port_id, float val, ControlUI* cui) +{ + if (cui->port_index == abs_port_id) { + if (!cui->update_pending) { + cui->update_pending = true; + Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &LadspaPluginUI::update_control_display), cui)); + } + } +} + +void +LadspaPluginUI::update_control_display (ControlUI* cui) +{ + /* XXX how do we handle logarithmic stuff here ? */ + + cui->update_pending = false; + + float val = plugin->get_parameter (cui->port_index); + + cui->ignore_change++; + if (cui->combo) { + std::map::iterator it; + for (it = cui->combo_map->begin(); it != cui->combo_map->end(); ++it) { + if (it->second == val) { + cui->combo->set_active_text(it->first); + break; + } + } + } else if (cui->adjustment == 0) { + + if (val > 0.5) { + cui->button->set_active (true); + } else { + cui->button->set_active (false); + } + + } else { + if (cui->logarithmic) { + val = log(val); + } + if (val != cui->adjustment->get_value()) { + cui->adjustment->set_value (val); + } + } + cui->ignore_change--; +} + +void +LadspaPluginUI::control_port_toggled (ControlUI* cui) +{ + if (!cui->ignore_change) { + insert->set_parameter (cui->port_index, cui->button->get_active()); + } +} + +void +LadspaPluginUI::control_combo_changed (ControlUI* cui) +{ + if (!cui->ignore_change) { + string value = cui->combo->get_active_text(); + std::map mapping = *cui->combo_map; + insert->set_parameter (cui->port_index, mapping[value]); + } + +} + +void +LadspaPluginUI::redirect_active_changed (Redirect* r, void* src) +{ + ENSURE_GUI_THREAD(bind (mem_fun(*this, &LadspaPluginUI::redirect_active_changed), r, src)); + + bypass_button.set_active (!r->active()); +} + +bool +LadspaPluginUI::start_updating (GdkEventAny* ignored) +{ + if (output_controls.size() > 0 ) { + screen_update_connection.disconnect(); + screen_update_connection = ARDOUR_UI::instance()->RapidScreenUpdate.connect + (mem_fun(*this, &LadspaPluginUI::output_update)); + } + return false; +} + +bool +LadspaPluginUI::stop_updating (GdkEventAny* ignored) +{ + if (output_controls.size() > 0 ) { + screen_update_connection.disconnect(); + } + return false; +} + +void +LadspaPluginUI::output_update () +{ + for (vector::iterator i = output_controls.begin(); i != output_controls.end(); ++i) { + float val = plugin->get_parameter ((*i)->port_index); + char buf[32]; + snprintf (buf, sizeof(buf), "%.2f", val); + (*i)->display_label->set_text (buf); + + /* autoscaling for the meter */ + if ((*i)->meterinfo && (*i)->meterinfo->packed) { + + if (val < (*i)->meterinfo->min) { + if ((*i)->meterinfo->min_unbound) + (*i)->meterinfo->min = val; + else + val = (*i)->meterinfo->min; + } + + if (val > (*i)->meterinfo->max) { + if ((*i)->meterinfo->max_unbound) + (*i)->meterinfo->max = val; + else + val = (*i)->meterinfo->max; + } + + if ((*i)->meterinfo->max > (*i)->meterinfo->min ) { + float lval = (val - (*i)->meterinfo->min) / ((*i)->meterinfo->max - (*i)->meterinfo->min) ; + (*i)->meterinfo->meter->set (lval ); + } + } + } +} + +vector +LadspaPluginUI::setup_scale_values(guint32 port_index, ControlUI* cui) +{ + vector enums; + boost::shared_ptr lp = boost::dynamic_pointer_cast (plugin); + + cui->combo_map = new std::map; + lrdf_defaults* defaults = lrdf_get_scale_values(lp->unique_id(), port_index); + if (defaults) { + for (uint32_t i = 0; i < defaults->count; ++i) { + enums.push_back(defaults->items[i].label); + pair newpair; + newpair.first = defaults->items[i].label; + newpair.second = defaults->items[i].value; + cui->combo_map->insert(newpair); + } + + lrdf_free_setting_values(defaults); + } + + return enums; +} diff --git a/gtk2_ardour/new_session_dialog.cc b/gtk2_ardour/new_session_dialog.cc index 47a2b2b6d3..993db62d59 100644 --- a/gtk2_ardour/new_session_dialog.cc +++ b/gtk2_ardour/new_session_dialog.cc @@ -141,15 +141,17 @@ NewSessionDialog::NewSessionDialog() advanced_table->attach(*m_control_bus_channel_count, 1, 2, 2, 3, Gtk::AttachOptions(), Gtk::AttachOptions(), 0, 0); advanced_table->attach(*m_master_bus_channel_count, 1, 2, 1, 2, Gtk::AttachOptions(), Gtk::AttachOptions(), 0, 0); advanced_table->attach(*m_create_master_bus, 0, 1, 1, 2, Gtk::FILL, Gtk::AttachOptions(), 0, 0); + m_connect_inputs->set_flags(Gtk::CAN_FOCUS); m_connect_inputs->set_relief(Gtk::RELIEF_NORMAL); m_connect_inputs->set_mode(true); - m_connect_inputs->set_active(false); + m_connect_inputs->set_active(true); m_connect_inputs->set_border_width(0); + m_limit_input_ports->set_flags(Gtk::CAN_FOCUS); m_limit_input_ports->set_relief(Gtk::RELIEF_NORMAL); m_limit_input_ports->set_mode(true); - m_limit_input_ports->set_sensitive(false); + m_limit_input_ports->set_sensitive(true); m_limit_input_ports->set_border_width(0); m_input_limit_count->set_flags(Gtk::CAN_FOCUS); m_input_limit_count->set_update_policy(Gtk::UPDATE_ALWAYS); @@ -157,6 +159,7 @@ NewSessionDialog::NewSessionDialog() m_input_limit_count->set_digits(0); m_input_limit_count->set_wrap(false); m_input_limit_count->set_sensitive(false); + input_port_limit_hbox->pack_start(*m_limit_input_ports, Gtk::PACK_SHRINK, 6); input_port_limit_hbox->pack_start(*m_input_limit_count, Gtk::PACK_EXPAND_PADDING, 0); input_port_vbox->pack_start(*m_connect_inputs, Gtk::PACK_SHRINK, 0); @@ -177,12 +180,12 @@ NewSessionDialog::NewSessionDialog() m_connect_outputs->set_flags(Gtk::CAN_FOCUS); m_connect_outputs->set_relief(Gtk::RELIEF_NORMAL); m_connect_outputs->set_mode(true); - m_connect_outputs->set_active(false); + m_connect_outputs->set_active(true); m_connect_outputs->set_border_width(0); m_limit_output_ports->set_flags(Gtk::CAN_FOCUS); m_limit_output_ports->set_relief(Gtk::RELIEF_NORMAL); m_limit_output_ports->set_mode(true); - m_limit_output_ports->set_sensitive(false); + m_limit_output_ports->set_sensitive(true); m_limit_output_ports->set_border_width(0); m_output_limit_count->set_flags(Gtk::CAN_FOCUS); m_output_limit_count->set_update_policy(Gtk::UPDATE_ALWAYS); @@ -597,12 +600,24 @@ void NewSessionDialog::connect_inputs_clicked () { m_limit_input_ports->set_sensitive(m_connect_inputs->get_active()); + + if (m_connect_inputs->get_active() && m_limit_input_ports->get_active()) { + m_input_limit_count->set_sensitive(true); + } else { + m_input_limit_count->set_sensitive(false); + } } void NewSessionDialog::connect_outputs_clicked () { m_limit_output_ports->set_sensitive(m_connect_outputs->get_active()); + + if (m_connect_outputs->get_active() && m_limit_output_ports->get_active()) { + m_output_limit_count->set_sensitive(true); + } else { + m_output_limit_count->set_sensitive(false); + } } void diff --git a/gtk2_ardour/pan_automation_time_axis.cc b/gtk2_ardour/pan_automation_time_axis.cc index 3169f65059..ec884151b5 100644 --- a/gtk2_ardour/pan_automation_time_axis.cc +++ b/gtk2_ardour/pan_automation_time_axis.cc @@ -108,7 +108,7 @@ void PanAutomationTimeAxisView::add_line (AutomationLine& line) { char buf[32]; - snprintf(buf,32,"Line %u",lines.size()+1); + snprintf(buf,32,"Line %zu",lines.size()+1); multiline_selector.append_text(buf); if (lines.empty()) { diff --git a/gtk2_ardour/plugin_selector.cc b/gtk2_ardour/plugin_selector.cc index e0a62b177f..2ebaaae100 100644 --- a/gtk2_ardour/plugin_selector.cc +++ b/gtk2_ardour/plugin_selector.cc @@ -49,7 +49,7 @@ PluginSelector::PluginSelector (PluginManager *mgr) manager = mgr; session = 0; - current_selection = PluginInfo::LADSPA; + current_selection = ARDOUR::LADSPA; lmodel = Gtk::ListStore::create(lcols); ladspa_display.set_model (lmodel); @@ -141,6 +141,7 @@ PluginSelector::PluginSelector (PluginManager *mgr) set_response_sensitive (RESPONSE_APPLY, false); get_vbox()->pack_start (*table); + // Notebook tab order must be the same in here as in set_correct_focus() using namespace Gtk::Notebook_Helpers; notebook.pages().push_back (TabElem (lscroller, _("LADSPA"))); @@ -161,6 +162,7 @@ PluginSelector::PluginSelector (PluginManager *mgr) ladspa_display.signal_button_press_event().connect_notify (mem_fun(*this, &PluginSelector::row_clicked)); ladspa_display.get_selection()->signal_changed().connect (mem_fun(*this, &PluginSelector::ladspa_display_selection_changed)); + ladspa_display.grab_focus(); #ifdef VST_SUPPORT if (Config->get_use_vst()) { @@ -188,6 +190,43 @@ PluginSelector::PluginSelector (PluginManager *mgr) #ifdef HAVE_COREAUDIO au_refiller (); #endif + + signal_show().connect (mem_fun (*this, &PluginSelector::set_correct_focus)); +} + +/** + * Makes sure keyboard focus is always in the plugin list + * of the selected notebook tab. + **/ +void +PluginSelector::set_correct_focus() +{ + int cp = notebook.get_current_page(); + + if (cp == 0) { + ladspa_display.grab_focus(); + return; + } + +#ifdef VST_SUPPORT + if (Config->get_use_vst()) { + cp--; + + if (cp == 0) { + vst_display.grab_focus(); + return; + } + } +#endif + +#ifdef HAVE_COREAUDIO + cp--; + + if (cp == 0) { + au_display.grab_focus(); + return; + } +#endif; } void @@ -286,7 +325,7 @@ PluginSelector::vst_display_selection_changed() btn_add->set_sensitive (false); } - current_selection = PluginInfo::VST; + current_selection = ARDOUR::VST; } #endif //VST_SUPPORT @@ -332,7 +371,7 @@ PluginSelector::au_display_selection_changed() btn_add->set_sensitive (false); } - current_selection = PluginInfo::AudioUnit; + current_selection = ARDOUR::AudioUnit; } #endif //HAVE_COREAUDIO @@ -361,19 +400,19 @@ PluginSelector::btn_add_clicked() Gtk::TreeModel::Row row; switch (current_selection) { - case PluginInfo::LADSPA: + case ARDOUR::LADSPA: row = *(ladspa_display.get_selection()->get_selected()); name = row[lcols.name]; pi = row[lcols.plugin]; break; - case PluginInfo::VST: + case ARDOUR::VST: #ifdef VST_SUPPORT row = *(vst_display.get_selection()->get_selected()); name = row[vcols.name]; pi = row[vcols.plugin]; #endif break; - case PluginInfo::AudioUnit: + case ARDOUR::AudioUnit: #ifdef HAVE_COREAUDIO row = *(au_display.get_selection()->get_selected()); name = row[aucols.name]; @@ -426,7 +465,7 @@ PluginSelector::ladspa_display_selection_changed() btn_add->set_sensitive (false); } - current_selection = PluginInfo::LADSPA; + current_selection = ARDOUR::LADSPA; } void diff --git a/gtk2_ardour/plugin_selector.h b/gtk2_ardour/plugin_selector.h index 583506972a..d71203131c 100644 --- a/gtk2_ardour/plugin_selector.h +++ b/gtk2_ardour/plugin_selector.h @@ -50,7 +50,7 @@ class PluginSelector : public ArdourDialog Gtk::ScrolledWindow auscroller; // AudioUnit Gtk::ScrolledWindow ascroller; // Added plugins - ARDOUR::PluginInfo::Type current_selection; + ARDOUR::PluginType current_selection; // page 1 struct LadspaColumns : public Gtk::TreeModel::ColumnRecord { @@ -147,6 +147,8 @@ class PluginSelector : public ArdourDialog void btn_apply_clicked(); void use_plugin (ARDOUR::PluginInfoPtr); void cleanup (); + + void set_correct_focus(); }; #endif // __ardour_plugin_selector_h__ diff --git a/gtk2_ardour/plugin_ui.cc b/gtk2_ardour/plugin_ui.cc index edc94864f2..4619d50359 100644 --- a/gtk2_ardour/plugin_ui.cc +++ b/gtk2_ardour/plugin_ui.cc @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -36,7 +37,6 @@ #include -#include #include #include #include @@ -51,6 +51,7 @@ #include "plugin_ui.h" #include "utils.h" #include "gui_thread.h" +#include "public_editor.h" #include "i18n.h" @@ -61,7 +62,7 @@ using namespace Gtkmm2ext; using namespace Gtk; using namespace sigc; -PluginUIWindow::PluginUIWindow (AudioEngine &engine, boost::shared_ptr insert, bool scrollable) +PluginUIWindow::PluginUIWindow (boost::shared_ptr insert, bool scrollable) : ArdourDialog ("plugin ui") { if (insert->plugin()->has_editor()) { @@ -90,7 +91,7 @@ PluginUIWindow::PluginUIWindow (AudioEngine &engine, boost::shared_ptradd (*pu); @@ -111,626 +112,22 @@ PluginUIWindow::PluginUIWindow (AudioEngine &engine, boost::shared_ptr 600) h = 600; set_default_size (450, h); } + } PluginUIWindow::~PluginUIWindow () { } - -LadspaPluginUI::LadspaPluginUI (AudioEngine &engine, boost::shared_ptr pi, bool scrollable) - : PlugUIBase (pi), - engine(engine), - button_table (initial_button_rows, initial_button_cols), - output_table (initial_output_rows, initial_output_cols), - hAdjustment(0.0, 0.0, 0.0), - vAdjustment(0.0, 0.0, 0.0), - scroller_view(hAdjustment, vAdjustment), - automation_menu (0), - is_scrollable(scrollable) +bool +PluginUIWindow::on_key_press_event (GdkEventKey* event) { - set_name ("PluginEditor"); - set_border_width (10); - set_homogeneous (false); - - settings_box.set_homogeneous (false); - - HBox* constraint_hbox = manage (new HBox); - HBox* smaller_hbox = manage (new HBox); - Label* combo_label = manage (new Label (_("Presets"))); - combo_label->set_use_markup (true); - - smaller_hbox->pack_start (*combo_label, false, false, 10); - smaller_hbox->pack_start (combo, false, false); - smaller_hbox->pack_start (save_button, false, false); - - constraint_hbox->set_spacing (5); - constraint_hbox->pack_start (*smaller_hbox, true, false); - constraint_hbox->pack_end (bypass_button, false, false); - - settings_box.pack_end (*constraint_hbox, false, false); - - pack_start (settings_box, false, false); - - if ( is_scrollable ) { - scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); - scroller.set_name ("PluginEditor"); - scroller_view.set_name("PluginEditor"); - scroller_view.add (hpacker); - scroller.add (scroller_view); - - pack_start (scroller, true, true); - - } - else { - pack_start (hpacker, false, false); - } - - insert->active_changed.connect (mem_fun(*this, &LadspaPluginUI::redirect_active_changed)); - bypass_button.set_active (!insert->active()); - - build (engine); + return PublicEditor::instance().on_key_press_event(event); } -LadspaPluginUI::~LadspaPluginUI () +bool +PluginUIWindow::on_key_release_event (GdkEventKey* event) { - if (output_controls.size() > 0) { - screen_update_connection.disconnect(); - } -} - -void -LadspaPluginUI::build (AudioEngine &engine) - -{ - guint32 i = 0; - guint32 x = 0; - Frame* frame; - Frame* bt_frame; - VBox* box; - int output_row, output_col; - int button_row, button_col; - int output_rows, output_cols; - int button_rows, button_cols; - guint32 n_ins=0, n_outs = 0; - - prefheight = 30; - hpacker.set_spacing (10); - - output_rows = initial_output_rows; - output_cols = initial_output_cols; - button_rows = initial_button_rows; - button_cols = initial_button_cols; - output_row = 0; - button_row = 0; - output_col = 0; - button_col = 0; - - button_table.set_homogeneous (false); - button_table.set_row_spacings (2); - button_table.set_col_spacings (2); - output_table.set_homogeneous (true); - output_table.set_row_spacings (2); - output_table.set_col_spacings (2); - button_table.set_border_width (5); - output_table.set_border_width (5); - - hpacker.set_border_width (10); - - bt_frame = manage (new Frame); - bt_frame->set_name ("BaseFrame"); - bt_frame->add (button_table); - hpacker.pack_start(*bt_frame, true, true); - - box = manage (new VBox); - box->set_border_width (5); - box->set_spacing (1); - - frame = manage (new Frame); - frame->set_name ("BaseFrame"); - frame->set_label (_("Controls")); - frame->add (*box); - hpacker.pack_start(*frame, true, true); - - /* find all ports. build control elements for all appropriate control ports */ - - for (i = 0; i < plugin->parameter_count(); ++i) { - - if (plugin->parameter_is_control (i)) { - - /* Don't show latency control ports */ - - if (plugin->describe_parameter (i) == X_("latency")) { - continue; - } - - ControlUI* cui; - - /* if we are scrollable, just use one long column */ - - if (!is_scrollable) { - if (x++ > 7){ - frame = manage (new Frame); - frame->set_name ("BaseFrame"); - box = manage (new VBox); - - box->set_border_width (5); - box->set_spacing (1); - - frame->add (*box); - hpacker.pack_start(*frame,true,true); - - x = 0; - } - } - - if ((cui = build_control_ui (engine, i, plugin->get_nth_control (i))) == 0) { - error << string_compose(_("Plugin Editor: could not build control element for port %1"), i) << endmsg; - continue; - } - - if (cui->control || cui->clickbox || cui->combo) { - - box->pack_start (*cui, false, false); - - } else if (cui->button) { - - if (button_row == button_rows) { - button_row = 0; - if (++button_col == button_cols) { - button_cols += 2; - button_table.resize (button_rows, button_cols); - } - } - - button_table.attach (*cui, button_col, button_col + 1, button_row, button_row+1, - FILL|EXPAND, FILL); - button_row++; - - } else if (cui->display) { - - output_table.attach (*cui, output_col, output_col + 1, output_row, output_row+1, - FILL|EXPAND, FILL); - - // TODO: The meters should be divided into multiple rows - - if (++output_col == output_cols) { - output_cols ++; - output_table.resize (output_rows, output_cols); - } - - /* old code, which divides meters into - * columns first, rows later. New code divides into one row - - if (output_row == output_rows) { - output_row = 0; - if (++output_col == output_cols) { - output_cols += 2; - output_table.resize (output_rows, output_cols); - } - } - - output_table.attach (*cui, output_col, output_col + 1, output_row, output_row+1, - FILL|EXPAND, FILL); - - output_row++; - */ - } - - /* HACK: ideally the preferred height would be queried from - the complete hpacker, but I can't seem to get that - information in time, so this is an estimation - */ - - prefheight += 30; - - } - } - - n_ins = plugin->get_info()->n_inputs; - n_outs = plugin->get_info()->n_outputs; - - if (box->children().empty()) { - hpacker.remove (*frame); - } - - if (button_table.children().empty()) { - hpacker.remove (*bt_frame); - } - - if (!output_table.children().empty()) { - frame = manage (new Frame); - frame->set_name ("BaseFrame"); - frame->add (output_table); - hpacker.pack_end (*frame, true, true); - } - - output_update (); - - output_table.show_all (); - button_table.show_all (); -} - -LadspaPluginUI::ControlUI::ControlUI () - : automate_button (X_("")) // force creation of a label -{ - automate_button.set_name ("PluginAutomateButton"); - ARDOUR_UI::instance()->tooltips().set_tip (automate_button, - _("Automation control")); - - /* don't fix the height, it messes up the bar controllers */ - - set_size_request_to_display_given_text (automate_button, X_("lngnuf"), 2, 2); - - ignore_change = 0; - display = 0; - button = 0; - control = 0; - clickbox = 0; - adjustment = 0; - meterinfo = 0; -} - -LadspaPluginUI::ControlUI::~ControlUI() -{ - if (adjustment) { - delete adjustment; - } - - if (meterinfo) { - delete meterinfo->meter; - delete meterinfo; - } -} - -void -LadspaPluginUI::automation_state_changed (ControlUI* cui) -{ - /* update button label */ - - switch (insert->get_port_automation_state (cui->port_index) & (Off|Play|Touch|Write)) { - case Off: - cui->automate_button.set_label (_("Off")); - break; - case Play: - cui->automate_button.set_label (_("Play")); - break; - case Write: - cui->automate_button.set_label (_("Write")); - break; - case Touch: - cui->automate_button.set_label (_("Touch")); - break; - default: - cui->automate_button.set_label (_("???")); - break; - } -} - - -static void integer_printer (char buf[32], Adjustment &adj, void *arg) -{ - snprintf (buf, 32, "%.0f", adj.get_value()); -} - -void -LadspaPluginUI::print_parameter (char *buf, uint32_t len, uint32_t param) -{ - plugin->print_parameter (param, buf, len); -} - -LadspaPluginUI::ControlUI* -LadspaPluginUI::build_control_ui (AudioEngine &engine, guint32 port_index, PBD::Controllable* mcontrol) - -{ - ControlUI* control_ui; - Plugin::ParameterDescriptor desc; - - plugin->get_parameter_descriptor (port_index, desc); - - control_ui = manage (new ControlUI ()); - control_ui->adjustment = 0; - control_ui->combo = 0; - control_ui->combo_map = 0; - control_ui->port_index = port_index; - control_ui->update_pending = false; - control_ui->label.set_text (desc.label); - control_ui->label.set_alignment (0.0, 0.5); - control_ui->label.set_name ("PluginParameterLabel"); - - control_ui->set_spacing (5); - - if (plugin->parameter_is_input (port_index)) { - - boost::shared_ptr lp; - - if ((lp = boost::dynamic_pointer_cast(plugin)) != 0) { - - lrdf_defaults* defaults = lrdf_get_scale_values(lp->unique_id(), port_index); - - if (defaults && defaults->count > 0) { - - control_ui->combo = new Gtk::ComboBoxText; - //control_ui->combo->set_value_in_list(true, false); - set_popdown_strings (*control_ui->combo, setup_scale_values(port_index, control_ui)); - control_ui->combo->signal_changed().connect (bind (mem_fun(*this, &LadspaPluginUI::control_combo_changed), control_ui)); - plugin->ParameterChanged.connect (bind (mem_fun (*this, &LadspaPluginUI::parameter_changed), control_ui)); - control_ui->pack_start(control_ui->label, true, true); - control_ui->pack_start(*control_ui->combo, false, true); - - update_control_display(control_ui); - - lrdf_free_setting_values(defaults); - return control_ui; - } - } - - if (desc.toggled) { - - /* Build a button */ - - control_ui->button = manage (new ToggleButton ()); - control_ui->button->set_name ("PluginEditorButton"); - control_ui->button->set_size_request (20, 20); - - control_ui->pack_start (control_ui->label, true, true); - control_ui->pack_start (*control_ui->button, false, true); - control_ui->pack_start (control_ui->automate_button, false, false); - - control_ui->button->signal_clicked().connect (bind (mem_fun(*this, &LadspaPluginUI::control_port_toggled), control_ui)); - - if(plugin->get_parameter (port_index) == 1){ - control_ui->button->set_active(true); - } - - return control_ui; - } - - control_ui->adjustment = new Adjustment (0, 0, 0, 0, 0); - - /* XXX this code is not right yet, because it doesn't handle - the absence of bounds in any sensible fashion. - */ - - control_ui->adjustment->set_lower (desc.lower); - control_ui->adjustment->set_upper (desc.upper); - - control_ui->logarithmic = desc.logarithmic; - if (control_ui->logarithmic) { - if (control_ui->adjustment->get_lower() == 0.0) { - control_ui->adjustment->set_lower (control_ui->adjustment->get_upper()/10000); - } - control_ui->adjustment->set_upper (log(control_ui->adjustment->get_upper())); - control_ui->adjustment->set_lower (log(control_ui->adjustment->get_lower())); - } - - float delta = desc.upper - desc.lower; - - control_ui->adjustment->set_page_size (delta/100.0); - control_ui->adjustment->set_step_increment (desc.step); - control_ui->adjustment->set_page_increment (desc.largestep); - - if (desc.integer_step) { - control_ui->clickbox = new ClickBox (control_ui->adjustment, "PluginUIClickBox"); - Gtkmm2ext::set_size_request_to_display_given_text (*control_ui->clickbox, "g9999999", 2, 2); - control_ui->clickbox->set_print_func (integer_printer, 0); - } else { - sigc::slot pslot = sigc::bind (mem_fun(*this, &LadspaPluginUI::print_parameter), (uint32_t) port_index); - - control_ui->control = new BarController (*control_ui->adjustment, *mcontrol, pslot); - // should really match the height of the text in the automation button+label - control_ui->control->set_size_request (200, 22); - control_ui->control->set_name (X_("PluginSlider")); - control_ui->control->set_style (BarController::LeftToRight); - control_ui->control->set_use_parent (true); - - control_ui->control->StartGesture.connect (bind (mem_fun(*this, &LadspaPluginUI::start_touch), control_ui)); - control_ui->control->StopGesture.connect (bind (mem_fun(*this, &LadspaPluginUI::stop_touch), control_ui)); - - } - - if (control_ui->logarithmic) { - control_ui->adjustment->set_value(log(plugin->get_parameter(port_index))); - } else{ - control_ui->adjustment->set_value(plugin->get_parameter(port_index)); - } - - /* XXX memory leak: SliderController not destroyed by ControlUI - destructor, and manage() reports object hierarchy - ambiguity. - */ - - control_ui->pack_start (control_ui->label, true, true); - if (desc.integer_step) { - control_ui->pack_start (*control_ui->clickbox, false, false); - } else { - control_ui->pack_start (*control_ui->control, false, false); - } - - control_ui->pack_start (control_ui->automate_button, false, false); - control_ui->adjustment->signal_value_changed().connect (bind (mem_fun(*this, &LadspaPluginUI::control_adjustment_changed), control_ui)); - control_ui->automate_button.signal_clicked().connect (bind (mem_fun(*this, &LadspaPluginUI::astate_clicked), control_ui, (uint32_t) port_index)); - - automation_state_changed (control_ui); - - plugin->ParameterChanged.connect (bind (mem_fun(*this, &LadspaPluginUI::parameter_changed), control_ui)); - insert->automation_list (port_index).automation_state_changed.connect - (bind (mem_fun(*this, &LadspaPluginUI::automation_state_changed), control_ui)); - - } else if (plugin->parameter_is_output (port_index)) { - - control_ui->display = manage (new EventBox); - control_ui->display->set_name ("ParameterValueDisplay"); - - control_ui->display_label = manage (new Label); - - control_ui->display_label->set_name ("ParameterValueDisplay"); - - control_ui->display->add (*control_ui->display_label); - Gtkmm2ext::set_size_request_to_display_given_text (*control_ui->display, "-99,99", 2, 2); - - control_ui->display->show_all (); - - /* set up a meter */ - /* TODO: only make a meter if the port is Hinted for it */ - - MeterInfo * info = new MeterInfo(port_index); - control_ui->meterinfo = info; - - info->meter = new FastMeter (5, 100, FastMeter::Vertical); - - info->min_unbound = desc.min_unbound; - info->max_unbound = desc.max_unbound; - - info->min = desc.lower; - info->max = desc.upper; - - control_ui->vbox = manage (new VBox); - control_ui->hbox = manage (new HBox); - - control_ui->label.set_angle(90); - control_ui->hbox->pack_start (control_ui->label, false, false); - control_ui->hbox->pack_start (*info->meter, false, false); - - control_ui->vbox->pack_start (*control_ui->hbox, false, false); - - control_ui->vbox->pack_start (*control_ui->display, false, false); - - control_ui->pack_start (*control_ui->vbox); - - control_ui->meterinfo->meter->show_all(); - control_ui->meterinfo->packed = true; - - output_controls.push_back (control_ui); - } - - plugin->ParameterChanged.connect (bind (mem_fun(*this, &LadspaPluginUI::parameter_changed), control_ui)); - return control_ui; -} - -void -LadspaPluginUI::start_touch (LadspaPluginUI::ControlUI* cui) -{ - insert->automation_list (cui->port_index).start_touch (); -} - -void -LadspaPluginUI::stop_touch (LadspaPluginUI::ControlUI* cui) -{ - insert->automation_list (cui->port_index).stop_touch (); -} - -void -LadspaPluginUI::astate_clicked (ControlUI* cui, uint32_t port) -{ - using namespace Menu_Helpers; - - if (automation_menu == 0) { - automation_menu = manage (new Menu); - automation_menu->set_name ("ArdourContextMenu"); - } - - MenuList& items (automation_menu->items()); - - items.clear (); - items.push_back (MenuElem (_("Off"), - bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Off, cui))); - items.push_back (MenuElem (_("Play"), - bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Play, cui))); - items.push_back (MenuElem (_("Write"), - bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Write, cui))); - items.push_back (MenuElem (_("Touch"), - bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Touch, cui))); - - automation_menu->popup (1, 0); -} - -void -LadspaPluginUI::set_automation_state (AutoState state, ControlUI* cui) -{ - insert->set_port_automation_state (cui->port_index, state); -} - -void -LadspaPluginUI::control_adjustment_changed (ControlUI* cui) -{ - if (cui->ignore_change) { - return; - } - - double value = cui->adjustment->get_value(); - - if (cui->logarithmic) { - value = exp(value); - } - - insert->set_parameter (cui->port_index, (float) value); -} - -void -LadspaPluginUI::parameter_changed (uint32_t abs_port_id, float val, ControlUI* cui) -{ - if (cui->port_index == abs_port_id) { - if (!cui->update_pending) { - cui->update_pending = true; - Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &LadspaPluginUI::update_control_display), cui)); - } - } -} - -void -LadspaPluginUI::update_control_display (ControlUI* cui) -{ - /* XXX how do we handle logarithmic stuff here ? */ - - cui->update_pending = false; - - float val = plugin->get_parameter (cui->port_index); - - cui->ignore_change++; - if (cui->combo) { - std::map::iterator it; - for (it = cui->combo_map->begin(); it != cui->combo_map->end(); ++it) { - if (it->second == val) { - cui->combo->set_active_text(it->first); - break; - } - } - } else if (cui->adjustment == 0) { - - if (val > 0.5) { - cui->button->set_active (true); - } else { - cui->button->set_active (false); - } - - } else { - if (cui->logarithmic) { - val = log(val); - } - if (val != cui->adjustment->get_value()) { - cui->adjustment->set_value (val); - } - } - cui->ignore_change--; -} - -void -LadspaPluginUI::control_port_toggled (ControlUI* cui) -{ - if (!cui->ignore_change) { - insert->set_parameter (cui->port_index, cui->button->get_active()); - } -} - -void -LadspaPluginUI::control_combo_changed (ControlUI* cui) -{ - if (!cui->ignore_change) { - string value = cui->combo->get_active_text(); - std::map mapping = *cui->combo_map; - insert->set_parameter (cui->port_index, mapping[value]); - } - + return PublicEditor::instance().on_key_release_event(event); } void @@ -742,91 +139,6 @@ PluginUIWindow::plugin_going_away (ARDOUR::Redirect* ignored) delete_when_idle (this); } -void -LadspaPluginUI::redirect_active_changed (Redirect* r, void* src) -{ - ENSURE_GUI_THREAD(bind (mem_fun(*this, &LadspaPluginUI::redirect_active_changed), r, src)); - - bypass_button.set_active (!r->active()); -} - -bool -LadspaPluginUI::start_updating (GdkEventAny* ignored) -{ - if (output_controls.size() > 0 ) { - screen_update_connection.disconnect(); - screen_update_connection = ARDOUR_UI::instance()->RapidScreenUpdate.connect - (mem_fun(*this, &LadspaPluginUI::output_update)); - } - return false; -} - -bool -LadspaPluginUI::stop_updating (GdkEventAny* ignored) -{ - if (output_controls.size() > 0 ) { - screen_update_connection.disconnect(); - } - return false; -} - -void -LadspaPluginUI::output_update () -{ - for (vector::iterator i = output_controls.begin(); i != output_controls.end(); ++i) { - float val = plugin->get_parameter ((*i)->port_index); - char buf[32]; - snprintf (buf, sizeof(buf), "%.2f", val); - (*i)->display_label->set_text (buf); - - /* autoscaling for the meter */ - if ((*i)->meterinfo && (*i)->meterinfo->packed) { - - if (val < (*i)->meterinfo->min) { - if ((*i)->meterinfo->min_unbound) - (*i)->meterinfo->min = val; - else - val = (*i)->meterinfo->min; - } - - if (val > (*i)->meterinfo->max) { - if ((*i)->meterinfo->max_unbound) - (*i)->meterinfo->max = val; - else - val = (*i)->meterinfo->max; - } - - if ((*i)->meterinfo->max > (*i)->meterinfo->min ) { - float lval = (val - (*i)->meterinfo->min) / ((*i)->meterinfo->max - (*i)->meterinfo->min) ; - (*i)->meterinfo->meter->set (lval ); - } - } - } -} - -vector -LadspaPluginUI::setup_scale_values(guint32 port_index, ControlUI* cui) -{ - vector enums; - boost::shared_ptr lp = boost::dynamic_pointer_cast (plugin); - - cui->combo_map = new std::map; - lrdf_defaults* defaults = lrdf_get_scale_values(lp->unique_id(), port_index); - if (defaults) { - for (uint32_t i = 0; i < defaults->count; ++i) { - enums.push_back(defaults->items[i].label); - pair newpair; - newpair.first = defaults->items[i].label; - newpair.second = defaults->items[i].value; - cui->combo_map->insert(newpair); - } - - lrdf_free_setting_values(defaults); - } - - return enums; -} - PlugUIBase::PlugUIBase (boost::shared_ptr pi) : insert (pi), plugin (insert->plugin()), @@ -893,4 +205,3 @@ PlugUIBase::bypass_toggled () insert->set_active (!x, this); } } - diff --git a/gtk2_ardour/plugin_ui.h b/gtk2_ardour/plugin_ui.h index dc1e61887b..5c940843f7 100644 --- a/gtk2_ardour/plugin_ui.h +++ b/gtk2_ardour/plugin_ui.h @@ -45,7 +45,6 @@ #include namespace ARDOUR { - class AudioEngine; class PluginInsert; class Plugin; class VSTPlugin; @@ -90,7 +89,7 @@ class PlugUIBase : public virtual sigc::trackable class LadspaPluginUI : public PlugUIBase, public Gtk::VBox { public: - LadspaPluginUI (ARDOUR::AudioEngine &, boost::shared_ptr plug, bool scrollable=false); + LadspaPluginUI (boost::shared_ptr plug, bool scrollable=false); ~LadspaPluginUI (); gint get_preferred_height () { return prefheight; } @@ -99,7 +98,6 @@ class LadspaPluginUI : public PlugUIBase, public Gtk::VBox bool stop_updating(GdkEventAny*); private: - ARDOUR::AudioEngine &engine; Gtk::HBox settings_box; Gtk::HBox hpacker; @@ -174,8 +172,8 @@ class LadspaPluginUI : public PlugUIBase, public Gtk::VBox sigc::connection screen_update_connection; void output_update(); - void build (ARDOUR::AudioEngine &); - ControlUI* build_control_ui (ARDOUR::AudioEngine &, guint32 port_index, PBD::Controllable *); + void build (); + ControlUI* build_control_ui (guint32 port_index, PBD::Controllable *); std::vector setup_scale_values(guint32 port_index, ControlUI* cui); void control_adjustment_changed (ControlUI* cui); void parameter_changed (uint32_t, float, ControlUI* cui); @@ -197,19 +195,21 @@ class LadspaPluginUI : public PlugUIBase, public Gtk::VBox class PluginUIWindow : public ArdourDialog { public: - PluginUIWindow (ARDOUR::AudioEngine &, boost::shared_ptr insert, bool scrollable=false); + PluginUIWindow (boost::shared_ptr insert, bool scrollable=false); ~PluginUIWindow (); PlugUIBase& pluginui() { return *_pluginui; } void resize_preferred(); + + virtual bool on_key_press_event (GdkEventKey*); + virtual bool on_key_release_event (GdkEventKey*); private: PlugUIBase* _pluginui; void plugin_going_away (ARDOUR::Redirect*); }; - #ifdef VST_SUPPORT class VSTPluginUI : public PlugUIBase, public Gtk::VBox { @@ -235,16 +235,12 @@ class VSTPluginUI : public PlugUIBase, public Gtk::VBox #endif // VST_SUPPORT #ifdef HAVE_COREAUDIO -class AUPluginUI : public PlugUIBase +class AUPluginUI { public: - AUPluginUI (boost::shared_ptr, boost::shared_ptr); + AUPluginUI (boost::shared_ptr); ~AUPluginUI (); - gint get_preferred_height (); - bool start_updating(GdkEventAny*) {return false;} - bool stop_updating(GdkEventAny*) {return false;} - private: boost::shared_ptr au; }; diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index f70e4c20bd..f85210327c 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -31,6 +31,7 @@ namespace Gtk { class Editor; class TimeAxisViewItem; class TimeAxisView; +class PluginUIWindow; class PluginSelector; class PlaylistSelector; class XMLNode; @@ -171,6 +172,8 @@ class PublicEditor : public Gtk::Window, public Stateful { virtual bool canvas_markerview_end_handle_event(GdkEvent* event, ArdourCanvas::Item*,MarkerView*) = 0; static PublicEditor* _instance; + + friend class PluginUIWindow; }; #endif // __gtk_ardour_public_editor_h__ diff --git a/gtk2_ardour/redirect_box.cc b/gtk2_ardour/redirect_box.cc index 74198265d9..f93dfb9433 100644 --- a/gtk2_ardour/redirect_box.cc +++ b/gtk2_ardour/redirect_box.cc @@ -957,44 +957,61 @@ RedirectBox::edit_redirect (boost::shared_ptr redirect) if ((plugin_insert = boost::dynamic_pointer_cast (insert)) != 0) { - PluginUIWindow *plugin_ui; - - if (plugin_insert->get_gui() == 0) { - - string title; - string maker = plugin_insert->plugin()->maker(); - string::size_type email_pos; - - if ((email_pos = maker.find_first_of ('<')) != string::npos) { - maker = maker.substr (0, email_pos - 1); - } - - if (maker.length() > 32) { - maker = maker.substr (0, 32); - maker += " ..."; - } + ARDOUR::PluginType type = plugin_insert->type(); - title = string_compose(_("ardour: %1: %2 (by %3)"), _route->name(), plugin_insert->name(), maker); + if (type == ARDOUR::LADSPA || type == ARDOUR::VST) { + PluginUIWindow *plugin_ui; + + if (plugin_insert->get_gui() == 0) { + + string title; + string maker = plugin_insert->plugin()->maker(); + string::size_type email_pos; + + if ((email_pos = maker.find_first_of ('<')) != string::npos) { + maker = maker.substr (0, email_pos - 1); + } + + if (maker.length() > 32) { + maker = maker.substr (0, 32); + maker += " ..."; + } + + title = string_compose(_("ardour: %1: %2 (by %3)"), _route->name(), plugin_insert->name(), maker); + + plugin_ui = new PluginUIWindow (plugin_insert); + if (_owner_is_mixer) { + ARDOUR_UI::instance()->the_mixer()->ensure_float (*plugin_ui); + } else { + ARDOUR_UI::instance()->the_editor().ensure_float (*plugin_ui); + } + plugin_ui->set_title (title); + plugin_insert->set_gui (plugin_ui); - plugin_ui = new PluginUIWindow (_session.engine(), plugin_insert); - if (_owner_is_mixer) { - ARDOUR_UI::instance()->the_mixer()->ensure_float (*plugin_ui); } else { - ARDOUR_UI::instance()->the_editor().ensure_float (*plugin_ui); + plugin_ui = reinterpret_cast (plugin_insert->get_gui()); + } + + if (plugin_ui->is_visible()) { + plugin_ui->get_window()->raise (); + } else { + plugin_ui->show_all (); + } +#ifdef HAVE_COREAUDIO + } else if (type == ARDOUR::AudioUnit) { + AUPluginUI* plugin_ui; + if (plugin_insert->get_gui() == 0) { + plugin_ui = new AUPluginUI (plugin_insert); + } else { + plugin_ui = reinterpret_cast (plugin_insert->get_gui()); } - plugin_ui->set_title (title); - plugin_insert->set_gui (plugin_ui); + // raise window, somehow +#endif } else { - plugin_ui = reinterpret_cast (plugin_insert->get_gui()); + warning << "Unsupported plugin sent to RedirectBox::edit_redirect()" << endmsg; + return; } - - if (plugin_ui->is_visible()) { - plugin_ui->get_window()->raise (); - } else { - plugin_ui->show_all (); - } - } else if ((port_insert = boost::dynamic_pointer_cast (insert)) != 0) { if (!_session.engine().connected()) { diff --git a/gtk2_ardour/route_params_ui.cc b/gtk2_ardour/route_params_ui.cc index 86ac1e035e..8d8efad8a2 100644 --- a/gtk2_ardour/route_params_ui.cc +++ b/gtk2_ardour/route_params_ui.cc @@ -556,7 +556,7 @@ RouteParams_UI::redirect_selected (boost::shared_ptr redirect, if ((plugin_insert = boost::dynamic_pointer_cast (insert)) != 0) { - LadspaPluginUI *plugin_ui = new LadspaPluginUI (session->engine(), plugin_insert, true); + LadspaPluginUI *plugin_ui = new LadspaPluginUI (plugin_insert, true); if (place == PreFader) { cleanup_pre_view(); diff --git a/libs/ardour/ardour/audio_diskstream.h b/libs/ardour/ardour/audio_diskstream.h index e2dfc5fd0c..0cc2079d8e 100644 --- a/libs/ardour/ardour/audio_diskstream.h +++ b/libs/ardour/ardour/audio_diskstream.h @@ -211,11 +211,11 @@ class AudioDiskstream : public Diskstream /* The two central butler operations */ int do_flush (Session::RunContext context, bool force = false); - int do_refill () { return _do_refill(_mixdown_buffer, _gain_buffer, _conversion_buffer); } + int do_refill () { return _do_refill(_mixdown_buffer, _gain_buffer); } int do_refill_with_alloc(); - int read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer, char * workbuf, + int read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer, jack_nframes_t& start, jack_nframes_t cnt, ChannelInfo& channel_info, int channel, bool reversed); @@ -251,10 +251,9 @@ class AudioDiskstream : public Diskstream static size_t _working_buffers_size; static Sample* _mixdown_buffer; static gain_t* _gain_buffer; - static char* _conversion_buffer; - // Uh, /really/ private? (death to friend classes) - int _do_refill (Sample *mixdown_buffer, float *gain_buffer, char *workbuf); + // Uh, /really/ private? (there should probably be less friends of Diskstream) + int _do_refill (Sample *mixdown_buffer, float *gain_buffer); std::vector capturing_sources; diff --git a/libs/ardour/ardour/audio_track.h b/libs/ardour/ardour/audio_track.h index 15b99297c8..9892179085 100644 --- a/libs/ardour/ardour/audio_track.h +++ b/libs/ardour/ardour/audio_track.h @@ -51,7 +51,7 @@ class AudioTrack : public Track int use_diskstream (string name); int use_diskstream (const PBD::ID& id); - int export_stuff (vector& buffers, char * workbuf, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t end_frame); + int export_stuff (vector& buffers, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t end_frame); void freeze (InterThreadInfo&); void unfreeze (); diff --git a/libs/ardour/ardour/audio_unit.h b/libs/ardour/ardour/audio_unit.h index 1c8d6cbc2d..348a8ff863 100644 --- a/libs/ardour/ardour/audio_unit.h +++ b/libs/ardour/ardour/audio_unit.h @@ -96,6 +96,8 @@ class AUPlugin : public ARDOUR::Plugin std::vector > parameter_map; }; +typedef boost::shared_ptr AUPluginPtr; + class AUPluginInfo : public PluginInfo { public: AUPluginInfo () { }; diff --git a/libs/ardour/ardour/audioplaylist.h b/libs/ardour/ardour/audioplaylist.h index 5a77067f8f..bd76c30289 100644 --- a/libs/ardour/ardour/audioplaylist.h +++ b/libs/ardour/ardour/audioplaylist.h @@ -60,7 +60,7 @@ class AudioPlaylist : public ARDOUR::Playlist void clear (bool with_delete = false, bool with_save = true); - jack_nframes_t read (Sample *dst, Sample *mixdown, float *gain_buffer, char * workbuf, jack_nframes_t start, jack_nframes_t cnt, uint32_t chan_n=0); + jack_nframes_t read (Sample *dst, Sample *mixdown, float *gain_buffer, jack_nframes_t start, jack_nframes_t cnt, uint32_t chan_n=0); int set_state (const XMLNode&); UndoAction get_memento() const; diff --git a/libs/ardour/ardour/audioregion.h b/libs/ardour/ardour/audioregion.h index 683e946713..0c08392325 100644 --- a/libs/ardour/ardour/audioregion.h +++ b/libs/ardour/ardour/audioregion.h @@ -106,13 +106,13 @@ class AudioRegion : public Region uint32_t chan_n=0, double samples_per_unit= 1.0) const; virtual jack_nframes_t read_at (Sample *buf, Sample *mixdown_buf, - float *gain_buf, char * workbuf, jack_nframes_t position, jack_nframes_t cnt, + float *gain_buf, jack_nframes_t position, jack_nframes_t cnt, uint32_t chan_n = 0, jack_nframes_t read_frames = 0, jack_nframes_t skip_frames = 0) const; jack_nframes_t master_read_at (Sample *buf, Sample *mixdown_buf, - float *gain_buf, char * workbuf, + float *gain_buf, jack_nframes_t position, jack_nframes_t cnt, uint32_t chan_n=0) const; XMLNode& state (bool); @@ -177,7 +177,7 @@ class AudioRegion : public Region void recompute_gain_at_start (); jack_nframes_t _read_at (const SourceList&, Sample *buf, Sample *mixdown_buffer, - float *gain_buffer, char * workbuf, jack_nframes_t position, jack_nframes_t cnt, + float *gain_buffer, jack_nframes_t position, jack_nframes_t cnt, uint32_t chan_n = 0, jack_nframes_t read_frames = 0, jack_nframes_t skip_frames = 0) const; diff --git a/libs/ardour/ardour/audiosource.h b/libs/ardour/ardour/audiosource.h index 35158a24e7..786423d9f8 100644 --- a/libs/ardour/ardour/audiosource.h +++ b/libs/ardour/ardour/audiosource.h @@ -66,8 +66,8 @@ class AudioSource : public Source virtual jack_nframes_t available_peaks (double zoom) const; - virtual jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const; - virtual jack_nframes_t write (Sample *src, jack_nframes_t cnt, char * workbuf); + virtual jack_nframes_t read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const; + virtual jack_nframes_t write (Sample *src, jack_nframes_t cnt); virtual float sample_rate () const = 0; @@ -124,8 +124,8 @@ class AudioSource : public Source int do_build_peak (jack_nframes_t, jack_nframes_t); - virtual jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const = 0; - virtual jack_nframes_t write_unlocked (Sample *dst, jack_nframes_t cnt, char * workbuf) = 0; + virtual jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const = 0; + virtual jack_nframes_t write_unlocked (Sample *dst, jack_nframes_t cnt) = 0; virtual string peak_path(string audio_path) = 0; virtual string old_peak_path(string audio_path) = 0; diff --git a/libs/ardour/ardour/coreaudiosource.h b/libs/ardour/ardour/coreaudiosource.h index ba9f122fc9..cf25c466ee 100644 --- a/libs/ardour/ardour/coreaudiosource.h +++ b/libs/ardour/ardour/coreaudiosource.h @@ -38,9 +38,9 @@ class CoreAudioSource : public AudioFileSource { void set_header_timeline_position () {}; protected: - jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const; + jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const; - jack_nframes_t write_unlocked (Sample *dst, jack_nframes_t cnt, char * workbuf) + jack_nframes_t write_unlocked (Sample *dst, jack_nframes_t cnt) { return 0; } diff --git a/libs/ardour/ardour/crossfade.h b/libs/ardour/ardour/crossfade.h index ebafa0e8cc..aea7b31852 100644 --- a/libs/ardour/ardour/crossfade.h +++ b/libs/ardour/ardour/crossfade.h @@ -92,7 +92,7 @@ class Crossfade : public Stateful, public StateManager ARDOUR::AudioRegion& out() const { return *_out; } jack_nframes_t read_at (Sample *buf, Sample *mixdown_buffer, - float *gain_buffer, char * workbuf, jack_nframes_t position, jack_nframes_t cnt, + float *gain_buffer, jack_nframes_t position, jack_nframes_t cnt, uint32_t chan_n, jack_nframes_t read_frames = 0, jack_nframes_t skip_frames = 0); diff --git a/libs/ardour/ardour/destructive_filesource.h b/libs/ardour/ardour/destructive_filesource.h index 5b773898c3..fb2a3be47b 100644 --- a/libs/ardour/ardour/destructive_filesource.h +++ b/libs/ardour/ardour/destructive_filesource.h @@ -49,7 +49,7 @@ class DestructiveFileSource : public SndFileSource { static void setup_standard_crossfades (jack_nframes_t sample_rate); protected: - jack_nframes_t write_unlocked (Sample *src, jack_nframes_t cnt, char * workbuf); + jack_nframes_t write_unlocked (Sample *src, jack_nframes_t cnt); virtual void handle_header_position_change (); @@ -65,7 +65,7 @@ class DestructiveFileSource : public SndFileSource { Sample* xfade_buf; void init (); - jack_nframes_t crossfade (Sample* data, jack_nframes_t cnt, int dir, char * workbuf); + jack_nframes_t crossfade (Sample* data, jack_nframes_t cnt, int dir); void set_timeline_position (jack_nframes_t); }; diff --git a/libs/ardour/ardour/diskstream.h b/libs/ardour/ardour/diskstream.h index ebce516d8b..e0202a4fae 100644 --- a/libs/ardour/ardour/diskstream.h +++ b/libs/ardour/ardour/diskstream.h @@ -117,8 +117,8 @@ class Diskstream : public Stateful, public sigc::trackable uint32_t n_channels() { return _n_channels; } - static jack_nframes_t disk_io_frames() { return disk_io_chunk_frames; } - static void set_disk_io_chunk_frames (uint32_t n) { disk_io_chunk_frames = n; } + static jack_nframes_t disk_io_frames() { return disk_io_chunk_frames; } + static void set_disk_io_chunk_frames (uint32_t n) { disk_io_chunk_frames = n; } /* Stateful */ virtual XMLNode& get_state(void) = 0; diff --git a/libs/ardour/ardour/insert.h b/libs/ardour/ardour/insert.h index a4c4439942..c81d4e5761 100644 --- a/libs/ardour/ardour/insert.h +++ b/libs/ardour/ardour/insert.h @@ -29,6 +29,7 @@ #include #include #include +#include class XMLNode; @@ -39,8 +40,8 @@ namespace MIDI { namespace ARDOUR { class Session; -class Plugin; class Route; +class Plugin; class Insert : public Redirect { @@ -149,6 +150,8 @@ class PluginInsert : public Insert } } + PluginType type (); + string describe_parameter (uint32_t); jack_nframes_t latency(); diff --git a/libs/ardour/ardour/plugin.h b/libs/ardour/ardour/plugin.h index 6b11a975ca..e5a81f1ef9 100644 --- a/libs/ardour/ardour/plugin.h +++ b/libs/ardour/ardour/plugin.h @@ -47,27 +47,22 @@ class AudioEngine; class Session; class Plugin; + typedef boost::shared_ptr PluginPtr; class PluginInfo { public: - enum Type { - AudioUnit, - LADSPA, - VST - }; - PluginInfo () { } PluginInfo (const PluginInfo &o) : name(o.name), n_inputs(o.n_inputs), n_outputs(o.n_outputs), unique_id(o.unique_id), path (o.path), index(o.index) {} virtual ~PluginInfo () { } - + string name; string category; uint32_t n_inputs; uint32_t n_outputs; - Type type; + ARDOUR::PluginType type; long unique_id; @@ -187,7 +182,7 @@ class Plugin : public Stateful, public sigc::trackable vector controls; }; -PluginPtr find_plugin(ARDOUR::Session&, string name, long unique_id, PluginInfo::Type); +PluginPtr find_plugin(ARDOUR::Session&, string name, long unique_id, ARDOUR::PluginType); } // namespace ARDOUR diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index ebb13011fc..e2b14eccfa 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -974,8 +974,6 @@ class Session : public sigc::trackable, public Stateful ExportContext }; - char * conversion_buffer(RunContext context) { return _conversion_buffers[context]; } - /* VST support */ static long vst_callback (AEffect* effect, @@ -1059,7 +1057,6 @@ class Session : public sigc::trackable, public Stateful vector _passthru_buffers; vector _silent_buffers; vector _send_buffers; - map _conversion_buffers; jack_nframes_t current_block_size; jack_nframes_t _worst_output_latency; jack_nframes_t _worst_input_latency; diff --git a/libs/ardour/ardour/sndfilesource.h b/libs/ardour/ardour/sndfilesource.h index 4764339451..ab3e61eb29 100644 --- a/libs/ardour/ardour/sndfilesource.h +++ b/libs/ardour/ardour/sndfilesource.h @@ -56,8 +56,8 @@ class SndFileSource : public AudioFileSource { protected: void set_header_timeline_position (); - jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const; - jack_nframes_t write_unlocked (Sample *dst, jack_nframes_t cnt, char * workbuf); + jack_nframes_t read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const; + jack_nframes_t write_unlocked (Sample *dst, jack_nframes_t cnt); jack_nframes_t write_float (Sample* data, jack_nframes_t pos, jack_nframes_t cnt); diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index b2230f12d7..0a3a7b731c 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -243,7 +243,14 @@ namespace ARDOUR { PeakDatum min; PeakDatum max; }; -} + + enum PluginType { + AudioUnit, + LADSPA, + VST + }; + +} // namespace ARDOUR std::istream& operator>>(std::istream& o, ARDOUR::SampleFormat& sf); std::istream& operator>>(std::istream& o, ARDOUR::HeaderFormat& sf); @@ -254,7 +261,6 @@ session_frame_to_track_frame (jack_nframes_t session_frame, double speed) return (jack_nframes_t)( (double)session_frame * speed ); } - static inline jack_nframes_t track_frame_to_session_frame (jack_nframes_t track_frame, double speed) { diff --git a/libs/ardour/ardour/vst_plugin.h b/libs/ardour/ardour/vst_plugin.h index 5253da7b0a..4fb5b0babb 100644 --- a/libs/ardour/ardour/vst_plugin.h +++ b/libs/ardour/ardour/vst_plugin.h @@ -113,6 +113,8 @@ class VSTPluginInfo : public PluginInfo PluginPtr load (Session& session); }; +typedef boost::shared_ptr VSTPluginInfoPtr; + } // namespace ARDOUR #endif /* __ardour_vst_plugin_h__ */ diff --git a/libs/ardour/audio_diskstream.cc b/libs/ardour/audio_diskstream.cc index 7d2a2103bb..9619f404fa 100644 --- a/libs/ardour/audio_diskstream.cc +++ b/libs/ardour/audio_diskstream.cc @@ -58,7 +58,6 @@ using namespace PBD; size_t AudioDiskstream::_working_buffers_size = 0; Sample* AudioDiskstream::_mixdown_buffer = 0; gain_t* AudioDiskstream::_gain_buffer = 0; -char* AudioDiskstream::_conversion_buffer = 0; AudioDiskstream::AudioDiskstream (Session &sess, const string &name, Diskstream::Flag flag) : Diskstream(sess, name, flag) @@ -188,7 +187,6 @@ AudioDiskstream::allocate_working_buffers() _working_buffers_size = disk_io_frames(); _mixdown_buffer = new Sample[_working_buffers_size]; _gain_buffer = new gain_t[_working_buffers_size]; - _conversion_buffer = new char[_working_buffers_size * 4]; } void @@ -196,11 +194,9 @@ AudioDiskstream::free_working_buffers() { delete _mixdown_buffer; delete _gain_buffer; - delete _conversion_buffer; _working_buffers_size = 0; _mixdown_buffer = 0; _gain_buffer = 0; - _conversion_buffer = 0; } void @@ -895,7 +891,6 @@ AudioDiskstream::overwrite_existing_buffers () { Sample* mixdown_buffer; float* gain_buffer; - char * workbuf; int ret = -1; bool reversed = (_visible_speed * _session.transport_speed()) < 0.0f; @@ -906,7 +901,6 @@ AudioDiskstream::overwrite_existing_buffers () mixdown_buffer = new Sample[size]; gain_buffer = new float[size]; - workbuf = new char[size*4]; /* reduce size so that we can fill the buffer correctly. */ size--; @@ -932,8 +926,7 @@ AudioDiskstream::overwrite_existing_buffers () jack_nframes_t to_read = size - overwrite_offset; - if (read ((*chan).playback_buf->buffer() + overwrite_offset, mixdown_buffer, gain_buffer, workbuf, - start, to_read, *chan, n, reversed)) { + if (read ((*chan).playback_buf->buffer() + overwrite_offset, mixdown_buffer, gain_buffer, start, to_read, *chan, n, reversed)) { error << string_compose(_("AudioDiskstream %1: when refilling, cannot read %2 from playlist at frame %3"), _id, size, playback_sample) << endmsg; goto out; @@ -943,7 +936,7 @@ AudioDiskstream::overwrite_existing_buffers () cnt -= to_read; - if (read ((*chan).playback_buf->buffer(), mixdown_buffer, gain_buffer, workbuf, + if (read ((*chan).playback_buf->buffer(), mixdown_buffer, gain_buffer, start, cnt, *chan, n, reversed)) { error << string_compose(_("AudioDiskstream %1: when refilling, cannot read %2 from playlist at frame %3"), _id, size, playback_sample) << endmsg; @@ -958,7 +951,6 @@ AudioDiskstream::overwrite_existing_buffers () pending_overwrite = false; delete [] gain_buffer; delete [] mixdown_buffer; - delete [] workbuf; return ret; } @@ -1022,7 +1014,7 @@ AudioDiskstream::internal_playback_seek (jack_nframes_t distance) } int -AudioDiskstream::read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer, char * workbuf, jack_nframes_t& start, jack_nframes_t cnt, +AudioDiskstream::read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer, jack_nframes_t& start, jack_nframes_t cnt, ChannelInfo& channel_info, int channel, bool reversed) { jack_nframes_t this_read = 0; @@ -1079,7 +1071,7 @@ AudioDiskstream::read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer, this_read = min(cnt,this_read); - if (audio_playlist()->read (buf+offset, mixdown_buffer, gain_buffer, workbuf, start, this_read, channel) != this_read) { + if (audio_playlist()->read (buf+offset, mixdown_buffer, gain_buffer, start, this_read, channel) != this_read) { error << string_compose(_("AudioDiskstream %1: cannot read %2 from playlist at frame %3"), _id, this_read, start) << endmsg; return -1; @@ -1117,19 +1109,17 @@ AudioDiskstream::do_refill_with_alloc() { Sample* mix_buf = new Sample[disk_io_chunk_frames]; float* gain_buf = new float[disk_io_chunk_frames]; - char* work_buf = new char[disk_io_chunk_frames * 4]; - int ret = _do_refill(mix_buf, gain_buf, work_buf); + int ret = _do_refill(mix_buf, gain_buf); delete [] mix_buf; delete [] gain_buf; - delete [] work_buf; return ret; } int -AudioDiskstream::_do_refill (Sample* mixdown_buffer, float* gain_buffer, char * workbuf) +AudioDiskstream::_do_refill (Sample* mixdown_buffer, float* gain_buffer) { int32_t ret = 0; jack_nframes_t to_read; @@ -1143,7 +1133,6 @@ AudioDiskstream::_do_refill (Sample* mixdown_buffer, float* gain_buffer, char * assert(mixdown_buffer); assert(gain_buffer); - assert(workbuf); channels.front().playback_buf->get_write_vector (&vector); @@ -1284,7 +1273,7 @@ AudioDiskstream::_do_refill (Sample* mixdown_buffer, float* gain_buffer, char * if (to_read) { - if (read (buf1, mixdown_buffer, gain_buffer, workbuf, file_frame_tmp, to_read, chan, chan_n, reversed)) { + if (read (buf1, mixdown_buffer, gain_buffer, file_frame_tmp, to_read, chan, chan_n, reversed)) { ret = -1; goto out; } @@ -1302,7 +1291,7 @@ AudioDiskstream::_do_refill (Sample* mixdown_buffer, float* gain_buffer, char * so read some or all of vector.len[1] as well. */ - if (read (buf2, mixdown_buffer, gain_buffer, workbuf, file_frame_tmp, to_read, chan, chan_n, reversed)) { + if (read (buf2, mixdown_buffer, gain_buffer, file_frame_tmp, to_read, chan, chan_n, reversed)) { ret = -1; goto out; } @@ -1336,8 +1325,6 @@ AudioDiskstream::_do_refill (Sample* mixdown_buffer, float* gain_buffer, char * int AudioDiskstream::do_flush (Session::RunContext context, bool force_flush) { - char* workbuf = _session.conversion_buffer(context); - uint32_t to_write; int32_t ret = 0; RingBufferNPT::rw_vector vector; @@ -1427,7 +1414,7 @@ AudioDiskstream::do_flush (Session::RunContext context, bool force_flush) } } - if ((!(*chan).write_source) || (*chan).write_source->write (vector.buf[0], to_write, workbuf) != to_write) { + if ((!(*chan).write_source) || (*chan).write_source->write (vector.buf[0], to_write) != to_write) { error << string_compose(_("AudioDiskstream %1: cannot write to disk"), _id) << endmsg; return -1; } @@ -1444,7 +1431,7 @@ AudioDiskstream::do_flush (Session::RunContext context, bool force_flush) to_write = min ((jack_nframes_t)(disk_io_chunk_frames - to_write), (jack_nframes_t) vector.len[1]); - if ((*chan).write_source->write (vector.buf[1], to_write, workbuf) != to_write) { + if ((*chan).write_source->write (vector.buf[1], to_write) != to_write) { error << string_compose(_("AudioDiskstream %1: cannot write to disk"), _id) << endmsg; return -1; } diff --git a/libs/ardour/audio_playlist.cc b/libs/ardour/audio_playlist.cc index 93d380679d..328c9b25f5 100644 --- a/libs/ardour/audio_playlist.cc +++ b/libs/ardour/audio_playlist.cc @@ -177,7 +177,7 @@ struct RegionSortByLayer { }; jack_nframes_t -AudioPlaylist::read (Sample *buf, Sample *mixdown_buffer, float *gain_buffer, char * workbuf, jack_nframes_t start, +AudioPlaylist::read (Sample *buf, Sample *mixdown_buffer, float *gain_buffer, jack_nframes_t start, jack_nframes_t cnt, unsigned chan_n) { jack_nframes_t ret = cnt; @@ -250,12 +250,12 @@ AudioPlaylist::read (Sample *buf, Sample *mixdown_buffer, float *gain_buffer, ch for (vector::iterator i = r.begin(); i != r.end(); ++i) { AudioRegion* const ar = dynamic_cast(*i); assert(ar); - ar->read_at (buf, mixdown_buffer, gain_buffer, workbuf, start, cnt, chan_n, read_frames, skip_frames); + ar->read_at (buf, mixdown_buffer, gain_buffer, start, cnt, chan_n, read_frames, skip_frames); _read_data_count += ar->read_data_count(); } for (vector::iterator i = x.begin(); i != x.end(); ++i) { - (*i)->read_at (buf, mixdown_buffer, gain_buffer, workbuf, start, cnt, chan_n); + (*i)->read_at (buf, mixdown_buffer, gain_buffer, start, cnt, chan_n); /* don't JACK up _read_data_count, since its the same data as we just read from the regions, and the OS should handle that for us. diff --git a/libs/ardour/audio_track.cc b/libs/ardour/audio_track.cc index 78af23e3df..2f33012546 100644 --- a/libs/ardour/audio_track.cc +++ b/libs/ardour/audio_track.cc @@ -627,7 +627,7 @@ AudioTrack::silent_roll (jack_nframes_t nframes, jack_nframes_t start_frame, jac } int -AudioTrack::export_stuff (vector& buffers, char * workbuf, uint32_t nbufs, jack_nframes_t start, jack_nframes_t nframes) +AudioTrack::export_stuff (vector& buffers, uint32_t nbufs, jack_nframes_t start, jack_nframes_t nframes) { gain_t gain_automation[nframes]; gain_t gain_buffer[nframes]; @@ -645,7 +645,7 @@ AudioTrack::export_stuff (vector& buffers, char * workbuf, uint32_t nbu AudioPlaylist* const apl = dynamic_cast(diskstream.playlist()); assert(apl); - if (apl->read (buffers[0], mix_buffer, gain_buffer, workbuf, start, nframes) != nframes) { + if (apl->read (buffers[0], mix_buffer, gain_buffer, start, nframes) != nframes) { return -1; } @@ -655,7 +655,7 @@ AudioTrack::export_stuff (vector& buffers, char * workbuf, uint32_t nbu ++bi; for (; bi != buffers.end(); ++bi, ++n) { if (n < diskstream.n_channels()) { - if (apl->read ((*bi), mix_buffer, gain_buffer, workbuf, start, nframes, n) != nframes) { + if (apl->read ((*bi), mix_buffer, gain_buffer, start, nframes, n) != nframes) { return -1; } b = (*bi); diff --git a/libs/ardour/audio_unit.cc b/libs/ardour/audio_unit.cc index 25c8aeb53b..0a31df40ee 100644 --- a/libs/ardour/audio_unit.cc +++ b/libs/ardour/audio_unit.cc @@ -322,7 +322,7 @@ AUPluginInfo::discover () AUPluginInfoPtr plug(new AUPluginInfo); plug->name = AUPluginInfo::get_name (temp); - plug->type = PluginInfo::AudioUnit; + plug->type = ARDOUR::AudioUnit; plug->n_inputs = 0; plug->n_outputs = 0; plug->category = "AudioUnit"; diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index 20d1dbfbd6..4b07599924 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -466,22 +466,22 @@ AudioRegion::read_peaks (PeakData *buf, jack_nframes_t npeaks, jack_nframes_t of } jack_nframes_t -AudioRegion::read_at (Sample *buf, Sample *mixdown_buffer, float *gain_buffer, char * workbuf, jack_nframes_t position, +AudioRegion::read_at (Sample *buf, Sample *mixdown_buffer, float *gain_buffer, jack_nframes_t position, jack_nframes_t cnt, uint32_t chan_n, jack_nframes_t read_frames, jack_nframes_t skip_frames) const { - return _read_at (sources, buf, mixdown_buffer, gain_buffer, workbuf, position, cnt, chan_n, read_frames, skip_frames); + return _read_at (sources, buf, mixdown_buffer, gain_buffer, position, cnt, chan_n, read_frames, skip_frames); } jack_nframes_t -AudioRegion::master_read_at (Sample *buf, Sample *mixdown_buffer, float *gain_buffer, char * workbuf, jack_nframes_t position, +AudioRegion::master_read_at (Sample *buf, Sample *mixdown_buffer, float *gain_buffer, jack_nframes_t position, jack_nframes_t cnt, uint32_t chan_n) const { - return _read_at (master_sources, buf, mixdown_buffer, gain_buffer, workbuf, position, cnt, chan_n, 0, 0); + return _read_at (master_sources, buf, mixdown_buffer, gain_buffer, position, cnt, chan_n, 0, 0); } jack_nframes_t -AudioRegion::_read_at (const SourceList& srcs, Sample *buf, Sample *mixdown_buffer, float *gain_buffer, char * workbuf, +AudioRegion::_read_at (const SourceList& srcs, Sample *buf, Sample *mixdown_buffer, float *gain_buffer, jack_nframes_t position, jack_nframes_t cnt, uint32_t chan_n, jack_nframes_t read_frames, jack_nframes_t skip_frames) const { @@ -526,7 +526,7 @@ AudioRegion::_read_at (const SourceList& srcs, Sample *buf, Sample *mixdown_buff _read_data_count = 0; - if (srcs[chan_n]->read (mixdown_buffer, _start + internal_offset, to_read, workbuf) != to_read) { + if (srcs[chan_n]->read (mixdown_buffer, _start + internal_offset, to_read) != to_read) { return 0; /* "read nothing" */ } @@ -1188,7 +1188,7 @@ AudioRegion::exportme (Session& session, AudioExportSpecification& spec) if (spec.channels == 1) { - if (sources.front()->read (spec.dataF, _start + spec.pos, to_read, 0) != to_read) { + if (sources.front()->read (spec.dataF, _start + spec.pos, to_read) != to_read) { goto out; } @@ -1198,7 +1198,7 @@ AudioRegion::exportme (Session& session, AudioExportSpecification& spec) for (uint32_t chan = 0; chan < spec.channels; ++chan) { - if (sources[chan]->read (buf, _start + spec.pos, to_read, 0) != to_read) { + if (sources[chan]->read (buf, _start + spec.pos, to_read) != to_read) { goto out; } @@ -1260,7 +1260,6 @@ AudioRegion::normalize_to (float target_dB) { const jack_nframes_t blocksize = 64 * 1024; Sample buf[blocksize]; - char workbuf[blocksize * 4]; jack_nframes_t fpos; jack_nframes_t fend; jack_nframes_t to_read; @@ -1289,7 +1288,7 @@ AudioRegion::normalize_to (float target_dB) /* read it in */ - if (source (n).read (buf, fpos, to_read, workbuf) != to_read) { + if (source (n).read (buf, fpos, to_read) != to_read) { return; } diff --git a/libs/ardour/audiosource.cc b/libs/ardour/audiosource.cc index bf7a32c885..ab5ac437c3 100644 --- a/libs/ardour/audiosource.cc +++ b/libs/ardour/audiosource.cc @@ -379,17 +379,17 @@ AudioSource::initialize_peakfile (bool newfile, string audio_path) } jack_nframes_t -AudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const +AudioSource::read (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const { Glib::Mutex::Lock lm (_lock); - return read_unlocked (dst, start, cnt, workbuf); + return read_unlocked (dst, start, cnt); } jack_nframes_t -AudioSource::write (Sample *dst, jack_nframes_t cnt, char * workbuf) +AudioSource::write (Sample *dst, jack_nframes_t cnt) { Glib::Mutex::Lock lm (_lock); - return write_unlocked (dst, cnt, workbuf); + return write_unlocked (dst, cnt); } int @@ -406,7 +406,6 @@ AudioSource::read_peaks (PeakData *peaks, jack_nframes_t npeaks, jack_nframes_t int ret = -1; PeakData* staging = 0; Sample* raw_staging = 0; - char * workbuf = 0; int peakfile = -1; expected_peaks = (cnt / (double) frames_per_peak); @@ -445,9 +444,8 @@ AudioSource::read_peaks (PeakData *peaks, jack_nframes_t npeaks, jack_nframes_t */ Sample* raw_staging = new Sample[cnt]; - workbuf = new char[cnt*4]; - if (read_unlocked (raw_staging, start, cnt, workbuf) != cnt) { + if (read_unlocked (raw_staging, start, cnt) != cnt) { error << _("cannot read sample data for unscaled peak computation") << endmsg; return -1; } @@ -458,7 +456,6 @@ AudioSource::read_peaks (PeakData *peaks, jack_nframes_t npeaks, jack_nframes_t } delete [] raw_staging; - delete [] workbuf; return 0; } @@ -624,7 +621,6 @@ AudioSource::read_peaks (PeakData *peaks, jack_nframes_t npeaks, jack_nframes_t jack_nframes_t nvisual_peaks = 0; jack_nframes_t chunksize = (jack_nframes_t) min (cnt, (jack_nframes_t) 4096); raw_staging = new Sample[chunksize]; - workbuf = new char[chunksize *4]; jack_nframes_t frame_pos = start; double pixel_pos = floor (frame_pos / samples_per_visual_peak); @@ -640,7 +636,7 @@ AudioSource::read_peaks (PeakData *peaks, jack_nframes_t npeaks, jack_nframes_t to_read = min (chunksize, (_length - current_frame)); - if ((frames_read = read_unlocked (raw_staging, current_frame, to_read, workbuf)) == 0) { + if ((frames_read = read_unlocked (raw_staging, current_frame, to_read)) == 0) { error << string_compose(_("AudioSource[%1]: peak read - cannot read %2 samples at offset %3") , _name, to_read, current_frame) << endmsg; @@ -688,10 +684,6 @@ AudioSource::read_peaks (PeakData *peaks, jack_nframes_t npeaks, jack_nframes_t delete [] raw_staging; } - if (workbuf) { - delete [] workbuf; - } - return ret; } @@ -760,7 +752,6 @@ AudioSource::do_build_peak (jack_nframes_t first_frame, jack_nframes_t cnt) Sample xmin, xmax; uint32_t peaki; PeakData* peakbuf; - char * workbuf = 0; jack_nframes_t frames_read; jack_nframes_t frames_to_read; off_t first_peak_byte; @@ -781,8 +772,6 @@ AudioSource::do_build_peak (jack_nframes_t first_frame, jack_nframes_t cnt) peakbuf = new PeakData[(cnt/frames_per_peak)+1]; peaki = 0; - workbuf = new char[max(frames_per_peak, cnt) * 4]; - if ((peakfile = ::open (peakpath.c_str(), O_RDWR|O_CREAT, 0664)) < 0) { error << string_compose(_("AudioSource: cannot open peakpath \"%1\" (%2)"), peakpath, strerror (errno)) << endmsg; return -1; @@ -794,7 +783,7 @@ AudioSource::do_build_peak (jack_nframes_t first_frame, jack_nframes_t cnt) /* lock for every read */ - if ((frames_read = read (buf, current_frame, frames_to_read, workbuf)) != frames_to_read) { + if ((frames_read = read (buf, current_frame, frames_to_read)) != frames_to_read) { error << string_compose(_("%1: could not write read raw data for peak computation (%2)"), _name, strerror (errno)) << endmsg; goto out; } @@ -831,8 +820,6 @@ AudioSource::do_build_peak (jack_nframes_t first_frame, jack_nframes_t cnt) if (peakfile >= 0) { close (peakfile); } - if (workbuf) - delete [] workbuf; return ret; } diff --git a/libs/ardour/configuration.cc b/libs/ardour/configuration.cc index 58da77f933..84c3e3a834 100644 --- a/libs/ardour/configuration.cc +++ b/libs/ardour/configuration.cc @@ -236,7 +236,7 @@ Configuration::set_state (const XMLNode& root) } } - AudioDiskstream::set_disk_io_chunk_frames (minimum_disk_io_bytes.get() / sizeof (Sample)); + Diskstream::set_disk_io_chunk_frames (minimum_disk_io_bytes.get() / sizeof (Sample)); return 0; } diff --git a/libs/ardour/coreaudiosource.cc b/libs/ardour/coreaudiosource.cc index 5e9de225d4..f0fcac14e2 100644 --- a/libs/ardour/coreaudiosource.cc +++ b/libs/ardour/coreaudiosource.cc @@ -153,7 +153,7 @@ CoreAudioSource::~CoreAudioSource () } jack_nframes_t -CoreAudioSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const +CoreAudioSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const { OSStatus err = noErr; diff --git a/libs/ardour/crossfade.cc b/libs/ardour/crossfade.cc index dc4c074844..379c9333b0 100644 --- a/libs/ardour/crossfade.cc +++ b/libs/ardour/crossfade.cc @@ -402,7 +402,7 @@ Crossfade::compute (AudioRegion& a, AudioRegion& b, CrossfadeModel model) jack_nframes_t Crossfade::read_at (Sample *buf, Sample *mixdown_buffer, - float *gain_buffer, char * workbuf, jack_nframes_t start, jack_nframes_t cnt, uint32_t chan_n, + float *gain_buffer, jack_nframes_t start, jack_nframes_t cnt, uint32_t chan_n, jack_nframes_t read_frames, jack_nframes_t skip_frames) { jack_nframes_t offset; @@ -438,8 +438,8 @@ Crossfade::read_at (Sample *buf, Sample *mixdown_buffer, offset = start - _position; - _out->read_at (crossfade_buffer_out, mixdown_buffer, gain_buffer, workbuf, start, to_write, chan_n, read_frames, skip_frames); - _in->read_at (crossfade_buffer_in, mixdown_buffer, gain_buffer, workbuf, start, to_write, chan_n, read_frames, skip_frames); + _out->read_at (crossfade_buffer_out, mixdown_buffer, gain_buffer, start, to_write, chan_n, read_frames, skip_frames); + _in->read_at (crossfade_buffer_in, mixdown_buffer, gain_buffer, start, to_write, chan_n, read_frames, skip_frames); float* fiv = new float[to_write]; float* fov = new float[to_write]; diff --git a/libs/ardour/destructive_filesource.cc b/libs/ardour/destructive_filesource.cc index 43fafff30a..65ca8dae67 100644 --- a/libs/ardour/destructive_filesource.cc +++ b/libs/ardour/destructive_filesource.cc @@ -158,7 +158,7 @@ DestructiveFileSource::clear_capture_marks () } jack_nframes_t -DestructiveFileSource::crossfade (Sample* data, jack_nframes_t cnt, int fade_in, char * workbuf) +DestructiveFileSource::crossfade (Sample* data, jack_nframes_t cnt, int fade_in) { jack_nframes_t xfade = min (xfade_frames, cnt); jack_nframes_t nofade = cnt - xfade; @@ -272,7 +272,7 @@ DestructiveFileSource::crossfade (Sample* data, jack_nframes_t cnt, int fade_in, } jack_nframes_t -DestructiveFileSource::write_unlocked (Sample* data, jack_nframes_t cnt, char * workbuf) +DestructiveFileSource::write_unlocked (Sample* data, jack_nframes_t cnt) { jack_nframes_t old_file_pos; @@ -297,7 +297,7 @@ DestructiveFileSource::write_unlocked (Sample* data, jack_nframes_t cnt, char * jack_nframes_t ofilepos = file_pos; // fade in - if (crossfade (data, subcnt, 1, workbuf) != subcnt) { + if (crossfade (data, subcnt, 1) != subcnt) { return 0; } @@ -306,7 +306,7 @@ DestructiveFileSource::write_unlocked (Sample* data, jack_nframes_t cnt, char * // fade out subcnt = cnt - subcnt; - if (crossfade (tmpdata, subcnt, 0, workbuf) != subcnt) { + if (crossfade (tmpdata, subcnt, 0) != subcnt) { return 0; } @@ -324,7 +324,7 @@ DestructiveFileSource::write_unlocked (Sample* data, jack_nframes_t cnt, char * /* move to the correct location place */ file_pos = capture_start_frame; - if (crossfade (data, cnt, 1, workbuf) != cnt) { + if (crossfade (data, cnt, 1) != cnt) { return 0; } @@ -337,7 +337,7 @@ DestructiveFileSource::write_unlocked (Sample* data, jack_nframes_t cnt, char * _capture_start = false; _capture_end = false; - if (crossfade (data, cnt, 0, workbuf) != cnt) { + if (crossfade (data, cnt, 0) != cnt) { return 0; } diff --git a/libs/ardour/diskstream.cc b/libs/ardour/diskstream.cc index 9312de5bf1..b2d481077f 100644 --- a/libs/ardour/diskstream.cc +++ b/libs/ardour/diskstream.cc @@ -19,6 +19,7 @@ */ #include +#include #include #include #include @@ -55,7 +56,12 @@ using namespace std; using namespace ARDOUR; using namespace PBD; -jack_nframes_t Diskstream::disk_io_chunk_frames = 0; +/* XXX This goes uninitialized when there is no ~/.ardour2 directory. + * I can't figure out why, so this will do for now (just stole the + * default from configuration_vars.h). 0 is not a good value for + * allocating buffer sizes.. + */ +jack_nframes_t Diskstream::disk_io_chunk_frames = 1024 * 256; sigc::signal Diskstream::DiskstreamCreated; sigc::signal*> Diskstream::DeleteSources; diff --git a/libs/ardour/import.cc b/libs/ardour/import.cc index b70a7bbc9c..c68eb16aae 100644 --- a/libs/ardour/import.cc +++ b/libs/ardour/import.cc @@ -57,7 +57,6 @@ Session::import_audiofile (import_status& status) SF_INFO info; float *data = 0; Sample **channel_data = 0; - char * workbuf = 0; long nfiles = 0; long n; string basepath; @@ -156,7 +155,6 @@ Session::import_audiofile (import_status& status) data = new float[BLOCKSIZE * info.channels]; channel_data = new Sample * [ info.channels ]; - workbuf = new char[BLOCKSIZE * 4]; for (n = 0; n < info.channels; ++n) { channel_data[n] = new Sample[BLOCKSIZE]; @@ -188,7 +186,7 @@ Session::import_audiofile (import_status& status) /* flush to disk */ for (chn = 0; chn < info.channels; ++chn) { - newfiles[chn]->write (channel_data[chn], nread, workbuf); + newfiles[chn]->write (channel_data[chn], nread); } so_far += nread; @@ -255,9 +253,6 @@ Session::import_audiofile (import_status& status) if (data) { delete [] data; } - if (workbuf) { - delete [] workbuf; - } if (channel_data) { for (n = 0; n < info.channels; ++n) { diff --git a/libs/ardour/insert.cc b/libs/ardour/insert.cc index a057fef931..18727e8b5b 100644 --- a/libs/ardour/insert.cc +++ b/libs/ardour/insert.cc @@ -30,9 +30,18 @@ #include #include #include + +#ifdef VST_SUPPORT #include +#endif + +#ifdef HAVE_COREAUDIO +#include +#endif + #include #include +#include #include "i18n.h" @@ -45,7 +54,6 @@ Insert::Insert(Session& s, Placement p) { } - Insert::Insert(Session& s, Placement p, int imin, int imax, int omin, int omax) : Redirect (s, s.next_insert_name(), p, imin, imax, omin, omax) { @@ -505,12 +513,19 @@ PluginInsert::plugin_factory (boost::shared_ptr other) #ifdef VST_SUPPORT boost::shared_ptr vp; #endif +#ifdef HAVE_COREAUDIO + boost::shared_ptr ap; +#endif if ((lp = boost::dynamic_pointer_cast (other)) != 0) { return boost::shared_ptr (new LadspaPlugin (*lp)); #ifdef VST_SUPPORT } else if ((vp = boost::dynamic_pointer_cast (other)) != 0) { return boost::shared_ptr (new VSTPlugin (*vp)); +#endif +#ifdef HAVE_COREAUDIO + } else if ((ap = boost::dynamic_pointer_cast (other)) != 0) { + return boost::shared_ptr (new AUPlugin (*ap)); #endif } @@ -630,7 +645,7 @@ PluginInsert::set_state(const XMLNode& node) XMLPropertyList plist; const XMLProperty *prop; long unique = 0; - PluginInfo::Type type; + ARDOUR::PluginType type; if ((prop = node.property ("type")) == 0) { error << _("XML node describing insert is missing the `type' field") << endmsg; @@ -638,9 +653,9 @@ PluginInsert::set_state(const XMLNode& node) } if (prop->value() == X_("ladspa") || prop->value() == X_("Ladspa")) { /* handle old school sessions */ - type = PluginInfo::LADSPA; + type = ARDOUR::LADSPA; } else if (prop->value() == X_("vst")) { - type = PluginInfo::VST; + type = ARDOUR::VST; } else { error << string_compose (_("unknown plugin type %1 in plugin insert state"), prop->value()) @@ -807,6 +822,35 @@ PluginInsert::state_factory (std::string why) const return state; } +ARDOUR::PluginType +PluginInsert::type () +{ + boost::shared_ptr lp; +#ifdef VST_SUPPORT + boost::shared_ptr vp; +#endif +#ifdef HAVE_COREAUDIO + boost::shared_ptr ap; +#endif + + PluginPtr other = plugin (); + + if ((lp = boost::dynamic_pointer_cast (other)) != 0) { + return ARDOUR::LADSPA; +#ifdef VST_SUPPORT + } else if ((vp = boost::dynamic_pointer_cast (other)) != 0) { + return ARDOUR::VST; +#endif +#ifdef HAVE_COREAUDIO + } else if ((ap = boost::dynamic_pointer_cast (other)) != 0) { + return ARDOUR::AudioUnit; +#endif + } else { + /* NOT REACHED */ + return (ARDOUR::PluginType) 0; + } +} + /*************************************************************** Port inserts: send output to a port, pick up input at a port ***************************************************************/ diff --git a/libs/ardour/panner.cc b/libs/ardour/panner.cc index 8336c4697c..f866b5ae10 100644 --- a/libs/ardour/panner.cc +++ b/libs/ardour/panner.cc @@ -1258,10 +1258,10 @@ Panner::set_state (const XMLNode& node) float x, y; prop = (*niter)->property (X_("x")); - sscanf (prop->value().c_str(), "%.12g", &x); + sscanf (prop->value().c_str(), "%g", &x); prop = (*niter)->property (X_("y")); - sscanf (prop->value().c_str(), "%.12g", &y); + sscanf (prop->value().c_str(), "%g", &y); outputs.push_back (Output (x, y)); } diff --git a/libs/ardour/plugin.cc b/libs/ardour/plugin.cc index 8ea95b8903..bedc32a0b3 100644 --- a/libs/ardour/plugin.cc +++ b/libs/ardour/plugin.cc @@ -244,25 +244,25 @@ Plugin::save_preset (string name, string domain) } PluginPtr -ARDOUR::find_plugin(Session& session, string name, long unique_id, PluginInfo::Type type) +ARDOUR::find_plugin(Session& session, string name, long unique_id, PluginType type) { PluginManager *mgr = PluginManager::the_manager(); PluginInfoList plugs; switch (type) { - case PluginInfo::LADSPA: + case ARDOUR::LADSPA: plugs = mgr->ladspa_plugin_info(); break; #ifdef VST_SUPPORT - case PluginInfo::VST: + case ARDOUR::VST: plugs = mgr->vst_plugin_info(); unique_id = 0; // VST plugins don't have a unique id. break; #endif #ifdef HAVE_COREAUDIO - case PluginInfo::AudioUnit: + case ARDOUR::AudioUnit: plugs = AUPluginInfo::discover (); unique_id = 0; // Neither do AU. break; diff --git a/libs/ardour/plugin_manager.cc b/libs/ardour/plugin_manager.cc index 2a753617e8..5b3a4658a8 100644 --- a/libs/ardour/plugin_manager.cc +++ b/libs/ardour/plugin_manager.cc @@ -254,7 +254,7 @@ PluginManager::ladspa_discover (string path) info->index = i; info->n_inputs = 0; info->n_outputs = 0; - info->type = PluginInfo::LADSPA; + info->type = ARDOUR::LADSPA; info->unique_id = descriptor->UniqueID; for (uint32_t n=0; n < descriptor->PortCount; ++n) { @@ -397,7 +397,7 @@ PluginManager::vst_discover (string path) info->index = 0; info->n_inputs = finfo->numInputs; info->n_outputs = finfo->numOutputs; - info->type = PluginInfo::VST; + info->type = ARDOUR::VST; _vst_plugin_info.push_back (info); fst_free_info (finfo); diff --git a/libs/ardour/reverse.cc b/libs/ardour/reverse.cc index 13dd531bac..3fe6aaa630 100644 --- a/libs/ardour/reverse.cc +++ b/libs/ardour/reverse.cc @@ -49,7 +49,6 @@ Reverse::run (AudioRegion& region) AudioRegion::SourceList::iterator si; const jack_nframes_t blocksize = 256 * 1048; Sample buf[blocksize]; - char * workbuf = 0;; jack_nframes_t fpos; jack_nframes_t fend; jack_nframes_t fstart; @@ -62,8 +61,6 @@ Reverse::run (AudioRegion& region) goto out; } - workbuf = new char[blocksize * 4]; - fend = region.start() + region.length(); fstart = region.start(); @@ -85,7 +82,7 @@ Reverse::run (AudioRegion& region) /* read it in */ - if (region.source (n).read (buf, fpos, to_read, workbuf) != to_read) { + if (region.source (n).read (buf, fpos, to_read) != to_read) { goto out; } @@ -97,7 +94,7 @@ Reverse::run (AudioRegion& region) /* write it out */ - if ((*si)->write (buf, to_read, workbuf) != to_read) { + if ((*si)->write (buf, to_read) != to_read) { goto out; } } @@ -123,9 +120,6 @@ Reverse::run (AudioRegion& region) delete *si; } } - if (workbuf) { - delete [] workbuf; - } return ret; } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index d2b7c7afc1..4a0d820381 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -394,10 +394,6 @@ Session::~Session () free(*i); } - for (map::iterator i = _conversion_buffers.begin(); i != _conversion_buffers.end(); ++i) { - delete [] (i->second); - } - AudioDiskstream::free_working_buffers(); #undef TRACK_DESTRUCTION @@ -3596,7 +3592,6 @@ Session::write_one_audio_track (AudioTrack& track, jack_nframes_t start, jack_nf jack_nframes_t this_chunk; jack_nframes_t to_do; vector buffers; - char * workbuf = 0; // any bigger than this seems to cause stack overflows in called functions const jack_nframes_t chunk_size = (128 * 1024)/4; @@ -3666,13 +3661,11 @@ Session::write_one_audio_track (AudioTrack& track, jack_nframes_t start, jack_nf buffers.push_back (b); } - workbuf = new char[chunk_size * 4]; - while (to_do && !itt.cancel) { this_chunk = min (to_do, chunk_size); - if (track.export_stuff (buffers, workbuf, nchans, start, this_chunk)) { + if (track.export_stuff (buffers, nchans, start, this_chunk)) { goto out; } @@ -3681,7 +3674,7 @@ Session::write_one_audio_track (AudioTrack& track, jack_nframes_t start, jack_nf AudioFileSource* afs = dynamic_cast(*src); if (afs) { - if (afs->write (buffers[n], this_chunk, workbuf) != this_chunk) { + if (afs->write (buffers[n], this_chunk) != this_chunk) { goto out; } } @@ -3735,10 +3728,6 @@ Session::write_one_audio_track (AudioTrack& track, jack_nframes_t start, jack_nf free(*i); } - if (workbuf) { - delete [] workbuf; - } - g_atomic_int_set (&processing_prohibited, 0); itt.done = true; diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index a4e5144447..ebf2b6efd5 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -191,9 +191,6 @@ Session::first_stage_init (string fullpath, string snapshot_name) xfade_model = ShortCrossfade; destructive_index = 0; - /* allocate conversion buffers */ - _conversion_buffers[ButlerContext] = new char[AudioDiskstream::disk_io_frames() * 4]; - _conversion_buffers[TransportContext] = new char[AudioDiskstream::disk_io_frames() * 4]; AudioDiskstream::allocate_working_buffers(); /* default short fade = 15ms */ diff --git a/libs/ardour/session_timefx.cc b/libs/ardour/session_timefx.cc index 7eec1e578b..45733c75ae 100644 --- a/libs/ardour/session_timefx.cc +++ b/libs/ardour/session_timefx.cc @@ -96,7 +96,6 @@ Session::tempoize_region (TimeStretchRequest& tsr) for (uint32_t i = 0; i < sources.size(); ++i) { gain_t gain_buffer[bufsize]; Sample buffer[bufsize]; - char workbuf[bufsize*4]; jack_nframes_t pos = 0; jack_nframes_t this_read = 0; @@ -110,7 +109,7 @@ Session::tempoize_region (TimeStretchRequest& tsr) not the ones currently in use, in case it's already been subject to timefx. */ - if ((this_read = tsr.region->master_read_at (buffer, buffer, gain_buffer, workbuf, pos + tsr.region->position(), this_time)) != this_time) { + if ((this_read = tsr.region->master_read_at (buffer, buffer, gain_buffer, pos + tsr.region->position(), this_time)) != this_time) { error << string_compose (_("tempoize: error reading data from %1"), sources[i]->name()) << endmsg; goto out; } @@ -123,7 +122,7 @@ Session::tempoize_region (TimeStretchRequest& tsr) st.putSamples (buffer, this_read); while ((this_read = st.receiveSamples (buffer, bufsize)) > 0 && tsr.running) { - if (sources[i]->write (buffer, this_read, workbuf) != this_read) { + if (sources[i]->write (buffer, this_read) != this_read) { error << string_compose (_("error writing tempo-adjusted data to %1"), sources[i]->name()) << endmsg; goto out; } @@ -135,7 +134,7 @@ Session::tempoize_region (TimeStretchRequest& tsr) } while (tsr.running && (this_read = st.receiveSamples (buffer, bufsize)) > 0) { - if (sources[i]->write (buffer, this_read, workbuf) != this_read) { + if (sources[i]->write (buffer, this_read) != this_read) { error << string_compose (_("error writing tempo-adjusted data to %1"), sources[i]->name()) << endmsg; goto out; } diff --git a/libs/ardour/sndfilesource.cc b/libs/ardour/sndfilesource.cc index 5936f62570..b487d4e3a3 100644 --- a/libs/ardour/sndfilesource.cc +++ b/libs/ardour/sndfilesource.cc @@ -292,7 +292,7 @@ SndFileSource::sample_rate () const } jack_nframes_t -SndFileSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt, char * workbuf) const +SndFileSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t cnt) const { int32_t nread; float *ptr; @@ -367,7 +367,7 @@ SndFileSource::read_unlocked (Sample *dst, jack_nframes_t start, jack_nframes_t } jack_nframes_t -SndFileSource::write_unlocked (Sample *data, jack_nframes_t cnt, char * workbuf) +SndFileSource::write_unlocked (Sample *data, jack_nframes_t cnt) { if (!writable()) { return 0; diff --git a/libs/ardour/track.cc b/libs/ardour/track.cc index dbd1a15401..1efd18ae22 100644 --- a/libs/ardour/track.cc +++ b/libs/ardour/track.cc @@ -152,7 +152,7 @@ bool Track::can_record() { bool will_record = true; - for (int i = 0; i < _inputs.size() && will_record; i++) { + for (size_t i = 0; i < _inputs.size() && will_record; i++) { if (!_inputs[i]->connected()) will_record = false; } From 57f7f71ce3c1acae5a50e903d2dd472743df8043 Mon Sep 17 00:00:00 2001 From: Hans Fugal Date: Sat, 12 Aug 2006 21:49:20 +0000 Subject: [PATCH 2/2] r316@gandalf: fugalh | 2006-08-11 17:06:48 -0600 Reconstitution. Comiples, untested. git-svn-id: svn://localhost/ardour2/branches/undo@797 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/ardour_ui.cc | 1 + gtk2_ardour/audio_region_view.cc | 4 +- gtk2_ardour/automation_line.cc | 11 ++- gtk2_ardour/automation_time_axis.cc | 12 +-- gtk2_ardour/editor.cc | 6 +- gtk2_ardour/editor_audio_import.cc | 2 +- gtk2_ardour/editor_keyboard.cc | 2 +- gtk2_ardour/editor_markers.cc | 14 ++-- gtk2_ardour/editor_mouse.cc | 48 ++++++------ gtk2_ardour/editor_ops.cc | 76 +++++++++--------- gtk2_ardour/editor_tempodisplay.cc | 12 +-- gtk2_ardour/editor_timefx.cc | 2 +- gtk2_ardour/gain_automation_time_axis.cc | 2 +- gtk2_ardour/location_ui.cc | 6 +- gtk2_ardour/pan_automation_time_axis.cc | 2 +- gtk2_ardour/redirect_automation_time_axis.cc | 2 +- gtk2_ardour/region_gain_line.cc | 8 +- gtk2_ardour/route_time_axis.cc | 6 +- gtk2_ardour/route_ui.cc | 4 +- libs/ardour/ardour/automation_event.h | 2 + libs/ardour/ardour/curve.h | 2 + libs/ardour/ardour/location.h | 1 + libs/ardour/ardour/session.h | 11 +++ libs/ardour/audio_diskstream.cc | 2 +- libs/ardour/automation_event.cc | 4 + libs/ardour/curve.cc | 3 + libs/ardour/session.cc | 25 ++++++ libs/ardour/session_command.cc | 79 ++++++++++++++++--- libs/ardour/session_state.cc | 62 +++++++++++++++ libs/ardour/session_transport.cc | 2 +- libs/pbd/pbd/memento_command.h | 82 +++++++------------- libs/pbd/pbd/stateful.h | 3 + libs/pbd/undo.cc | 8 ++ 33 files changed, 335 insertions(+), 171 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 12c2d63b80..8a75396ed2 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -1488,6 +1488,7 @@ ARDOUR_UI::restore_state (string name) name = session->name(); } session->restore_state (name); + session->restore_history (name); } } diff --git a/gtk2_ardour/audio_region_view.cc b/gtk2_ardour/audio_region_view.cc index bdea3d39a2..915fa05750 100644 --- a/gtk2_ardour/audio_region_view.cc +++ b/gtk2_ardour/audio_region_view.cc @@ -906,13 +906,13 @@ AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev) 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)); + trackview.session().add_command (new MementoCommand(audio_region(), &before, &after)); } audio_region().envelope().add (fx, y); XMLNode &after = audio_region().envelope().get_state(); - trackview.session().add_command (new MementoCommand(audio_region().envelope(), before, after)); + trackview.session().add_command (new MementoCommand(audio_region().envelope(), &before, &after)); trackview.session().commit_reversible_command (); } diff --git a/gtk2_ardour/automation_line.cc b/gtk2_ardour/automation_line.cc index f3e30c4523..c0ba957af8 100644 --- a/gtk2_ardour/automation_line.cc +++ b/gtk2_ardour/automation_line.cc @@ -244,6 +244,9 @@ AutomationLine::AutomationLine (const string & name, TimeAxisView& tv, ArdourCan line->signal_event().connect (mem_fun (*this, &AutomationLine::event_handler)); alist.StateChanged.connect (mem_fun(*this, &AutomationLine::list_changed)); + + trackview.session().register_with_memento_command_factory(_id, this); + } AutomationLine::~AutomationLine () @@ -888,7 +891,7 @@ AutomationLine::start_drag (ControlPoint* cp, float fraction) } trackview.editor.current_session()->begin_reversible_command (str); - trackview.editor.current_session()->add_command (new MementoUndoCommand(*this, get_state())); + trackview.editor.current_session()->add_command (new MementoCommand(*this, &get_state(), 0)); first_drag_fraction = fraction; last_drag_fraction = fraction; @@ -937,7 +940,7 @@ AutomationLine::end_drag (ControlPoint* cp) update_pending = false; - trackview.editor.current_session()->add_command (new MementoRedoCommand(*this, get_state())); + trackview.editor.current_session()->add_command (new MementoCommand(*this, 0, &get_state())); trackview.editor.current_session()->commit_reversible_command (); trackview.editor.current_session()->set_dirty (); } @@ -1018,7 +1021,7 @@ AutomationLine::remove_point (ControlPoint& cp) alist.erase (mr.start, mr.end); - trackview.editor.current_session()->add_command(new MementoCommand(*this, before, get_state())); + trackview.editor.current_session()->add_command(new MementoCommand(*this, &before, &get_state())); trackview.editor.current_session()->commit_reversible_command (); trackview.editor.current_session()->set_dirty (); } @@ -1228,7 +1231,7 @@ AutomationLine::clear () /* parent must create command */ XMLNode &before = get_state(); alist.clear(); - trackview.editor.current_session()->add_command (new MementoCommand(*this, before, get_state())); + trackview.editor.current_session()->add_command (new MementoCommand(*this, &before, &get_state())); trackview.editor.current_session()->commit_reversible_command (); trackview.editor.current_session()->set_dirty (); } diff --git a/gtk2_ardour/automation_time_axis.cc b/gtk2_ardour/automation_time_axis.cc index 7025a11178..80ed2acd16 100644 --- a/gtk2_ardour/automation_time_axis.cc +++ b/gtk2_ardour/automation_time_axis.cc @@ -482,7 +482,7 @@ AutomationTimeAxisView::cut_copy_clear_one (AutomationLine& line, Selection& sel case Cut: if ((what_we_got = alist.cut (selection.time.front().start, selection.time.front().end)) != 0) { editor.get_cut_buffer().add (what_we_got); - _session.add_command(new MementoCommand(alist, before, alist.get_state())); + _session.add_command(new MementoCommand(alist, &before, &alist.get_state())); ret = true; } break; @@ -494,7 +494,7 @@ AutomationTimeAxisView::cut_copy_clear_one (AutomationLine& line, Selection& sel case Clear: if ((what_we_got = alist.cut (selection.time.front().start, selection.time.front().end)) != 0) { - _session.add_command(new MementoCommand(alist, before, alist.get_state())); + _session.add_command(new MementoCommand(alist, &before, &alist.get_state())); delete what_we_got; what_we_got = 0; ret = true; @@ -526,7 +526,7 @@ AutomationTimeAxisView::reset_objects_one (AutomationLine& line, PointSelection& { AutomationList& alist (line.the_list()); - _session.add_command (new MementoUndoCommand(alist, alist.get_state())); + _session.add_command (new MementoCommand(alist, &alist.get_state(), 0)); for (PointSelection::iterator i = selection.begin(); i != selection.end(); ++i) { @@ -569,7 +569,7 @@ AutomationTimeAxisView::cut_copy_clear_objects_one (AutomationLine& line, PointS case Cut: if ((what_we_got = alist.cut ((*i).start, (*i).end)) != 0) { editor.get_cut_buffer().add (what_we_got); - _session.add_command (new MementoCommand(alist, before, alist.get_state())); + _session.add_command (new MementoCommand(alist, &before, &alist.get_state())); ret = true; } break; @@ -581,7 +581,7 @@ AutomationTimeAxisView::cut_copy_clear_objects_one (AutomationLine& line, PointS case Clear: if ((what_we_got = alist.cut ((*i).start, (*i).end)) != 0) { - _session.add_command (new MementoCommand(alist, before, alist.get_state())); + _session.add_command (new MementoCommand(alist, &before, &alist.get_state())); delete what_we_got; what_we_got = 0; ret = true; @@ -640,7 +640,7 @@ AutomationTimeAxisView::paste_one (AutomationLine& line, jack_nframes_t pos, flo XMLNode &before = alist.get_state(); alist.paste (copy, pos, times); - _session.add_command (new MementoCommand(alist, before, alist.get_state())); + _session.add_command (new MementoCommand(alist, &before, &alist.get_state())); return true; } diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 513251085c..74822fc7ea 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -705,6 +705,7 @@ Editor::Editor (AudioEngine& eng) ControlProtocol::ScrollTimeline.connect (mem_fun (*this, &Editor::control_scroll)); constructed = true; instant_save (); + } Editor::~Editor() @@ -1339,6 +1340,9 @@ Editor::connect_to_session (Session *t) no_route_list_redisplay = false; redisplay_route_list (); } + + /* register for undo history */ + session->register_with_memento_command_factory(_id, this); } void @@ -2888,7 +2892,7 @@ void Editor::commit_reversible_command () { if (session) { - session->commit_reversible_command (new MementoCommand(*this, *before, get_state())); + session->commit_reversible_command (new MementoCommand(*this, before, &get_state())); } } diff --git a/gtk2_ardour/editor_audio_import.cc b/gtk2_ardour/editor_audio_import.cc index 7524f9605c..8887135374 100644 --- a/gtk2_ardour/editor_audio_import.cc +++ b/gtk2_ardour/editor_audio_import.cc @@ -323,7 +323,7 @@ Editor::finish_bringing_in_audio (AudioRegion& region, uint32_t in_chans, uint32 begin_reversible_command (_("insert sndfile")); XMLNode &before = playlist->get_state(); playlist->add_region (*copy, pos); - session->add_command (new MementoCommand(*playlist, before, playlist->get_state())); + session->add_command (new MementoCommand(*playlist, &before, &playlist->get_state())); commit_reversible_command (); pos += region.length(); diff --git a/gtk2_ardour/editor_keyboard.cc b/gtk2_ardour/editor_keyboard.cc index f48d860d15..95289c7f5a 100644 --- a/gtk2_ardour/editor_keyboard.cc +++ b/gtk2_ardour/editor_keyboard.cc @@ -108,7 +108,7 @@ Editor::kbd_mute_unmute_region () 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)); + session->add_command (new MementoCommand(*(entered_regionview->region().playlist()), &before, &after)); commit_reversible_command(); } } diff --git a/gtk2_ardour/editor_markers.cc b/gtk2_ardour/editor_markers.cc index ccc1415888..40f00c2e10 100644 --- a/gtk2_ardour/editor_markers.cc +++ b/gtk2_ardour/editor_markers.cc @@ -294,7 +294,7 @@ Editor::mouse_add_new_marker (jack_nframes_t where) XMLNode &before = session->locations()->get_state(); session->locations()->add (location, true); XMLNode &after = session->locations()->get_state(); - session->add_command (new MementoCommand(*(session->locations()), before, after)); + session->add_command (new MementoCommand(*(session->locations()), &before, &after)); session->commit_reversible_command (); } } @@ -334,7 +334,7 @@ Editor::really_remove_marker (Location* loc) XMLNode &before = session->locations()->get_state(); session->locations()->remove (loc); XMLNode &after = session->locations()->get_state(); - session->add_command (new MementoCommand(*(session->locations()), before, after)); + session->add_command (new MementoCommand(*(session->locations()), &before, &after)); session->commit_reversible_command (); return FALSE; } @@ -847,7 +847,7 @@ Editor::marker_menu_rename () loc->set_name (txt); XMLNode &after = session->locations()->get_state(); - session->add_command (new MementoCommand(*(session->locations()), before, after)); + session->add_command (new MementoCommand(*(session->locations()), &before, &after)); commit_reversible_command (); } @@ -876,14 +876,14 @@ Editor::new_transport_marker_menu_set_loop () session->locations()->add (loc, true); session->set_auto_loop_location (loc); XMLNode &after = session->locations()->get_state(); - session->add_command (new MementoCommand(*(session->locations()), before, after)); + session->add_command (new MementoCommand(*(session->locations()), &before, &after)); } else { XMLNode &before = tll->get_state(); tll->set_hidden (false, this); tll->set (temp_location->start(), temp_location->end()); XMLNode &after = tll->get_state(); - session->add_command (new MementoCommand(*tll, before, after)); + session->add_command (new MementoCommand(*tll, &before, &after)); } commit_reversible_command (); @@ -904,13 +904,13 @@ Editor::new_transport_marker_menu_set_punch () session->locations()->add (tpl, true); session->set_auto_punch_location (tpl); XMLNode &after = session->locations()->get_state(); - session->add_command (new MementoCommand(*(session->locations()), before, after)); + session->add_command (new MementoCommand(*(session->locations()), &before, &after)); } else { XMLNode &before = tpl->get_state(); tpl->set_hidden(false, this); tpl->set(temp_location->start(), temp_location->end()); XMLNode &after = tpl->get_state(); - session->add_command (new MementoCommand(*tpl, before, after)); + session->add_command (new MementoCommand(*tpl, &before, &after)); } commit_reversible_command (); diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index 18c7f0727d..db42e0c414 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -1824,8 +1824,8 @@ Editor::fade_in_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* even XMLNode &after = arv->audio_region().get_state(); session->add_command(new MementoCommand(arv->audio_region(), - before, - after)); + &before, + &after)); commit_reversible_command (); fade_in_drag_motion_callback (item, event); } @@ -1920,7 +1920,7 @@ Editor::fade_out_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* eve arv->audio_region().set_fade_out_length (fade_length); XMLNode &after = arv->region().get_state(); - session->add_command(new MementoCommand(arv->region(), before, after)); + session->add_command(new MementoCommand(arv->region(), &before, &after)); commit_reversible_command (); fade_out_drag_motion_callback (item, event); @@ -2175,7 +2175,7 @@ Editor::marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event } XMLNode &after = session->locations()->get_state(); - session->add_command(new MementoCommand(*(session->locations()), before, after)); + session->add_command(new MementoCommand(*(session->locations()), &before, &after)); commit_reversible_command (); marker_drag_line->hide(); @@ -2292,7 +2292,7 @@ Editor::meter_marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* XMLNode &before = map.get_state(); map.add_meter (marker->meter(), when); XMLNode &after = map.get_state(); - session->add_command(new MementoCommand(map, before, after)); + session->add_command(new MementoCommand(map, &before, &after)); commit_reversible_command (); // delete the dummy marker we used for visual representation of copying. @@ -2303,7 +2303,7 @@ Editor::meter_marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* XMLNode &before = map.get_state(); map.move_meter (marker->meter(), when); XMLNode &after = map.get_state(); - session->add_command(new MementoCommand(map, before, after)); + session->add_command(new MementoCommand(map, &before, &after)); commit_reversible_command (); } } @@ -2424,7 +2424,7 @@ Editor::tempo_marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* XMLNode &before = map.get_state(); map.add_tempo (marker->tempo(), when); XMLNode &after = map.get_state(); - session->add_command (new MementoCommand(map, before, after)); + session->add_command (new MementoCommand(map, &before, &after)); commit_reversible_command (); // delete the dummy marker we used for visual representation of copying. @@ -2435,7 +2435,7 @@ Editor::tempo_marker_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* XMLNode &before = map.get_state(); map.move_tempo (marker->tempo(), when); XMLNode &after = map.get_state(); - session->add_command (new MementoCommand(map, before, after)); + session->add_command (new MementoCommand(map, &before, &after)); commit_reversible_command (); } } @@ -2799,7 +2799,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) insert_result = affected_playlists.insert (to_playlist); if (insert_result.second) { - session->add_command (new MementoUndoCommand(*to_playlist, to_playlist->get_state())); + session->add_command (new MementoCommand(*to_playlist, &to_playlist->get_state(), 0)); } latest_regionview = 0; @@ -3235,7 +3235,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) insert_result = motion_frozen_playlists.insert (pl); if (insert_result.second) { pl->freeze(); - session->add_command(new MementoUndoCommand(*pl, pl->get_state())); + session->add_command(new MementoCommand(*pl, &pl->get_state(), 0)); } } } @@ -3363,7 +3363,7 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event insert_result = motion_frozen_playlists.insert(to_playlist); if (insert_result.second) { to_playlist->freeze(); - session->add_command(new MementoUndoCommand(*to_playlist, to_playlist->get_state())); + session->add_command(new MementoCommand(*to_playlist, &to_playlist->get_state(), 0)); } } @@ -3445,7 +3445,7 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event out: for (set::iterator p = motion_frozen_playlists.begin(); p != motion_frozen_playlists.end(); ++p) { (*p)->thaw (); - session->add_command (new MementoRedoCommand(*(*p), (*p)->get_state())); + session->add_command (new MementoCommand(*(*p), 0, & (*p)->get_state())); } motion_frozen_playlists.clear (); @@ -3640,10 +3640,10 @@ Editor::start_selection_grab (ArdourCanvas::Item* item, GdkEvent* event) Playlist* playlist = clicked_trackview->playlist(); - before = &(playlist->get_state()); + XMLNode *before = &(playlist->get_state()); clicked_trackview->playlist()->add_region (*region, selection->time[clicked_selection].start); - XMLNode &after = playlist->get_state(); - session->add_command(new MementoCommand(*playlist, *before, after)); + XMLNode *after = &(playlist->get_state()); + session->add_command(new MementoCommand(*playlist, before, after)); commit_reversible_command (); @@ -4010,7 +4010,7 @@ Editor::trim_motion_callback (ArdourCanvas::Item* item, GdkEvent* event) Playlist * pl = (*i)->region().playlist(); insert_result = motion_frozen_playlists.insert (pl); if (insert_result.second) { - session->add_command(new MementoUndoCommand(*pl, pl->get_state())); + session->add_command(new MementoCommand(*pl, &pl->get_state(), 0)); } } } @@ -4200,7 +4200,7 @@ Editor::trim_finished_callback (ArdourCanvas::Item* item, GdkEvent* event) for (set::iterator p = motion_frozen_playlists.begin(); p != motion_frozen_playlists.end(); ++p) { //(*p)->thaw (); - session->add_command (new MementoRedoCommand(*(*p), (*p)->get_state())); + session->add_command (new MementoCommand(*(*p), 0, &(*p)->get_state())); } motion_frozen_playlists.clear (); @@ -4238,7 +4238,7 @@ Editor::point_trim (GdkEvent* event) XMLNode &before = pl->get_state(); (*i)->region().trim_front (new_bound, this); XMLNode &after = pl->get_state(); - session->add_command(new MementoCommand(*pl, before, after)); + session->add_command(new MementoCommand(*pl, &before, &after)); } } @@ -4249,7 +4249,7 @@ Editor::point_trim (GdkEvent* event) XMLNode &before = pl->get_state(); rv->region().trim_front (new_bound, this); XMLNode &after = pl->get_state(); - session->add_command(new MementoCommand(*pl, before, after)); + session->add_command(new MementoCommand(*pl, &before, &after)); } } @@ -4269,7 +4269,7 @@ Editor::point_trim (GdkEvent* event) XMLNode &before = pl->get_state(); (*i)->region().trim_end (new_bound, this); XMLNode &after = pl->get_state(); - session->add_command(new MementoCommand(*pl, before, after)); + session->add_command(new MementoCommand(*pl, &before, &after)); } } @@ -4280,7 +4280,7 @@ Editor::point_trim (GdkEvent* event) XMLNode &before = pl->get_state(); rv->region().trim_end (new_bound, this); XMLNode &after = pl->get_state(); - session->add_command (new MementoCommand(*pl, before, after)); + session->add_command (new MementoCommand(*pl, &before, &after)); } } @@ -4303,7 +4303,7 @@ Editor::thaw_region_after_trim (RegionView& rv) region.thaw (_("trimmed region")); XMLNode &after = region.playlist()->get_state(); - session->add_command (new MementoRedoCommand(*(region.playlist()), after)); + session->add_command (new MementoCommand(*(region.playlist()), 0, &after)); AudioRegionView* arv = dynamic_cast(&rv); if (arv) @@ -4448,7 +4448,7 @@ Editor::end_range_markerbar_op (ArdourCanvas::Item* item, GdkEvent* event) newloc = new Location(temp_location->start(), temp_location->end(), "unnamed", Location::IsRangeMarker); session->locations()->add (newloc, true); XMLNode &after = session->locations()->get_state(); - session->add_command(new MementoCommand(*(session->locations()), before, after)); + session->add_command(new MementoCommand(*(session->locations()), &before, &after)); commit_reversible_command (); range_bar_drag_rect->hide(); @@ -4831,7 +4831,7 @@ Editor::mouse_brush_insert_region (RegionView* rv, jack_nframes_t pos) XMLNode &before = playlist->get_state(); playlist->add_region (*(new AudioRegion (arv->audio_region())), (jack_nframes_t) (pos * speed)); XMLNode &after = playlist->get_state(); - session->add_command(new MementoCommand(*playlist, before, after)); + session->add_command(new MementoCommand(*playlist, &before, &after)); // playlist is frozen, so we have to update manually diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 1e5f336e52..55a863c6e3 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -213,7 +213,7 @@ Editor::split_regions_at (jack_nframes_t where, RegionSelection& regions) XMLNode &before = pl->get_state(); pl->split_region ((*a)->region(), where); XMLNode &after = pl->get_state(); - session->add_command(new MementoCommand(*pl, before, after)); + session->add_command(new MementoCommand(*pl, &before, &after)); } a = tmp; @@ -236,7 +236,7 @@ Editor::remove_clicked_region () XMLNode &before = playlist->get_state(); playlist->remove_region (&clicked_regionview->region()); XMLNode &after = playlist->get_state(); - session->add_command(new MementoCommand(*playlist, before, after)); + session->add_command(new MementoCommand(*playlist, &before, &after)); commit_reversible_command (); } @@ -412,7 +412,7 @@ Editor::nudge_forward (bool next) 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)); + session->add_command (new MementoCommand(*(r.playlist()), &before, &after)); } commit_reversible_command (); @@ -452,7 +452,7 @@ Editor::nudge_backward (bool next) r.set_position (0, this); } XMLNode &after = r.playlist()->get_state(); - session->add_command(new MementoCommand(*(r.playlist()), before, after)); + session->add_command(new MementoCommand(*(r.playlist()), &before, &after)); } commit_reversible_command (); @@ -488,7 +488,7 @@ Editor::nudge_forward_capture_offset () 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)); + session->add_command(new MementoCommand(*(r.playlist()), &before, &after)); } commit_reversible_command (); @@ -520,7 +520,7 @@ Editor::nudge_backward_capture_offset () r.set_position (0, this); } XMLNode &after = r.playlist()->get_state(); - session->add_command(new MementoCommand(*(r.playlist()), before, after)); + session->add_command(new MementoCommand(*(r.playlist()), &before, &after)); } commit_reversible_command (); @@ -1300,7 +1300,7 @@ Editor::add_location_from_selection () XMLNode &before = session->locations()->get_state(); session->locations()->add (location, true); XMLNode &after = session->locations()->get_state(); - session->add_command(new MementoCommand(*(session->locations()), before, after)); + session->add_command(new MementoCommand(*(session->locations()), &before, &after)); session->commit_reversible_command (); } @@ -1314,7 +1314,7 @@ Editor::add_location_from_playhead_cursor () XMLNode &before = session->locations()->get_state(); session->locations()->add (location, true); XMLNode &after = session->locations()->get_state(); - session->add_command(new MementoCommand(*(session->locations()), before, after)); + session->add_command(new MementoCommand(*(session->locations()), &before, &after)); session->commit_reversible_command (); } @@ -1333,7 +1333,7 @@ Editor::add_location_from_audio_region () XMLNode &before = session->locations()->get_state(); session->locations()->add (location, true); XMLNode &after = session->locations()->get_state(); - session->add_command(new MementoCommand(*(session->locations()), before, after)); + session->add_command(new MementoCommand(*(session->locations()), &before, &after)); session->commit_reversible_command (); } @@ -1752,7 +1752,7 @@ Editor::clear_markers () XMLNode &before = session->locations()->get_state(); session->locations()->clear_markers (); XMLNode &after = session->locations()->get_state(); - session->add_command(new MementoCommand(*(session->locations()), before, after)); + session->add_command(new MementoCommand(*(session->locations()), &before, &after)); session->commit_reversible_command (); } } @@ -1773,7 +1773,7 @@ Editor::clear_ranges () if (punchloc) session->locations()->add (punchloc); XMLNode &after = session->locations()->get_state(); - session->add_command(new MementoCommand(*(session->locations()), before, after)); + session->add_command(new MementoCommand(*(session->locations()), &before, &after)); session->commit_reversible_command (); } } @@ -1785,7 +1785,7 @@ Editor::clear_locations () XMLNode &before = session->locations()->get_state(); session->locations()->clear (); XMLNode &after = session->locations()->get_state(); - session->add_command(new MementoCommand(*(session->locations()), before, after)); + session->add_command(new MementoCommand(*(session->locations()), &before, &after)); session->commit_reversible_command (); session->locations()->clear (); } @@ -1835,7 +1835,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); - session->add_command(new MementoCommand(*playlist, before, playlist->get_state())); + session->add_command(new MementoCommand(*playlist, &before, &playlist->get_state())); commit_reversible_command (); } @@ -1871,7 +1871,7 @@ Editor::insert_region_list_selection (float times) begin_reversible_command (_("insert region")); XMLNode &before = playlist->get_state(); playlist->add_region (*(createRegion (*region)), edit_cursor->current_frame, times); - session->add_command(new MementoCommand(*playlist, before, playlist->get_state())); + session->add_command(new MementoCommand(*playlist, &before, &playlist->get_state())); commit_reversible_command (); } @@ -2308,7 +2308,7 @@ Editor::separate_region_from_selection () } if (doing_undo) - session->add_command(new MementoCommand(*playlist, *before, playlist->get_state())); + session->add_command(new MementoCommand(*playlist, before, &playlist->get_state())); } } } @@ -2359,7 +2359,7 @@ Editor::separate_regions_using_location (Location& loc) playlist->partition ((jack_nframes_t)(loc.start() * speed), (jack_nframes_t)(loc.end() * speed), true); if (doing_undo) - session->add_command(new MementoCommand(*playlist, *before, playlist->get_state())); + session->add_command(new MementoCommand(*playlist, before, &playlist->get_state())); } } } @@ -2433,7 +2433,7 @@ Editor::crop_region_to_selection () XMLNode &before = (*i)->get_state(); region->trim_to (start, cnt, this); XMLNode &after = (*i)->get_state(); - session->add_command (new MementoCommand(*(*i), before, after)); + session->add_command (new MementoCommand(*(*i), &before, &after)); } commit_reversible_command (); @@ -2476,7 +2476,7 @@ Editor::region_fill_track () XMLNode &before = pl->get_state(); pl->add_region (*(new AudioRegion (*ar)), ar->last_frame(), times); - session->add_command (new MementoCommand(*pl, before, pl->get_state())); + session->add_command (new MementoCommand(*pl, &before, &pl->get_state())); } commit_reversible_command (); @@ -2526,7 +2526,7 @@ Editor::region_fill_selection () XMLNode &before = playlist->get_state(); playlist->add_region (*(createRegion (*region)), start, times); - session->add_command (new MementoCommand(*playlist, before, playlist->get_state())); + session->add_command (new MementoCommand(*playlist, &before, &playlist->get_state())); } commit_reversible_command (); @@ -2544,7 +2544,7 @@ Editor::set_a_regions_sync_position (Region& region, jack_nframes_t 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)); + session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); commit_reversible_command (); } @@ -2565,7 +2565,7 @@ Editor::set_region_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)); + session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); commit_reversible_command (); } @@ -2578,7 +2578,7 @@ Editor::remove_region_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)); + session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); commit_reversible_command (); } } @@ -2594,7 +2594,7 @@ Editor::naturalize () 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)); + session->add_command (new MementoCommand((*i)->region(), &before, &after)); } commit_reversible_command (); } @@ -2669,7 +2669,7 @@ Editor::align_selection_relative (RegionPoint point, jack_nframes_t position) } XMLNode &after = region.playlist()->get_state(); - session->add_command(new MementoCommand(*(region.playlist()), before, after)); + session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); } @@ -2722,7 +2722,7 @@ Editor::align_region_internal (Region& region, RegionPoint point, jack_nframes_t } XMLNode &after = region.playlist()->get_state(); - session->add_command(new MementoCommand(*(region.playlist()), before, after)); + session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); } void @@ -2747,7 +2747,7 @@ Editor::trim_region_to_edit_cursor () 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)); + session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); commit_reversible_command (); } @@ -2773,7 +2773,7 @@ Editor::trim_region_from_edit_cursor () 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)); + session->add_command(new MementoCommand(*(region.playlist()), &before, &after)); commit_reversible_command (); } @@ -2888,7 +2888,7 @@ Editor::bounce_range_selection () XMLNode &before = playlist->get_state(); atv->audio_track()->bounce_range (start, cnt, itt); XMLNode &after = playlist->get_state(); - session->add_command (new MementoCommand (*playlist, before, after)); + session->add_command (new MementoCommand (*playlist, &before, &after)); } commit_reversible_command (); @@ -3006,7 +3006,7 @@ Editor::cut_copy_regions (CutCopyOp op) insert_result = freezelist.insert (pl); if (insert_result.second) { pl->freeze (); - session->add_command (new MementoUndoCommand(*pl, pl->get_state())); + session->add_command (new MementoCommand(*pl, &pl->get_state(), 0)); } } } @@ -3070,7 +3070,7 @@ Editor::cut_copy_regions (CutCopyOp op) for (set::iterator pl = freezelist.begin(); pl != freezelist.end(); ++pl) { (*pl)->thaw (); - session->add_command (new MementoRedoCommand(*(*pl), (*pl)->get_state())); + session->add_command (new MementoCommand(*(*pl), 0, &(*pl)->get_state())); } } @@ -3185,7 +3185,7 @@ Editor::paste_named_selection (float times) XMLNode &before = apl->get_state(); apl->paste (**chunk, edit_cursor->current_frame, times); - session->add_command(new MementoCommand(*apl, before, apl->get_state())); + session->add_command(new MementoCommand(*apl, &before, &apl->get_state())); if (tmp != ns->playlists.end()) { chunk = tmp; @@ -3216,7 +3216,7 @@ Editor::duplicate_some_regions (RegionSelection& regions, float times) playlist = (*i)->region().playlist(); XMLNode &before = playlist->get_state(); playlist->duplicate (r, r.last_frame(), times); - session->add_command(new MementoCommand(*playlist, before, playlist->get_state())); + session->add_command(new MementoCommand(*playlist, &before, &playlist->get_state())); c.disconnect (); @@ -3257,7 +3257,7 @@ Editor::duplicate_selection (float times) XMLNode &before = playlist->get_state(); playlist->duplicate (**ri, selection->time[clicked_selection].end, times); XMLNode &after = playlist->get_state(); - session->add_command (new MementoCommand(*playlist, before, after)); + session->add_command (new MementoCommand(*playlist, &before, &after)); ++ri; if (ri == new_regions.end()) { @@ -3308,7 +3308,7 @@ Editor::clear_playlist (Playlist& playlist) XMLNode &before = playlist.get_state(); playlist.clear (); XMLNode &after = playlist.get_state(); - session->add_command (new MementoCommand(playlist, before, after)); + session->add_command (new MementoCommand(playlist, &before, &after)); commit_reversible_command (); } @@ -3345,7 +3345,7 @@ Editor::nudge_track (bool use_edit_cursor, bool forwards) XMLNode &before = playlist->get_state(); playlist->nudge_after (start, distance, forwards); XMLNode &after = playlist->get_state(); - session->add_command (new MementoCommand(*playlist, before, after)); + session->add_command (new MementoCommand(*playlist, &before, &after)); } commit_reversible_command (); @@ -3401,7 +3401,7 @@ Editor::normalize_region () 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())); + session->add_command (new MementoCommand(arv->region(), &before, &arv->region().get_state())); } commit_reversible_command (); @@ -3428,7 +3428,7 @@ Editor::denormalize_region () 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())); + session->add_command (new MementoCommand(arv->region(), &before, &arv->region().get_state())); } commit_reversible_command (); @@ -3475,7 +3475,7 @@ Editor::apply_filter (AudioFilter& filter, string command) XMLNode &before = playlist->get_state(); playlist->replace_region (arv->region(), *(filter.results.front()), arv->region().position()); XMLNode &after = playlist->get_state(); - session->add_command(new MementoCommand(*playlist, before, after)); + session->add_command(new MementoCommand(*playlist, &before, &after)); } else { goto out; } diff --git a/gtk2_ardour/editor_tempodisplay.cc b/gtk2_ardour/editor_tempodisplay.cc index 9f7fe7cf09..91710c5fc9 100644 --- a/gtk2_ardour/editor_tempodisplay.cc +++ b/gtk2_ardour/editor_tempodisplay.cc @@ -277,7 +277,7 @@ Editor::mouse_add_new_tempo_event (jack_nframes_t frame) XMLNode &before = map.get_state(); map.add_tempo (Tempo (bpm), requested); XMLNode &after = map.get_state(); - session->add_command(new MementoCommand(map, before, after)); + session->add_command(new MementoCommand(map, &before, &after)); commit_reversible_command (); map.dump (cerr); @@ -317,7 +317,7 @@ Editor::mouse_add_new_meter_event (jack_nframes_t frame) begin_reversible_command (_("add meter mark")); XMLNode &before = map.get_state(); map.add_meter (Meter (bpb, note_type), requested); - session->add_command(new MementoCommand(map, before, map.get_state())); + session->add_command(new MementoCommand(map, &before, &map.get_state())); commit_reversible_command (); map.dump (cerr); @@ -369,7 +369,7 @@ Editor::edit_meter_section (MeterSection* section) XMLNode &before = session->tempo_map().get_state(); session->tempo_map().replace_meter (*section, Meter (bpb, note_type)); XMLNode &after = session->tempo_map().get_state(); - session->add_command(new MementoCommand(session->tempo_map(), before, after)); + session->add_command(new MementoCommand(session->tempo_map(), &before, &after)); commit_reversible_command (); } @@ -399,7 +399,7 @@ Editor::edit_tempo_section (TempoSection* section) session->tempo_map().replace_tempo (*section, Tempo (bpm)); session->tempo_map().move_tempo (*section, when); XMLNode &after = session->tempo_map().get_state(); - session->add_command (new MementoCommand(session->tempo_map(), before, after)); + session->add_command (new MementoCommand(session->tempo_map(), &before, &after)); commit_reversible_command (); } @@ -448,7 +448,7 @@ Editor::real_remove_tempo_marker (TempoSection *section) XMLNode &before = session->tempo_map().get_state(); session->tempo_map().remove_tempo (*section); XMLNode &after = session->tempo_map().get_state(); - session->add_command(new MementoCommand(session->tempo_map(), before, after)); + session->add_command(new MementoCommand(session->tempo_map(), &before, &after)); commit_reversible_command (); return FALSE; @@ -482,7 +482,7 @@ Editor::real_remove_meter_marker (MeterSection *section) XMLNode &before = session->tempo_map().get_state(); session->tempo_map().remove_meter (*section); XMLNode &after = session->tempo_map().get_state(); - session->add_command(new MementoCommand(session->tempo_map(), before, after)); + session->add_command(new MementoCommand(session->tempo_map(), &before, &after)); commit_reversible_command (); return FALSE; } diff --git a/gtk2_ardour/editor_timefx.cc b/gtk2_ardour/editor_timefx.cc index 3fe0023d07..a3288ea8d0 100644 --- a/gtk2_ardour/editor_timefx.cc +++ b/gtk2_ardour/editor_timefx.cc @@ -210,7 +210,7 @@ Editor::do_timestretch (TimeStretchDialog& dialog) XMLNode &before = playlist->get_state(); playlist->replace_region (region, *new_region, region.position()); XMLNode &after = playlist->get_state(); - session->add_command (new MementoCommand(*playlist, before, after)); + session->add_command (new MementoCommand(*playlist, &before, &after)); i = tmp; } diff --git a/gtk2_ardour/gain_automation_time_axis.cc b/gtk2_ardour/gain_automation_time_axis.cc index c86c1390f3..47657e3292 100644 --- a/gtk2_ardour/gain_automation_time_axis.cc +++ b/gtk2_ardour/gain_automation_time_axis.cc @@ -67,7 +67,7 @@ GainAutomationTimeAxisView::add_automation_event (ArdourCanvas::Item* item, GdkE XMLNode &before = curve.get_state(); curve.add (when, y); XMLNode &after = curve.get_state(); - _session.add_command(new MementoCommand(curve, before, after)); + _session.add_command(new MementoCommand(curve, &before, &after)); _session.commit_reversible_command (); _session.set_dirty (); } diff --git a/gtk2_ardour/location_ui.cc b/gtk2_ardour/location_ui.cc index deb4c1da36..12e7079de2 100644 --- a/gtk2_ardour/location_ui.cc +++ b/gtk2_ardour/location_ui.cc @@ -658,7 +658,7 @@ gint LocationUI::do_location_remove (ARDOUR::Location *loc) XMLNode &before = session->locations()->get_state(); session->locations()->remove (loc); XMLNode &after = session->locations()->get_state(); - session->add_command(new MementoCommand(*(session->locations()), before, after)); + session->add_command(new MementoCommand(*(session->locations()), &before, &after)); session->commit_reversible_command (); return FALSE; @@ -777,7 +777,7 @@ LocationUI::add_new_location() XMLNode &before = session->locations()->get_state(); session->locations()->add (location, true); XMLNode &after = session->locations()->get_state(); - session->add_command (new MementoCommand(*(session->locations()), before, after)); + session->add_command (new MementoCommand(*(session->locations()), &before, &after)); session->commit_reversible_command (); } @@ -794,7 +794,7 @@ LocationUI::add_new_range() XMLNode &before = session->locations()->get_state(); session->locations()->add (location, true); XMLNode &after = session->locations()->get_state(); - session->add_command (new MementoCommand(*(session->locations()), before, after)); + session->add_command (new MementoCommand(*(session->locations()), &before, &after)); session->commit_reversible_command (); } } diff --git a/gtk2_ardour/pan_automation_time_axis.cc b/gtk2_ardour/pan_automation_time_axis.cc index ec884151b5..bbd4b3b06c 100644 --- a/gtk2_ardour/pan_automation_time_axis.cc +++ b/gtk2_ardour/pan_automation_time_axis.cc @@ -92,7 +92,7 @@ PanAutomationTimeAxisView::add_automation_event (ArdourCanvas::Item* item, GdkEv XMLNode &before = alist.get_state(); alist.add (when, y); XMLNode &after = alist.get_state(); - _session.add_command(new MementoCommand(alist, before, after)); + _session.add_command(new MementoCommand(alist, &before, &after)); _session.commit_reversible_command (); _session.set_dirty (); } diff --git a/gtk2_ardour/redirect_automation_time_axis.cc b/gtk2_ardour/redirect_automation_time_axis.cc index e527fd1d5e..f1e8eae9eb 100644 --- a/gtk2_ardour/redirect_automation_time_axis.cc +++ b/gtk2_ardour/redirect_automation_time_axis.cc @@ -102,7 +102,7 @@ RedirectAutomationTimeAxisView::add_automation_event (ArdourCanvas::Item* item, XMLNode &before = alist.get_state(); alist.add (when, y); XMLNode &after = alist.get_state(); - _session.add_command(new MementoCommand(alist, before, after)); + _session.add_command(new MementoCommand(alist, &before, &after)); _session.commit_reversible_command (); _session.set_dirty (); } diff --git a/gtk2_ardour/region_gain_line.cc b/gtk2_ardour/region_gain_line.cc index 0a4a3d29ea..e2b1d6c826 100644 --- a/gtk2_ardour/region_gain_line.cc +++ b/gtk2_ardour/region_gain_line.cc @@ -48,7 +48,7 @@ AudioRegionGainLine::start_drag (ControlPoint* cp, float fraction) { AutomationLine::start_drag(cp,fraction); if (!rv.audio_region().envelope_active()) { - trackview.session().add_command(new MementoUndoCommand(rv.audio_region(), rv.audio_region().get_state())); + trackview.session().add_command(new MementoCommand(rv.audio_region(), &rv.audio_region().get_state(), 0)); rv.audio_region().set_envelope_active(false); } } @@ -68,12 +68,12 @@ AudioRegionGainLine::remove_point (ControlPoint& cp) 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)); + trackview.session().add_command(new MementoCommand(rv.audio_region(), &before, &after)); } alist.erase (mr.start, mr.end); - trackview.editor.current_session()->add_command (new MementoCommand(*this, before, get_state())); + trackview.editor.current_session()->add_command (new MementoCommand(*this, &before, &get_state())); trackview.editor.current_session()->commit_reversible_command (); trackview.editor.current_session()->set_dirty (); } @@ -83,7 +83,7 @@ AudioRegionGainLine::end_drag (ControlPoint* cp) { if (!rv.audio_region().envelope_active()) { rv.audio_region().set_envelope_active(true); - trackview.session().add_command(new MementoRedoCommand(rv.audio_region(), rv.audio_region().get_state())); + trackview.session().add_command(new MementoCommand(rv.audio_region(), 0, &rv.audio_region().get_state())); } AutomationLine::end_drag(cp); } diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index 82d5b53cba..0d7405e4f6 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -1056,7 +1056,7 @@ RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op) case Cut: if ((what_we_got = playlist->cut (time)) != 0) { editor.get_cut_buffer().add (what_we_got); - _session.add_command( new MementoCommand(*playlist, before, playlist->get_state())); + _session.add_command( new MementoCommand(*playlist, &before, &playlist->get_state())); ret = true; } break; @@ -1068,7 +1068,7 @@ RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op) case Clear: if ((what_we_got = playlist->cut (time)) != 0) { - _session.add_command( new MementoCommand(*playlist, before, playlist->get_state())); + _session.add_command( new MementoCommand(*playlist, &before, &playlist->get_state())); what_we_got->unref (); ret = true; } @@ -1099,7 +1099,7 @@ RouteTimeAxisView::paste (jack_nframes_t pos, float times, Selection& selection, XMLNode &before = playlist->get_state(); playlist->paste (**p, pos, times); - _session.add_command( new MementoCommand(*playlist, before, playlist->get_state())); + _session.add_command( new MementoCommand(*playlist, &before, &playlist->get_state())); return true; } diff --git a/gtk2_ardour/route_ui.cc b/gtk2_ardour/route_ui.cc index 863e73d33e..998385f66b 100644 --- a/gtk2_ardour/route_ui.cc +++ b/gtk2_ardour/route_ui.cc @@ -575,7 +575,7 @@ RouteUI::reversibly_apply_route_boolean (string name, void (Route::*func)(bool, XMLNode &before = _route->get_state(); bind(mem_fun(*_route, func), yn, arg)(); XMLNode &after = _route->get_state(); - _session.add_command (new MementoCommand(*_route, before, after)); + _session.add_command (new MementoCommand(*_route, &before, &after)); _session.commit_reversible_command (); } @@ -586,7 +586,7 @@ RouteUI::reversibly_apply_audio_track_boolean (string name, void (AudioTrack::*f XMLNode &before = audio_track()->get_state(); bind (mem_fun (*audio_track(), func), yn, arg)(); XMLNode &after = audio_track()->get_state(); - _session.add_command (new MementoCommand(*audio_track(), before, after)); + _session.add_command (new MementoCommand(*audio_track(), &before, &after)); _session.commit_reversible_command (); } diff --git a/libs/ardour/ardour/automation_event.h b/libs/ardour/ardour/automation_event.h index 5864de73c6..dad94161d0 100644 --- a/libs/ardour/ardour/automation_event.h +++ b/libs/ardour/ardour/automation_event.h @@ -183,6 +183,8 @@ class AutomationList : public StateManager, public Stateful } }; + static sigc::signal AutomationListCreated; + protected: PBD::ID _id; struct State : public ARDOUR::StateManager::State { diff --git a/libs/ardour/ardour/curve.h b/libs/ardour/ardour/curve.h index 7f8a43cfe1..7ba6b5fa6c 100644 --- a/libs/ardour/ardour/curve.h +++ b/libs/ardour/ardour/curve.h @@ -59,6 +59,8 @@ class Curve : public AutomationList AutomationEventList::iterator closest_control_point_after (double xval); void solve (); + + static sigc::signal CurveCreated; protected: ControlEvent* point_factory (double,double) const; diff --git a/libs/ardour/ardour/location.h b/libs/ardour/ardour/location.h index ff953d1d78..beae4a6e07 100644 --- a/libs/ardour/ardour/location.h +++ b/libs/ardour/ardour/location.h @@ -149,6 +149,7 @@ class Locations : public Stateful, public StateManager XMLNode& get_state (void); int set_state (const XMLNode&); PBD::ID id() { return _id; } + Location *get_location_by_id(PBD::ID); Location* auto_loop_location () const; Location* auto_punch_location () const; diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index e2b14eccfa..d067de4e68 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -302,6 +302,7 @@ class Session : public sigc::trackable, public Stateful template void foreach_route (T *obj, void (T::*func)(Route&, A), A arg); boost::shared_ptr route_by_name (string); + boost::shared_ptr route_by_id (PBD::ID); boost::shared_ptr route_by_remote_id (uint32_t id); bool route_name_unique (string) const; @@ -478,6 +479,7 @@ class Session : public sigc::trackable, public Stateful int restore_state (string snapshot_name); int save_template (string template_name); int save_history (string snapshot_name = ""); + int restore_history (string snapshot_name); static int rename_template (string old_name, string new_name); @@ -713,6 +715,10 @@ class Session : public sigc::trackable, public Stateful sigc::signal NamedSelectionAdded; sigc::signal NamedSelectionRemoved; + /* Curves and AutomationLists (TODO when they go away) */ + void add_curve(Curve*); + void add_automation_list(AutomationList*); + /* fade curves */ float get_default_fade_length () const { return default_fade_msecs; } @@ -840,6 +846,7 @@ class Session : public sigc::trackable, public Stateful // 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 *); class GlobalSoloStateCommand : public Command { GlobalRouteBooleanState before, after; @@ -1586,6 +1593,10 @@ 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; + /* DEFAULT FADE CURVES */ float default_fade_steepness; diff --git a/libs/ardour/audio_diskstream.cc b/libs/ardour/audio_diskstream.cc index 9619f404fa..d3e64104a0 100644 --- a/libs/ardour/audio_diskstream.cc +++ b/libs/ardour/audio_diskstream.cc @@ -1614,7 +1614,7 @@ AudioDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_ca _playlist->thaw (); XMLNode &after = _playlist->get_state(); - _session.add_command (new MementoCommand(*_playlist, before, after)); + _session.add_command (new MementoCommand(*_playlist, &before, &after)); } mark_write_completed = true; diff --git a/libs/ardour/automation_event.cc b/libs/ardour/automation_event.cc index dc1767d1e7..cf69c634b1 100644 --- a/libs/ardour/automation_event.cc +++ b/libs/ardour/automation_event.cc @@ -64,6 +64,8 @@ AutomationList::AutomationList (double defval, bool with_state) if (!no_state) { save_state (_("initial")); } + + AutomationListCreated(this); } AutomationList::AutomationList (const AutomationList& other) @@ -91,6 +93,7 @@ AutomationList::AutomationList (const AutomationList& other) } mark_dirty (); + AutomationListCreated(this); } AutomationList::AutomationList (const AutomationList& other, double start, double end) @@ -123,6 +126,7 @@ AutomationList::AutomationList (const AutomationList& other, double start, doubl delete section; mark_dirty (); + AutomationListCreated(this); } AutomationList::~AutomationList() diff --git a/libs/ardour/curve.cc b/libs/ardour/curve.cc index 977b6dfd7b..5879cb5988 100644 --- a/libs/ardour/curve.cc +++ b/libs/ardour/curve.cc @@ -45,6 +45,7 @@ Curve::Curve (double minv, double maxv, double canv, bool nostate) { min_yval = minv; max_yval = maxv; + CurveCreated(this); } Curve::Curve (const Curve& other) @@ -52,6 +53,7 @@ Curve::Curve (const Curve& other) { min_yval = other.min_yval; max_yval = other.max_yval; + CurveCreated(this); } Curve::Curve (const Curve& other, double start, double end) @@ -59,6 +61,7 @@ Curve::Curve (const Curve& other, double start, double end) { min_yval = other.min_yval; max_yval = other.max_yval; + CurveCreated(this); } Curve::~Curve () diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 4a0d820381..1bd11cacc0 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -2226,6 +2226,20 @@ Session::route_by_name (string name) return shared_ptr ((Route*) 0); } +shared_ptr +Session::route_by_id (PBD::ID id) +{ + shared_ptr r = routes.reader (); + + for (RouteList::iterator i = r->begin(); i != r->end(); ++i) { + if ((*i)->id() == id) { + return *i; + } + } + + return shared_ptr ((Route*) 0); +} + shared_ptr Session::route_by_remote_id (uint32_t id) { @@ -3794,3 +3808,14 @@ Session::set_xfade_model (CrossfadeModel xm) } } +void +Session::add_curve(Curve *curve) +{ + curves[curve->id()] = curve; +} + +void +Session::add_automation_list(AutomationList *al) +{ + automation_lists[al->id()] = al; +} diff --git a/libs/ardour/session_command.cc b/libs/ardour/session_command.cc index 556c6ea9a3..4021fae573 100644 --- a/libs/ardour/session_command.cc +++ b/libs/ardour/session_command.cc @@ -2,24 +2,85 @@ #include #include #include +#include +#include +#include +#include +#include +using namespace PBD; +#include "i18n.h" + namespace ARDOUR { +static map registry; + +void Session::register_with_memento_command_factory(PBD::ID id, Stateful *ptr) +{ + registry[id] = ptr; +} + Command *Session::memento_command_factory(XMLNode *n) { PBD::ID id; - XMLNode *before, *after; + XMLNode *before = 0, *after = 0; - /* get obj_id */ + /* get id */ + id = PBD::ID(n->property("obj_id")->value()); - /* get before and/or after */ + /* get before/after */ + if (n->name() == "MementoCommand") + { + before = n->children().front(); + after = n->children().back(); + } else if (n->name() == "MementoUndoCommand") + before = n->children().front(); + else if (n->name() == "MementoRedoCommand") + after = n->children().front(); - /* get an object by id by trial and error, and use it to construct an - * appropriate memento command */ - // e.g. - if (Diskstream *obj = diskstream_by_id(id)) - return new MementoCommand(*obj, *before, *after); - // etc. + + /* create command */ + string obj_T = n->children().front()->name(); + if (obj_T == "AudioRegion" || obj_T == "Region") + { + if (audio_regions.count(id)) + return new MementoCommand(*audio_regions[id], before, after); + } + else if (obj_T == "AudioSource") + { + if (audio_sources.count(id)) + return new MementoCommand(*audio_sources[id], before, after); + } + else if (obj_T == "Location") + return new MementoCommand(*_locations.get_location_by_id(id), before, after); + else if (obj_T == "Locations") + return new MementoCommand(_locations, before, after); + else if (obj_T == "TempoMap") + return new MementoCommand(*_tempo_map, before, after); + else if (obj_T == "Playlist" || obj_T == "AudioPlaylist") + { + if (Playlist *pl = playlist_by_name(before->property("name")->value())) + return new MementoCommand(*pl, before, after); + } + else if (obj_T == "Route") // inlcudes AudioTrack + return new MementoCommand(*route_by_id(id), before, after); + // For Editor and AutomationLine which are off-limits here + else if (registry.count(id)) + return new MementoCommand(*registry[id], before, after); + else if (obj_T == "Curve") + { + if (curves.count(id)) + return new MementoCommand(*curves[id], before, after); + } + else if (obj_T == "AutomationList") + { + if (automation_lists.count(id)) + return new MementoCommand(*automation_lists[id], before, after); + } + + /* we failed */ + error << _("could not reconstitute MementoCommand from XMLNode. id=") << id.to_s() << endmsg; + return 0; } // solo diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index ebf2b6efd5..903d6f558a 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -266,6 +266,8 @@ Session::first_stage_init (string fullpath, string snapshot_name) Redirect::RedirectCreated.connect (mem_fun (*this, &Session::add_redirect)); AudioDiskstream::DiskstreamCreated.connect (mem_fun (*this, &Session::add_diskstream)); 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)); Controllable::Created.connect (mem_fun (*this, &Session::add_controllable)); Controllable::GoingAway.connect (mem_fun (*this, &Session::remove_controllable)); @@ -3328,3 +3330,63 @@ Session::save_history (string snapshot_name) return 0; } + +int +Session::restore_history (string snapshot_name) +{ + XMLTree tree; + string xmlpath; + + /* read xml */ + xmlpath = _path + snapshot_name + ".history"; + + if (access (xmlpath.c_str(), F_OK)) { + error << string_compose(_("%1: session history file \"%2\" doesn't exist!"), _name, xmlpath) << endmsg; + return 1; + } + + if (!tree.read (xmlpath)) { + error << string_compose(_("Could not understand ardour file %1"), xmlpath) << endmsg; + return -1; + } + + /* replace history */ + history.clear(); + for (XMLNodeConstIterator it = tree.root()->children().begin(); + it != tree.root()->children().end(); + it++) + { + XMLNode *t = *it; + UndoTransaction ut; + struct timeval tv; + + 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); + + for (XMLNodeConstIterator child_it = t->children().begin(); + child_it != t->children().end(); + child_it++) + { + XMLNode *n = *child_it; + Command *c; + if (n->name() == "MementoCommand" || + n->name() == "MementoUndoCommand" || + n->name() == "MementoRedoCommand") + { + c = memento_command_factory(n); + if (c) + ut.add_command(c); + } + else + { + error << string_compose(_("Couldn't figure out how to make a Command out of a %1 XMLNode."), n->name()) << endmsg; + } + } + history.add(ut); + } + return 0; +} diff --git a/libs/ardour/session_transport.cc b/libs/ardour/session_transport.cc index 1f70a9ebb8..0e3895caf1 100644 --- a/libs/ardour/session_transport.cc +++ b/libs/ardour/session_transport.cc @@ -324,7 +324,7 @@ Session::non_realtime_stop (bool abort) XMLNode &before = loc->get_state(); loc->set_end(_transport_frame); XMLNode &after = loc->get_state(); - add_command (new MementoCommand(*loc, before, after)); + add_command (new MementoCommand(*loc, &before, &after)); } _end_location_is_free = false; diff --git a/libs/pbd/pbd/memento_command.h b/libs/pbd/pbd/memento_command.h index 122dcb4c86..3a72fc9841 100644 --- a/libs/pbd/pbd/memento_command.h +++ b/libs/pbd/pbd/memento_command.h @@ -36,70 +36,44 @@ class MementoCommand : public Command public: MementoCommand(XMLNode &state); MementoCommand(obj_T &obj, - XMLNode &before, - XMLNode &after + XMLNode *before, + XMLNode *after ) : obj(obj), before(before), after(after) {} - void operator() () { obj.set_state(after); } - void undo() { obj.set_state(before); } + void operator() () + { + if (after) + obj.set_state(*after); + } + void undo() + { + if (before) + obj.set_state(*before); + } virtual XMLNode &get_state() { - XMLNode *node = new XMLNode("MementoCommand"); + string name; + if (before && after) + name = "MementoCommand"; + else if (before) + name = "MementoUndoCommand"; + 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()); - node->add_child_copy(before); - node->add_child_copy(after); + + if (before) + node->add_child_copy(*before); + if (after) + node->add_child_copy(*after); + return *node; } protected: obj_T &obj; - XMLNode &before, &after; -}; - -template -class MementoUndoCommand : public Command -{ -public: - MementoUndoCommand(XMLNode &state); - MementoUndoCommand(obj_T &obj, - XMLNode &before) - : obj(obj), before(before) {} - void operator() () { /* noop */ } - void undo() { obj.set_state(before); } - virtual XMLNode &get_state() - { - XMLNode *node = new XMLNode("MementoUndoCommand"); - node->add_property("obj_id", obj.id().to_s()); - node->add_property("type_name", typeid(obj).name()); - node->add_child_copy(before); - return *node; - } -protected: - obj_T &obj; - XMLNode &before; -}; - -template -class MementoRedoCommand : public Command -{ -public: - MementoRedoCommand(XMLNode &state); - MementoRedoCommand(obj_T &obj, - XMLNode &after) - : obj(obj), after(after) {} - void operator() () { obj.set_state(after); } - void undo() { /* noop */ } - virtual XMLNode &get_state() - { - XMLNode *node = new XMLNode("MementoRedoCommand"); - node->add_property("obj_id", obj.id().to_s()); - node->add_property("type_name", typeid(obj).name()); - node->add_child_copy(after); - return *node; - } -protected: - obj_T &obj; - XMLNode &after; + XMLNode *before, *after; }; #endif // __lib_pbd_memento_h__ diff --git a/libs/pbd/pbd/stateful.h b/libs/pbd/pbd/stateful.h index 3038f16b4f..5adddfc1c0 100644 --- a/libs/pbd/pbd/stateful.h +++ b/libs/pbd/pbd/stateful.h @@ -22,6 +22,7 @@ #define __pbd_stateful_h__ #include +#include class XMLNode; @@ -41,10 +42,12 @@ class Stateful { virtual void add_instant_xml (XMLNode&, const std::string& dir); XMLNode *instant_xml (const std::string& str, const std::string& dir); + PBD::ID id() { return _id; } protected: XMLNode *_extra_xml; XMLNode *_instant_xml; + PBD::ID _id; }; #endif /* __pbd_stateful_h__ */ diff --git a/libs/pbd/undo.cc b/libs/pbd/undo.cc index 8d1b416c16..6f421de84e 100644 --- a/libs/pbd/undo.cc +++ b/libs/pbd/undo.cc @@ -23,6 +23,7 @@ #include #include #include +#include using namespace std; using namespace sigc; @@ -87,6 +88,13 @@ UndoTransaction::redo () XMLNode &UndoTransaction::get_state() { XMLNode *node = new XMLNode ("UndoTransaction"); + stringstream ss; + ss << _timestamp.tv_sec; + node->add_property("tv_sec", ss.str()); + ss.str(""); + ss << _timestamp.tv_usec; + node->add_property("tv_usec", ss.str()); + node->add_property("name", _name); list::iterator it; for (it=actions.begin(); it!=actions.end(); it++)