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 HAVE_AUDIOUNITS
49 #include "ardour/audio_unit.h"
53 #include "ardour/lv2_plugin.h"
56 #include "pbd/stl_delete.h"
62 using namespace ARDOUR;
65 PBD::Signal0<bool> Plugin::PresetFileExists;
67 Plugin::Plugin (AudioEngine& e, Session& s)
71 , _have_pending_stop_events (false)
75 Plugin::Plugin (const Plugin& other)
76 : StatefulDestructible()
78 , _engine (other._engine)
79 , _session (other._session)
82 , _have_pending_stop_events (false)
93 Plugin::remove_preset (string name)
95 do_remove_preset (name);
96 _presets.erase (preset_by_label (name)->uri);
97 PresetRemoved (); /* EMIT SIGNAL */
101 Plugin::save_preset (string name)
103 string const uri = do_save_preset (name);
106 _presets.insert (make_pair (uri, PresetRecord (uri, name)));
107 PresetAdded (); /* EMIT SIGNAL */
110 return !uri.empty ();
114 ARDOUR::find_plugin(Session& session, string identifier, PluginType type)
116 PluginManager *mgr = PluginManager::the_manager();
117 PluginInfoList plugs;
121 plugs = mgr->ladspa_plugin_info();
126 plugs = mgr->lv2_plugin_info();
132 plugs = mgr->vst_plugin_info();
136 #ifdef HAVE_AUDIOUNITS
137 case ARDOUR::AudioUnit:
138 plugs = mgr->au_plugin_info();
143 return PluginPtr ((Plugin *) 0);
146 PluginInfoList::iterator i;
148 for (i = plugs.begin(); i != plugs.end(); ++i) {
149 if (identifier == (*i)->unique_id){
150 return (*i)->load (session);
155 /* hmm, we didn't find it. could be because in older versions of Ardour.
156 we used to store the name of a VST plugin, not its unique ID. so try
160 for (i = plugs.begin(); i != plugs.end(); ++i) {
161 if (identifier == (*i)->name){
162 return (*i)->load (session);
167 return PluginPtr ((Plugin*) 0);
171 Plugin::output_streams () const
173 /* LADSPA & VST should not get here because they do not
174 return "infinite" i/o counts.
176 return ChanCount::ZERO;
180 Plugin::input_streams () const
182 /* LADSPA & VST should not get here because they do not
183 return "infinite" i/o counts.
185 return ChanCount::ZERO;
188 const Plugin::PresetRecord *
189 Plugin::preset_by_label (const string& label)
192 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
193 if (i->second.label == label) {
201 const Plugin::PresetRecord *
202 Plugin::preset_by_uri (const string& uri)
204 map<string, PresetRecord>::const_iterator pr = _presets.find (uri);
205 if (pr != _presets.end()) {
213 Plugin::connect_and_run (BufferSet& bufs,
214 ChanMapping in_map, ChanMapping out_map,
215 pframes_t nframes, framecnt_t offset)
217 if (bufs.count().n_midi() > 0) {
219 /* Track notes that we are sending to the plugin */
220 MidiBuffer& b = bufs.get_midi (0);
222 _tracker.track (b.begin(), b.end(), looped);
224 if (_have_pending_stop_events) {
225 /* Transmit note-offs that are pending from the last transport stop */
226 bufs.merge_from (_pending_stop_events, 0);
227 _have_pending_stop_events = false;
235 Plugin::realtime_handle_transport_stopped ()
237 /* Create note-offs for any active notes and put them in _pending_stop_events, to be picked
238 up on the next call to connect_and_run ().
241 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
242 _pending_stop_events.get_midi(0).clear ();
243 _tracker.resolve_notes (_pending_stop_events.get_midi (0), 0);
244 _have_pending_stop_events = true;