2 * Copyright (C) 2016-2017 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <gtkmm/frame.h>
20 #include <gtkmm/label.h>
21 #include <gtkmm/stock.h>
22 #include <gtkmm/table.h>
24 #include "plugin_setup_dialog.h"
27 using namespace ARDOUR;
28 using namespace ArdourWidgets;
31 PluginSetupDialog::PluginSetupDialog (boost::shared_ptr<ARDOUR::Route> r, boost::shared_ptr<ARDOUR::PluginInsert> pi, ARDOUR::Route::PluginSetupOptions flags)
32 : ArdourDialog (_("Plugin Setup"), true, false)
35 , _keep_mapping (_("Copy I/O Map"), ArdourButton::led_default_elements)
36 , _fan_out (_("Fan out"), ArdourButton::led_default_elements)
38 assert (flags != Route::None);
40 Gtk::Table *tbl = manage (new Gtk::Table ());
41 tbl->set_spacings (6);
42 get_vbox()->pack_start (*tbl);
45 if (flags & Route::CanReplace) {
46 boost::shared_ptr<Processor> old = _route->the_instrument ();
47 boost::shared_ptr<PluginInsert> opi = boost::dynamic_pointer_cast<PluginInsert> (old);
50 opi->configured_io (_cur_inputs, _cur_outputs);
52 Gtk::Label* l = manage (new Label (
53 _("An Instrument plugin is already present.")
55 tbl->attach (*l, 0, 2, row, row + 1, EXPAND|FILL, SHRINK); ++row;
57 l = manage (new Label (_("Replace"), ALIGN_END));
58 tbl->attach (*l, 0, 1, row, row + 1, EXPAND|FILL, SHRINK);
60 l = manage (new Label (string_compose ("'%1'", old->name ()), ALIGN_START));
61 tbl->attach (*l, 1, 2, row, row + 1, EXPAND|FILL, SHRINK); ++row;
63 l = manage (new Label (_("with"), ALIGN_END));
64 tbl->attach (*l, 0, 1, row, row + 1, EXPAND|FILL, SHRINK);
66 l = manage (new Label (string_compose ("'%1'", pi->name ()), ALIGN_START));
67 tbl->attach (*l, 1, 2, row, row + 1, EXPAND|FILL, SHRINK); ++row;
69 Box* box = manage (new HBox ());
70 box->set_border_width (2);
71 box->pack_start (_keep_mapping, true, true);
72 Frame* f = manage (new Frame ());
73 f->set_label (_("I/O Pin Mapping"));
75 tbl->attach (*f, 0, 1, row, row + 1, EXPAND|FILL, SHRINK, 0, 8);
77 _keep_mapping.signal_clicked.connect (sigc::mem_fun (*this, &PluginSetupDialog::apply_mapping));
78 add_button ("Replace", 2);
81 Gtk::Label *l = manage (new Label (string_compose (
82 _("Configure Plugin '%1'"), pi->name ()
84 tbl->attach (*l, 0, 2, row, row + 1, EXPAND|FILL, SHRINK); ++row;
87 if (flags & Route::MultiOut) {
88 setup_output_presets ();
89 Box* box = manage (new HBox ());
90 box->set_border_width (2);
91 box->pack_start (_out_presets, true, true);
92 box->pack_start (_fan_out, false, false);
93 Frame* f = manage (new Frame ());
94 f->set_label (_("Output Configuration"));
96 tbl->attach (*f, 1, 2, row, row + 1, EXPAND|FILL, SHRINK, 0, 8);
97 _fan_out.signal_clicked.connect (sigc::mem_fun (*this, &PluginSetupDialog::toggle_fan_out));
98 _fan_out.set_active (true);
100 _pi->set_preset_out (_pi->natural_output_streams ());
101 update_sensitivity (_pi->natural_output_streams ().n_audio ());
102 _fan_out.set_active (false);
105 _keep_mapping.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 ());
150 } else if (ppc.size() == 1 && _pi->strict_io ()) {
151 select_output_preset (*ppc.begin ());
153 select_output_preset (0);
158 PluginSetupDialog::select_output_preset (uint32_t n_audio)
160 _pi->set_preset_out (ChanCount (DataType::AUDIO, n_audio));
161 _out_presets.set_text (preset_label (n_audio));
162 update_sensitivity (n_audio);
166 PluginSetupDialog::update_sensitivity (uint32_t n_audio)
168 if (_cur_outputs.n_audio () > 0 && _cur_outputs.n_audio () == n_audio) {
169 // TODO check _cur_inputs if not reconfigurable?
170 _keep_mapping.set_sensitive (true);
172 _keep_mapping.set_sensitive (false);
174 _fan_out.set_sensitive (n_audio > 2);
178 PluginSetupDialog::io_match () const
180 if (_cur_outputs.n_audio () > 0 && _cur_outputs.n_audio () == _pi->preset_out ().n_audio ()) {
188 PluginSetupDialog::apply_mapping ()
191 _keep_mapping.set_active (!_keep_mapping.get_active ());
193 boost::shared_ptr<Processor> old = _route->the_instrument ();
194 boost::shared_ptr<PluginInsert> opi = boost::dynamic_pointer_cast<PluginInsert> (old);
196 if (_keep_mapping.get_active () && opi && io_match ()) {
197 _pi->pre_seed (_cur_inputs, _cur_outputs, opi->input_map (0), opi->output_map (0), opi->thru_map ());
199 _pi->pre_seed (ChanCount (), ChanCount (), ChanMapping (), ChanMapping (), ChanMapping());
204 PluginSetupDialog::toggle_fan_out ()
206 _fan_out.set_active (!_fan_out.get_active ());
210 PluginSetupDialog::preset_label (uint32_t n_audio) const
224 rv = string_compose (P_("%1 Channel", "%1 Channels", n_audio), n_audio);