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\" ", pthread_self(), opcode, plug->name());
65 SHOW_CALLBACK ("am callback 0x%x, opcode = %ld", pthread_self(), opcode);
70 case audioMasterAutomate:
71 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
72 // index, value, returns 0
74 effect->setParameter (effect, 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
112 case audioMasterGetTime:
113 SHOW_CALLBACK ("amc: audioMasterGetTime\n");
114 // returns const VstTimeInfo* (or 0 if not supported)
115 // <value> should contain a mask indicating which fields are required
116 // (see valid masks above), as some items may require extensive
118 memset(&_timeInfo, 0, sizeof(_timeInfo));
120 _timeInfo.samplePos = session->transport_frame();
121 _timeInfo.sampleRate = session->frame_rate();
124 if (value & (kVstTempoValid)) {
125 const Tempo& t (session->tempo_map().tempo_at (session->transport_frame()));
126 _timeInfo.tempo = t.beats_per_minute ();
127 _timeInfo.flags |= (kVstTempoValid);
129 if (value & (kVstBarsValid)) {
130 const Meter& m (session->tempo_map().meter_at (session->transport_frame()));
131 _timeInfo.timeSigNumerator = m.beats_per_bar ();
132 _timeInfo.timeSigDenominator = m.note_divisor ();
133 _timeInfo.flags |= (kVstBarsValid);
136 if (session->transport_speed() != 0.0f) {
137 _timeInfo.flags |= kVstTransportPlaying;
141 return (long)&_timeInfo;
143 case audioMasterProcessEvents:
144 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
145 // VstEvents* in <ptr>
148 case audioMasterSetTime:
149 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
150 // VstTimenfo* in <ptr>, filter in <value>, not supported
152 case audioMasterTempoAt:
153 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
154 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
156 const Tempo& t (session->tempo_map().tempo_at (value));
157 return t.beats_per_minute() * 1000;
163 case audioMasterGetNumAutomatableParameters:
164 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
167 case audioMasterGetParameterQuantization:
168 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
169 // returns the integer value for +1.0 representation,
170 // or 1 if full single float precision is maintained
171 // in automation. parameter index in <value> (-1: all, any)
174 case audioMasterIOChanged:
175 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
176 // numInputs and/or numOutputs has changed
179 case audioMasterNeedIdle:
180 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
181 // plug needs idle calls (outside its editor window)
183 plug->fst()->wantIdle = 1;
187 case audioMasterSizeWindow:
188 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
189 // index: width, value: height
192 case audioMasterGetSampleRate:
193 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
195 return session->frame_rate();
199 case audioMasterGetBlockSize:
200 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
202 return session->get_block_size();
206 case audioMasterGetInputLatency:
207 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
210 case audioMasterGetOutputLatency:
211 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
214 case audioMasterGetPreviousPlug:
215 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
216 // input pin in <value> (-1: first to come), returns cEffect*
219 case audioMasterGetNextPlug:
220 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
221 // output pin in <value> (-1: first to come), returns cEffect*
223 case audioMasterWillReplaceOrAccumulate:
224 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
225 // returns: 0: not supported, 1: replace, 2: accumulate
228 case audioMasterGetCurrentProcessLevel:
229 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
230 // returns: 0: not supported,
231 // 1: currently in user thread (gui)
232 // 2: currently in audio thread (where process is called)
233 // 3: currently in 'sequencer' thread (midi, timer etc)
234 // 4: currently offline processing and thus in user thread
235 // other: not defined, but probably pre-empting user thread.
238 case audioMasterGetAutomationState:
239 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
240 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
244 case audioMasterOfflineStart:
245 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
246 case audioMasterOfflineRead:
247 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
248 // ptr points to offline structure, see below. return 0: error, 1 ok
251 case audioMasterOfflineWrite:
252 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
256 case audioMasterOfflineGetCurrentPass:
257 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
258 case audioMasterOfflineGetCurrentMetaPass:
259 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
262 case audioMasterSetOutputSampleRate:
263 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
264 // for variable i/o, sample rate in <opt>
267 case audioMasterGetSpeakerArrangement:
268 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
269 // (long)input in <value>, output in <ptr>
272 case audioMasterGetVendorString:
273 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
274 // fills <ptr> with a string identifying the vendor (max 64 char)
275 strcpy ((char*) ptr, "Linux Audio Systems");
278 case audioMasterGetProductString:
279 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
280 // fills <ptr> with a string with product name (max 64 char)
281 strcpy ((char*) ptr, "Ardour");
284 case audioMasterGetVendorVersion:
285 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
286 // returns vendor-specific version
289 case audioMasterVendorSpecific:
290 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
291 // no definition, vendor specific handling
294 case audioMasterSetIcon:
295 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
296 // void* in <ptr>, format not defined yet
299 case audioMasterCanDo:
300 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
301 // string in ptr, see below
304 case audioMasterGetLanguage:
305 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
309 case audioMasterOpenWindow:
310 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
311 // returns platform specific ptr
314 case audioMasterCloseWindow:
315 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
316 // close window, platform specific handle in <ptr>
319 case audioMasterGetDirectory:
320 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
321 // get plug directory, FSSpec on MAC, else char*
324 case audioMasterUpdateDisplay:
325 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
326 // something has changed, update 'multi-fx' display
328 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
332 case audioMasterBeginEdit:
333 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
334 // begin of automation session (when mouse down), parameter index in <index>
337 case audioMasterEndEdit:
338 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
339 // end of automation session (when mouse up), parameter index in <index>
342 case audioMasterOpenFileSelector:
343 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
344 // open a fileselector window with VstFileSelect* in <ptr>
348 SHOW_CALLBACK ("VST master dispatcher: undefed: %d\n", opcode);