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/midi_buffer.h"
50 #include "ardour/midi_state_tracker.h"
51 #include "ardour/plugin.h"
52 #include "ardour/plugin_manager.h"
53 #include "ardour/port.h"
54 #include "ardour/session.h"
55 #include "ardour/types.h"
57 #ifdef AUDIOUNIT_SUPPORT
58 #include "ardour/audio_unit.h"
62 #include "ardour/lv2_plugin.h"
65 #include "pbd/stl_delete.h"
71 using namespace ARDOUR;
74 namespace ARDOUR { class AudioEngine; }
76 #ifdef NO_PLUGIN_STATE
77 static bool seen_get_state_message = false;
78 static bool seen_set_state_message = false;
82 PluginInfo::is_instrument () const
84 return (n_inputs.n_midi() != 0) && (n_outputs.n_audio() > 0);
87 Plugin::Plugin (AudioEngine& e, Session& s)
91 , _have_presets (false)
92 , _have_pending_stop_events (false)
93 , _parameter_changed_since_last_preset (false)
95 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
98 Plugin::Plugin (const Plugin& other)
99 : StatefulDestructible()
101 , _engine (other._engine)
102 , _session (other._session)
103 , _info (other._info)
105 , _have_presets (false)
106 , _have_pending_stop_events (false)
107 , _parameter_changed_since_last_preset (false)
109 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
117 Plugin::remove_preset (string name)
119 do_remove_preset (name);
120 _presets.erase (preset_by_label (name)->uri);
122 _last_preset.uri = "";
123 _parameter_changed_since_last_preset = false;
124 PresetRemoved (); /* EMIT SIGNAL */
127 /** @return PresetRecord with empty URI on failure */
129 Plugin::save_preset (string name)
131 string const uri = do_save_preset (name);
134 _presets.insert (make_pair (uri, PresetRecord (uri, name)));
135 PresetAdded (); /* EMIT SIGNAL */
138 return PresetRecord (uri, name);
142 ARDOUR::find_plugin(Session& session, string identifier, PluginType type)
144 PluginManager& mgr (PluginManager::instance());
145 PluginInfoList plugs;
149 plugs = mgr.ladspa_plugin_info();
154 plugs = mgr.lv2_plugin_info();
158 #ifdef WINDOWS_VST_SUPPORT
159 case ARDOUR::Windows_VST:
160 plugs = mgr.windows_vst_plugin_info();
166 plugs = mgr.lxvst_plugin_info();
170 #ifdef AUDIOUNIT_SUPPORT
171 case ARDOUR::AudioUnit:
172 plugs = mgr.au_plugin_info();
177 return PluginPtr ((Plugin *) 0);
180 PluginInfoList::iterator i;
182 for (i = plugs.begin(); i != plugs.end(); ++i) {
183 if (identifier == (*i)->unique_id){
184 return (*i)->load (session);
188 #ifdef WINDOWS_VST_SUPPORT
189 /* hmm, we didn't find it. could be because in older versions of Ardour.
190 we used to store the name of a VST plugin, not its unique ID. so try
194 for (i = plugs.begin(); i != plugs.end(); ++i) {
195 if (identifier == (*i)->name){
196 return (*i)->load (session);
202 /* hmm, we didn't find it. could be because in older versions of Ardour.
203 we used to store the name of a VST plugin, not its unique ID. so try
207 for (i = plugs.begin(); i != plugs.end(); ++i) {
208 if (identifier == (*i)->name){
209 return (*i)->load (session);
214 return PluginPtr ((Plugin*) 0);
218 Plugin::output_streams () const
220 /* LADSPA & VST should not get here because they do not
221 return "infinite" i/o counts.
223 return ChanCount::ZERO;
227 Plugin::input_streams () const
229 /* LADSPA & VST should not get here because they do not
230 return "infinite" i/o counts.
232 return ChanCount::ZERO;
235 const Plugin::PresetRecord *
236 Plugin::preset_by_label (const string& label)
239 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
240 if (i->second.label == label) {
248 const Plugin::PresetRecord *
249 Plugin::preset_by_uri (const string& uri)
251 map<string, PresetRecord>::const_iterator pr = _presets.find (uri);
252 if (pr != _presets.end()) {
260 Plugin::connect_and_run (BufferSet& bufs,
261 ChanMapping /*in_map*/, ChanMapping /*out_map*/,
262 pframes_t /* nframes */, framecnt_t /*offset*/)
264 if (bufs.count().n_midi() > 0) {
266 /* Track notes that we are sending to the plugin */
268 const MidiBuffer& b = bufs.get_midi (0);
270 _tracker.track (b.begin(), b.end());
272 if (_have_pending_stop_events) {
273 /* Transmit note-offs that are pending from the last transport stop */
274 bufs.merge_from (_pending_stop_events, 0);
275 _have_pending_stop_events = false;
283 Plugin::realtime_handle_transport_stopped ()
289 Plugin::realtime_locate ()
295 Plugin::monitoring_changed ()
301 Plugin::resolve_midi ()
303 /* Create note-offs for any active notes and put them in _pending_stop_events, to be picked
304 up on the next call to connect_and_run ().
307 _pending_stop_events.get_midi(0).clear ();
308 _tracker.resolve_notes (_pending_stop_events.get_midi (0), /* split cycle offset*/ Port::port_offset());
309 _have_pending_stop_events = true;
313 vector<Plugin::PresetRecord>
314 Plugin::get_presets ()
316 vector<PresetRecord> p;
318 #ifndef NO_PLUGIN_STATE
319 if (!_have_presets) {
321 _have_presets = true;
324 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
325 p.push_back (i->second);
328 if (!seen_set_state_message) {
329 info << string_compose (_("Plugin presets are not supported in this build of %1. Consider paying for a full version"),
332 seen_set_state_message = true;
339 /** Set parameters using a preset */
341 Plugin::load_preset (PresetRecord r)
344 _parameter_changed_since_last_preset = false;
346 PresetLoaded (); /* EMIT SIGNAL */
351 Plugin::clear_preset ()
353 _last_preset.uri = "";
354 _last_preset.label = "";
355 _parameter_changed_since_last_preset = false;
357 PresetLoaded (); /* EMIT SIGNAL */
361 Plugin::set_parameter (uint32_t /* which */, float /* value */)
363 _parameter_changed_since_last_preset = true;
364 _session.set_dirty ();
365 PresetDirty (); /* EMIT SIGNAL */
369 Plugin::parameter_changed_externally (uint32_t which, float /* value */)
371 _parameter_changed_since_last_preset = true;
372 _session.set_dirty ();
373 ParameterChangedExternally (which, get_parameter (which)); /* EMIT SIGNAL */
374 PresetDirty (); /* EMIT SIGNAL */
378 Plugin::set_state (const XMLNode& node, int /*version*/)
380 XMLProperty const * p = node.property (X_("last-preset-uri"));
382 _last_preset.uri = p->value ();
385 p = node.property (X_("last-preset-label"));
387 _last_preset.label = p->value ();
390 p = node.property (X_("parameter-changed-since-last-preset"));
392 _parameter_changed_since_last_preset = string_is_affirmative (p->value ());
401 XMLNode* root = new XMLNode (state_node_name ());
402 LocaleGuard lg (X_("C"));
404 root->add_property (X_("last-preset-uri"), _last_preset.uri);
405 root->add_property (X_("last-preset-label"), _last_preset.label);
406 root->add_property (X_("parameter-changed-since-last-preset"), _parameter_changed_since_last_preset ? X_("yes") : X_("no"));
408 #ifndef NO_PLUGIN_STATE
411 if (!seen_get_state_message) {
412 info << string_compose (_("Saving plugin settings is not supported in this build of %1. Consider paying for the full version"),
415 seen_get_state_message = true;
423 Plugin::set_info (PluginInfoPtr info)