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/session.h"
54 #include "ardour/types.h"
56 #ifdef AUDIOUNIT_SUPPORT
57 #include "ardour/audio_unit.h"
61 #include "ardour/lv2_plugin.h"
64 #include "pbd/stl_delete.h"
70 using namespace ARDOUR;
73 namespace ARDOUR { class AudioEngine; }
75 #ifdef NO_PLUGIN_STATE
76 static bool seen_get_state_message = false;
77 static bool seen_set_state_message = false;
81 PluginInfo::is_instrument () const
83 return (n_inputs.n_midi() != 0) && (n_outputs.n_audio() > 0);
86 Plugin::Plugin (AudioEngine& e, Session& s)
90 , _have_presets (false)
91 , _have_pending_stop_events (false)
92 , _parameter_changed_since_last_preset (false)
94 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
97 Plugin::Plugin (const Plugin& other)
98 : StatefulDestructible()
100 , _engine (other._engine)
101 , _session (other._session)
102 , _info (other._info)
104 , _have_presets (false)
105 , _have_pending_stop_events (false)
106 , _parameter_changed_since_last_preset (false)
108 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
116 Plugin::remove_preset (string name)
118 do_remove_preset (name);
119 _presets.erase (preset_by_label (name)->uri);
121 _last_preset.uri = "";
122 _parameter_changed_since_last_preset = false;
123 PresetRemoved (); /* EMIT SIGNAL */
126 /** @return PresetRecord with empty URI on failure */
128 Plugin::save_preset (string name)
130 string const uri = do_save_preset (name);
133 _presets.insert (make_pair (uri, PresetRecord (uri, name)));
134 PresetAdded (); /* EMIT SIGNAL */
137 return PresetRecord (uri, name);
141 ARDOUR::find_plugin(Session& session, string identifier, PluginType type)
143 PluginManager& mgr (PluginManager::instance());
144 PluginInfoList plugs;
148 plugs = mgr.ladspa_plugin_info();
153 plugs = mgr.lv2_plugin_info();
157 #ifdef WINDOWS_VST_SUPPORT
158 case ARDOUR::Windows_VST:
159 plugs = mgr.windows_vst_plugin_info();
165 plugs = mgr.lxvst_plugin_info();
169 #ifdef AUDIOUNIT_SUPPORT
170 case ARDOUR::AudioUnit:
171 plugs = mgr.au_plugin_info();
176 return PluginPtr ((Plugin *) 0);
179 PluginInfoList::iterator i;
181 for (i = plugs.begin(); i != plugs.end(); ++i) {
182 if (identifier == (*i)->unique_id){
183 return (*i)->load (session);
187 #ifdef WINDOWS_VST_SUPPORT
188 /* hmm, we didn't find it. could be because in older versions of Ardour.
189 we used to store the name of a VST plugin, not its unique ID. so try
193 for (i = plugs.begin(); i != plugs.end(); ++i) {
194 if (identifier == (*i)->name){
195 return (*i)->load (session);
201 /* hmm, we didn't find it. could be because in older versions of Ardour.
202 we used to store the name of a VST plugin, not its unique ID. so try
206 for (i = plugs.begin(); i != plugs.end(); ++i) {
207 if (identifier == (*i)->name){
208 return (*i)->load (session);
213 return PluginPtr ((Plugin*) 0);
217 Plugin::output_streams () const
219 /* LADSPA & VST should not get here because they do not
220 return "infinite" i/o counts.
222 return ChanCount::ZERO;
226 Plugin::input_streams () const
228 /* LADSPA & VST should not get here because they do not
229 return "infinite" i/o counts.
231 return ChanCount::ZERO;
234 const Plugin::PresetRecord *
235 Plugin::preset_by_label (const string& label)
238 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
239 if (i->second.label == label) {
247 const Plugin::PresetRecord *
248 Plugin::preset_by_uri (const string& uri)
250 map<string, PresetRecord>::const_iterator pr = _presets.find (uri);
251 if (pr != _presets.end()) {
259 Plugin::connect_and_run (BufferSet& bufs,
260 ChanMapping /*in_map*/, ChanMapping /*out_map*/,
261 pframes_t /* nframes */, framecnt_t /*offset*/)
263 if (bufs.count().n_midi() > 0) {
265 /* Track notes that we are sending to the plugin */
267 MidiBuffer& b = bufs.get_midi (0);
269 _tracker.track (b.begin(), b.end());
271 if (_have_pending_stop_events) {
272 /* Transmit note-offs that are pending from the last transport stop */
273 bufs.merge_from (_pending_stop_events, 0);
274 _have_pending_stop_events = false;
282 Plugin::realtime_handle_transport_stopped ()
288 Plugin::realtime_locate ()
294 Plugin::monitoring_changed ()
300 Plugin::resolve_midi ()
302 /* Create note-offs for any active notes and put them in _pending_stop_events, to be picked
303 up on the next call to connect_and_run ().
306 _pending_stop_events.get_midi(0).clear ();
307 _tracker.resolve_notes (_pending_stop_events.get_midi (0), 0);
308 _have_pending_stop_events = true;
312 vector<Plugin::PresetRecord>
313 Plugin::get_presets ()
315 vector<PresetRecord> p;
317 #ifndef NO_PLUGIN_STATE
318 if (!_have_presets) {
320 _have_presets = true;
323 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
324 p.push_back (i->second);
327 if (!seen_set_state_message) {
328 info << string_compose (_("Plugin presets are not supported in this build of %1. Consider paying for a full version"),
337 /** Set parameters using a preset */
339 Plugin::load_preset (PresetRecord r)
342 _parameter_changed_since_last_preset = false;
344 PresetLoaded (); /* EMIT SIGNAL */
349 Plugin::clear_preset ()
351 _last_preset.uri = "";
352 _last_preset.label = "";
353 _parameter_changed_since_last_preset = false;
355 PresetLoaded (); /* EMIT SIGNAL */
358 /** @param val `plugin' value */
360 Plugin::set_parameter (uint32_t which, float)
362 _parameter_changed_since_last_preset = true;
363 _session.set_dirty ();
364 ParameterChanged (which, get_parameter (which)); /* EMIT SIGNAL */
368 Plugin::set_state (const XMLNode& node, int /*version*/)
370 XMLProperty const * p = node.property (X_("last-preset-uri"));
372 _last_preset.uri = p->value ();
375 p = node.property (X_("last-preset-label"));
377 _last_preset.label = p->value ();
380 p = node.property (X_("parameter-changed-since-last-preset"));
382 _parameter_changed_since_last_preset = string_is_affirmative (p->value ());
391 XMLNode* root = new XMLNode (state_node_name ());
392 LocaleGuard lg (X_("POSIX"));
394 root->add_property (X_("last-preset-uri"), _last_preset.uri);
395 root->add_property (X_("last-preset-label"), _last_preset.label);
396 root->add_property (X_("parameter-changed-since-last-preset"), _parameter_changed_since_last_preset ? X_("yes") : X_("no"));
398 #ifndef NO_PLUGIN_STATE
401 if (!seen_get_state_message) {
402 info << string_compose (_("Saving plugin settings is not supported in this build of %1. Consider paying for the full version"),
405 seen_get_state_message = true;
413 Plugin::set_info (PluginInfoPtr info)