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.
25 #include "ardour/session.h"
26 #include "ardour/tempo.h"
27 #include "ardour/windows_vst_plugin.h"
28 #include "ardour/vestige/aeffectx.h"
29 #include "ardour/vst_types.h"
33 #define DEBUG_CALLBACKS
34 static int debug_callbacks = -1;
36 #ifdef DEBUG_CALLBACKS
37 #define SHOW_CALLBACK if (debug_callbacks) printf
39 #define SHOW_CALLBACK(...)
42 using namespace ARDOUR;
44 intptr_t Session::vst_callback (
53 static VstTimeInfo _timeInfo;
57 if (debug_callbacks < 0) {
58 debug_callbacks = (getenv ("ARDOUR_DEBUG_VST_CALLBACKS") != 0);
61 if (effect && effect->user) {
62 plug = (VSTPlugin *) (effect->user);
63 session = &plug->session();
65 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self().p, opcode, plug->name());
67 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self(), opcode, plug->name());
73 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self().p, opcode);
75 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self(), opcode);
81 case audioMasterAutomate:
82 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
83 // index, value, returns 0
85 plug->set_parameter (index, opt);
89 case audioMasterVersion:
90 SHOW_CALLBACK ("amc: audioMasterVersion\n");
91 // vst version, currently 2 (0 for older)
94 case audioMasterCurrentId:
95 SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
96 // returns the unique id of a plug that's currently
100 case audioMasterIdle:
101 SHOW_CALLBACK ("amc: audioMasterIdle\n");
102 // call application idle routine (this will
103 // call effEditIdle for all open editors too)
105 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
109 case audioMasterPinConnected:
110 SHOW_CALLBACK ("amc: audioMasterPinConnected\n");
111 // inquire if an input or output is beeing connected;
112 // index enumerates input or output counting from zero:
113 // value is 0 for input and != 0 otherwise. note: the
114 // return value is 0 for <true> such that older versions
115 // will always return true.
118 case audioMasterWantMidi:
119 SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
120 // <value> is a filter which is currently ignored
122 plug->get_info()->n_inputs.set_midi (1);
126 case audioMasterGetTime:
127 SHOW_CALLBACK ("amc: audioMasterGetTime\n");
128 // returns const VstTimeInfo* (or 0 if not supported)
129 // <value> should contain a mask indicating which fields are required
130 // (see valid masks above), as some items may require extensive
132 memset(&_timeInfo, 0, sizeof(_timeInfo));
134 _timeInfo.samplePos = session->transport_frame();
135 _timeInfo.sampleRate = session->frame_rate();
138 if (value & (kVstTempoValid)) {
139 const Tempo& t (session->tempo_map().tempo_at (session->transport_frame()));
140 _timeInfo.tempo = t.beats_per_minute ();
141 _timeInfo.flags |= (kVstTempoValid);
143 if (value & (kVstBarsValid)) {
144 const Meter& m (session->tempo_map().meter_at (session->transport_frame()));
145 _timeInfo.timeSigNumerator = m.divisions_per_bar ();
146 _timeInfo.timeSigDenominator = m.note_divisor ();
147 _timeInfo.flags |= (kVstBarsValid);
150 if (session->transport_speed() != 0.0f) {
151 _timeInfo.flags |= kVstTransportPlaying;
155 return (long)&_timeInfo;
157 case audioMasterProcessEvents:
158 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
159 // VstEvents* in <ptr>
162 case audioMasterSetTime:
163 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
164 // VstTimenfo* in <ptr>, filter in <value>, not supported
166 case audioMasterTempoAt:
167 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
168 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
170 const Tempo& t (session->tempo_map().tempo_at (value));
171 return t.beats_per_minute() * 1000;
177 case audioMasterGetNumAutomatableParameters:
178 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
181 case audioMasterGetParameterQuantization:
182 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
183 // returns the integer value for +1.0 representation,
184 // or 1 if full single float precision is maintained
185 // in automation. parameter index in <value> (-1: all, any)
188 case audioMasterIOChanged:
189 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
190 // numInputs and/or numOutputs has changed
193 case audioMasterNeedIdle:
194 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
195 // plug needs idle calls (outside its editor window)
197 plug->state()->wantIdle = 1;
201 case audioMasterSizeWindow:
202 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
203 // index: width, value: height
206 case audioMasterGetSampleRate:
207 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
209 return session->frame_rate();
213 case audioMasterGetBlockSize:
214 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
216 return session->get_block_size();
220 case audioMasterGetInputLatency:
221 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
224 case audioMasterGetOutputLatency:
225 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
228 case audioMasterGetPreviousPlug:
229 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
230 // input pin in <value> (-1: first to come), returns cEffect*
233 case audioMasterGetNextPlug:
234 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
235 // output pin in <value> (-1: first to come), returns cEffect*
237 case audioMasterWillReplaceOrAccumulate:
238 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
239 // returns: 0: not supported, 1: replace, 2: accumulate
242 case audioMasterGetCurrentProcessLevel:
243 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
244 // returns: 0: not supported,
245 // 1: currently in user thread (gui)
246 // 2: currently in audio thread (where process is called)
247 // 3: currently in 'sequencer' thread (midi, timer etc)
248 // 4: currently offline processing and thus in user thread
249 // other: not defined, but probably pre-empting user thread.
252 case audioMasterGetAutomationState:
253 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
254 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
258 case audioMasterOfflineStart:
259 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
262 case audioMasterOfflineRead:
263 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
264 // ptr points to offline structure, see below. return 0: error, 1 ok
267 case audioMasterOfflineWrite:
268 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
272 case audioMasterOfflineGetCurrentPass:
273 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
276 case audioMasterOfflineGetCurrentMetaPass:
277 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
280 case audioMasterSetOutputSampleRate:
281 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
282 // for variable i/o, sample rate in <opt>
285 case audioMasterGetSpeakerArrangement:
286 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
287 // (long)input in <value>, output in <ptr>
290 case audioMasterGetVendorString:
291 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
292 // fills <ptr> with a string identifying the vendor (max 64 char)
293 strcpy ((char*) ptr, "Linux Audio Systems");
296 case audioMasterGetProductString:
297 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
298 // fills <ptr> with a string with product name (max 64 char)
299 strcpy ((char*) ptr, PROGRAM_NAME);
302 case audioMasterGetVendorVersion:
303 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
304 // returns vendor-specific version
307 case audioMasterVendorSpecific:
308 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
309 // no definition, vendor specific handling
312 case audioMasterSetIcon:
313 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
314 // void* in <ptr>, format not defined yet
317 case audioMasterCanDo:
318 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
319 // string in ptr, see below
322 case audioMasterGetLanguage:
323 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
327 case audioMasterOpenWindow:
328 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
329 // returns platform specific ptr
332 case audioMasterCloseWindow:
333 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
334 // close window, platform specific handle in <ptr>
337 case audioMasterGetDirectory:
338 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
339 // get plug directory, FSSpec on MAC, else char*
342 case audioMasterUpdateDisplay:
343 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
344 // something has changed, update 'multi-fx' display
346 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
350 case audioMasterBeginEdit:
351 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
352 // begin of automation session (when mouse down), parameter index in <index>
355 case audioMasterEndEdit:
356 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
357 // end of automation session (when mouse up), parameter index in <index>
360 case audioMasterOpenFileSelector:
361 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
362 // open a fileselector window with VstFileSelect* in <ptr>
366 SHOW_CALLBACK ("VST master dispatcher: undefed: %d\n", opcode);