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; }
71
#ifdef NO_PLUGIN_STATE
72
static bool seen_get_state_message = false;
73
static bool seen_set_state_message = false;
77
PluginInfo::is_instrument () const
79
return (n_inputs.n_midi() != 0) && (n_outputs.n_audio() > 0);
82
Plugin::Plugin (AudioEngine& e, Session& s)
86
, _have_presets (false)
87
, _have_pending_stop_events (false)
88
, _parameter_changed_since_last_preset (false)
90
_pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
93
Plugin::Plugin (const Plugin& other)
94
: StatefulDestructible()
96
, _engine (other._engine)
97
, _session (other._session)
100
, _have_presets (false)
101
, _have_pending_stop_events (false)
102
, _parameter_changed_since_last_preset (false)
104
_pending_stop_events.ensure_buffers (DataType::MIDI, 1, 4096);
112
Plugin::remove_preset (string name)
114
do_remove_preset (name);
115
_presets.erase (preset_by_label (name)->uri);
117
_last_preset.uri = "";
118
_parameter_changed_since_last_preset = false;
119
PresetRemoved (); /* EMIT SIGNAL */
122
/** @return PresetRecord with empty URI on failure */
124
Plugin::save_preset (string name)
126
string const uri = do_save_preset (name);
129
_presets.insert (make_pair (uri, PresetRecord (uri, name)));
130
PresetAdded (); /* EMIT SIGNAL */
133
return PresetRecord (uri, name);
137
ARDOUR::find_plugin(Session& session, string identifier, PluginType type)
139
PluginManager& mgr (PluginManager::instance());
140
PluginInfoList plugs;
144
plugs = mgr.ladspa_plugin_info();
149
plugs = mgr.lv2_plugin_info();
153
#ifdef WINDOWS_VST_SUPPORT
154
case ARDOUR::Windows_VST:
155
plugs = mgr.windows_vst_plugin_info();
161
plugs = mgr.lxvst_plugin_info();
165
#ifdef AUDIOUNIT_SUPPORT
166
case ARDOUR::AudioUnit:
167
plugs = mgr.au_plugin_info();
172
return PluginPtr ((Plugin *) 0);
175
PluginInfoList::iterator i;
177
for (i = plugs.begin(); i != plugs.end(); ++i) {
178
if (identifier == (*i)->unique_id){
179
return (*i)->load (session);
183
#ifdef WINDOWS_VST_SUPPORT
184
/* hmm, we didn't find it. could be because in older versions of Ardour.
185
we used to store the name of a VST plugin, not its unique ID. so try
189
for (i = plugs.begin(); i != plugs.end(); ++i) {
190
if (identifier == (*i)->name){
191
return (*i)->load (session);
197
/* hmm, we didn't find it. could be because in older versions of Ardour.
198
we used to store the name of a VST plugin, not its unique ID. so try
202
for (i = plugs.begin(); i != plugs.end(); ++i) {
203
if (identifier == (*i)->name){
204
return (*i)->load (session);
209
return PluginPtr ((Plugin*) 0);
213
Plugin::output_streams () const
215
/* LADSPA & VST should not get here because they do not
216
return "infinite" i/o counts.
218
return ChanCount::ZERO;
222
Plugin::input_streams () const
224
/* LADSPA & VST should not get here because they do not
225
return "infinite" i/o counts.
227
return ChanCount::ZERO;
230
const Plugin::PresetRecord *
231
Plugin::preset_by_label (const string& label)
234
for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
235
if (i->second.label == label) {
243
const Plugin::PresetRecord *
244
Plugin::preset_by_uri (const string& uri)
246
map<string, PresetRecord>::const_iterator pr = _presets.find (uri);
247
if (pr != _presets.end()) {
255
Plugin::connect_and_run (BufferSet& bufs,
256
ChanMapping /*in_map*/, ChanMapping /*out_map*/,
257
pframes_t /* nframes */, framecnt_t /*offset*/)
259
if (bufs.count().n_midi() > 0) {
261
/* Track notes that we are sending to the plugin */
263
MidiBuffer& b = bufs.get_midi (0);
265
_tracker.track (b.begin(), b.end());
267
if (_have_pending_stop_events) {
268
/* Transmit note-offs that are pending from the last transport stop */
269
bufs.merge_from (_pending_stop_events, 0);
270
_have_pending_stop_events = false;
278
Plugin::realtime_handle_transport_stopped ()
284
Plugin::realtime_locate ()
290
Plugin::monitoring_changed ()
296
Plugin::resolve_midi ()
298
/* Create note-offs for any active notes and put them in _pending_stop_events, to be picked
299
up on the next call to connect_and_run ().
302
_pending_stop_events.get_midi(0).clear ();
303
_tracker.resolve_notes (_pending_stop_events.get_midi (0), 0);
304
_have_pending_stop_events = true;
308
vector<Plugin::PresetRecord>
309
Plugin::get_presets ()
311
vector<PresetRecord> p;
313
#ifndef NO_PLUGIN_STATE
314
if (!_have_presets) {
316
_have_presets = true;
319
for (map<string, PresetRecord>::const_iterator i = _presets.begin(); i != _presets.end(); ++i) {
320
p.push_back (i->second);
323
if (!seen_set_state_message) {
324
info << string_compose (_("Plugin presets are not supported in this build of %1. Consider paying for a full version"),
333
/** Set parameters using a preset */
335
Plugin::load_preset (PresetRecord r)
338
_parameter_changed_since_last_preset = false;
340
PresetLoaded (); /* EMIT SIGNAL */
345
Plugin::clear_preset ()
347
_last_preset.uri = "";
348
_last_preset.label = "";
349
_parameter_changed_since_last_preset = false;
351
PresetLoaded (); /* EMIT SIGNAL */
354
/** @param val `plugin' value */
356
Plugin::set_parameter (uint32_t which, float)
358
_parameter_changed_since_last_preset = true;
359
_session.set_dirty ();
360
ParameterChanged (which, get_parameter (which)); /* EMIT SIGNAL */
364
Plugin::set_state (const XMLNode& node, int /*version*/)
366
XMLProperty const * p = node.property (X_("last-preset-uri"));
368
_last_preset.uri = p->value ();
371
p = node.property (X_("last-preset-label"));
373
_last_preset.label = p->value ();
376
p = node.property (X_("parameter-changed-since-last-preset"));
378
_parameter_changed_since_last_preset = string_is_affirmative (p->value ());
387
XMLNode* root = new XMLNode (state_node_name ());
388
LocaleGuard lg (X_("POSIX"));
390
root->add_property (X_("last-preset-uri"), _last_preset.uri);
391
root->add_property (X_("last-preset-label"), _last_preset.label);
392
root->add_property (X_("parameter-changed-since-last-preset"), _parameter_changed_since_last_preset ? X_("yes") : X_("no"));
394
#ifndef NO_PLUGIN_STATE
397
if (!seen_get_state_message) {
398
info << string_compose (_("Saving plugin settings is not supported in this build of %1. Consider paying for the full version"),
401
seen_get_state_message = true;
409
Plugin::set_info (PluginInfoPtr info)