2 Copyright (C) 2000-2002 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 "libardour-config.h"
28 #include <cstdio> // so libraptor doesn't complain
41 #include "pbd/compose.h"
42 #include "pbd/error.h"
43 #include "pbd/xml++.h"
45 #include "ardour/buffer_set.h"
46 #include "ardour/chan_count.h"
47 #include "ardour/chan_mapping.h"
48 #include "ardour/data_type.h"
49 #include "ardour/luaproc.h"
50 #include "ardour/midi_buffer.h"
51 #include "ardour/midi_state_tracker.h"
52 #include "ardour/plugin.h"
53 #include "ardour/plugin_manager.h"
54 #include "ardour/port.h"
55 #include "ardour/session.h"
56 #include "ardour/types.h"
58 #ifdef AUDIOUNIT_SUPPORT
59 #include "ardour/audio_unit.h"
63 #include "ardour/lv2_plugin.h"
66 #include "pbd/stl_delete.h"
72 using namespace ARDOUR;
75 namespace ARDOUR { class AudioEngine; }
77 #ifdef NO_PLUGIN_STATE
78 static bool seen_get_state_message = false;
79 static bool seen_set_state_message = false;
82 PBD::Signal2<void, std::string, Plugin*> Plugin::PresetsChanged;
85 PluginInfo::needs_midi_input () const
87 return (n_inputs.n_midi() != 0);
91 PluginInfo::is_instrument () const
93 return (n_inputs.n_midi() != 0) && (n_outputs.n_audio() > 0) && (n_inputs.n_audio() == 0);
96 Plugin::Plugin (AudioEngine& e, Session& s)
101 , _have_presets (false)
102 , _have_pending_stop_events (false)
103 , _parameter_changed_since_last_preset (false)
105 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
108 Plugin::Plugin (const Plugin& other)
109 : StatefulDestructible()
111 , _engine (other._engine)
112 , _session (other._session)
113 , _info (other._info)
115 , _owner (other._owner)
116 , _have_presets (false)
117 , _have_pending_stop_events (false)
118 , _parameter_changed_since_last_preset (false)
120 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
128 Plugin::remove_preset (string name)
130 Plugin::PresetRecord const * p = preset_by_label (name);
132 PBD::error << _("Trying to remove nonexistent preset.") << endmsg;
136 PBD::error << _("Cannot remove plugin factory preset.") << endmsg;
140 do_remove_preset (name);
141 _presets.erase (p->uri);
143 _last_preset.uri = "";
144 _parameter_changed_since_last_preset = false;
145 _have_presets = false;
146 PresetsChanged (unique_id(), this); /* EMIT SIGNAL */
147 PresetRemoved (); /* EMIT SIGNAL */
150 /** @return PresetRecord with empty URI on failure */
152 Plugin::save_preset (string name)
154 if (preset_by_label (name)) {
155 PBD::error << _("Preset with given name already exists.") << endmsg;
156 return Plugin::PresetRecord ();
159 string const uri = do_save_preset (name);
162 _presets.insert (make_pair (uri, PresetRecord (uri, name)));
163 _have_presets = false;
164 PresetsChanged (unique_id(), this); /* EMIT SIGNAL */
165 PresetAdded (); /* EMIT SIGNAL */
168 return PresetRecord (uri, name);
172 ARDOUR::find_plugin(Session& session, string identifier, PluginType type)
174 PluginManager& mgr (PluginManager::instance());
175 PluginInfoList plugs;
179 plugs = mgr.lua_plugin_info();
183 plugs = mgr.ladspa_plugin_info();
188 plugs = mgr.lv2_plugin_info();
192 #ifdef WINDOWS_VST_SUPPORT
193 case ARDOUR::Windows_VST:
194 plugs = mgr.windows_vst_plugin_info();
200 plugs = mgr.lxvst_plugin_info();
204 #ifdef MACVST_SUPPORT
206 plugs = mgr.mac_vst_plugin_info();
210 #ifdef AUDIOUNIT_SUPPORT
211 case ARDOUR::AudioUnit:
212 plugs = mgr.au_plugin_info();
217 return PluginPtr ((Plugin *) 0);
220 PluginInfoList::iterator i;
222 for (i = plugs.begin(); i != plugs.end(); ++i) {
223 if (identifier == (*i)->unique_id){
224 return (*i)->load (session);
228 #ifdef WINDOWS_VST_SUPPORT
229 /* hmm, we didn't find it. could be because in older versions of Ardour.
230 we used to store the name of a VST plugin, not its unique ID. so try
234 for (i = plugs.begin(); i != plugs.end(); ++i) {
235 if (identifier == (*i)->name){
236 return (*i)->load (session);
242 /* hmm, we didn't find it. could be because in older versions of Ardour.
243 we used to store the name of a VST plugin, not its unique ID. so try
247 for (i = plugs.begin(); i != plugs.end(); ++i) {
248 if (identifier == (*i)->name){
249 return (*i)->load (session);
254 return PluginPtr ((Plugin*) 0);
258 Plugin::output_streams () const
260 /* LADSPA & VST should not get here because they do not
261 return "infinite" i/o counts.
263 return ChanCount::ZERO;
267 Plugin::input_streams () const
269 /* LADSPA & VST should not get here because they do not
270 return "infinite" i/o counts.
272 return ChanCount::ZERO;
275 Plugin::IOPortDescription
276 Plugin::describe_io_port (ARDOUR::DataType dt, bool input, uint32_t id) const
278 std::stringstream ss;
280 case DataType::AUDIO:
281 ss << _("Audio") << " ";
284 ss << _("Midi") << " ";
291 ss << _("In") << " ";
293 ss << _("Out") << " ";
298 Plugin::IOPortDescription iod (ss.str());
302 PluginOutputConfiguration
303 Plugin::possible_output () const
305 PluginOutputConfiguration oc;
307 oc.insert (_info->n_outputs.n_audio ());
312 const Plugin::PresetRecord *
313 Plugin::preset_by_label (const string& label)
315 #ifndef NO_PLUGIN_STATE
316 if (!_have_presets) {
318 _have_presets = true;
322 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
323 if (i->second.label == label) {
331 const Plugin::PresetRecord *
332 Plugin::preset_by_uri (const string& uri)
334 #ifndef NO_PLUGIN_STATE
335 if (!_have_presets) {
337 _have_presets = true;
340 map<string, PresetRecord>::const_iterator pr = _presets.find (uri);
341 if (pr != _presets.end()) {
349 Plugin::connect_and_run (BufferSet& bufs,
350 framepos_t /*start*/, framepos_t /*end*/, double /*speed*/,
351 ChanMapping /*in_map*/, ChanMapping /*out_map*/,
352 pframes_t /* nframes */, framecnt_t /*offset*/)
354 if (bufs.count().n_midi() > 0) {
356 /* Track notes that we are sending to the plugin */
358 const MidiBuffer& b = bufs.get_midi (0);
360 _tracker.track (b.begin(), b.end());
362 if (_have_pending_stop_events) {
363 /* Transmit note-offs that are pending from the last transport stop */
364 bufs.merge_from (_pending_stop_events, 0);
365 _have_pending_stop_events = false;
373 Plugin::realtime_handle_transport_stopped ()
379 Plugin::realtime_locate ()
385 Plugin::monitoring_changed ()
391 Plugin::resolve_midi ()
393 /* Create note-offs for any active notes and put them in _pending_stop_events, to be picked
394 up on the next call to connect_and_run ().
397 _pending_stop_events.get_midi(0).clear ();
398 _tracker.resolve_notes (_pending_stop_events.get_midi (0), 0);
399 _have_pending_stop_events = true;
402 vector<Plugin::PresetRecord>
403 Plugin::get_presets ()
405 vector<PresetRecord> p;
407 #ifndef NO_PLUGIN_STATE
408 if (!_have_presets) {
410 _have_presets = true;
413 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
414 p.push_back (i->second);
417 if (!seen_set_state_message) {
418 info << string_compose (_("Plugin presets are not supported in this build of %1. Consider paying for a full version"),
421 seen_set_state_message = true;
428 /** Set parameters using a preset */
430 Plugin::load_preset (PresetRecord r)
433 _parameter_changed_since_last_preset = false;
435 _session.set_dirty ();
436 PresetLoaded (); /* EMIT SIGNAL */
441 Plugin::clear_preset ()
443 _last_preset.uri = "";
444 _last_preset.label = "";
445 _parameter_changed_since_last_preset = false;
447 _session.set_dirty ();
448 PresetLoaded (); /* EMIT SIGNAL */
452 Plugin::set_parameter (uint32_t /* which */, float /* value */)
454 _parameter_changed_since_last_preset = true;
455 PresetDirty (); /* EMIT SIGNAL */
459 Plugin::parameter_changed_externally (uint32_t which, float /* value */)
461 _parameter_changed_since_last_preset = true;
462 _session.set_dirty ();
463 ParameterChangedExternally (which, get_parameter (which)); /* EMIT SIGNAL */
464 PresetDirty (); /* EMIT SIGNAL */
468 Plugin::set_state (const XMLNode& node, int /*version*/)
470 node.get_property (X_("last-preset-uri"), _last_preset.uri);
471 node.get_property (X_("last-preset-label"), _last_preset.label);
472 node.get_property (X_("parameter-changed-since-last-preset"), _parameter_changed_since_last_preset);
479 XMLNode* root = new XMLNode (state_node_name ());
481 root->set_property (X_("last-preset-uri"), _last_preset.uri);
482 root->set_property (X_("last-preset-label"), _last_preset.label);
483 root->set_property (X_("parameter-changed-since-last-preset"), _parameter_changed_since_last_preset);
485 #ifndef NO_PLUGIN_STATE
488 if (!seen_get_state_message) {
489 info << string_compose (_("Saving plugin settings is not supported in this build of %1. Consider paying for the full version"),
492 seen_get_state_message = true;
500 Plugin::set_info (PluginInfoPtr info)
506 Plugin::parameter_label (uint32_t which) const
508 if (which >= parameter_count ()) {
511 ParameterDescriptor pd;
512 get_parameter_descriptor (which, pd);