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
39 #include "pbd/compose.h"
40 #include "pbd/error.h"
41 #include "pbd/xml++.h"
43 #include "ardour/buffer_set.h"
44 #include "ardour/chan_count.h"
45 #include "ardour/chan_mapping.h"
46 #include "ardour/data_type.h"
47 #include "ardour/midi_buffer.h"
48 #include "ardour/midi_state_tracker.h"
49 #include "ardour/plugin.h"
50 #include "ardour/plugin_manager.h"
51 #include "ardour/session.h"
52 #include "ardour/types.h"
54 #ifdef AUDIOUNIT_SUPPORT
55 #include "ardour/audio_unit.h"
59 #include "ardour/lv2_plugin.h"
62 #include "pbd/stl_delete.h"
68 using namespace ARDOUR;
71 namespace ARDOUR { class AudioEngine; }
73 #ifdef NO_PLUGIN_STATE
74 static bool seen_get_state_message = false;
75 static bool seen_set_state_message = false;
79 PluginInfo::is_instrument () const
81 return (n_inputs.n_midi() != 0) && (n_outputs.n_audio() > 0);
84 Plugin::Plugin (AudioEngine& e, Session& s)
88 , _have_presets (false)
89 , _have_pending_stop_events (false)
90 , _parameter_changed_since_last_preset (false)
92 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
95 Plugin::Plugin (const Plugin& other)
96 : StatefulDestructible()
98 , _engine (other._engine)
99 , _session (other._session)
100 , _info (other._info)
102 , _have_presets (false)
103 , _have_pending_stop_events (false)
104 , _parameter_changed_since_last_preset (false)
106 _pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
114 Plugin::remove_preset (string name)
116 do_remove_preset (name);
117 _presets.erase (preset_by_label (name)->uri);
119 _last_preset.uri = "";
120 _parameter_changed_since_last_preset = false;
121 PresetRemoved (); /* EMIT SIGNAL */
124 /** @return PresetRecord with empty URI on failure */
126 Plugin::save_preset (string name)
128 string const uri = do_save_preset (name);
131 _presets.insert (make_pair (uri, PresetRecord (uri, name)));
132 PresetAdded (); /* EMIT SIGNAL */
135 return PresetRecord (uri, name);
139 ARDOUR::find_plugin(Session& session, string identifier, PluginType type)
141 PluginManager& mgr (PluginManager::instance());
142 PluginInfoList plugs;
146 plugs = mgr.ladspa_plugin_info();
151 plugs = mgr.lv2_plugin_info();
155 #ifdef WINDOWS_VST_SUPPORT
156 case ARDOUR::Windows_VST:
157 plugs = mgr.windows_vst_plugin_info();
163 plugs = mgr.lxvst_plugin_info();
167 #ifdef AUDIOUNIT_SUPPORT
168 case ARDOUR::AudioUnit:
169 plugs = mgr.au_plugin_info();
174 return PluginPtr ((Plugin *) 0);
177 PluginInfoList::iterator i;
179 for (i = plugs.begin(); i != plugs.end(); ++i) {
180 if (identifier == (*i)->unique_id){
181 return (*i)->load (session);
185 #ifdef WINDOWS_VST_SUPPORT
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);
199 /* hmm, we didn't find it. could be because in older versions of Ardour.
200 we used to store the name of a VST plugin, not its unique ID. so try
204 for (i = plugs.begin(); i != plugs.end(); ++i) {
205 if (identifier == (*i)->name){
206 return (*i)->load (session);
211 return PluginPtr ((Plugin*) 0);
215 Plugin::output_streams () const
217 /* LADSPA & VST should not get here because they do not
218 return "infinite" i/o counts.
220 return ChanCount::ZERO;
224 Plugin::input_streams () const
226 /* LADSPA & VST should not get here because they do not
227 return "infinite" i/o counts.
229 return ChanCount::ZERO;
232 const Plugin::PresetRecord *
233 Plugin::preset_by_label (const string& label)
236 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
237 if (i->second.label == label) {
245 const Plugin::PresetRecord *
246 Plugin::preset_by_uri (const string& uri)
248 map<string, PresetRecord>::const_iterator pr = _presets.find (uri);
249 if (pr != _presets.end()) {
257 Plugin::connect_and_run (BufferSet& bufs,
258 ChanMapping /*in_map*/, ChanMapping /*out_map*/,
259 pframes_t /* nframes */, framecnt_t /*offset*/)
261 if (bufs.count().n_midi() > 0) {
263 /* Track notes that we are sending to the plugin */
265 MidiBuffer& b = bufs.get_midi (0);
267 _tracker.track (b.begin(), b.end());
269 if (_have_pending_stop_events) {
270 /* Transmit note-offs that are pending from the last transport stop */
271 bufs.merge_from (_pending_stop_events, 0);
272 _have_pending_stop_events = false;
280 Plugin::realtime_handle_transport_stopped ()
286 Plugin::realtime_locate ()
292 Plugin::monitoring_changed ()
298 Plugin::resolve_midi ()
300 /* Create note-offs for any active notes and put them in _pending_stop_events, to be picked
301 up on the next call to connect_and_run ().
304 _pending_stop_events.get_midi(0).clear ();
305 _tracker.resolve_notes (_pending_stop_events.get_midi (0), 0);
306 _have_pending_stop_events = true;
310 vector<Plugin::PresetRecord>
311 Plugin::get_presets ()
313 vector<PresetRecord> p;
315 #ifndef NO_PLUGIN_STATE
316 if (!_have_presets) {
318 _have_presets = true;
321 for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
322 p.push_back (i->second);
325 if (!seen_set_state_message) {
326 info << string_compose (_("Plugin presets are not supported in this build of %1. Consider paying for a full version"),
335 /** Set parameters using a preset */
337 Plugin::load_preset (PresetRecord r)
340 _parameter_changed_since_last_preset = false;
342 PresetLoaded (); /* EMIT SIGNAL */
347 Plugin::clear_preset ()
349 _last_preset.uri = "";
350 _last_preset.label = "";
351 _parameter_changed_since_last_preset = false;
353 PresetLoaded (); /* EMIT SIGNAL */
356 /** @param val `plugin' value */
358 Plugin::set_parameter (uint32_t which, float)
360 _parameter_changed_since_last_preset = true;
361 _session.set_dirty ();
362 ParameterChanged (which, get_parameter (which)); /* EMIT SIGNAL */
366 Plugin::set_state (const XMLNode& node, int /*version*/)
368 XMLProperty const * p = node.property (X_("last-preset-uri"));
370 _last_preset.uri = p->value ();
373 p = node.property (X_("last-preset-label"));
375 _last_preset.label = p->value ();
378 p = node.property (X_("parameter-changed-since-last-preset"));
380 _parameter_changed_since_last_preset = string_is_affirmative (p->value ());
389 XMLNode* root = new XMLNode (state_node_name ());
390 LocaleGuard lg (X_("POSIX"));
392 root->add_property (X_("last-preset-uri"), _last_preset.uri);
393 root->add_property (X_("last-preset-label"), _last_preset.label);
394 root->add_property (X_("parameter-changed-since-last-preset"), _parameter_changed_since_last_preset ? X_("yes") : X_("no"));
396 #ifndef NO_PLUGIN_STATE
399 if (!seen_get_state_message) {
400 info << string_compose (_("Saving plugin settings is not supported in this build of %1. Consider paying for the full version"),
403 seen_get_state_message = true;
411 Plugin::set_info (PluginInfoPtr info)