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/debug.h"
27 #include "ardour/session.h"
28 #include "ardour/tempo.h"
29 #include "ardour/windows_vst_plugin.h"
30 #include "ardour/vestige/aeffectx.h"
31 #include "ardour/vst_types.h"
32 #ifdef WINDOWS_VST_SUPPORT
38 using namespace ARDOUR;
40 #define SHOW_CALLBACK(MSG) DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose (MSG " val = %1 idx = %2", index, value))
42 int Session::vst_current_loading_id = 0;
43 const char* Session::vst_can_do_strings[] = {
45 X_("sendVstTimeInfo"),
47 X_("sendVstMidiEvent"),
48 X_("receiveVstEvents"),
49 X_("receiveVstMidiEvent"),
52 X_("shellCategorycurID")
54 const int Session::vst_can_do_string_count = sizeof (vst_can_do_strings) / sizeof (char*);
56 intptr_t Session::vst_callback (
65 static VstTimeInfo _timeInfo;
69 if (effect && effect->user) {
70 plug = (VSTPlugin *) (effect->user);
71 session = &plug->session();
72 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("am callback 0x%1%2, opcode = %3%4, plugin = \"%5\" ",
73 std::hex, (void*) DEBUG_THREAD_SELF,
74 std::dec, opcode, plug->name()));
78 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("am callback 0x%1%2, opcode = %3%4",
79 std::hex, (void*) DEBUG_THREAD_SELF,
85 case audioMasterAutomate:
86 SHOW_CALLBACK ("audioMasterAutomate");
87 // index, value, returns 0
89 plug->parameter_changed_externally (index, opt);
93 case audioMasterVersion:
94 SHOW_CALLBACK ("audioMasterVersion");
95 // vst version, currently 2 (0 for older)
98 case audioMasterCurrentId:
99 SHOW_CALLBACK ("audioMasterCurrentId");
100 // returns the unique id of a plug that's currently loading
101 return vst_current_loading_id;
103 case audioMasterIdle:
104 SHOW_CALLBACK ("audioMasterIdle");
105 #ifdef WINDOWS_VST_SUPPORT
106 fst_audio_master_idle();
109 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
113 case audioMasterPinConnected:
114 SHOW_CALLBACK ("audioMasterPinConnected");
115 // inquire if an input or output is beeing connected;
116 // index enumerates input or output counting from zero:
117 // value is 0 for input and != 0 otherwise. note: the
118 // return value is 0 for <true> such that older versions
119 // will always return true.
122 // but ardour always connects all buffers, so we're good
127 if (index < plug->plugin()->numInputs) {
132 if (index < plug->plugin()->numOutputs) {
141 case audioMasterWantMidi:
142 SHOW_CALLBACK ("audioMasterWantMidi");
143 // <value> is a filter which is currently ignored
144 if (plug && plug->get_info() != NULL) {
145 plug->get_info()->n_inputs.set_midi (1);
149 case audioMasterGetTime:
150 SHOW_CALLBACK ("audioMasterGetTime");
151 // returns const VstTimeInfo* (or 0 if not supported)
152 // <value> should contain a mask indicating which fields are required
153 // (see valid masks above), as some items may require extensive
158 framepos_t now = session->transport_frame();
160 _timeInfo.samplePos = now;
161 _timeInfo.sampleRate = session->frame_rate();
163 const TempoMetric& tm (session->tempo_map().metric_at (now));
165 if (value & (kVstTempoValid)) {
166 const Tempo& t (tm.tempo());
167 _timeInfo.tempo = t.beats_per_minute ();
168 _timeInfo.flags |= (kVstTempoValid);
170 if (value & (kVstTimeSigValid)) {
171 const Meter& m (tm.meter());
172 _timeInfo.timeSigNumerator = m.divisions_per_bar ();
173 _timeInfo.timeSigDenominator = m.note_divisor ();
174 _timeInfo.flags |= (kVstTimeSigValid);
176 if ((value & (kVstPpqPosValid)) || (value & (kVstBarsValid))) {
177 Timecode::BBT_Time bbt;
180 session->tempo_map().bbt_time_rt (now, bbt);
182 /* PPQ = pulse per quarter
183 * VST's "pulse" is our "division".
185 * 8 divisions per bar, 1 division = quarter, so 8 quarters per bar, ppq = 1
186 * 8 divisions per bar, 1 division = eighth, so 4 quarters per bar, ppq = 2
187 * 4 divisions per bar, 1 division = quarter, so 4 quarters per bar, ppq = 1
188 * 4 divisions per bar, 1 division = half, so 8 quarters per bar, ppq = 0.5
189 * 4 divisions per bar, 1 division = fifth, so (4 * 5/4) quarters per bar, ppq = 5/4
191 * general: divs_per_bar / (note_type / 4.0)
193 double ppq_scaling = tm.meter().note_divisor() / 4.0;
195 /* Note that this assumes constant meter/tempo throughout the session. Stupid VST */
196 double ppqBar = double(bbt.bars - 1) * tm.meter().divisions_per_bar();
197 double ppqBeat = double(bbt.beats - 1);
198 double ppqTick = double(bbt.ticks) / Timecode::BBT_Time::ticks_per_beat;
200 ppqBar *= ppq_scaling;
201 ppqBeat *= ppq_scaling;
202 ppqTick *= ppq_scaling;
204 if (value & (kVstPpqPosValid)) {
205 _timeInfo.ppqPos = ppqBar + ppqBeat + ppqTick;
206 _timeInfo.flags |= (kVstPpqPosValid);
209 if (value & (kVstBarsValid)) {
210 _timeInfo.barStartPos = ppqBar;
211 _timeInfo.flags |= (kVstBarsValid);
219 if (value & (kVstSmpteValid)) {
222 session->timecode_time (now, t);
224 _timeInfo.smpteOffset = (t.hours * t.rate * 60.0 * 60.0) +
225 (t.minutes * t.rate * 60.0) +
226 (t.seconds * t.rate) +
230 _timeInfo.smpteOffset *= 80.0; /* VST spec is 1/80th frames */
232 if (session->timecode_drop_frames()) {
233 if (session->timecode_frames_per_second() == 30.0) {
234 _timeInfo.smpteFrameRate = 5;
236 _timeInfo.smpteFrameRate = 4; /* 29.97 assumed, thanks VST */
239 if (session->timecode_frames_per_second() == 24.0) {
240 _timeInfo.smpteFrameRate = 0;
241 } else if (session->timecode_frames_per_second() == 24.975) {
242 _timeInfo.smpteFrameRate = 2;
243 } else if (session->timecode_frames_per_second() == 25.0) {
244 _timeInfo.smpteFrameRate = 1;
246 _timeInfo.smpteFrameRate = 3; /* 30 fps */
249 _timeInfo.flags |= (kVstSmpteValid);
253 //if this is found to be burdensome to plugins,
254 //we should cache the previous state at a global level,
255 //and only set this flag when the transport changes state
256 _timeInfo.flags |= (kVstTransportChanged);
258 if (session->transport_speed() != 0.0f) {
259 _timeInfo.flags |= (kVstTransportPlaying);
262 if (session->get_play_loop()) {
263 _timeInfo.flags |= (kVstTransportCycleActive);
267 _timeInfo.samplePos = 0;
268 _timeInfo.sampleRate = AudioEngine::instance()->sample_rate();
271 return (intptr_t) &_timeInfo;
273 case audioMasterProcessEvents:
274 SHOW_CALLBACK ("audioMasterProcessEvents");
275 // VstEvents* in <ptr>
276 if (plug && plug->midi_buffer()) {
277 VstEvents* v = (VstEvents*)ptr;
278 for (int n = 0 ; n < v->numEvents; ++n) {
279 VstMidiEvent *vme = (VstMidiEvent*) (v->events[n]->dump);
280 if (vme->type == kVstMidiType) {
281 plug->midi_buffer()->push_back(vme->deltaFrames, 3, (uint8_t*)vme->midiData);
287 case audioMasterSetTime:
288 SHOW_CALLBACK ("audioMasterSetTime");
289 // VstTimenfo* in <ptr>, filter in <value>, not supported
291 case audioMasterTempoAt:
292 SHOW_CALLBACK ("audioMasterTempoAt");
293 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
295 const Tempo& t (session->tempo_map().tempo_at (value));
296 return t.beats_per_minute() * 1000;
302 case audioMasterGetNumAutomatableParameters:
303 SHOW_CALLBACK ("audioMasterGetNumAutomatableParameters");
306 case audioMasterGetParameterQuantization:
307 SHOW_CALLBACK ("audioMasterGetParameterQuantization");
308 // returns the integer value for +1.0 representation,
309 // or 1 if full single float precision is maintained
310 // in automation. parameter index in <value> (-1: all, any)
313 case audioMasterIOChanged:
314 SHOW_CALLBACK ("audioMasterIOChanged");
315 // numInputs and/or numOutputs has changed
318 case audioMasterNeedIdle:
319 SHOW_CALLBACK ("audioMasterNeedIdle");
320 // plug needs idle calls (outside its editor window)
322 plug->state()->wantIdle = 1;
326 case audioMasterSizeWindow:
327 SHOW_CALLBACK ("audioMasterSizeWindow");
328 if (plug && plug->state()) {
329 plug->state()->width = index;
330 plug->state()->height = value;
331 plug->state()->want_resize = 1;
335 case audioMasterGetSampleRate:
336 SHOW_CALLBACK ("audioMasterGetSampleRate");
338 return session->frame_rate();
342 case audioMasterGetBlockSize:
343 SHOW_CALLBACK ("audioMasterGetBlockSize");
345 return session->get_block_size();
349 case audioMasterGetInputLatency:
350 SHOW_CALLBACK ("audioMasterGetInputLatency");
353 case audioMasterGetOutputLatency:
354 SHOW_CALLBACK ("audioMasterGetOutputLatency");
357 case audioMasterGetPreviousPlug:
358 SHOW_CALLBACK ("audioMasterGetPreviousPlug");
359 // input pin in <value> (-1: first to come), returns cEffect*
362 case audioMasterGetNextPlug:
363 SHOW_CALLBACK ("audioMasterGetNextPlug");
364 // output pin in <value> (-1: first to come), returns cEffect*
366 case audioMasterWillReplaceOrAccumulate:
367 SHOW_CALLBACK ("audioMasterWillReplaceOrAccumulate");
368 // returns: 0: not supported, 1: replace, 2: accumulate
371 case audioMasterGetCurrentProcessLevel:
372 SHOW_CALLBACK ("audioMasterGetCurrentProcessLevel");
373 // returns: 0: not supported,
374 // 1: currently in user thread (gui)
375 // 2: currently in audio thread (where process is called)
376 // 3: currently in 'sequencer' thread (midi, timer etc)
377 // 4: currently offline processing and thus in user thread
378 // other: not defined, but probably pre-empting user thread.
381 case audioMasterGetAutomationState:
382 SHOW_CALLBACK ("audioMasterGetAutomationState");
383 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
387 case audioMasterOfflineStart:
388 SHOW_CALLBACK ("audioMasterOfflineStart");
391 case audioMasterOfflineRead:
392 SHOW_CALLBACK ("audioMasterOfflineRead");
393 // ptr points to offline structure, see below. return 0: error, 1 ok
396 case audioMasterOfflineWrite:
397 SHOW_CALLBACK ("audioMasterOfflineWrite");
401 case audioMasterOfflineGetCurrentPass:
402 SHOW_CALLBACK ("audioMasterOfflineGetCurrentPass");
405 case audioMasterOfflineGetCurrentMetaPass:
406 SHOW_CALLBACK ("audioMasterOfflineGetCurrentMetaPass");
409 case audioMasterSetOutputSampleRate:
410 SHOW_CALLBACK ("audioMasterSetOutputSampleRate");
411 // for variable i/o, sample rate in <opt>
414 case audioMasterGetSpeakerArrangement:
415 SHOW_CALLBACK ("audioMasterGetSpeakerArrangement");
416 // (long)input in <value>, output in <ptr>
419 case audioMasterGetVendorString:
420 SHOW_CALLBACK ("audioMasterGetVendorString");
421 // fills <ptr> with a string identifying the vendor (max 64 char)
422 strcpy ((char*) ptr, "Linux Audio Systems");
425 case audioMasterGetProductString:
426 SHOW_CALLBACK ("audioMasterGetProductString");
427 // fills <ptr> with a string with product name (max 64 char)
428 strcpy ((char*) ptr, PROGRAM_NAME);
431 case audioMasterGetVendorVersion:
432 SHOW_CALLBACK ("audioMasterGetVendorVersion");
433 // returns vendor-specific version
436 case audioMasterVendorSpecific:
437 SHOW_CALLBACK ("audioMasterVendorSpecific");
438 // no definition, vendor specific handling
441 case audioMasterSetIcon:
442 SHOW_CALLBACK ("audioMasterSetIcon");
443 // void* in <ptr>, format not defined yet
446 case audioMasterCanDo:
447 SHOW_CALLBACK ("audioMasterCanDo");
448 // string in ptr, (const char*)ptr
449 for (int i = 0; i < vst_can_do_string_count; i++) {
450 if (! strcmp(vst_can_do_strings[i], (const char*)ptr)) {
456 case audioMasterGetLanguage:
457 SHOW_CALLBACK ("audioMasterGetLanguage");
461 case audioMasterOpenWindow:
462 SHOW_CALLBACK ("audioMasterOpenWindow");
463 // returns platform specific ptr
466 case audioMasterCloseWindow:
467 SHOW_CALLBACK ("audioMasterCloseWindow");
468 // close window, platform specific handle in <ptr>
471 case audioMasterGetDirectory:
472 SHOW_CALLBACK ("audioMasterGetDirectory");
473 // get plug directory, FSSpec on MAC, else char*
476 case audioMasterUpdateDisplay:
477 SHOW_CALLBACK ("audioMasterUpdateDisplay");
478 // something has changed, update 'multi-fx' display
480 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
484 case audioMasterBeginEdit:
485 SHOW_CALLBACK ("audioMasterBeginEdit");
486 // begin of automation session (when mouse down), parameter index in <index>
489 case audioMasterEndEdit:
490 SHOW_CALLBACK ("audioMasterEndEdit");
491 // end of automation session (when mouse up), parameter index in <index>
494 case audioMasterOpenFileSelector:
495 SHOW_CALLBACK ("audioMasterOpenFileSelector");
496 // open a fileselector window with VstFileSelect* in <ptr>
500 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("VST master dispatcher: undefed: %1\n", opcode));