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_dialog.h"
54 #include "ardour_ui.h"
56 #include "plugin_ui.h"
58 #include "gui_thread.h"
59 #include "public_editor.h"
61 #include "latency_gui.h"
62 #include "plugin_eq_gui.h"
67 using namespace ARDOUR;
69 using namespace Gtkmm2ext;
73 PluginUIWindow::PluginUIWindow (Gtk::Window* win, boost::shared_ptr<PluginInsert> insert, bool scrollable)
76 bool have_gui = false;
80 Label* label = manage (new Label());
81 label->set_markup ("<b>THIS IS THE PLUGIN UI</b>");
83 if (insert->plugin()->has_editor()) {
84 switch (insert->type()) {
86 have_gui = create_vst_editor (insert);
89 case ARDOUR::AudioUnit:
90 have_gui = create_audiounit_editor (insert);
94 error << _("Eh? LADSPA plugins don't have editors!") << endmsg;
98 have_gui = create_lv2_editor (insert);
103 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
106 error << _("unknown type of editor-supplying plugin")
109 throw failed_constructor ();
116 GenericPluginUI* pu = new GenericPluginUI (insert, scrollable);
122 Gtk::HBox *hbox = new Gtk::HBox();
123 hbox->pack_start( *pu);
124 // TODO: this should be nicer
125 hbox->pack_start( eqgui_bin );
130 set_wmclass (X_("ardour_plugin_editor"), "Ardour");
132 signal_map_event().connect (mem_fun (*pu, &GenericPluginUI::start_updating));
133 signal_unmap_event().connect (mem_fun (*pu, &GenericPluginUI::stop_updating));
136 // set_position (Gtk::WIN_POS_MOUSE);
137 set_name ("PluginEditor");
138 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
140 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window*> (this)), false);
141 death_connection = insert->GoingAway.connect (mem_fun(*this, &PluginUIWindow::plugin_going_away));
143 gint h = _pluginui->get_preferred_height ();
144 gint w = _pluginui->get_preferred_width ();
147 if (h > 600) h = 600;
148 if (w > 600) w = 600;
155 set_default_size (w, h);
158 PluginUIWindow::~PluginUIWindow ()
164 PluginUIWindow::set_parent (Gtk::Window* win)
170 PluginUIWindow::on_map ()
173 set_keep_above (true);
177 PluginUIWindow::on_enter_notify_event (GdkEventCrossing *ev)
179 Keyboard::the_keyboard().enter_window (ev, this);
184 PluginUIWindow::on_leave_notify_event (GdkEventCrossing *ev)
186 Keyboard::the_keyboard().leave_window (ev, this);
191 PluginUIWindow::on_focus_in_event (GdkEventFocus *ev)
193 Window::on_focus_in_event (ev);
194 //Keyboard::the_keyboard().magic_widget_grab_focus ();
199 PluginUIWindow::on_focus_out_event (GdkEventFocus *ev)
201 Window::on_focus_out_event (ev);
202 //Keyboard::the_keyboard().magic_widget_drop_focus ();
207 PluginUIWindow::on_show ()
210 _pluginui->update_presets ();
216 // set_transient_for (*parent);
221 PluginUIWindow::on_hide ()
227 PluginUIWindow::create_vst_editor(boost::shared_ptr<PluginInsert> insert)
233 boost::shared_ptr<VSTPlugin> vp;
235 if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (insert->plugin())) == 0) {
236 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
238 throw failed_constructor ();
240 VSTPluginUI* vpu = new VSTPluginUI (insert, vp);
244 vpu->package (*this);
253 PluginUIWindow::create_audiounit_editor (boost::shared_ptr<PluginInsert> insert)
255 #if !defined(HAVE_AUDIOUNITS) || !defined(GTKOSX)
259 _pluginui = create_au_gui (insert, &box);
263 extern sigc::signal<void,bool> ApplicationActivationChanged;
264 ApplicationActivationChanged.connect (mem_fun (*this, &PluginUIWindow::app_activated));
271 PluginUIWindow::app_activated (bool yn)
273 #if defined (HAVE_AUDIOUNITS) && defined(GTKOSX)
274 cerr << "APP activated ? " << yn << endl;
278 _pluginui->activate ();
283 was_visible = is_visible();
285 _pluginui->deactivate ();
292 PluginUIWindow::create_lv2_editor(boost::shared_ptr<PluginInsert> insert)
298 boost::shared_ptr<LV2Plugin> vp;
300 if ((vp = boost::dynamic_pointer_cast<LV2Plugin> (insert->plugin())) == 0) {
301 error << _("create_lv2_editor called on non-LV2 plugin") << endmsg;
302 throw failed_constructor ();
304 LV2PluginUI* lpu = new LV2PluginUI (insert, vp);
307 lpu->package (*this);
316 PluginUIWindow::on_key_press_event (GdkEventKey* event)
318 if (!key_press_focus_accelerator_handler (*this, event)) {
319 return PublicEditor::instance().on_key_press_event(event);
326 PluginUIWindow::on_key_release_event (GdkEventKey* event)
332 PluginUIWindow::plugin_going_away ()
334 ENSURE_GUI_THREAD(mem_fun(*this, &PluginUIWindow::plugin_going_away));
337 _pluginui->stop_updating(0);
340 death_connection.disconnect ();
342 delete_when_idle (this);
345 PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
347 plugin (insert->plugin()),
348 save_button(_("Add")),
349 bypass_button (_("Bypass")),
351 plugin_analysis_expander (_("Plugin analysis"))
353 //preset_combo.set_use_arrows_always(true);
355 preset_combo.set_size_request (100, -1);
356 preset_combo.set_active_text ("");
357 preset_combo.signal_changed().connect(mem_fun(*this, &PlugUIBase::setting_selected));
359 save_button.set_name ("PluginSaveButton");
360 save_button.signal_clicked().connect(mem_fun(*this, &PlugUIBase::save_plugin_setting));
362 insert->ActiveChanged.connect (bind(
363 mem_fun(*this, &PlugUIBase::processor_active_changed),
364 boost::weak_ptr<Processor>(insert)));
366 bypass_button.set_active (!pi->active());
368 bypass_button.set_name ("PluginBypassButton");
369 bypass_button.signal_toggled().connect (mem_fun(*this, &PlugUIBase::bypass_toggled));
370 focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
372 focus_button.signal_button_release_event().connect (mem_fun(*this, &PlugUIBase::focus_toggled));
373 focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
375 /* these images are not managed, so that we can remove them at will */
377 focus_out_image = new Image (get_icon (X_("computer_keyboard")));
378 focus_in_image = new Image (get_icon (X_("computer_keyboard_active")));
380 focus_button.add (*focus_out_image);
382 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow the plugin to receive keyboard events that Ardour would normally use as a shortcut"), "");
383 ARDOUR_UI::instance()->set_tip (&bypass_button, _("Click to enable/disable this plugin"), "");
385 plugin_analysis_expander.property_expanded().signal_changed().connect( mem_fun(*this, &PlugUIBase::toggle_plugin_analysis));
387 plugin_analysis_expander.set_expanded(false);
390 PlugUIBase::~PlugUIBase()
396 PlugUIBase::set_latency_label ()
399 nframes_t l = insert->effective_latency ();
400 nframes_t sr = insert->session().frame_rate();
403 snprintf (buf, sizeof (buf), "latency (%d samples)", l);
405 snprintf (buf, sizeof (buf), "latency (%.2f msecs)", (float) l / ((float) sr / 1000.0f));
408 latency_label.set_text (buf);
412 PlugUIBase::latency_button_clicked ()
415 latency_gui = new LatencyGUI (*(insert.get()), insert->session().frame_rate(), insert->session().get_block_size());
416 latency_dialog = new ArdourDialog ("Edit Latency", false, false);
417 latency_dialog->get_vbox()->pack_start (*latency_gui);
418 latency_dialog->signal_hide().connect (mem_fun (*this, &PlugUIBase::set_latency_label));
421 latency_dialog->show_all ();
425 PlugUIBase::processor_active_changed (boost::weak_ptr<Processor> weak_p)
427 ENSURE_GUI_THREAD(bind (mem_fun(*this, &PlugUIBase::processor_active_changed), weak_p));
428 boost::shared_ptr<Processor> p (weak_p);
430 bypass_button.set_active (!p->active());
435 PlugUIBase::setting_selected()
437 if (preset_combo.get_active_text().length() > 0) {
438 const Plugin::PresetRecord* pr = plugin->preset_by_label(preset_combo.get_active_text());
440 plugin->load_preset(pr->uri);
442 warning << string_compose(_("Plugin preset %1 not found"),
443 preset_combo.get_active_text()) << endmsg;
449 PlugUIBase::save_plugin_setting ()
451 ArdourPrompter prompter (true);
452 prompter.set_prompt(_("Name of New Preset:"));
453 prompter.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT);
454 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
455 prompter.set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY);
460 switch (prompter.run ()) {
461 case Gtk::RESPONSE_ACCEPT:
463 prompter.get_result(name);
465 if (plugin->save_preset(name)) {
467 preset_combo.set_active_text (name);
475 PlugUIBase::bypass_toggled ()
479 if ((x = bypass_button.get_active()) == insert->active()) {
481 insert->deactivate ();
489 PlugUIBase::focus_toggled (GdkEventButton* ev)
491 if (Keyboard::the_keyboard().some_magic_widget_has_focus()) {
492 Keyboard::the_keyboard().magic_widget_drop_focus();
493 focus_button.remove ();
494 focus_button.add (*focus_out_image);
495 focus_out_image->show ();
496 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow the plugin to receive keyboard events that Ardour would normally use as a shortcut"), "");
498 Keyboard::the_keyboard().magic_widget_grab_focus();
499 focus_button.remove ();
500 focus_button.add (*focus_in_image);
501 focus_in_image->show ();
502 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow normal use of Ardour keyboard shortcuts"), "");
509 PlugUIBase::toggle_plugin_analysis()
511 if (plugin_analysis_expander.get_expanded() &&
512 !plugin_analysis_expander.get_child()) {
514 PluginEqGui *foo = new PluginEqGui(insert);
515 plugin_analysis_expander.add( *foo );
516 plugin_analysis_expander.show_all();
521 if (!plugin_analysis_expander.get_expanded() &&
522 (gui = plugin_analysis_expander.get_child())) {
525 //plugin_analysis_expander.remove(*gui);
526 plugin_analysis_expander.remove();
530 Gtk::Widget *toplevel = plugin_analysis_expander.get_toplevel();
532 std::cerr << "No toplevel widget?!?!" << std::endl;
536 Gtk::Container *cont = dynamic_cast<Gtk::Container *>(toplevel);
538 std::cerr << "Toplevel widget is not a container?!?" << std::endl;
542 Gtk::Allocation alloc(0, 0, 50, 50); // Just make it small
543 toplevel->size_allocate(alloc);
548 PlugUIBase::update_presets ()
550 vector<string> preset_labels;
551 vector<ARDOUR::Plugin::PresetRecord> presets = plugin->get_presets();
552 for (vector<ARDOUR::Plugin::PresetRecord>::const_iterator i = presets.begin();
553 i != presets.end(); ++i) {
554 preset_labels.push_back(i->label);
556 set_popdown_strings (preset_combo, preset_labels);