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 <gtkmm/box.h>
31 #include <gtkmm2ext/click_box.h>
32 #include <gtkmm2ext/fastmeter.h>
33 #include <gtkmm2ext/barcontroller.h>
34 #include <gtkmm2ext/utils.h>
35 #include <gtkmm2ext/doi.h>
36 #include <gtkmm2ext/slider_controller.h>
38 #include <midi++/manager.h>
40 #include <ardour/plugin.h>
41 #include <ardour/plugin_insert.h>
42 #include <ardour/ladspa_plugin.h>
44 #include <ardour/vst_plugin.h>
47 #include <ardour/lv2_plugin.h>
48 #include "lv2_plugin_ui.h"
53 #include "ardour_ui.h"
55 #include "plugin_ui.h"
57 #include "gui_thread.h"
58 #include "public_editor.h"
64 using namespace ARDOUR;
66 using namespace Gtkmm2ext;
70 PluginUIWindow::PluginUIWindow (Gtk::Window* win, boost::shared_ptr<PluginInsert> insert, bool scrollable)
73 bool have_gui = false;
77 Label* label = manage (new Label());
78 label->set_markup ("<b>THIS IS THE PLUGIN UI</b>");
80 if (insert->plugin()->has_editor()) {
81 switch (insert->type()) {
83 have_gui = create_vst_editor (insert);
86 case ARDOUR::AudioUnit:
87 have_gui = create_audiounit_editor (insert);
91 error << _("Eh? LADSPA plugins don't have editors!") << endmsg;
95 have_gui = create_lv2_editor (insert);
100 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
103 error << _("unknown type of editor-supplying plugin")
106 throw failed_constructor ();
113 GenericPluginUI* pu = new GenericPluginUI (insert, scrollable);
119 Gtk::HBox *hbox = new Gtk::HBox();
120 hbox->pack_start( *pu);
121 // TODO: this should be nicer
122 hbox->pack_start( eqgui_bin );
127 set_wmclass (X_("ardour_plugin_editor"), "Ardour");
129 signal_map_event().connect (mem_fun (*pu, &GenericPluginUI::start_updating));
130 signal_unmap_event().connect (mem_fun (*pu, &GenericPluginUI::stop_updating));
133 // set_position (Gtk::WIN_POS_MOUSE);
134 set_name ("PluginEditor");
135 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
137 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window*> (this)), false);
138 insert->GoingAway.connect (mem_fun(*this, &PluginUIWindow::plugin_going_away));
140 gint h = _pluginui->get_preferred_height ();
141 gint w = _pluginui->get_preferred_width ();
144 if (h > 600) h = 600;
145 if (w > 600) w = 600;
152 set_default_size (w, h);
155 PluginUIWindow::~PluginUIWindow ()
160 PluginUIWindow::set_parent (Gtk::Window* win)
166 PluginUIWindow::on_map ()
169 set_keep_above (true);
173 PluginUIWindow::on_enter_notify_event (GdkEventCrossing *ev)
175 Keyboard::the_keyboard().enter_window (ev, this);
180 PluginUIWindow::on_leave_notify_event (GdkEventCrossing *ev)
182 Keyboard::the_keyboard().leave_window (ev, this);
187 PluginUIWindow::on_focus_in_event (GdkEventFocus *ev)
189 Window::on_focus_in_event (ev);
190 //Keyboard::the_keyboard().magic_widget_grab_focus ();
195 PluginUIWindow::on_focus_out_event (GdkEventFocus *ev)
197 Window::on_focus_out_event (ev);
198 //Keyboard::the_keyboard().magic_widget_drop_focus ();
203 PluginUIWindow::on_show ()
206 _pluginui->update_presets ();
212 // set_transient_for (*parent);
217 PluginUIWindow::on_hide ()
223 PluginUIWindow::create_vst_editor(boost::shared_ptr<PluginInsert> insert)
229 boost::shared_ptr<VSTPlugin> vp;
231 if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (insert->plugin())) == 0) {
232 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
234 throw failed_constructor ();
236 VSTPluginUI* vpu = new VSTPluginUI (insert, vp);
240 vpu->package (*this);
249 PluginUIWindow::create_audiounit_editor (boost::shared_ptr<PluginInsert> insert)
251 #if !defined(HAVE_AUDIOUNITS) || !defined(GTKOSX)
255 _pluginui = create_au_gui (insert, &box);
259 extern sigc::signal<void,bool> ApplicationActivationChanged;
260 ApplicationActivationChanged.connect (mem_fun (*this, &PluginUIWindow::app_activated));
267 PluginUIWindow::app_activated (bool yn)
269 #if defined (HAVE_AUDIOUNITS) && defined(GTKOSX)
270 cerr << "APP activated ? " << yn << endl;
274 _pluginui->activate ();
279 was_visible = is_visible();
281 _pluginui->deactivate ();
288 PluginUIWindow::create_lv2_editor(boost::shared_ptr<PluginInsert> insert)
294 boost::shared_ptr<LV2Plugin> vp;
296 if ((vp = boost::dynamic_pointer_cast<LV2Plugin> (insert->plugin())) == 0) {
297 error << _("create_lv2_editor called on non-LV2 plugin") << endmsg;
298 throw failed_constructor ();
300 LV2PluginUI* lpu = new LV2PluginUI (insert, vp);
303 lpu->package (*this);
312 PluginUIWindow::on_key_press_event (GdkEventKey* event)
314 if (!key_press_focus_accelerator_handler (*this, event)) {
315 return PublicEditor::instance().on_key_press_event(event);
322 PluginUIWindow::on_key_release_event (GdkEventKey* event)
328 PluginUIWindow::plugin_going_away ()
330 ENSURE_GUI_THREAD(mem_fun(*this, &PluginUIWindow::plugin_going_away));
333 _pluginui->stop_updating(0);
335 delete_when_idle (this);
338 PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
340 plugin (insert->plugin()),
341 save_button(_("Add")),
342 bypass_button (_("Bypass")),
343 latency_gui (*pi, pi->session().frame_rate(), pi->session().get_block_size())
345 //preset_combo.set_use_arrows_always(true);
346 set_popdown_strings (preset_combo, plugin->get_presets());
347 preset_combo.set_size_request (100, -1);
348 preset_combo.set_active_text ("");
349 preset_combo.signal_changed().connect(mem_fun(*this, &PlugUIBase::setting_selected));
351 save_button.set_name ("PluginSaveButton");
352 save_button.signal_clicked().connect(mem_fun(*this, &PlugUIBase::save_plugin_setting));
354 insert->ActiveChanged.connect (bind(
355 mem_fun(*this, &PlugUIBase::processor_active_changed),
356 boost::weak_ptr<Processor>(insert)));
358 bypass_button.set_active (!pi->active());
360 bypass_button.set_name ("PluginBypassButton");
361 bypass_button.signal_toggled().connect (mem_fun(*this, &PlugUIBase::bypass_toggled));
362 focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
364 focus_button.signal_button_release_event().connect (mem_fun(*this, &PlugUIBase::focus_toggled));
365 focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
367 /* these images are not managed, so that we can remove them at will */
369 focus_out_image = new Image (get_icon (X_("computer_keyboard")));
370 focus_in_image = new Image (get_icon (X_("computer_keyboard_active")));
372 focus_button.add (*focus_out_image);
374 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to focus all keyboard events on this plugin window"), "");
375 ARDOUR_UI::instance()->set_tip (&bypass_button, _("Click to enable/disable this plugin"), "");
379 PlugUIBase::processor_active_changed (boost::weak_ptr<Processor> weak_p)
381 ENSURE_GUI_THREAD(bind (mem_fun(*this, &PlugUIBase::processor_active_changed), weak_p));
382 boost::shared_ptr<Processor> p (weak_p);
384 bypass_button.set_active (!p->active());
389 PlugUIBase::setting_selected()
391 if (preset_combo.get_active_text().length() > 0) {
392 if (!plugin->load_preset(preset_combo.get_active_text())) {
393 warning << string_compose(_("Plugin preset %1 not found"), preset_combo.get_active_text()) << endmsg;
399 PlugUIBase::save_plugin_setting ()
401 ArdourPrompter prompter (true);
402 prompter.set_prompt(_("Name of New Preset:"));
403 prompter.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT);
404 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
405 prompter.set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY);
409 switch (prompter.run ()) {
410 case Gtk::RESPONSE_ACCEPT:
414 prompter.get_result(name);
417 if(plugin->save_preset(name)){
418 set_popdown_strings (preset_combo, plugin->get_presets());
419 preset_combo.set_active_text (name);
427 PlugUIBase::bypass_toggled ()
431 if ((x = bypass_button.get_active()) == insert->active()) {
432 insert->set_active (!x);
437 PlugUIBase::focus_toggled (GdkEventButton* ev)
439 if (Keyboard::the_keyboard().some_magic_widget_has_focus()) {
440 Keyboard::the_keyboard().magic_widget_drop_focus();
441 focus_button.remove ();
442 focus_button.add (*focus_out_image);
443 focus_out_image->show ();
444 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to focus all keyboard events on this plugin window"), "");
446 Keyboard::the_keyboard().magic_widget_grab_focus();
447 focus_button.remove ();
448 focus_button.add (*focus_in_image);
449 focus_in_image->show ();
450 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to remove keyboard focus from this plugin window"), "");
457 PlugUIBase::update_presets ()
459 set_popdown_strings (preset_combo, plugin->get_presets());