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.
24 #include <fst/vestige/aeffectx.h>
26 #include "ardour/session.h"
27 #include "ardour/tempo.h"
28 #include "ardour/vst_plugin.h"
32 #define DEBUG_CALLBACKS
33 static int debug_callbacks
= -1;
35 #ifdef DEBUG_CALLBACKS
36 #define SHOW_CALLBACK if (debug_callbacks) printf
38 #define SHOW_CALLBACK(...)
41 using namespace ARDOUR
;
43 long Session::vst_callback (AEffect
* effect
,
50 static VstTimeInfo _timeInfo
;
54 if (debug_callbacks
< 0) {
55 debug_callbacks
= (getenv ("ARDOUR_DEBUG_VST_CALLBACKS") != 0);
58 if (effect
&& effect
->user
) {
59 plug
= (VSTPlugin
*) (effect
->user
);
60 session
= &plug
->session();
61 SHOW_CALLBACK ("am callback 0x%x, opcode = %ld, plugin = \"%s\" ", (int) pthread_self(), opcode
, plug
->name());
65 SHOW_CALLBACK ("am callback 0x%x, opcode = %ld", (int) pthread_self(), opcode
);
70 case audioMasterAutomate
:
71 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
72 // index, value, returns 0
74 plug
->set_parameter (index
, opt
);
78 case audioMasterVersion
:
79 SHOW_CALLBACK ("amc: audioMasterVersion\n");
80 // vst version, currently 2 (0 for older)
83 case audioMasterCurrentId
:
84 SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
85 // returns the unique id of a plug that's currently
90 SHOW_CALLBACK ("amc: audioMasterIdle\n");
91 // call application idle routine (this will
92 // call effEditIdle for all open editors too)
94 effect
->dispatcher(effect
, effEditIdle
, 0, 0, NULL
, 0.0f
);
98 case audioMasterPinConnected
:
99 SHOW_CALLBACK ("amc: audioMasterPinConnected\n");
100 // inquire if an input or output is beeing connected;
101 // index enumerates input or output counting from zero:
102 // value is 0 for input and != 0 otherwise. note: the
103 // return value is 0 for <true> such that older versions
104 // will always return true.
107 case audioMasterWantMidi
:
108 SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
109 // <value> is a filter which is currently ignored
111 plug
->get_info()->n_inputs
.set_midi (1);
115 case audioMasterGetTime
:
116 SHOW_CALLBACK ("amc: audioMasterGetTime\n");
117 // returns const VstTimeInfo* (or 0 if not supported)
118 // <value> should contain a mask indicating which fields are required
119 // (see valid masks above), as some items may require extensive
121 memset(&_timeInfo
, 0, sizeof(_timeInfo
));
123 _timeInfo
.samplePos
= session
->transport_frame();
124 _timeInfo
.sampleRate
= session
->frame_rate();
127 if (value
& (kVstTempoValid
)) {
128 const Tempo
& t (session
->tempo_map().tempo_at (session
->transport_frame()));
129 _timeInfo
.tempo
= t
.beats_per_minute ();
130 _timeInfo
.flags
|= (kVstTempoValid
);
132 if (value
& (kVstBarsValid
)) {
133 const Meter
& m (session
->tempo_map().meter_at (session
->transport_frame()));
134 _timeInfo
.timeSigNumerator
= m
.beats_per_bar ();
135 _timeInfo
.timeSigDenominator
= m
.note_divisor ();
136 _timeInfo
.flags
|= (kVstBarsValid
);
139 if (session
->transport_speed() != 0.0f
) {
140 _timeInfo
.flags
|= kVstTransportPlaying
;
144 return (long)&_timeInfo
;
146 case audioMasterProcessEvents
:
147 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
148 // VstEvents* in <ptr>
151 case audioMasterSetTime
:
152 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
153 // VstTimenfo* in <ptr>, filter in <value>, not supported
155 case audioMasterTempoAt
:
156 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
157 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
159 const Tempo
& t (session
->tempo_map().tempo_at (value
));
160 return t
.beats_per_minute() * 1000;
166 case audioMasterGetNumAutomatableParameters
:
167 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
170 case audioMasterGetParameterQuantization
:
171 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
172 // returns the integer value for +1.0 representation,
173 // or 1 if full single float precision is maintained
174 // in automation. parameter index in <value> (-1: all, any)
177 case audioMasterIOChanged
:
178 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
179 // numInputs and/or numOutputs has changed
182 case audioMasterNeedIdle
:
183 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
184 // plug needs idle calls (outside its editor window)
186 plug
->fst()->wantIdle
= 1;
190 case audioMasterSizeWindow
:
191 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
192 // index: width, value: height
195 case audioMasterGetSampleRate
:
196 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
198 return session
->frame_rate();
202 case audioMasterGetBlockSize
:
203 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
205 return session
->get_block_size();
209 case audioMasterGetInputLatency
:
210 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
213 case audioMasterGetOutputLatency
:
214 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
217 case audioMasterGetPreviousPlug
:
218 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
219 // input pin in <value> (-1: first to come), returns cEffect*
222 case audioMasterGetNextPlug
:
223 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
224 // output pin in <value> (-1: first to come), returns cEffect*
226 case audioMasterWillReplaceOrAccumulate
:
227 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
228 // returns: 0: not supported, 1: replace, 2: accumulate
231 case audioMasterGetCurrentProcessLevel
:
232 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
233 // returns: 0: not supported,
234 // 1: currently in user thread (gui)
235 // 2: currently in audio thread (where process is called)
236 // 3: currently in 'sequencer' thread (midi, timer etc)
237 // 4: currently offline processing and thus in user thread
238 // other: not defined, but probably pre-empting user thread.
241 case audioMasterGetAutomationState
:
242 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
243 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
247 case audioMasterOfflineStart
:
248 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
249 case audioMasterOfflineRead
:
250 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
251 // ptr points to offline structure, see below. return 0: error, 1 ok
254 case audioMasterOfflineWrite
:
255 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
259 case audioMasterOfflineGetCurrentPass
:
260 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
261 case audioMasterOfflineGetCurrentMetaPass
:
262 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
265 case audioMasterSetOutputSampleRate
:
266 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
267 // for variable i/o, sample rate in <opt>
270 case audioMasterGetSpeakerArrangement
:
271 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
272 // (long)input in <value>, output in <ptr>
275 case audioMasterGetVendorString
:
276 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
277 // fills <ptr> with a string identifying the vendor (max 64 char)
278 strcpy ((char*) ptr
, "Linux Audio Systems");
281 case audioMasterGetProductString
:
282 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
283 // fills <ptr> with a string with product name (max 64 char)
284 strcpy ((char*) ptr
, "Ardour");
287 case audioMasterGetVendorVersion
:
288 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
289 // returns vendor-specific version
292 case audioMasterVendorSpecific
:
293 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
294 // no definition, vendor specific handling
297 case audioMasterSetIcon
:
298 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
299 // void* in <ptr>, format not defined yet
302 case audioMasterCanDo
:
303 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
304 // string in ptr, see below
307 case audioMasterGetLanguage
:
308 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
312 case audioMasterOpenWindow
:
313 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
314 // returns platform specific ptr
317 case audioMasterCloseWindow
:
318 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
319 // close window, platform specific handle in <ptr>
322 case audioMasterGetDirectory
:
323 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
324 // get plug directory, FSSpec on MAC, else char*
327 case audioMasterUpdateDisplay
:
328 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
329 // something has changed, update 'multi-fx' display
331 effect
->dispatcher(effect
, effEditIdle
, 0, 0, NULL
, 0.0f
);
335 case audioMasterBeginEdit
:
336 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
337 // begin of automation session (when mouse down), parameter index in <index>
340 case audioMasterEndEdit
:
341 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
342 // end of automation session (when mouse up), parameter index in <index>
345 case audioMasterOpenFileSelector
:
346 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
347 // open a fileselector window with VstFileSelect* in <ptr>
351 SHOW_CALLBACK ("VST master dispatcher: undefed: %ld\n", opcode
);