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::is_instrument () const
87 return (n_inputs.n_midi() != 0) && (n_outputs.n_audio() > 0);
90 Plugin::Plugin (AudioEngine& e, Session& s)
94 , _have_presets (false)
95 , _have_pending_stop_events (false)
96 , _parameter_changed_since_last_preset (false)
98 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
99 PresetsChanged.connect_same_thread (_preset_connection, boost::bind (&Plugin::update_presets, this, _1 ,_2));
102 Plugin::Plugin (const Plugin& other)
103 : StatefulDestructible()
105 , _engine (other._engine)
106 , _session (other._session)
107 , _info (other._info)
109 , _have_presets (false)
110 , _have_pending_stop_events (false)
111 , _parameter_changed_since_last_preset (false)
113 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
114 PresetsChanged.connect_same_thread (_preset_connection, boost::bind (&Plugin::update_presets, this, _1 ,_2));
122 Plugin::remove_preset (string name)
124 Plugin::PresetRecord const * p = preset_by_label (name);
126 PBD::error << _("Cannot remove plugin factory preset.") << endmsg;
130 do_remove_preset (name);
131 _presets.erase (preset_by_label (name)->uri);
133 _last_preset.uri = "";
134 _parameter_changed_since_last_preset = false;
135 PresetRemoved (); /* EMIT SIGNAL */
136 PresetsChanged (unique_id(), this); /* EMIT SIGNAL */
139 /** @return PresetRecord with empty URI on failure */
141 Plugin::save_preset (string name)
143 if (preset_by_label (name)) {
144 PBD::error << _("Preset with given name already exists.") << endmsg;
145 return Plugin::PresetRecord ();
148 string const uri = do_save_preset (name);
151 _presets.insert (make_pair (uri, PresetRecord (uri, name)));
152 PresetAdded (); /* EMIT SIGNAL */
153 PresetsChanged (unique_id(), this); /* EMIT SIGNAL */
156 return PresetRecord (uri, name);
160 ARDOUR::find_plugin(Session& session, string identifier, PluginType type)
162 PluginManager& mgr (PluginManager::instance());
163 PluginInfoList plugs;
167 plugs = mgr.lua_plugin_info();
171 plugs = mgr.ladspa_plugin_info();
176 plugs = mgr.lv2_plugin_info();
180 #ifdef WINDOWS_VST_SUPPORT
181 case ARDOUR::Windows_VST:
182 plugs = mgr.windows_vst_plugin_info();
188 plugs = mgr.lxvst_plugin_info();
192 #ifdef AUDIOUNIT_SUPPORT
193 case ARDOUR::AudioUnit:
194 plugs = mgr.au_plugin_info();
199 return PluginPtr ((Plugin *) 0);
202 PluginInfoList::iterator i;
204 for (i = plugs.begin(); i != plugs.end(); ++i) {
205 if (identifier == (*i)->unique_id){
206 return (*i)->load (session);
210 #ifdef WINDOWS_VST_SUPPORT
211 /* hmm, we didn't find it. could be because in older versions of Ardour.
212 we used to store the name of a VST plugin, not its unique ID. so try
216 for (i = plugs.begin(); i != plugs.end(); ++i) {
217 if (identifier == (*i)->name){
218 return (*i)->load (session);
224 /* hmm, we didn't find it. could be because in older versions of Ardour.
225 we used to store the name of a VST plugin, not its unique ID. so try
229 for (i = plugs.begin(); i != plugs.end(); ++i) {
230 if (identifier == (*i)->name){
231 return (*i)->load (session);
236 return PluginPtr ((Plugin*) 0);
240 Plugin::output_streams () const
242 /* LADSPA & VST should not get here because they do not
243 return "infinite" i/o counts.
245 return ChanCount::ZERO;
249 Plugin::input_streams () const
251 /* LADSPA & VST should not get here because they do not
252 return "infinite" i/o counts.
254 return ChanCount::ZERO;
257 Plugin::IOPortDescription
258 Plugin::describe_io_port (ARDOUR::DataType dt, bool input, uint32_t id) const
260 std::stringstream ss;
262 case DataType::AUDIO:
263 ss << _("Audio") << " ";
266 ss << _("Midi") << " ";
273 ss << _("In") << " ";
275 ss << _("Out") << " ";
280 Plugin::IOPortDescription iod (ss.str());
284 PluginOutputConfiguration
285 Plugin::possible_output () const
287 PluginOutputConfiguration oc;
289 oc.insert (_info->n_outputs.n_audio ());
294 const Plugin::PresetRecord *
295 Plugin::preset_by_label (const string& label)
297 #ifndef NO_PLUGIN_STATE
298 if (!_have_presets) {
300 _have_presets = true;
304 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
305 if (i->second.label == label) {
313 const Plugin::PresetRecord *
314 Plugin::preset_by_uri (const string& uri)
316 #ifndef NO_PLUGIN_STATE
317 if (!_have_presets) {
319 _have_presets = true;
322 map<string, PresetRecord>::const_iterator pr = _presets.find (uri);
323 if (pr != _presets.end()) {
331 Plugin::connect_and_run (BufferSet& bufs,
332 ChanMapping /*in_map*/, ChanMapping /*out_map*/,
333 pframes_t /* nframes */, framecnt_t /*offset*/)
335 if (bufs.count().n_midi() > 0) {
337 /* Track notes that we are sending to the plugin */
339 const MidiBuffer& b = bufs.get_midi (0);
341 _tracker.track (b.begin(), b.end());
343 if (_have_pending_stop_events) {
344 /* Transmit note-offs that are pending from the last transport stop */
345 bufs.merge_from (_pending_stop_events, 0);
346 _have_pending_stop_events = false;
354 Plugin::realtime_handle_transport_stopped ()
360 Plugin::realtime_locate ()
366 Plugin::monitoring_changed ()
372 Plugin::resolve_midi ()
374 /* Create note-offs for any active notes and put them in _pending_stop_events, to be picked
375 up on the next call to connect_and_run ().
378 _pending_stop_events.get_midi(0).clear ();
379 _tracker.resolve_notes (_pending_stop_events.get_midi (0), /* split cycle offset*/ Port::port_offset());
380 _have_pending_stop_events = true;
384 Plugin::update_presets (std::string src_unique_id, Plugin* src )
386 if (src == this || unique_id() != src_unique_id) {
389 _have_presets = false;
390 // TODO check if a preset was added/removed and emit the proper signal
391 // so far no subscriber distinguishes between PresetAdded and PresetRemoved
395 vector<Plugin::PresetRecord>
396 Plugin::get_presets ()
398 vector<PresetRecord> p;
400 #ifndef NO_PLUGIN_STATE
401 if (!_have_presets) {
403 _have_presets = true;
406 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
407 p.push_back (i->second);
410 if (!seen_set_state_message) {
411 info << string_compose (_("Plugin presets are not supported in this build of %1. Consider paying for a full version"),
414 seen_set_state_message = true;
421 /** Set parameters using a preset */
423 Plugin::load_preset (PresetRecord r)
426 _parameter_changed_since_last_preset = false;
428 PresetLoaded (); /* EMIT SIGNAL */
433 Plugin::clear_preset ()
435 _last_preset.uri = "";
436 _last_preset.label = "";
437 _parameter_changed_since_last_preset = false;
439 PresetLoaded (); /* EMIT SIGNAL */
443 Plugin::set_parameter (uint32_t /* which */, float /* value */)
445 _parameter_changed_since_last_preset = true;
446 _session.set_dirty ();
447 PresetDirty (); /* EMIT SIGNAL */
451 Plugin::parameter_changed_externally (uint32_t which, float /* value */)
453 _parameter_changed_since_last_preset = true;
454 _session.set_dirty ();
455 ParameterChangedExternally (which, get_parameter (which)); /* EMIT SIGNAL */
456 PresetDirty (); /* EMIT SIGNAL */
460 Plugin::set_state (const XMLNode& node, int /*version*/)
462 XMLProperty const * p = node.property (X_("last-preset-uri"));
464 _last_preset.uri = p->value ();
467 p = node.property (X_("last-preset-label"));
469 _last_preset.label = p->value ();
472 p = node.property (X_("parameter-changed-since-last-preset"));
474 _parameter_changed_since_last_preset = string_is_affirmative (p->value ());
483 XMLNode* root = new XMLNode (state_node_name ());
486 root->add_property (X_("last-preset-uri"), _last_preset.uri);
487 root->add_property (X_("last-preset-label"), _last_preset.label);
488 root->add_property (X_("parameter-changed-since-last-preset"), _parameter_changed_since_last_preset ? X_("yes") : X_("no"));
490 #ifndef NO_PLUGIN_STATE
493 if (!seen_get_state_message) {
494 info << string_compose (_("Saving plugin settings is not supported in this build of %1. Consider paying for the full version"),
497 seen_get_state_message = true;
505 Plugin::set_info (PluginInfoPtr info)