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/buffer_set.h"
42 #include "ardour/chan_count.h"
43 #include "ardour/chan_mapping.h"
44 #include "ardour/data_type.h"
45 #include "ardour/midi_buffer.h"
46 #include "ardour/midi_state_tracker.h"
47 #include "ardour/plugin.h"
48 #include "ardour/plugin_manager.h"
49 #include "ardour/session.h"
50 #include "ardour/types.h"
52 #ifdef AUDIOUNIT_SUPPORT
53 #include "ardour/audio_unit.h"
57 #include "ardour/lv2_plugin.h"
60 #include "pbd/stl_delete.h"
66 using namespace ARDOUR;
69 namespace ARDOUR { class AudioEngine; }
72 PluginInfo::is_instrument () const
74 return (n_inputs.n_midi() != 0) && (n_outputs.n_audio() > 0);
77 Plugin::Plugin (AudioEngine& e, Session& s)
81 , _have_presets (false)
82 , _have_pending_stop_events (false)
83 , _parameter_changed_since_last_preset (false)
85 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
88 Plugin::Plugin (const Plugin& other)
89 : StatefulDestructible()
91 , _engine (other._engine)
92 , _session (other._session)
95 , _have_presets (false)
96 , _have_pending_stop_events (false)
97 , _parameter_changed_since_last_preset (false)
99 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
107 Plugin::remove_preset (string name)
109 do_remove_preset (name);
110 _presets.erase (preset_by_label (name)->uri);
112 _last_preset.uri = "";
113 _parameter_changed_since_last_preset = false;
114 PresetRemoved (); /* EMIT SIGNAL */
117 /** @return PresetRecord with empty URI on failure */
119 Plugin::save_preset (string name)
121 string const uri = do_save_preset (name);
124 _presets.insert (make_pair (uri, PresetRecord (uri, name)));
125 PresetAdded (); /* EMIT SIGNAL */
128 return PresetRecord (uri, name);
132 ARDOUR::find_plugin(Session& session, string identifier, PluginType type)
134 PluginManager& mgr (PluginManager::instance());
135 PluginInfoList plugs;
139 plugs = mgr.ladspa_plugin_info();
144 plugs = mgr.lv2_plugin_info();
148 #ifdef WINDOWS_VST_SUPPORT
149 case ARDOUR::Windows_VST:
150 plugs = mgr.windows_vst_plugin_info();
156 plugs = mgr.lxvst_plugin_info();
160 #ifdef AUDIOUNIT_SUPPORT
161 case ARDOUR::AudioUnit:
162 plugs = mgr.au_plugin_info();
167 return PluginPtr ((Plugin *) 0);
170 PluginInfoList::iterator i;
172 for (i = plugs.begin(); i != plugs.end(); ++i) {
173 if (identifier == (*i)->unique_id){
174 return (*i)->load (session);
178 #ifdef WINDOWS_VST_SUPPORT
179 /* hmm, we didn't find it. could be because in older versions of Ardour.
180 we used to store the name of a VST plugin, not its unique ID. so try
184 for (i = plugs.begin(); i != plugs.end(); ++i) {
185 if (identifier == (*i)->name){
186 return (*i)->load (session);
192 /* hmm, we didn't find it. could be because in older versions of Ardour.
193 we used to store the name of a VST plugin, not its unique ID. so try
197 for (i = plugs.begin(); i != plugs.end(); ++i) {
198 if (identifier == (*i)->name){
199 return (*i)->load (session);
204 return PluginPtr ((Plugin*) 0);
208 Plugin::output_streams () const
210 /* LADSPA & VST should not get here because they do not
211 return "infinite" i/o counts.
213 return ChanCount::ZERO;
217 Plugin::input_streams () const
219 /* LADSPA & VST should not get here because they do not
220 return "infinite" i/o counts.
222 return ChanCount::ZERO;
225 const Plugin::PresetRecord *
226 Plugin::preset_by_label (const string& label)
229 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
230 if (i->second.label == label) {
238 const Plugin::PresetRecord *
239 Plugin::preset_by_uri (const string& uri)
241 map<string, PresetRecord>::const_iterator pr = _presets.find (uri);
242 if (pr != _presets.end()) {
250 Plugin::connect_and_run (BufferSet& bufs,
251 ChanMapping /*in_map*/, ChanMapping /*out_map*/,
252 pframes_t /* nframes */, framecnt_t /*offset*/)
254 if (bufs.count().n_midi() > 0) {
256 /* Track notes that we are sending to the plugin */
258 MidiBuffer& b = bufs.get_midi (0);
261 _tracker.track (b.begin(), b.end(), looped);
263 if (_have_pending_stop_events) {
264 /* Transmit note-offs that are pending from the last transport stop */
265 bufs.merge_from (_pending_stop_events, 0);
266 _have_pending_stop_events = false;
274 Plugin::realtime_handle_transport_stopped ()
280 Plugin::realtime_locate ()
286 Plugin::monitoring_changed ()
292 Plugin::resolve_midi ()
294 /* Create note-offs for any active notes and put them in _pending_stop_events, to be picked
295 up on the next call to connect_and_run ().
298 _pending_stop_events.get_midi(0).clear ();
299 _tracker.resolve_notes (_pending_stop_events.get_midi (0), 0);
300 _have_pending_stop_events = true;
303 vector<Plugin::PresetRecord>
304 Plugin::get_presets ()
306 if (!_have_presets) {
308 _have_presets = true;
311 vector<PresetRecord> p;
312 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
313 p.push_back (i->second);
319 /** Set parameters using a preset */
321 Plugin::load_preset (PresetRecord r)
324 _parameter_changed_since_last_preset = false;
326 PresetLoaded (); /* EMIT SIGNAL */
331 Plugin::clear_preset ()
333 _last_preset.uri = "";
334 _last_preset.label = "";
335 _parameter_changed_since_last_preset = false;
337 PresetLoaded (); /* EMIT SIGNAL */
340 /** @param val `plugin' value */
342 Plugin::set_parameter (uint32_t which, float val)
344 _parameter_changed_since_last_preset = true;
345 _session.set_dirty ();
346 ParameterChanged (which, val); /* EMIT SIGNAL */
350 Plugin::set_state (const XMLNode& node, int /*version*/)
352 XMLProperty const * p = node.property (X_("last-preset-uri"));
354 _last_preset.uri = p->value ();
357 p = node.property (X_("last-preset-label"));
359 _last_preset.label = p->value ();
362 p = node.property (X_("parameter-changed-since-last-preset"));
364 _parameter_changed_since_last_preset = string_is_affirmative (p->value ());
373 XMLNode* root = new XMLNode (state_node_name ());
374 LocaleGuard lg (X_("POSIX"));
376 root->add_property (X_("last-preset-uri"), _last_preset.uri);
377 root->add_property (X_("last-preset-label"), _last_preset.label);
378 root->add_property (X_("parameter-changed-since-last-preset"), _parameter_changed_since_last_preset ? X_("yes") : X_("no"));
385 Plugin::set_info (PluginInfoPtr info)