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/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 (Gtk::Window* win, boost::shared_ptr<PluginInsert> insert, bool scrollable)
67 bool have_gui = false;
71 if (insert->plugin()->has_editor()) {
72 switch (insert->type()) {
74 have_gui = create_vst_editor (insert);
77 case ARDOUR::AudioUnit:
78 have_gui = create_audiounit_editor (insert);
82 error << _("Eh? LADSPA plugins don't have editors!") << endmsg;
87 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
90 error << _("unknown type of editor-supplying plugin")
93 throw failed_constructor ();
100 GenericPluginUI* pu = new GenericPluginUI (insert, scrollable);
105 set_wmclass (X_("ardour_plugin_editor"), "Ardour");
107 signal_map_event().connect (mem_fun (*pu, &GenericPluginUI::start_updating));
108 signal_unmap_event().connect (mem_fun (*pu, &GenericPluginUI::stop_updating));
111 // set_position (Gtk::WIN_POS_MOUSE);
112 set_name ("PluginEditor");
113 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
115 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window*> (this)), false);
116 insert->GoingAway.connect (mem_fun(*this, &PluginUIWindow::plugin_going_away));
118 gint h = _pluginui->get_preferred_height ();
119 gint w = _pluginui->get_preferred_width ();
122 if (h > 600) h = 600;
123 if (w > 600) w = 600;
130 set_default_size (w, h);
133 PluginUIWindow::~PluginUIWindow ()
138 PluginUIWindow::set_parent (Gtk::Window* win)
144 PluginUIWindow::on_map ()
147 set_keep_above (true);
151 PluginUIWindow::on_show ()
154 _pluginui->update_presets ();
160 // set_transient_for (*parent);
165 PluginUIWindow::on_hide ()
171 PluginUIWindow::create_vst_editor(boost::shared_ptr<PluginInsert> insert)
177 boost::shared_ptr<VSTPlugin> vp;
179 if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (insert->plugin())) == 0) {
180 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
182 throw failed_constructor ();
184 VSTPluginUI* vpu = new VSTPluginUI (insert, vp);
188 vpu->package (*this);
197 PluginUIWindow::create_audiounit_editor (boost::shared_ptr<PluginInsert> insert)
199 #if !defined(HAVE_AUDIOUNITS) || !defined(GTKOSX)
203 _pluginui = create_au_gui (insert, &box);
207 extern sigc::signal<void,bool> ApplicationActivationChanged;
208 ApplicationActivationChanged.connect (mem_fun (*this, &PluginUIWindow::app_activated));
215 PluginUIWindow::app_activated (bool yn)
217 #if defined (HAVE_AUDIOUNITS) && defined(GTKOSX)
218 cerr << "APP activated ? " << yn << endl;
222 _pluginui->activate ();
227 was_visible = is_visible();
229 _pluginui->deactivate ();
236 PluginUIWindow::on_key_press_event (GdkEventKey* event)
242 if (!key_press_focus_accelerator_handler (*this, event)) {
243 return PublicEditor::instance().on_key_press_event(event);
250 PluginUIWindow::on_key_release_event (GdkEventKey* event)
256 PluginUIWindow::plugin_going_away ()
258 ENSURE_GUI_THREAD(mem_fun(*this, &PluginUIWindow::plugin_going_away));
261 _pluginui->stop_updating(0);
263 delete_when_idle (this);
266 PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
268 plugin (insert->plugin()),
269 save_button(_("Add")),
270 bypass_button (_("Bypass"))
272 //preset_combo.set_use_arrows_always(true);
273 set_popdown_strings (preset_combo, plugin->get_presets());
274 preset_combo.set_size_request (100, -1);
275 preset_combo.set_active_text ("");
276 preset_combo.signal_changed().connect(mem_fun(*this, &PlugUIBase::setting_selected));
278 save_button.set_name ("PluginSaveButton");
279 save_button.signal_clicked().connect(mem_fun(*this, &PlugUIBase::save_plugin_setting));
281 insert->active_changed.connect (mem_fun(*this, &PlugUIBase::redirect_active_changed));
282 bypass_button.set_active (!pi->active());
284 bypass_button.set_name ("PluginBypassButton");
285 bypass_button.signal_toggled().connect (mem_fun(*this, &PlugUIBase::bypass_toggled));
289 PlugUIBase::redirect_active_changed (Redirect* r, void* src)
291 ENSURE_GUI_THREAD(bind (mem_fun(*this, &PlugUIBase::redirect_active_changed), r, src));
292 bypass_button.set_active (!r->active());
296 PlugUIBase::setting_selected()
298 if (preset_combo.get_active_text().length() > 0) {
299 if (!plugin->load_preset(preset_combo.get_active_text())) {
300 warning << string_compose(_("Plugin preset %1 not found"), preset_combo.get_active_text()) << endmsg;
306 PlugUIBase::save_plugin_setting ()
308 ArdourPrompter prompter (true);
309 prompter.set_prompt(_("Name of New Preset:"));
310 prompter.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT);
311 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
315 switch (prompter.run ()) {
316 case Gtk::RESPONSE_ACCEPT:
320 prompter.get_result(name);
323 if(plugin->save_preset(name)){
324 set_popdown_strings (preset_combo, plugin->get_presets());
325 preset_combo.set_active_text (name);
333 PlugUIBase::bypass_toggled ()
337 if ((x = bypass_button.get_active()) == insert->active()) {
338 insert->set_active (!x, this);
339 if (insert->active()) {
340 bypass_button.set_label (_("Bypass"));
342 bypass_button.set_label (_("Active"));
348 PlugUIBase::update_presets ()
350 set_popdown_strings (preset_combo, plugin->get_presets());