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"
31 #ifdef WINDOWS_VST_SUPPORT
37 #define DEBUG_CALLBACKS
38 static int debug_callbacks = -1;
40 #ifdef DEBUG_CALLBACKS
41 #define SHOW_CALLBACK if (debug_callbacks) printf
43 #define SHOW_CALLBACK(...)
46 using namespace ARDOUR;
48 intptr_t Session::vst_callback (
57 static VstTimeInfo _timeInfo;
61 if (debug_callbacks < 0) {
62 debug_callbacks = (getenv ("ARDOUR_DEBUG_VST_CALLBACKS") != 0);
65 if (effect && effect->user) {
66 plug = (VSTPlugin *) (effect->user);
67 session = &plug->session();
69 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self().p, opcode, plug->name());
71 SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self(), opcode, plug->name());
77 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self().p, opcode);
79 SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self(), opcode);
85 case audioMasterAutomate:
86 SHOW_CALLBACK ("amc: audioMasterAutomate\n");
87 // index, value, returns 0
89 plug->set_parameter (index, opt);
93 case audioMasterVersion:
94 SHOW_CALLBACK ("amc: audioMasterVersion\n");
95 // vst version, currently 2 (0 for older)
98 case audioMasterCurrentId:
99 SHOW_CALLBACK ("amc: audioMasterCurrentId\n");
100 // returns the unique id of a plug that's currently
104 case audioMasterIdle:
105 SHOW_CALLBACK ("amc: audioMasterIdle\n");
106 #ifdef WINDOWS_VST_SUPPORT
107 fst_audio_master_idle();
110 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
114 case audioMasterPinConnected:
115 SHOW_CALLBACK ("amc: audioMasterPinConnected\n");
116 // inquire if an input or output is beeing connected;
117 // index enumerates input or output counting from zero:
118 // value is 0 for input and != 0 otherwise. note: the
119 // return value is 0 for <true> such that older versions
120 // will always return true.
123 case audioMasterWantMidi:
124 SHOW_CALLBACK ("amc: audioMasterWantMidi\n");
125 // <value> is a filter which is currently ignored
127 plug->get_info()->n_inputs.set_midi (1);
131 case audioMasterGetTime:
132 SHOW_CALLBACK ("amc: audioMasterGetTime\n");
133 // returns const VstTimeInfo* (or 0 if not supported)
134 // <value> should contain a mask indicating which fields are required
135 // (see valid masks above), as some items may require extensive
140 framepos_t now = session->transport_frame();
142 _timeInfo.samplePos = now;
143 _timeInfo.sampleRate = session->frame_rate();
145 const TempoMetric& tm (session->tempo_map().metric_at (now));
147 if (value & (kVstTempoValid)) {
148 const Tempo& t (tm.tempo());
149 _timeInfo.tempo = t.beats_per_minute ();
150 _timeInfo.flags |= (kVstTempoValid);
152 if (value & (kVstTimeSigValid)) {
153 const Meter& m (tm.meter());
154 _timeInfo.timeSigNumerator = m.divisions_per_bar ();
155 _timeInfo.timeSigDenominator = m.note_divisor ();
156 _timeInfo.flags |= (kVstTimeSigValid);
158 if ((value & (kVstPpqPosValid)) || (value & (kVstBarsValid))) {
159 Timecode::BBT_Time bbt;
162 session->tempo_map().bbt_time_rt (now, bbt);
164 /* PPQ = pulse per quarter
165 * VST's "pulse" is our "division".
167 * 8 divisions per bar, 1 division = quarter, so 8 quarters per bar, ppq = 1
168 * 8 divisions per bar, 1 division = eighth, so 4 quarters per bar, ppq = 2
169 * 4 divisions per bar, 1 division = quarter, so 4 quarters per bar, ppq = 1
170 * 4 divisions per bar, 1 division = half, so 8 quarters per bar, ppq = 0.5
171 * 4 divisions per bar, 1 division = fifth, so (4 * 5/4) quarters per bar, ppq = 5/4
173 * general: divs_per_bar / (note_type / 4.0)
175 double ppq_scaling = tm.meter().note_divisor() / 4.0;
177 /* Note that this assumes constant meter/tempo throughout the session. Stupid VST */
178 double ppqBar = double(bbt.bars - 1) * tm.meter().divisions_per_bar();
179 double ppqBeat = double(bbt.beats - 1);
180 double ppqTick = double(bbt.ticks) / Timecode::BBT_Time::ticks_per_beat;
182 ppqBar *= ppq_scaling;
183 ppqBeat *= ppq_scaling;
184 ppqTick *= ppq_scaling;
186 if (value & (kVstPpqPosValid)) {
187 _timeInfo.ppqPos = ppqBar + ppqBeat + ppqTick;
188 _timeInfo.flags |= (kVstPpqPosValid);
191 if (value & (kVstBarsValid)) {
192 _timeInfo.barStartPos = ppqBar;
193 _timeInfo.flags |= (kVstBarsValid);
201 if (value & (kVstSmpteValid)) {
204 session->timecode_time (now, t);
206 _timeInfo.smpteOffset = (t.hours * t.rate * 60.0 * 60.0) +
207 (t.minutes * t.rate * 60.0) +
208 (t.seconds * t.rate) +
212 _timeInfo.smpteOffset *= 80.0; /* VST spec is 1/80th frames */
214 if (session->timecode_drop_frames()) {
215 if (session->timecode_frames_per_second() == 30.0) {
216 _timeInfo.smpteFrameRate = 5;
218 _timeInfo.smpteFrameRate = 4; /* 29.97 assumed, thanks VST */
221 if (session->timecode_frames_per_second() == 24.0) {
222 _timeInfo.smpteFrameRate = 0;
223 } else if (session->timecode_frames_per_second() == 24.975) {
224 _timeInfo.smpteFrameRate = 2;
225 } else if (session->timecode_frames_per_second() == 25.0) {
226 _timeInfo.smpteFrameRate = 1;
228 _timeInfo.smpteFrameRate = 3; /* 30 fps */
231 _timeInfo.flags |= (kVstSmpteValid);
234 if (session->transport_speed() != 0.0f) {
235 _timeInfo.flags |= (kVstTransportPlaying);
238 if (session->get_play_loop()) {
242 _timeInfo.samplePos = 0;
243 _timeInfo.sampleRate = AudioEngine::instance()->sample_rate();
246 return (intptr_t) &_timeInfo;
248 case audioMasterProcessEvents:
249 SHOW_CALLBACK ("amc: audioMasterProcessEvents\n");
250 // VstEvents* in <ptr>
253 case audioMasterSetTime:
254 SHOW_CALLBACK ("amc: audioMasterSetTime\n");
255 // VstTimenfo* in <ptr>, filter in <value>, not supported
257 case audioMasterTempoAt:
258 SHOW_CALLBACK ("amc: audioMasterTempoAt\n");
259 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
261 const Tempo& t (session->tempo_map().tempo_at (value));
262 return t.beats_per_minute() * 1000;
268 case audioMasterGetNumAutomatableParameters:
269 SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n");
272 case audioMasterGetParameterQuantization:
273 SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n");
274 // returns the integer value for +1.0 representation,
275 // or 1 if full single float precision is maintained
276 // in automation. parameter index in <value> (-1: all, any)
279 case audioMasterIOChanged:
280 SHOW_CALLBACK ("amc: audioMasterIOChanged\n");
281 // numInputs and/or numOutputs has changed
284 case audioMasterNeedIdle:
285 SHOW_CALLBACK ("amc: audioMasterNeedIdle\n");
286 // plug needs idle calls (outside its editor window)
288 plug->state()->wantIdle = 1;
292 case audioMasterSizeWindow:
293 SHOW_CALLBACK ("amc: audioMasterSizeWindow\n");
294 // index: width, value: height
297 case audioMasterGetSampleRate:
298 SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n");
300 return session->frame_rate();
304 case audioMasterGetBlockSize:
305 SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n");
307 return session->get_block_size();
311 case audioMasterGetInputLatency:
312 SHOW_CALLBACK ("amc: audioMasterGetInputLatency\n");
315 case audioMasterGetOutputLatency:
316 SHOW_CALLBACK ("amc: audioMasterGetOutputLatency\n");
319 case audioMasterGetPreviousPlug:
320 SHOW_CALLBACK ("amc: audioMasterGetPreviousPlug\n");
321 // input pin in <value> (-1: first to come), returns cEffect*
324 case audioMasterGetNextPlug:
325 SHOW_CALLBACK ("amc: audioMasterGetNextPlug\n");
326 // output pin in <value> (-1: first to come), returns cEffect*
328 case audioMasterWillReplaceOrAccumulate:
329 SHOW_CALLBACK ("amc: audioMasterWillReplaceOrAccumulate\n");
330 // returns: 0: not supported, 1: replace, 2: accumulate
333 case audioMasterGetCurrentProcessLevel:
334 SHOW_CALLBACK ("amc: audioMasterGetCurrentProcessLevel\n");
335 // returns: 0: not supported,
336 // 1: currently in user thread (gui)
337 // 2: currently in audio thread (where process is called)
338 // 3: currently in 'sequencer' thread (midi, timer etc)
339 // 4: currently offline processing and thus in user thread
340 // other: not defined, but probably pre-empting user thread.
343 case audioMasterGetAutomationState:
344 SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n");
345 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
349 case audioMasterOfflineStart:
350 SHOW_CALLBACK ("amc: audioMasterOfflineStart\n");
353 case audioMasterOfflineRead:
354 SHOW_CALLBACK ("amc: audioMasterOfflineRead\n");
355 // ptr points to offline structure, see below. return 0: error, 1 ok
358 case audioMasterOfflineWrite:
359 SHOW_CALLBACK ("amc: audioMasterOfflineWrite\n");
363 case audioMasterOfflineGetCurrentPass:
364 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentPass\n");
367 case audioMasterOfflineGetCurrentMetaPass:
368 SHOW_CALLBACK ("amc: audioMasterOfflineGetCurrentMetaPass\n");
371 case audioMasterSetOutputSampleRate:
372 SHOW_CALLBACK ("amc: audioMasterSetOutputSampleRate\n");
373 // for variable i/o, sample rate in <opt>
376 case audioMasterGetSpeakerArrangement:
377 SHOW_CALLBACK ("amc: audioMasterGetSpeakerArrangement\n");
378 // (long)input in <value>, output in <ptr>
381 case audioMasterGetVendorString:
382 SHOW_CALLBACK ("amc: audioMasterGetVendorString\n");
383 // fills <ptr> with a string identifying the vendor (max 64 char)
384 strcpy ((char*) ptr, "Linux Audio Systems");
387 case audioMasterGetProductString:
388 SHOW_CALLBACK ("amc: audioMasterGetProductString\n");
389 // fills <ptr> with a string with product name (max 64 char)
390 strcpy ((char*) ptr, PROGRAM_NAME);
393 case audioMasterGetVendorVersion:
394 SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n");
395 // returns vendor-specific version
398 case audioMasterVendorSpecific:
399 SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n");
400 // no definition, vendor specific handling
403 case audioMasterSetIcon:
404 SHOW_CALLBACK ("amc: audioMasterSetIcon\n");
405 // void* in <ptr>, format not defined yet
408 case audioMasterCanDo:
409 SHOW_CALLBACK ("amc: audioMasterCanDo\n");
410 // string in ptr, (const char*)ptr
413 case audioMasterGetLanguage:
414 SHOW_CALLBACK ("amc: audioMasterGetLanguage\n");
418 case audioMasterOpenWindow:
419 SHOW_CALLBACK ("amc: audioMasterOpenWindow\n");
420 // returns platform specific ptr
423 case audioMasterCloseWindow:
424 SHOW_CALLBACK ("amc: audioMasterCloseWindow\n");
425 // close window, platform specific handle in <ptr>
428 case audioMasterGetDirectory:
429 SHOW_CALLBACK ("amc: audioMasterGetDirectory\n");
430 // get plug directory, FSSpec on MAC, else char*
433 case audioMasterUpdateDisplay:
434 SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n");
435 // something has changed, update 'multi-fx' display
437 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
441 case audioMasterBeginEdit:
442 SHOW_CALLBACK ("amc: audioMasterBeginEdit\n");
443 // begin of automation session (when mouse down), parameter index in <index>
446 case audioMasterEndEdit:
447 SHOW_CALLBACK ("amc: audioMasterEndEdit\n");
448 // end of automation session (when mouse up), parameter index in <index>
451 case audioMasterOpenFileSelector:
452 SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n");
453 // open a fileselector window with VstFileSelect* in <ptr>
457 SHOW_CALLBACK ("VST master dispatcher: undefed: %d\n", opcode);