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.
21 #include "gtk2ardour-config.h"
29 #include "pbd/stl_delete.h"
30 #include "pbd/xml++.h"
31 #include "pbd/failed_constructor.h"
33 #include <gtkmm/widget.h>
34 #include <gtkmm/box.h>
35 #include <gtkmm2ext/click_box.h>
36 #include <gtkmm2ext/fastmeter.h>
37 #include <gtkmm2ext/barcontroller.h>
38 #include <gtkmm2ext/utils.h>
39 #include <gtkmm2ext/doi.h>
40 #include <gtkmm2ext/slider_controller.h>
42 #include "midi++/manager.h"
44 #include "ardour/plugin.h"
45 #include "ardour/plugin_insert.h"
46 #include "ardour/ladspa_plugin.h"
48 #include "ardour/vst_plugin.h"
51 #include "ardour/lv2_plugin.h"
52 #include "lv2_plugin_ui.h"
57 #include "ardour_dialog.h"
58 #include "ardour_ui.h"
60 #include "plugin_ui.h"
62 #include "gui_thread.h"
63 #include "public_editor.h"
65 #include "latency_gui.h"
66 #include "plugin_eq_gui.h"
71 using namespace ARDOUR;
73 using namespace Gtkmm2ext;
77 PluginUIWindow::PluginUIWindow (Gtk::Window* win, boost::shared_ptr<PluginInsert> insert, bool scrollable)
80 bool have_gui = false;
84 Label* label = manage (new Label());
85 label->set_markup ("<b>THIS IS THE PLUGIN UI</b>");
87 if (insert->plugin()->has_editor()) {
88 switch (insert->type()) {
90 have_gui = create_vst_editor (insert);
93 case ARDOUR::AudioUnit:
94 have_gui = create_audiounit_editor (insert);
98 error << _("Eh? LADSPA plugins don't have editors!") << endmsg;
102 have_gui = create_lv2_editor (insert);
107 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
110 error << _("unknown type of editor-supplying plugin")
113 throw failed_constructor ();
120 GenericPluginUI* pu = new GenericPluginUI (insert, scrollable);
126 Gtk::HBox *hbox = new Gtk::HBox();
127 hbox->pack_start( *pu);
128 // TODO: this should be nicer
129 hbox->pack_start( eqgui_bin );
134 set_wmclass (X_("ardour_plugin_editor"), "Ardour");
136 signal_map_event().connect (mem_fun (*pu, &GenericPluginUI::start_updating));
137 signal_unmap_event().connect (mem_fun (*pu, &GenericPluginUI::stop_updating));
140 // set_position (Gtk::WIN_POS_MOUSE);
141 set_name ("PluginEditor");
142 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
144 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window*> (this)), false);
145 death_connection = insert->GoingAway.connect (mem_fun(*this, &PluginUIWindow::plugin_going_away));
147 gint h = _pluginui->get_preferred_height ();
148 gint w = _pluginui->get_preferred_width ();
151 if (h > 600) h = 600;
152 if (w > 600) w = 600;
159 set_default_size (w, h);
162 PluginUIWindow::~PluginUIWindow ()
168 PluginUIWindow::set_parent (Gtk::Window* win)
174 PluginUIWindow::on_map ()
177 set_keep_above (true);
181 PluginUIWindow::on_enter_notify_event (GdkEventCrossing *ev)
183 Keyboard::the_keyboard().enter_window (ev, this);
188 PluginUIWindow::on_leave_notify_event (GdkEventCrossing *ev)
190 Keyboard::the_keyboard().leave_window (ev, this);
195 PluginUIWindow::on_focus_in_event (GdkEventFocus *ev)
197 Window::on_focus_in_event (ev);
198 //Keyboard::the_keyboard().magic_widget_grab_focus ();
203 PluginUIWindow::on_focus_out_event (GdkEventFocus *ev)
205 Window::on_focus_out_event (ev);
206 //Keyboard::the_keyboard().magic_widget_drop_focus ();
211 PluginUIWindow::on_show ()
214 _pluginui->update_presets ();
220 // set_transient_for (*parent);
225 PluginUIWindow::on_hide ()
231 PluginUIWindow::create_vst_editor(boost::shared_ptr<PluginInsert> insert)
237 boost::shared_ptr<VSTPlugin> vp;
239 if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (insert->plugin())) == 0) {
240 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
242 throw failed_constructor ();
244 VSTPluginUI* vpu = new VSTPluginUI (insert, vp);
248 vpu->package (*this);
257 PluginUIWindow::create_audiounit_editor (boost::shared_ptr<PluginInsert> insert)
259 #if !defined(HAVE_AUDIOUNITS) || !defined(GTKOSX)
263 _pluginui = create_au_gui (insert, &box);
267 extern sigc::signal<void,bool> ApplicationActivationChanged;
268 ApplicationActivationChanged.connect (mem_fun (*this, &PluginUIWindow::app_activated));
275 PluginUIWindow::app_activated (bool yn)
277 #if defined (HAVE_AUDIOUNITS) && defined(GTKOSX)
278 cerr << "APP activated ? " << yn << endl;
282 _pluginui->activate ();
287 was_visible = is_visible();
289 _pluginui->deactivate ();
296 PluginUIWindow::create_lv2_editor(boost::shared_ptr<PluginInsert> insert)
302 boost::shared_ptr<LV2Plugin> vp;
304 if ((vp = boost::dynamic_pointer_cast<LV2Plugin> (insert->plugin())) == 0) {
305 error << _("create_lv2_editor called on non-LV2 plugin") << endmsg;
306 throw failed_constructor ();
308 LV2PluginUI* lpu = new LV2PluginUI (insert, vp);
311 lpu->package (*this);
320 PluginUIWindow::on_key_press_event (GdkEventKey* event)
322 if (!key_press_focus_accelerator_handler (*this, event)) {
323 return PublicEditor::instance().on_key_press_event(event);
330 PluginUIWindow::on_key_release_event (GdkEventKey* event)
336 PluginUIWindow::plugin_going_away ()
338 ENSURE_GUI_THREAD(mem_fun(*this, &PluginUIWindow::plugin_going_away));
341 _pluginui->stop_updating(0);
344 death_connection.disconnect ();
346 delete_when_idle (this);
349 PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
351 plugin (insert->plugin()),
352 save_button(_("Add")),
353 bypass_button (_("Bypass")),
355 plugin_analysis_expander (_("Plugin analysis"))
357 //preset_combo.set_use_arrows_always(true);
359 preset_combo.set_size_request (100, -1);
360 preset_combo.set_active_text ("");
361 preset_combo.signal_changed().connect(mem_fun(*this, &PlugUIBase::setting_selected));
363 save_button.set_name ("PluginSaveButton");
364 save_button.signal_clicked().connect(mem_fun(*this, &PlugUIBase::save_plugin_setting));
366 insert->ActiveChanged.connect (bind(
367 mem_fun(*this, &PlugUIBase::processor_active_changed),
368 boost::weak_ptr<Processor>(insert)));
370 bypass_button.set_active (!pi->active());
372 bypass_button.set_name ("PluginBypassButton");
373 bypass_button.signal_toggled().connect (mem_fun(*this, &PlugUIBase::bypass_toggled));
374 focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
376 focus_button.signal_button_release_event().connect (mem_fun(*this, &PlugUIBase::focus_toggled));
377 focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
379 /* these images are not managed, so that we can remove them at will */
381 focus_out_image = new Image (get_icon (X_("computer_keyboard")));
382 focus_in_image = new Image (get_icon (X_("computer_keyboard_active")));
384 focus_button.add (*focus_out_image);
386 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow the plugin to receive keyboard events that Ardour would normally use as a shortcut"), "");
387 ARDOUR_UI::instance()->set_tip (&bypass_button, _("Click to enable/disable this plugin"), "");
389 plugin_analysis_expander.property_expanded().signal_changed().connect( mem_fun(*this, &PlugUIBase::toggle_plugin_analysis));
390 plugin_analysis_expander.set_expanded(false);
392 insert->GoingAway.connect (mem_fun (*this, &PlugUIBase::plugin_going_away));
395 PlugUIBase::~PlugUIBase()
401 PlugUIBase::plugin_going_away ()
403 /* drop references to the plugin/insert */
409 PlugUIBase::set_latency_label ()
412 nframes_t l = insert->effective_latency ();
413 nframes_t sr = insert->session().frame_rate();
416 snprintf (buf, sizeof (buf), "latency (%d samples)", l);
418 snprintf (buf, sizeof (buf), "latency (%.2f msecs)", (float) l / ((float) sr / 1000.0f));
421 latency_label.set_text (buf);
425 PlugUIBase::latency_button_clicked ()
428 latency_gui = new LatencyGUI (*(insert.get()), insert->session().frame_rate(), insert->session().get_block_size());
429 latency_dialog = new ArdourDialog ("Edit Latency", false, false);
430 latency_dialog->get_vbox()->pack_start (*latency_gui);
431 latency_dialog->signal_hide().connect (mem_fun (*this, &PlugUIBase::set_latency_label));
434 latency_dialog->show_all ();
438 PlugUIBase::processor_active_changed (boost::weak_ptr<Processor> weak_p)
440 ENSURE_GUI_THREAD(bind (mem_fun(*this, &PlugUIBase::processor_active_changed), weak_p));
441 boost::shared_ptr<Processor> p (weak_p);
443 bypass_button.set_active (!p->active());
448 PlugUIBase::setting_selected()
450 if (preset_combo.get_active_text().length() > 0) {
451 const Plugin::PresetRecord* pr = plugin->preset_by_label(preset_combo.get_active_text());
453 plugin->load_preset(pr->uri);
455 warning << string_compose(_("Plugin preset %1 not found"),
456 preset_combo.get_active_text()) << endmsg;
462 PlugUIBase::save_plugin_setting ()
464 ArdourPrompter prompter (true);
465 prompter.set_prompt(_("Name of New Preset:"));
466 prompter.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT);
467 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
468 prompter.set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY);
473 switch (prompter.run ()) {
474 case Gtk::RESPONSE_ACCEPT:
476 prompter.get_result(name);
478 if (plugin->save_preset(name)) {
480 preset_combo.set_active_text (name);
488 PlugUIBase::bypass_toggled ()
492 if ((x = bypass_button.get_active()) == insert->active()) {
494 insert->deactivate ();
502 PlugUIBase::focus_toggled (GdkEventButton* ev)
504 if (Keyboard::the_keyboard().some_magic_widget_has_focus()) {
505 Keyboard::the_keyboard().magic_widget_drop_focus();
506 focus_button.remove ();
507 focus_button.add (*focus_out_image);
508 focus_out_image->show ();
509 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow the plugin to receive keyboard events that Ardour would normally use as a shortcut"), "");
511 Keyboard::the_keyboard().magic_widget_grab_focus();
512 focus_button.remove ();
513 focus_button.add (*focus_in_image);
514 focus_in_image->show ();
515 ARDOUR_UI::instance()->set_tip (&focus_button, _("Click to allow normal use of Ardour keyboard shortcuts"), "");
522 PlugUIBase::toggle_plugin_analysis()
524 if (plugin_analysis_expander.get_expanded() &&
525 !plugin_analysis_expander.get_child()) {
527 PluginEqGui *foo = new PluginEqGui(insert);
528 plugin_analysis_expander.add( *foo );
529 plugin_analysis_expander.show_all();
534 if (!plugin_analysis_expander.get_expanded() &&
535 (gui = plugin_analysis_expander.get_child())) {
538 //plugin_analysis_expander.remove(*gui);
539 plugin_analysis_expander.remove();
543 Gtk::Widget *toplevel = plugin_analysis_expander.get_toplevel();
545 std::cerr << "No toplevel widget?!?!" << std::endl;
549 Gtk::Container *cont = dynamic_cast<Gtk::Container *>(toplevel);
551 std::cerr << "Toplevel widget is not a container?!?" << std::endl;
555 Gtk::Allocation alloc(0, 0, 50, 50); // Just make it small
556 toplevel->size_allocate(alloc);
561 PlugUIBase::update_presets ()
563 vector<string> preset_labels;
564 vector<ARDOUR::Plugin::PresetRecord> presets = plugin->get_presets();
565 for (vector<ARDOUR::Plugin::PresetRecord>::const_iterator i = presets.begin();
566 i != presets.end(); ++i) {
567 preset_labels.push_back(i->label);
569 set_popdown_strings (preset_combo, preset_labels);