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 <gtkmm2ext/click_box.h>
31 #include <gtkmm2ext/fastmeter.h>
32 #include <gtkmm2ext/barcontroller.h>
33 #include <gtkmm2ext/utils.h>
34 #include <gtkmm2ext/doi.h>
35 #include <gtkmm2ext/slider_controller.h>
37 #include <midi++/manager.h>
39 #include <ardour/plugin.h>
40 #include <ardour/insert.h>
41 #include <ardour/ladspa_plugin.h>
43 #include <ardour/vst_plugin.h>
48 #include "ardour_ui.h"
50 #include "plugin_ui.h"
52 #include "gui_thread.h"
53 #include "public_editor.h"
58 using namespace ARDOUR;
60 using namespace Gtkmm2ext;
64 PluginUIWindow::PluginUIWindow (boost::shared_ptr<PluginInsert> insert, bool scrollable)
65 : ArdourDialog ("plugin ui")
67 if (insert->plugin()->has_editor()) {
71 boost::shared_ptr<VSTPlugin> vp;
73 if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (insert->plugin())) != 0) {
76 VSTPluginUI* vpu = new VSTPluginUI (insert, vp);
79 get_vbox()->add (*vpu);
84 error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
86 throw failed_constructor ();
93 LadspaPluginUI* pu = new LadspaPluginUI (insert, scrollable);
96 get_vbox()->add (*pu);
98 set_wmclass (X_("ardour_plugin_editor"), "Ardour");
100 signal_map_event().connect (mem_fun (*pu, &LadspaPluginUI::start_updating));
101 signal_unmap_event().connect (mem_fun (*pu, &LadspaPluginUI::stop_updating));
104 set_position (Gtk::WIN_POS_MOUSE);
105 set_name ("PluginEditor");
106 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
108 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window*> (this)));
109 insert->GoingAway.connect (mem_fun(*this, &PluginUIWindow::plugin_going_away));
112 gint h = _pluginui->get_preferred_height ();
113 if (h > 600) h = 600;
114 set_default_size (450, h);
119 PluginUIWindow::~PluginUIWindow ()
124 PluginUIWindow::on_key_press_event (GdkEventKey* event)
126 if (!key_press_focus_accelerator_handler (*this, event)) {
127 return PublicEditor::instance().on_key_press_event(event);
134 PluginUIWindow::on_key_release_event (GdkEventKey* event)
140 PluginUIWindow::plugin_going_away ()
142 ENSURE_GUI_THREAD(mem_fun(*this, &PluginUIWindow::plugin_going_away));
144 _pluginui->stop_updating(0);
145 delete_when_idle (this);
148 PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
150 plugin (insert->plugin()),
151 save_button(_("Add")),
152 bypass_button (_("Bypass"))
154 //combo.set_use_arrows_always(true);
155 set_popdown_strings (combo, plugin->get_presets());
156 combo.set_size_request (100, -1);
157 combo.set_active_text ("");
158 combo.signal_changed().connect(mem_fun(*this, &PlugUIBase::setting_selected));
160 save_button.set_name ("PluginSaveButton");
161 save_button.signal_clicked().connect(mem_fun(*this, &PlugUIBase::save_plugin_setting));
163 bypass_button.set_name ("PluginBypassButton");
164 bypass_button.signal_toggled().connect (mem_fun(*this, &PlugUIBase::bypass_toggled));
168 PlugUIBase::setting_selected()
170 if (combo.get_active_text().length() > 0) {
171 if (!plugin->load_preset(combo.get_active_text())) {
172 warning << string_compose(_("Plugin preset %1 not found"), combo.get_active_text()) << endmsg;
179 PlugUIBase::save_plugin_setting ()
181 ArdourPrompter prompter (true);
182 prompter.set_prompt(_("Name of New Preset:"));
183 prompter.add_button (Gtk::Stock::ADD, Gtk::RESPONSE_ACCEPT);
184 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
188 switch (prompter.run ()) {
189 case Gtk::RESPONSE_ACCEPT:
193 prompter.get_result(name);
196 if(plugin->save_preset(name)){
197 set_popdown_strings (combo, plugin->get_presets());
198 combo.set_active_text (name);
206 PlugUIBase::bypass_toggled ()
210 if ((x = bypass_button.get_active()) == insert->active()) {
211 insert->set_active (!x, this);