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>
22 #include <gtkmm/stock.h>
23 #include <gtkmm/table.h>
25 #include "plugin_setup_dialog.h"
28 using namespace ARDOUR;
29 using namespace ArdourWidgets;
32 PluginSetupDialog::PluginSetupDialog (boost::shared_ptr<ARDOUR::Route> r, boost::shared_ptr<ARDOUR::PluginInsert> pi, ARDOUR::Route::PluginSetupOptions flags)
33 : ArdourDialog (_("Plugin Setup"), true, false)
36 , _keep_mapping (_("Copy I/O Map"), ArdourButton::led_default_elements)
37 , _fan_out (_("Fan out"), ArdourButton::led_default_elements)
39 assert (flags != Route::None);
41 Gtk::Table *tbl = manage (new Gtk::Table ());
42 tbl->set_spacings (6);
43 get_vbox()->pack_start (*tbl);
46 if (flags & Route::CanReplace) {
47 boost::shared_ptr<Processor> old = _route->the_instrument ();
48 boost::shared_ptr<PluginInsert> opi = boost::dynamic_pointer_cast<PluginInsert> (old);
51 opi->configured_io (_cur_inputs, _cur_outputs);
53 Gtk::Label* l = manage (new Label (
54 _("An Instrument plugin is already present.")
56 tbl->attach (*l, 0, 2, row, row + 1, EXPAND|FILL, SHRINK); ++row;
58 l = manage (new Label (_("Replace"), ALIGN_END));
59 tbl->attach (*l, 0, 1, row, row + 1, EXPAND|FILL, SHRINK);
61 l = manage (new Label (string_compose ("'%1'", old->name ()), ALIGN_START));
62 tbl->attach (*l, 1, 2, row, row + 1, EXPAND|FILL, SHRINK); ++row;
64 l = manage (new Label (_("with"), ALIGN_END));
65 tbl->attach (*l, 0, 1, row, row + 1, EXPAND|FILL, SHRINK);
67 l = manage (new Label (string_compose ("'%1'", pi->name ()), ALIGN_START));
68 tbl->attach (*l, 1, 2, row, row + 1, EXPAND|FILL, SHRINK); ++row;
70 Box* box = manage (new HBox ());
71 box->set_border_width (2);
72 box->pack_start (_keep_mapping, true, true);
73 Frame* f = manage (new Frame ());
74 f->set_label (_("I/O Pin Mapping"));
76 tbl->attach (*f, 0, 1, row, row + 1, EXPAND|FILL, SHRINK, 0, 8);
78 _keep_mapping.signal_clicked.connect (sigc::mem_fun (*this, &PluginSetupDialog::apply_mapping));
79 add_button ("Replace", 2);
82 Gtk::Label *l = manage (new Label (string_compose (
83 _("Configure Plugin '%1'"), pi->name ()
85 tbl->attach (*l, 0, 2, row, row + 1, EXPAND|FILL, SHRINK); ++row;
88 if (flags & Route::MultiOut) {
89 setup_output_presets ();
90 Box* box = manage (new HBox ());
91 box->set_border_width (2);
92 box->pack_start (_out_presets, true, true);
93 box->pack_start (_fan_out, false, false);
94 Frame* f = manage (new Frame ());
95 f->set_label (_("Output Configuration"));
97 tbl->attach (*f, 1, 2, row, row + 1, EXPAND|FILL, SHRINK, 0, 8);
98 _fan_out.signal_clicked.connect (sigc::mem_fun (*this, &PluginSetupDialog::toggle_fan_out));
100 _pi->set_preset_out (_pi->natural_output_streams ());
101 update_sensitivity (_pi->natural_output_streams ().n_audio ());
104 _keep_mapping.set_active (false);
105 _fan_out.set_active (false);
108 add_button (Stock::ADD, 0);
109 add_button (Stock::CANCEL, 1);
110 set_default_response (0);
116 PluginSetupDialog::setup_output_presets ()
118 // compare to PluginPinDialog::refill_output_presets ()
119 using namespace Menu_Helpers;
120 PluginOutputConfiguration ppc (_pi->plugin (0)->possible_output ());
122 _out_presets.AddMenuElem (MenuElem (_("Automatic"), sigc::bind (sigc::mem_fun (*this, &PluginSetupDialog::select_output_preset), 0)));
124 if (ppc.find (0) != ppc.end ()) {
133 if (ppc.find (_cur_outputs.n_audio ()) == ppc.end ()) {
134 ppc.insert (_cur_outputs.n_audio ());
138 bool have_matching_io = false;
140 for (PluginOutputConfiguration::const_iterator i = ppc.begin () ; i != ppc.end (); ++i) {
142 _out_presets.AddMenuElem (MenuElem (preset_label (*i), sigc::bind (sigc::mem_fun (*this, &PluginSetupDialog::select_output_preset), *i)));
143 if (*i == _cur_outputs.n_audio ()) {
144 have_matching_io = true;
148 if (have_matching_io) {
149 select_output_preset (_cur_outputs.n_audio ());
151 select_output_preset (0);
156 PluginSetupDialog::select_output_preset (uint32_t n_audio)
158 _pi->set_preset_out (ChanCount (DataType::AUDIO, n_audio));
159 _out_presets.set_text (preset_label (n_audio));
160 update_sensitivity (n_audio);
164 PluginSetupDialog::update_sensitivity (uint32_t n_audio)
166 if (_cur_outputs.n_audio () > 0 && _cur_outputs.n_audio () == n_audio) {
167 // TODO check _cur_inputs if not reconfigurable?
168 _keep_mapping.set_sensitive (true);
170 _keep_mapping.set_sensitive (false);
172 _fan_out.set_sensitive (n_audio > 2);
176 PluginSetupDialog::io_match () const
178 if (_cur_outputs.n_audio () > 0 && _cur_outputs.n_audio () == _pi->preset_out ().n_audio ()) {
186 PluginSetupDialog::apply_mapping ()
189 _keep_mapping.set_active (!_keep_mapping.get_active ());
191 boost::shared_ptr<Processor> old = _route->the_instrument ();
192 boost::shared_ptr<PluginInsert> opi = boost::dynamic_pointer_cast<PluginInsert> (old);
194 if (_keep_mapping.get_active () && opi && io_match ()) {
195 _pi->pre_seed (_cur_inputs, _cur_outputs, opi->input_map (0), opi->output_map (0), opi->thru_map ());
197 _pi->pre_seed (ChanCount (), ChanCount (), ChanMapping (), ChanMapping (), ChanMapping());
202 PluginSetupDialog::toggle_fan_out ()
204 _fan_out.set_active (!_fan_out.get_active ());
208 PluginSetupDialog::preset_label (uint32_t n_audio) const
222 rv = string_compose (P_("%1 Channel", "%1 Channels", n_audio), n_audio);