2 Copyright (C) 2000 Paul Davis
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
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <pbd/stl_delete.h>
26 #include <pbd/xml++.h>
27 #include <pbd/failed_constructor.h>
29 #include <gtkmm/widget.h>
30 #include <gtkmm2ext/click_box.h>
31 #include <gtkmm2ext/fastmeter.h>
32 #include <gtkmm2ext/barcontroller.h>
33 #include <gtkmm2ext/utils.h>
34 #include <gtkmm2ext/doi.h>
35 #include <gtkmm2ext/slider_controller.h>
37 #include <midi++/manager.h>
39 #include <ardour/plugin.h>
40 #include <ardour/plugin_insert.h>
41 #include <ardour/ladspa_plugin.h>
43 #include <ardour/vst_plugin.h>
48 #include "ardour_ui.h"
50 #include "plugin_ui.h"
52 #include "gui_thread.h"
53 #include "public_editor.h"
58 using namespace ARDOUR;
60 using namespace Gtkmm2ext;
64 PluginUIWindow::PluginUIWindow (boost::shared_ptr<PluginInsert> insert, nframes64_t sr, nframes64_t period, bool scrollable)
66 bool have_gui = false;
69 Label* label = manage (new Label());
70 label->set_markup ("<b>THIS IS THE PLUGIN UI</b>");
72 if (insert->plugin()->has_editor()) {
73 switch (insert->type()) {
75 have_gui = create_vst_editor (insert);
78 case ARDOUR::AudioUnit:
79 have_gui = create_audiounit_editor (insert);
83 error << _("Eh? LADSPA plugins don't have editors!") << endmsg;
88 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
91 error << _("unknown type of editor-supplying plugin")
94 throw failed_constructor ();
101 GenericPluginUI* pu = new GenericPluginUI (insert, scrollable);
106 set_wmclass (X_("ardour_plugin_editor"), "Ardour");
108 signal_map_event().connect (mem_fun (*pu, &GenericPluginUI::start_updating));
109 signal_unmap_event().connect (mem_fun (*pu, &GenericPluginUI::stop_updating));
112 // set_position (Gtk::WIN_POS_MOUSE);
113 set_name ("PluginEditor");
114 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
116 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window*> (this)), false);
117 insert->GoingAway.connect (mem_fun(*this, &PluginUIWindow::plugin_going_away));
119 gint h = _pluginui->get_preferred_height ();
120 gint w = _pluginui->get_preferred_width ();
123 if (h > 600) h = 600;
124 if (w > 600) w = 600;
131 set_default_size (w, h);
134 PluginUIWindow::~PluginUIWindow ()
139 PluginUIWindow::on_show ()
141 cerr << "PluginWindow shown\n";
147 PluginUIWindow::on_hide ()
149 cerr << "PluginWindow hidden\n";
154 PluginUIWindow::create_vst_editor(boost::shared_ptr<PluginInsert> insert)
160 boost::shared_ptr<VSTPlugin> vp;
162 if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (insert->plugin())) == 0) {
163 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
165 throw failed_constructor ();
167 VSTPluginUI* vpu = new VSTPluginUI (insert, vp);
171 vpu->package (*this);
180 PluginUIWindow::create_audiounit_editor (boost::shared_ptr<PluginInsert> insert)
182 #if !defined(HAVE_AUDIOUNITS) || !defined(GTKOSX)
186 _pluginui = create_au_gui (insert, &box);
190 extern sigc::signal<void,bool> ApplicationActivationChanged;
191 ApplicationActivationChanged.connect (mem_fun (*this, &PluginUIWindow::app_activated));
198 PluginUIWindow::app_activated (bool yn)
200 #if defined (HAVE_AUDIOUNITS) && defined(GTKOSX)
201 cerr << "APP activated ? " << yn << endl;
204 _pluginui->activate ();
208 _pluginui->deactivate ();
215 PluginUIWindow::on_key_press_event (GdkEventKey* event)
221 if (!key_press_focus_accelerator_handler (*this, event)) {
222 return PublicEditor::instance().on_key_press_event(event);
229 PluginUIWindow::on_key_release_event (GdkEventKey* event)
235 PluginUIWindow::plugin_going_away ()
237 ENSURE_GUI_THREAD(mem_fun(*this, &PluginUIWindow::plugin_going_away));
240 _pluginui->stop_updating(0);
242 delete_when_idle (this);
245 PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
247 plugin (insert->plugin()),
248 save_button(_("Add")),
249 bypass_button (_("Bypass")),
250 latency_gui (*pi, pi->session().frame_rate(), pi->session().get_block_size())
252 //preset_combo.set_use_arrows_always(true);
253 set_popdown_strings (preset_combo, plugin->get_presets());
254 preset_combo.set_size_request (100, -1);
255 preset_combo.set_active_text ("");
256 preset_combo.signal_changed().connect(mem_fun(*this, &PlugUIBase::setting_selected));
258 save_button.set_name ("PluginSaveButton");
259 save_button.signal_clicked().connect(mem_fun(*this, &PlugUIBase::save_plugin_setting));
261 insert->ActiveChanged.connect (bind(
262 mem_fun(*this, &PlugUIBase::processor_active_changed),
263 boost::weak_ptr<Processor>(insert)));
265 bypass_button.set_active (!pi->active());
267 bypass_button.set_name ("PluginBypassButton");
268 bypass_button.signal_toggled().connect (mem_fun(*this, &PlugUIBase::bypass_toggled));
272 PlugUIBase::processor_active_changed (boost::weak_ptr<Processor> weak_p)
274 ENSURE_GUI_THREAD(bind (mem_fun(*this, &PlugUIBase::processor_active_changed), weak_p));
275 boost::shared_ptr<Processor> p (weak_p);
277 bypass_button.set_active (!p->active());
282 PlugUIBase::setting_selected()
284 if (preset_combo.get_active_text().length() > 0) {
285 if (!plugin->load_preset(preset_combo.get_active_text())) {
286 warning << string_compose(_("Plugin preset %1 not found"), preset_combo.get_active_text()) << endmsg;
292 PlugUIBase::save_plugin_setting ()
294 ArdourPrompter prompter (true);
295 prompter.set_prompt(_("Name of New Preset:"));
296 prompter.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT);
297 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
301 switch (prompter.run ()) {
302 case Gtk::RESPONSE_ACCEPT:
306 prompter.get_result(name);
309 if(plugin->save_preset(name)){
310 set_popdown_strings (preset_combo, plugin->get_presets());
311 preset_combo.set_active_text (name);
319 PlugUIBase::bypass_toggled ()
323 if ((x = bypass_button.get_active()) == insert->active()) {
324 insert->set_active (!x);
325 if (insert->active()) {
326 bypass_button.set_label (_("Bypass"));
328 bypass_button.set_label (_("Active"));