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 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 ()
161 PluginUIWindow::set_parent (Gtk::Window* win)
167 PluginUIWindow::on_map ()
170 set_keep_above (true);
174 PluginUIWindow::on_enter_notify_event (GdkEventCrossing *ev)
176 Keyboard::the_keyboard().enter_window (ev, this);
181 PluginUIWindow::on_leave_notify_event (GdkEventCrossing *ev)
183 Keyboard::the_keyboard().leave_window (ev, this);
188 PluginUIWindow::on_focus_in_event (GdkEventFocus *ev)
190 Window::on_focus_in_event (ev);
191 //Keyboard::the_keyboard().magic_widget_grab_focus ();
196 PluginUIWindow::on_focus_out_event (GdkEventFocus *ev)
198 Window::on_focus_out_event (ev);
199 //Keyboard::the_keyboard().magic_widget_drop_focus ();
204 PluginUIWindow::on_show ()
207 _pluginui->update_presets ();
213 // set_transient_for (*parent);
218 PluginUIWindow::on_hide ()
224 PluginUIWindow::create_vst_editor(boost::shared_ptr<PluginInsert> insert)
230 boost::shared_ptr<VSTPlugin> vp;
232 if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (insert->plugin())) == 0) {
233 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
235 throw failed_constructor ();
237 VSTPluginUI* vpu = new VSTPluginUI (insert, vp);
241 vpu->package (*this);
250 PluginUIWindow::create_audiounit_editor (boost::shared_ptr<PluginInsert> insert)
252 #if !defined(HAVE_AUDIOUNITS) || !defined(GTKOSX)
256 _pluginui = create_au_gui (insert, &box);
260 extern sigc::signal<void,bool> ApplicationActivationChanged;
261 ApplicationActivationChanged.connect (mem_fun (*this, &PluginUIWindow::app_activated));
268 PluginUIWindow::app_activated (bool yn)
270 #if defined (HAVE_AUDIOUNITS) && defined(GTKOSX)
271 cerr << "APP activated ? " << yn << endl;
275 _pluginui->activate ();
280 was_visible = is_visible();
282 _pluginui->deactivate ();
289 PluginUIWindow::create_lv2_editor(boost::shared_ptr<PluginInsert> insert)
295 boost::shared_ptr<LV2Plugin> vp;
297 if ((vp = boost::dynamic_pointer_cast<LV2Plugin> (insert->plugin())) == 0) {
298 error << _("create_lv2_editor called on non-LV2 plugin") << endmsg;
299 throw failed_constructor ();
301 LV2PluginUI* lpu = new LV2PluginUI (insert, vp);
304 lpu->package (*this);
313 PluginUIWindow::on_key_press_event (GdkEventKey* event)
315 if (!key_press_focus_accelerator_handler (*this, event)) {
316 return PublicEditor::instance().on_key_press_event(event);
323 PluginUIWindow::on_key_release_event (GdkEventKey* event)
329 PluginUIWindow::plugin_going_away ()
331 ENSURE_GUI_THREAD(mem_fun(*this, &PluginUIWindow::plugin_going_away));
334 _pluginui->stop_updating(0);
336 delete_when_idle (this);
339 PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
341 plugin (insert->plugin()),
342 save_button(_("Add")),
343 bypass_button (_("Bypass")),
344 latency_gui (*pi, pi->session().frame_rate(), pi->session().get_block_size()),
345 eqgui_toggle (_("Freq Analysis"))
347 //preset_combo.set_use_arrows_always(true);
349 preset_combo.set_size_request (100, -1);
350 preset_combo.set_active_text ("");
351 preset_combo.signal_changed().connect(mem_fun(*this, &PlugUIBase::setting_selected));
353 save_button.set_name ("PluginSaveButton");
354 save_button.signal_clicked().connect(mem_fun(*this, &PlugUIBase::save_plugin_setting));
356 insert->ActiveChanged.connect (bind(
357 mem_fun(*this, &PlugUIBase::processor_active_changed),
358 boost::weak_ptr<Processor>(insert)));
360 eqgui_toggle.set_active (false);
361 eqgui_toggle.signal_toggled().connect( mem_fun(*this, &PlugUIBase::toggle_plugin_analysis));
364 bypass_button.set_active (!pi->active());
366 bypass_button.set_name ("PluginBypassButton");
367 bypass_button.signal_toggled().connect (mem_fun(*this, &PlugUIBase::bypass_toggled));
368 focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
370 focus_button.signal_button_release_event().connect (mem_fun(*this, &PlugUIBase::focus_toggled));
371 focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
373 /* these images are not managed, so that we can remove them at will */
375 focus_out_image = new Image (get_icon (X_("computer_keyboard")));
376 focus_in_image = new Image (get_icon (X_("computer_keyboard_active")));
378 focus_button.add (*focus_out_image);
380 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow the plugin to receive keyboard events that Ardour would normally use as a shortcut"), "");
381 ARDOUR_UI::instance()->set_tip (&bypass_button, _("Click to enable/disable this plugin"), "");
383 plugin_eq_bin.set_expanded(true);
387 PlugUIBase::processor_active_changed (boost::weak_ptr<Processor> weak_p)
389 ENSURE_GUI_THREAD(bind (mem_fun(*this, &PlugUIBase::processor_active_changed), weak_p));
390 boost::shared_ptr<Processor> p (weak_p);
392 bypass_button.set_active (!p->active());
397 PlugUIBase::setting_selected()
399 if (preset_combo.get_active_text().length() > 0) {
400 const Plugin::PresetRecord* pr = plugin->preset_by_label(preset_combo.get_active_text());
402 plugin->load_preset(pr->uri);
404 warning << string_compose(_("Plugin preset %1 not found"),
405 preset_combo.get_active_text()) << endmsg;
411 PlugUIBase::save_plugin_setting ()
413 ArdourPrompter prompter (true);
414 prompter.set_prompt(_("Name of New Preset:"));
415 prompter.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT);
416 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
417 prompter.set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY);
422 switch (prompter.run ()) {
423 case Gtk::RESPONSE_ACCEPT:
425 prompter.get_result(name);
427 if (plugin->save_preset(name)) {
429 preset_combo.set_active_text (name);
437 PlugUIBase::bypass_toggled ()
441 if ((x = bypass_button.get_active()) == insert->active()) {
443 insert->deactivate ();
451 PlugUIBase::focus_toggled (GdkEventButton* ev)
453 if (Keyboard::the_keyboard().some_magic_widget_has_focus()) {
454 Keyboard::the_keyboard().magic_widget_drop_focus();
455 focus_button.remove ();
456 focus_button.add (*focus_out_image);
457 focus_out_image->show ();
458 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow the plugin to receive keyboard events that Ardour would normally use as a shortcut"), "");
460 Keyboard::the_keyboard().magic_widget_grab_focus();
461 focus_button.remove ();
462 focus_button.add (*focus_in_image);
463 focus_in_image->show ();
464 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow normal use of Ardour keyboard shortcuts"), "");
471 PlugUIBase::toggle_plugin_analysis()
473 if (eqgui_toggle.get_active() && !plugin_eq_bin.get_child()) {
475 PluginEqGui *foo = new PluginEqGui(insert);
476 plugin_eq_bin.add( *foo );
477 plugin_eq_bin.show_all();
482 if (!eqgui_toggle.get_active() && (gui = plugin_eq_bin.get_child())) {
485 //plugin_eq_bin.remove(*gui);
486 plugin_eq_bin.remove();
490 Gtk::Widget *toplevel = plugin_eq_bin.get_toplevel();
492 std::cerr << "No toplevel widget?!?!" << std::endl;
496 Gtk::Container *cont = dynamic_cast<Gtk::Container *>(toplevel);
498 std::cerr << "Toplevel widget is not a container?!?" << std::endl;
502 Gtk::Allocation alloc(0, 0, 50, 50); // Just make it small
503 toplevel->size_allocate(alloc);
508 PlugUIBase::update_presets ()
510 vector<string> preset_labels;
511 vector<ARDOUR::Plugin::PresetRecord> presets = plugin->get_presets();
512 for (vector<ARDOUR::Plugin::PresetRecord>::const_iterator i = presets.begin();
513 i != presets.end(); ++i) {
514 preset_labels.push_back(i->label);
516 set_popdown_strings (preset_combo, preset_labels);