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"
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 intptr_t Session::vst_callback (
52 static VstTimeInfo _timeInfo;
53 WindowsVSTPlugin* plug;
56 if (debug_callbacks < 0) {
57 debug_callbacks = (getenv ("ARDOUR_DEBUG_VST_CALLBACKS") != 0);
60 if (effect && effect->user) {
61 plug = (WindowsVSTPlugin*) (effect->user);
62 session = &plug->session();
63 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self(), opcode, plug->name());
67 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self(), opcode);
72 case audioMasterAutomate:
73 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
74 // index, value, returns 0
76 plug->set_parameter (index, opt);
80 case audioMasterVersion:
81 SHOW_CALLBACK ("amc: audioMasterVersion\n");
82 // vst version, currently 2 (0 for older)
85 case audioMasterCurrentId:
86 SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
87 // returns the unique id of a plug that's currently
92 SHOW_CALLBACK ("amc: audioMasterIdle\n");
93 // call application idle routine (this will
94 // call effEditIdle for all open editors too)
96 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
100 case audioMasterPinConnected:
101 SHOW_CALLBACK ("amc: audioMasterPinConnected\n");
102 // inquire if an input or output is beeing connected;
103 // index enumerates input or output counting from zero:
104 // value is 0 for input and != 0 otherwise. note: the
105 // return value is 0 for <true> such that older versions
106 // will always return true.
109 case audioMasterWantMidi:
110 SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
111 // <value> is a filter which is currently ignored
113 plug->get_info()->n_inputs.set_midi (1);
117 case audioMasterGetTime:
118 SHOW_CALLBACK ("amc: audioMasterGetTime\n");
119 // returns const VstTimeInfo* (or 0 if not supported)
120 // <value> should contain a mask indicating which fields are required
121 // (see valid masks above), as some items may require extensive
123 memset(&_timeInfo, 0, sizeof(_timeInfo));
125 _timeInfo.samplePos = session->transport_frame();
126 _timeInfo.sampleRate = session->frame_rate();
129 if (value & (kVstTempoValid)) {
130 const Tempo& t (session->tempo_map().tempo_at (session->transport_frame()));
131 _timeInfo.tempo = t.beats_per_minute ();
132 _timeInfo.flags |= (kVstTempoValid);
134 if (value & (kVstBarsValid)) {
135 const Meter& m (session->tempo_map().meter_at (session->transport_frame()));
136 _timeInfo.timeSigNumerator = m.beats_per_bar ();
137 _timeInfo.timeSigDenominator = m.note_divisor ();
138 _timeInfo.flags |= (kVstBarsValid);
141 if (session->transport_speed() != 0.0f) {
142 _timeInfo.flags |= kVstTransportPlaying;
146 return (long)&_timeInfo;
148 case audioMasterProcessEvents:
149 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
150 // VstEvents* in <ptr>
153 case audioMasterSetTime:
154 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
155 // VstTimenfo* in <ptr>, filter in <value>, not supported
157 case audioMasterTempoAt:
158 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
159 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
161 const Tempo& t (session->tempo_map().tempo_at (value));
162 return t.beats_per_minute() * 1000;
168 case audioMasterGetNumAutomatableParameters:
169 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
172 case audioMasterGetParameterQuantization:
173 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
174 // returns the integer value for +1.0 representation,
175 // or 1 if full single float precision is maintained
176 // in automation. parameter index in <value> (-1: all, any)
179 case audioMasterIOChanged:
180 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
181 // numInputs and/or numOutputs has changed
184 case audioMasterNeedIdle:
185 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
186 // plug needs idle calls (outside its editor window)
188 plug->state()->wantIdle = 1;
192 case audioMasterSizeWindow:
193 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
194 // index: width, value: height
197 case audioMasterGetSampleRate:
198 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
200 return session->frame_rate();
204 case audioMasterGetBlockSize:
205 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
207 return session->get_block_size();
211 case audioMasterGetInputLatency:
212 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
215 case audioMasterGetOutputLatency:
216 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
219 case audioMasterGetPreviousPlug:
220 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
221 // input pin in <value> (-1: first to come), returns cEffect*
224 case audioMasterGetNextPlug:
225 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
226 // output pin in <value> (-1: first to come), returns cEffect*
228 case audioMasterWillReplaceOrAccumulate:
229 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
230 // returns: 0: not supported, 1: replace, 2: accumulate
233 case audioMasterGetCurrentProcessLevel:
234 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
235 // returns: 0: not supported,
236 // 1: currently in user thread (gui)
237 // 2: currently in audio thread (where process is called)
238 // 3: currently in 'sequencer' thread (midi, timer etc)
239 // 4: currently offline processing and thus in user thread
240 // other: not defined, but probably pre-empting user thread.
243 case audioMasterGetAutomationState:
244 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
245 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
249 case audioMasterOfflineStart:
250 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
251 case audioMasterOfflineRead:
252 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
253 // ptr points to offline structure, see below. return 0: error, 1 ok
256 case audioMasterOfflineWrite:
257 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
261 case audioMasterOfflineGetCurrentPass:
262 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
263 case audioMasterOfflineGetCurrentMetaPass:
264 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
267 case audioMasterSetOutputSampleRate:
268 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
269 // for variable i/o, sample rate in <opt>
272 case audioMasterGetSpeakerArrangement:
273 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
274 // (long)input in <value>, output in <ptr>
277 case audioMasterGetVendorString:
278 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
279 // fills <ptr> with a string identifying the vendor (max 64 char)
280 strcpy ((char*) ptr, "Linux Audio Systems");
283 case audioMasterGetProductString:
284 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
285 // fills <ptr> with a string with product name (max 64 char)
286 strcpy ((char*) ptr, "Ardour");
289 case audioMasterGetVendorVersion:
290 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
291 // returns vendor-specific version
294 case audioMasterVendorSpecific:
295 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
296 // no definition, vendor specific handling
299 case audioMasterSetIcon:
300 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
301 // void* in <ptr>, format not defined yet
304 case audioMasterCanDo:
305 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
306 // string in ptr, see below
309 case audioMasterGetLanguage:
310 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
314 case audioMasterOpenWindow:
315 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
316 // returns platform specific ptr
319 case audioMasterCloseWindow:
320 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
321 // close window, platform specific handle in <ptr>
324 case audioMasterGetDirectory:
325 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
326 // get plug directory, FSSpec on MAC, else char*
329 case audioMasterUpdateDisplay:
330 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
331 // something has changed, update 'multi-fx' display
333 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
337 case audioMasterBeginEdit:
338 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
339 // begin of automation session (when mouse down), parameter index in <index>
342 case audioMasterEndEdit:
343 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
344 // end of automation session (when mouse up), parameter index in <index>
347 case audioMasterOpenFileSelector:
348 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
349 // open a fileselector window with VstFileSelect* in <ptr>
353 SHOW_CALLBACK ("VST master dispatcher: undefed: %d\n", opcode);