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
37 #include "pbd/compose.h"
38 #include "pbd/error.h"
39 #include "pbd/xml++.h"
41 #include "ardour/ardour.h"
42 #include "ardour/session.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/plugin.h"
45 #include "ardour/ladspa_plugin.h"
46 #include "ardour/plugin_manager.h"
48 #ifdef AUDIOUNIT_SUPPORT
49 #include "ardour/audio_unit.h"
53 #include "ardour/lv2_plugin.h"
56 #include "pbd/stl_delete.h"
62 using namespace ARDOUR;
66 PluginInfo::is_instrument () const
68 return (n_inputs.n_midi() != 0) && (n_outputs.n_audio() > 0);
71 Plugin::Plugin (AudioEngine& e, Session& s)
75 , _have_presets (false)
76 , _have_pending_stop_events (false)
77 , _parameter_changed_since_last_preset (false)
79 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
82 Plugin::Plugin (const Plugin& other)
83 : StatefulDestructible()
85 , _engine (other._engine)
86 , _session (other._session)
89 , _have_presets (false)
90 , _have_pending_stop_events (false)
91 , _parameter_changed_since_last_preset (false)
93 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
101 Plugin::remove_preset (string name)
103 do_remove_preset (name);
104 _presets.erase (preset_by_label (name)->uri);
106 _last_preset.uri = "";
107 _parameter_changed_since_last_preset = false;
108 PresetRemoved (); /* EMIT SIGNAL */
111 /** @return PresetRecord with empty URI on failure */
113 Plugin::save_preset (string name)
115 string const uri = do_save_preset (name);
118 _presets.insert (make_pair (uri, PresetRecord (uri, name)));
119 PresetAdded (); /* EMIT SIGNAL */
122 return PresetRecord (uri, name);
126 ARDOUR::find_plugin(Session& session, string identifier, PluginType type)
128 PluginManager& mgr (PluginManager::instance());
129 PluginInfoList plugs;
133 plugs = mgr.ladspa_plugin_info();
138 plugs = mgr.lv2_plugin_info();
142 #ifdef WINDOWS_VST_SUPPORT
143 case ARDOUR::Windows_VST:
144 plugs = mgr.windows_vst_plugin_info();
150 plugs = mgr.lxvst_plugin_info();
154 #ifdef AUDIOUNIT_SUPPORT
155 case ARDOUR::AudioUnit:
156 plugs = mgr.au_plugin_info();
161 return PluginPtr ((Plugin *) 0);
164 PluginInfoList::iterator i;
166 for (i = plugs.begin(); i != plugs.end(); ++i) {
167 if (identifier == (*i)->unique_id){
168 return (*i)->load (session);
172 #ifdef WINDOWS_VST_SUPPORT
173 /* hmm, we didn't find it. could be because in older versions of Ardour.
174 we used to store the name of a VST plugin, not its unique ID. so try
178 for (i = plugs.begin(); i != plugs.end(); ++i) {
179 if (identifier == (*i)->name){
180 return (*i)->load (session);
186 /* hmm, we didn't find it. could be because in older versions of Ardour.
187 we used to store the name of a VST plugin, not its unique ID. so try
191 for (i = plugs.begin(); i != plugs.end(); ++i) {
192 if (identifier == (*i)->name){
193 return (*i)->load (session);
198 return PluginPtr ((Plugin*) 0);
202 Plugin::output_streams () const
204 /* LADSPA & VST should not get here because they do not
205 return "infinite" i/o counts.
207 return ChanCount::ZERO;
211 Plugin::input_streams () const
213 /* LADSPA & VST should not get here because they do not
214 return "infinite" i/o counts.
216 return ChanCount::ZERO;
219 const Plugin::PresetRecord *
220 Plugin::preset_by_label (const string& label)
223 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
224 if (i->second.label == label) {
232 const Plugin::PresetRecord *
233 Plugin::preset_by_uri (const string& uri)
235 map<string, PresetRecord>::const_iterator pr = _presets.find (uri);
236 if (pr != _presets.end()) {
244 Plugin::connect_and_run (BufferSet& bufs,
245 ChanMapping /*in_map*/, ChanMapping /*out_map*/,
246 pframes_t /* nframes */, framecnt_t /*offset*/)
248 if (bufs.count().n_midi() > 0) {
250 /* Track notes that we are sending to the plugin */
252 MidiBuffer& b = bufs.get_midi (0);
255 _tracker.track (b.begin(), b.end(), looped);
257 if (_have_pending_stop_events) {
258 /* Transmit note-offs that are pending from the last transport stop */
259 bufs.merge_from (_pending_stop_events, 0);
260 _have_pending_stop_events = false;
268 Plugin::realtime_handle_transport_stopped ()
274 Plugin::realtime_locate ()
280 Plugin::monitoring_changed ()
286 Plugin::resolve_midi ()
288 /* Create note-offs for any active notes and put them in _pending_stop_events, to be picked
289 up on the next call to connect_and_run ().
292 _pending_stop_events.get_midi(0).clear ();
293 _tracker.resolve_notes (_pending_stop_events.get_midi (0), 0);
294 _have_pending_stop_events = true;
297 vector<Plugin::PresetRecord>
298 Plugin::get_presets ()
300 if (!_have_presets) {
302 _have_presets = true;
305 vector<PresetRecord> p;
306 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
307 p.push_back (i->second);
313 /** Set parameters using a preset */
315 Plugin::load_preset (PresetRecord r)
318 _parameter_changed_since_last_preset = false;
320 PresetLoaded (); /* EMIT SIGNAL */
324 /** @param val `plugin' value */
326 Plugin::set_parameter (uint32_t which, float val)
328 _parameter_changed_since_last_preset = true;
329 _session.set_dirty ();
330 ParameterChanged (which, val); /* EMIT SIGNAL */
334 Plugin::set_state (const XMLNode& node, int /*version*/)
336 XMLProperty const * p = node.property (X_("last-preset-uri"));
338 _last_preset.uri = p->value ();
341 p = node.property (X_("last-preset-label"));
343 _last_preset.label = p->value ();
346 p = node.property (X_("parameter-changed-since-last-preset"));
348 _parameter_changed_since_last_preset = string_is_affirmative (p->value ());
357 XMLNode* root = new XMLNode (state_node_name ());
358 LocaleGuard lg (X_("POSIX"));
360 root->add_property (X_("last-preset-uri"), _last_preset.uri);
361 root->add_property (X_("last-preset-label"), _last_preset.label);
362 root->add_property (X_("parameter-changed-since-last-preset"), _parameter_changed_since_last_preset ? X_("yes") : X_("no"));
369 Plugin::set_info (PluginInfoPtr info)