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/audioengine.h"
26 #include "ardour/session.h"
27 #include "ardour/tempo.h"
28 #include "ardour/windows_vst_plugin.h"
29 #include "ardour/vestige/aeffectx.h"
30 #include "ardour/vst_types.h"
34 #define DEBUG_CALLBACKS
35 static int debug_callbacks = -1;
37 #ifdef DEBUG_CALLBACKS
38 #define SHOW_CALLBACK if (debug_callbacks) printf
40 #define SHOW_CALLBACK(...)
43 using namespace ARDOUR;
45 intptr_t Session::vst_callback (
54 static VstTimeInfo _timeInfo;
58 if (debug_callbacks < 0) {
59 debug_callbacks = (getenv ("ARDOUR_DEBUG_VST_CALLBACKS") != 0);
62 if (effect && effect->user) {
63 plug = (VSTPlugin *) (effect->user);
64 session = &plug->session();
66 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self().p, opcode, plug->name());
68 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self(), opcode, plug->name());
74 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self().p, opcode);
76 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self(), opcode);
82 case audioMasterAutomate:
83 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
84 // index, value, returns 0
86 plug->set_parameter (index, opt);
90 case audioMasterVersion:
91 SHOW_CALLBACK ("amc: audioMasterVersion\n");
92 // vst version, currently 2 (0 for older)
95 case audioMasterCurrentId:
96 SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
97 // returns the unique id of a plug that's currently
101 case audioMasterIdle:
102 SHOW_CALLBACK ("amc: audioMasterIdle\n");
103 // call application idle routine (this will
104 // call effEditIdle for all open editors too)
106 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
110 case audioMasterPinConnected:
111 SHOW_CALLBACK ("amc: audioMasterPinConnected\n");
112 // inquire if an input or output is beeing connected;
113 // index enumerates input or output counting from zero:
114 // value is 0 for input and != 0 otherwise. note: the
115 // return value is 0 for <true> such that older versions
116 // will always return true.
119 case audioMasterWantMidi:
120 SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
121 // <value> is a filter which is currently ignored
123 plug->get_info()->n_inputs.set_midi (1);
127 case audioMasterGetTime:
128 SHOW_CALLBACK ("amc: audioMasterGetTime\n");
129 // returns const VstTimeInfo* (or 0 if not supported)
130 // <value> should contain a mask indicating which fields are required
131 // (see valid masks above), as some items may require extensive
134 std::cerr << "VST get time callback, value = " << std::hex << value << std::dec << std::endl;
136 framepos_t now = session->transport_frame();
138 std::cerr << "\t@ " << now << std::endl;
140 _timeInfo.samplePos = now;
141 _timeInfo.sampleRate = session->frame_rate();
143 const TempoMetric& tm (session->tempo_map().metric_at (now));
145 if (value & (kVstTempoValid)) {
146 const Tempo& t (tm.tempo());
147 _timeInfo.tempo = t.beats_per_minute ();
148 _timeInfo.flags |= (kVstTempoValid);
149 std::cerr << "\ttempo makes " << std::hex << _timeInfo.flags << std::dec << std::endl;
151 if (value & (kVstTimeSigValid)) {
152 const Meter& m (tm.meter());
153 _timeInfo.timeSigNumerator = m.divisions_per_bar ();
154 _timeInfo.timeSigDenominator = m.note_divisor ();
155 _timeInfo.flags |= (kVstTimeSigValid);
156 std::cerr << "\ttimedig makes " << std::hex << _timeInfo.flags << std::dec << std::endl;
158 if (value & (kVstPpqPosValid)) {
159 Timecode::BBT_Time bbt;
161 session->tempo_map().bbt_time_rt (now, bbt);
163 /* Note that this assumes constant
164 meter/tempo throughout the session. We
165 can do better than this, because
166 progressive rock fans demand it.
168 double ppqBar = double(bbt.bars - 1) * tm.meter().divisions_per_bar();
169 double ppqBeat = double(bbt.beats - 1);
170 double ppqTick = double(bbt.ticks) / Timecode::BBT_Time::ticks_per_beat;
172 _timeInfo.ppqPos = ppqBar + ppqBeat + ppqTick;
173 _timeInfo.flags |= (kVstPpqPosValid);
174 std::cerr << "\tppq makes " << std::hex << _timeInfo.flags << std::dec << std::endl;
181 // _timeInfo.barStartPos = ppqBar;
182 // _timeInfo.flags |= kVstBarsValid;
184 if (session->transport_speed() != 0.0f) {
185 _timeInfo.flags |= kVstTransportPlaying;
188 _timeInfo.samplePos = 0;
189 _timeInfo.sampleRate = AudioEngine::instance()->sample_rate();
192 std::cerr << "\ttimeinfo valid = " << std::hex << _timeInfo.flags << std::dec << std::endl;
193 return (long)&_timeInfo;
195 case audioMasterProcessEvents:
196 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
197 // VstEvents* in <ptr>
200 case audioMasterSetTime:
201 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
202 // VstTimenfo* in <ptr>, filter in <value>, not supported
204 case audioMasterTempoAt:
205 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
206 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
208 const Tempo& t (session->tempo_map().tempo_at (value));
209 return t.beats_per_minute() * 1000;
215 case audioMasterGetNumAutomatableParameters:
216 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
219 case audioMasterGetParameterQuantization:
220 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
221 // returns the integer value for +1.0 representation,
222 // or 1 if full single float precision is maintained
223 // in automation. parameter index in <value> (-1: all, any)
226 case audioMasterIOChanged:
227 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
228 // numInputs and/or numOutputs has changed
231 case audioMasterNeedIdle:
232 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
233 // plug needs idle calls (outside its editor window)
235 plug->state()->wantIdle = 1;
239 case audioMasterSizeWindow:
240 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
241 // index: width, value: height
244 case audioMasterGetSampleRate:
245 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
247 return session->frame_rate();
251 case audioMasterGetBlockSize:
252 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
254 return session->get_block_size();
258 case audioMasterGetInputLatency:
259 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
262 case audioMasterGetOutputLatency:
263 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
266 case audioMasterGetPreviousPlug:
267 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
268 // input pin in <value> (-1: first to come), returns cEffect*
271 case audioMasterGetNextPlug:
272 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
273 // output pin in <value> (-1: first to come), returns cEffect*
275 case audioMasterWillReplaceOrAccumulate:
276 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
277 // returns: 0: not supported, 1: replace, 2: accumulate
280 case audioMasterGetCurrentProcessLevel:
281 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
282 // returns: 0: not supported,
283 // 1: currently in user thread (gui)
284 // 2: currently in audio thread (where process is called)
285 // 3: currently in 'sequencer' thread (midi, timer etc)
286 // 4: currently offline processing and thus in user thread
287 // other: not defined, but probably pre-empting user thread.
290 case audioMasterGetAutomationState:
291 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
292 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
296 case audioMasterOfflineStart:
297 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
300 case audioMasterOfflineRead:
301 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
302 // ptr points to offline structure, see below. return 0: error, 1 ok
305 case audioMasterOfflineWrite:
306 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
310 case audioMasterOfflineGetCurrentPass:
311 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
314 case audioMasterOfflineGetCurrentMetaPass:
315 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
318 case audioMasterSetOutputSampleRate:
319 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
320 // for variable i/o, sample rate in <opt>
323 case audioMasterGetSpeakerArrangement:
324 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
325 // (long)input in <value>, output in <ptr>
328 case audioMasterGetVendorString:
329 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
330 // fills <ptr> with a string identifying the vendor (max 64 char)
331 strcpy ((char*) ptr, "Linux Audio Systems");
334 case audioMasterGetProductString:
335 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
336 // fills <ptr> with a string with product name (max 64 char)
337 strcpy ((char*) ptr, PROGRAM_NAME);
340 case audioMasterGetVendorVersion:
341 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
342 // returns vendor-specific version
345 case audioMasterVendorSpecific:
346 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
347 // no definition, vendor specific handling
350 case audioMasterSetIcon:
351 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
352 // void* in <ptr>, format not defined yet
355 case audioMasterCanDo:
356 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
357 // string in ptr, see below
360 case audioMasterGetLanguage:
361 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
365 case audioMasterOpenWindow:
366 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
367 // returns platform specific ptr
370 case audioMasterCloseWindow:
371 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
372 // close window, platform specific handle in <ptr>
375 case audioMasterGetDirectory:
376 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
377 // get plug directory, FSSpec on MAC, else char*
380 case audioMasterUpdateDisplay:
381 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
382 // something has changed, update 'multi-fx' display
384 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
388 case audioMasterBeginEdit:
389 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
390 // begin of automation session (when mouse down), parameter index in <index>
393 case audioMasterEndEdit:
394 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
395 // end of automation session (when mouse up), parameter index in <index>
398 case audioMasterOpenFileSelector:
399 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
400 // open a fileselector window with VstFileSelect* in <ptr>
404 SHOW_CALLBACK ("VST master dispatcher: undefed: %d\n", opcode);