2 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3 * Copyright (C) 2011 Paul Davis
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <gtkmm/frame.h>
21 #include <gtkmm/label.h>
23 #include "plugin_setup_dialog.h"
26 using namespace ARDOUR;
29 PluginSetupDialog::PluginSetupDialog (boost::shared_ptr<ARDOUR::Route> r, boost::shared_ptr<ARDOUR::PluginInsert> pi, ARDOUR::Route::PluginSetupOptions flags)
30 : ArdourDialog (_("Plugin Setup"), true, false)
33 , _keep_mapping (_("Copy I/O Map"), ArdourButton::led_default_elements)
35 assert (flags != Route::None);
37 Gtk::Table *tbl = manage (new Gtk::Table ());
38 tbl->set_spacings (6);
39 get_vbox()->pack_start (*tbl);
42 if (flags & Route::CanReplace) {
43 boost::shared_ptr<Processor> old = _route->the_instrument ();
44 boost::shared_ptr<PluginInsert> opi = boost::dynamic_pointer_cast<PluginInsert> (old);
47 opi->configured_io (_cur_inputs, _cur_outputs);
49 Gtk::Label* l = manage (new Label (
50 _("An Instrument plugin is already present.")
52 tbl->attach (*l, 0, 2, row, row + 1, EXPAND|FILL, SHRINK); ++row;
54 l = manage (new Label (_("Replace"), ALIGN_END));
55 tbl->attach (*l, 0, 1, row, row + 1, EXPAND|FILL, SHRINK);
57 l = manage (new Label (string_compose ("'%1'", old->name ()), ALIGN_START));
58 tbl->attach (*l, 1, 2, row, row + 1, EXPAND|FILL, SHRINK); ++row;
60 l = manage (new Label (_("with"), ALIGN_END));
61 tbl->attach (*l, 0, 1, row, row + 1, EXPAND|FILL, SHRINK);
63 l = manage (new Label (string_compose ("'%1'", pi->name ()), ALIGN_START));
64 tbl->attach (*l, 1, 2, row, row + 1, EXPAND|FILL, SHRINK); ++row;
66 Box* box = manage (new HBox ());
67 box->set_border_width (2);
68 box->pack_start (_keep_mapping, true, true);
69 Frame* f = manage (new Frame ());
70 f->set_label (_("I/O Pin Mapping"));
72 tbl->attach (*f, 0, 1, row, row + 1, EXPAND|FILL, SHRINK, 0, 8);
74 _keep_mapping.signal_clicked.connect (sigc::mem_fun (*this, &PluginSetupDialog::apply_mapping));
75 add_button ("Replace", 2);
78 Gtk::Label *l = manage (new Label (string_compose (
79 _("Configure Plugin '%1'"), pi->name ()
81 tbl->attach (*l, 0, 2, row, row + 1, EXPAND|FILL, SHRINK); ++row;
84 if (flags & Route::MultiOut) {
85 setup_output_presets ();
86 Box* box = manage (new HBox ());
87 box->set_border_width (2);
88 box->pack_start (_out_presets, true, true);
89 Frame* f = manage (new Frame ());
90 f->set_label (_("Output Configuration"));
92 tbl->attach (*f, 1, 2, row, row + 1, EXPAND|FILL, SHRINK, 0, 8);
94 _pi->set_preset_out (_pi->natural_output_streams ());
95 update_sensitivity (_pi->natural_output_streams ().n_audio ());
98 _keep_mapping.set_active (false);
101 add_button (Stock::ADD, 0);
102 add_button (Stock::CANCEL, 1);
103 set_default_response (0);
109 PluginSetupDialog::setup_output_presets ()
111 // compare to PluginPinDialog::refill_output_presets ()
112 using namespace Menu_Helpers;
113 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
115 _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginSetupDialog::select_output_preset), 0)));
117 if (ppc.find (0) != ppc.end ()) {
126 if (ppc.find (_cur_outputs.n_audio ()) == ppc.end ()) {
127 ppc.insert (_cur_outputs.n_audio ());
131 bool have_matching_io = false;
133 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
135 _out_presets.AddMenuElem (MenuElem (preset_label (*i), sigc::bind (sigc::mem_fun (*this, &PluginSetupDialog::select_output_preset), *i)));
136 if (*i == _cur_outputs.n_audio ()) {
137 have_matching_io = true;
141 if (have_matching_io) {
142 select_output_preset (_cur_outputs.n_audio ());
144 select_output_preset (0);
149 PluginSetupDialog::select_output_preset (uint32_t n_audio)
151 _pi->set_preset_out (ChanCount (DataType::AUDIO, n_audio));
152 _out_presets.set_text (preset_label (n_audio));
153 update_sensitivity (n_audio);
157 PluginSetupDialog::update_sensitivity (uint32_t n_audio)
159 if (_cur_outputs.n_audio () > 0 && _cur_outputs.n_audio () == n_audio) {
160 // TODO check _cur_inputs if not reconfigurable?
161 _keep_mapping.set_sensitive (true);
163 _keep_mapping.set_sensitive (false);
168 PluginSetupDialog::io_match () const
170 if (_cur_outputs.n_audio () > 0 && _cur_outputs.n_audio () == _pi->preset_out ().n_audio ()) {
178 PluginSetupDialog::apply_mapping ()
181 _keep_mapping.set_active (!_keep_mapping.get_active ());
183 boost::shared_ptr<Processor> old = _route->the_instrument ();
184 boost::shared_ptr<PluginInsert> opi = boost::dynamic_pointer_cast<PluginInsert> (old);
186 if (_keep_mapping.get_active () && opi && io_match ()) {
187 _pi->pre_seed (_cur_inputs, _cur_outputs, opi->input_map (0), opi->output_map (0), opi->thru_map ());
189 _pi->pre_seed (ChanCount (), ChanCount (), ChanMapping (), ChanMapping (), ChanMapping());
194 PluginSetupDialog::preset_label (uint32_t n_audio) const
208 rv = string_compose (P_("%1 Channel", "%1 Channels", n_audio), n_audio);