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"
60 #include "plugin_eq_gui.h"
65 using namespace ARDOUR;
67 using namespace Gtkmm2ext;
71 PluginUIWindow::PluginUIWindow (Gtk::Window* win, boost::shared_ptr<PluginInsert> insert, bool scrollable)
74 bool have_gui = false;
78 Label* label = manage (new Label());
79 label->set_markup ("<b>THIS IS THE PLUGIN UI</b>");
81 if (insert->plugin()->has_editor()) {
82 switch (insert->type()) {
84 have_gui = create_vst_editor (insert);
87 case ARDOUR::AudioUnit:
88 have_gui = create_audiounit_editor (insert);
92 error << _("Eh? LADSPA plugins don't have editors!") << endmsg;
96 have_gui = create_lv2_editor (insert);
101 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
104 error << _("unknown type of editor-supplying plugin")
107 throw failed_constructor ();
114 GenericPluginUI* pu = new GenericPluginUI (insert, scrollable);
120 Gtk::HBox *hbox = new Gtk::HBox();
121 hbox->pack_start( *pu);
122 // TODO: this should be nicer
123 hbox->pack_start( eqgui_bin );
128 set_wmclass (X_("ardour_plugin_editor"), "Ardour");
130 signal_map_event().connect (mem_fun (*pu, &GenericPluginUI::start_updating));
131 signal_unmap_event().connect (mem_fun (*pu, &GenericPluginUI::stop_updating));
134 // set_position (Gtk::WIN_POS_MOUSE);
135 set_name ("PluginEditor");
136 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
138 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window*> (this)), false);
139 death_connection = insert->GoingAway.connect (mem_fun(*this, &PluginUIWindow::plugin_going_away));
141 gint h = _pluginui->get_preferred_height ();
142 gint w = _pluginui->get_preferred_width ();
145 if (h > 600) h = 600;
146 if (w > 600) w = 600;
153 set_default_size (w, h);
156 PluginUIWindow::~PluginUIWindow ()
162 PluginUIWindow::set_parent (Gtk::Window* win)
168 PluginUIWindow::on_map ()
171 set_keep_above (true);
175 PluginUIWindow::on_enter_notify_event (GdkEventCrossing *ev)
177 Keyboard::the_keyboard().enter_window (ev, this);
182 PluginUIWindow::on_leave_notify_event (GdkEventCrossing *ev)
184 Keyboard::the_keyboard().leave_window (ev, this);
189 PluginUIWindow::on_focus_in_event (GdkEventFocus *ev)
191 Window::on_focus_in_event (ev);
192 //Keyboard::the_keyboard().magic_widget_grab_focus ();
197 PluginUIWindow::on_focus_out_event (GdkEventFocus *ev)
199 Window::on_focus_out_event (ev);
200 //Keyboard::the_keyboard().magic_widget_drop_focus ();
205 PluginUIWindow::on_show ()
208 _pluginui->update_presets ();
214 // set_transient_for (*parent);
219 PluginUIWindow::on_hide ()
225 PluginUIWindow::create_vst_editor(boost::shared_ptr<PluginInsert> insert)
231 boost::shared_ptr<VSTPlugin> vp;
233 if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (insert->plugin())) == 0) {
234 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
236 throw failed_constructor ();
238 VSTPluginUI* vpu = new VSTPluginUI (insert, vp);
242 vpu->package (*this);
251 PluginUIWindow::create_audiounit_editor (boost::shared_ptr<PluginInsert> insert)
253 #if !defined(HAVE_AUDIOUNITS) || !defined(GTKOSX)
257 _pluginui = create_au_gui (insert, &box);
261 extern sigc::signal<void,bool> ApplicationActivationChanged;
262 ApplicationActivationChanged.connect (mem_fun (*this, &PluginUIWindow::app_activated));
269 PluginUIWindow::app_activated (bool yn)
271 #if defined (HAVE_AUDIOUNITS) && defined(GTKOSX)
272 cerr << "APP activated ? " << yn << endl;
276 _pluginui->activate ();
281 was_visible = is_visible();
283 _pluginui->deactivate ();
290 PluginUIWindow::create_lv2_editor(boost::shared_ptr<PluginInsert> insert)
296 boost::shared_ptr<LV2Plugin> vp;
298 if ((vp = boost::dynamic_pointer_cast<LV2Plugin> (insert->plugin())) == 0) {
299 error << _("create_lv2_editor called on non-LV2 plugin") << endmsg;
300 throw failed_constructor ();
302 LV2PluginUI* lpu = new LV2PluginUI (insert, vp);
305 lpu->package (*this);
314 PluginUIWindow::on_key_press_event (GdkEventKey* event)
316 if (!key_press_focus_accelerator_handler (*this, event)) {
317 return PublicEditor::instance().on_key_press_event(event);
324 PluginUIWindow::on_key_release_event (GdkEventKey* event)
330 PluginUIWindow::plugin_going_away ()
332 ENSURE_GUI_THREAD(mem_fun(*this, &PluginUIWindow::plugin_going_away));
335 _pluginui->stop_updating(0);
338 death_connection.disconnect ();
340 delete_when_idle (this);
343 PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
345 plugin (insert->plugin()),
346 save_button(_("Add")),
347 bypass_button (_("Bypass")),
348 latency_gui (*pi, pi->session().frame_rate(), pi->session().get_block_size()),
349 eqgui_toggle (_("Freq Analysis"))
351 //preset_combo.set_use_arrows_always(true);
353 preset_combo.set_size_request (100, -1);
354 preset_combo.set_active_text ("");
355 preset_combo.signal_changed().connect(mem_fun(*this, &PlugUIBase::setting_selected));
357 save_button.set_name ("PluginSaveButton");
358 save_button.signal_clicked().connect(mem_fun(*this, &PlugUIBase::save_plugin_setting));
360 insert->ActiveChanged.connect (bind(
361 mem_fun(*this, &PlugUIBase::processor_active_changed),
362 boost::weak_ptr<Processor>(insert)));
364 eqgui_toggle.set_active (false);
365 eqgui_toggle.signal_toggled().connect( mem_fun(*this, &PlugUIBase::toggle_plugin_analysis));
368 bypass_button.set_active (!pi->active());
370 bypass_button.set_name ("PluginBypassButton");
371 bypass_button.signal_toggled().connect (mem_fun(*this, &PlugUIBase::bypass_toggled));
372 focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
374 focus_button.signal_button_release_event().connect (mem_fun(*this, &PlugUIBase::focus_toggled));
375 focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
377 /* these images are not managed, so that we can remove them at will */
379 focus_out_image = new Image (get_icon (X_("computer_keyboard")));
380 focus_in_image = new Image (get_icon (X_("computer_keyboard_active")));
382 focus_button.add (*focus_out_image);
384 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow the plugin to receive keyboard events that Ardour would normally use as a shortcut"), "");
385 ARDOUR_UI::instance()->set_tip (&bypass_button, _("Click to enable/disable this plugin"), "");
387 plugin_eq_bin.set_expanded(true);
390 PlugUIBase::~PlugUIBase()
395 PlugUIBase::processor_active_changed (boost::weak_ptr<Processor> weak_p)
397 ENSURE_GUI_THREAD(bind (mem_fun(*this, &PlugUIBase::processor_active_changed), weak_p));
398 boost::shared_ptr<Processor> p (weak_p);
400 bypass_button.set_active (!p->active());
405 PlugUIBase::setting_selected()
407 if (preset_combo.get_active_text().length() > 0) {
408 const Plugin::PresetRecord* pr = plugin->preset_by_label(preset_combo.get_active_text());
410 plugin->load_preset(pr->uri);
412 warning << string_compose(_("Plugin preset %1 not found"),
413 preset_combo.get_active_text()) << endmsg;
419 PlugUIBase::save_plugin_setting ()
421 ArdourPrompter prompter (true);
422 prompter.set_prompt(_("Name of New Preset:"));
423 prompter.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT);
424 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
425 prompter.set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY);
430 switch (prompter.run ()) {
431 case Gtk::RESPONSE_ACCEPT:
433 prompter.get_result(name);
435 if (plugin->save_preset(name)) {
437 preset_combo.set_active_text (name);
445 PlugUIBase::bypass_toggled ()
449 if ((x = bypass_button.get_active()) == insert->active()) {
451 insert->deactivate ();
459 PlugUIBase::focus_toggled (GdkEventButton* ev)
461 if (Keyboard::the_keyboard().some_magic_widget_has_focus()) {
462 Keyboard::the_keyboard().magic_widget_drop_focus();
463 focus_button.remove ();
464 focus_button.add (*focus_out_image);
465 focus_out_image->show ();
466 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow the plugin to receive keyboard events that Ardour would normally use as a shortcut"), "");
468 Keyboard::the_keyboard().magic_widget_grab_focus();
469 focus_button.remove ();
470 focus_button.add (*focus_in_image);
471 focus_in_image->show ();
472 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow normal use of Ardour keyboard shortcuts"), "");
479 PlugUIBase::toggle_plugin_analysis()
481 if (eqgui_toggle.get_active() && !plugin_eq_bin.get_child()) {
483 PluginEqGui *foo = new PluginEqGui(insert);
484 plugin_eq_bin.add( *foo );
485 plugin_eq_bin.show_all();
490 if (!eqgui_toggle.get_active() && (gui = plugin_eq_bin.get_child())) {
493 //plugin_eq_bin.remove(*gui);
494 plugin_eq_bin.remove();
498 Gtk::Widget *toplevel = plugin_eq_bin.get_toplevel();
500 std::cerr << "No toplevel widget?!?!" << std::endl;
504 Gtk::Container *cont = dynamic_cast<Gtk::Container *>(toplevel);
506 std::cerr << "Toplevel widget is not a container?!?" << std::endl;
510 Gtk::Allocation alloc(0, 0, 50, 50); // Just make it small
511 toplevel->size_allocate(alloc);
516 PlugUIBase::update_presets ()
518 vector<string> preset_labels;
519 vector<ARDOUR::Plugin::PresetRecord> presets = plugin->get_presets();
520 for (vector<ARDOUR::Plugin::PresetRecord>::const_iterator i = presets.begin();
521 i != presets.end(); ++i) {
522 preset_labels.push_back(i->label);
524 set_popdown_strings (preset_combo, preset_labels);