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/plugin_insert.h"
30 #include "ardour/windows_vst_plugin.h"
31 #include "ardour/vestige/aeffectx.h"
32 #include "ardour/vst_types.h"
33 #ifdef WINDOWS_VST_SUPPORT
39 using namespace ARDOUR;
41 #define SHOW_CALLBACK(MSG) DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose (MSG " val = %1 idx = %2\n", index, value))
43 int Session::vst_current_loading_id = 0;
44 const char* Session::vst_can_do_strings[] = {
46 X_("sendVstTimeInfo"),
48 X_("sendVstMidiEvent"),
49 X_("receiveVstEvents"),
50 X_("receiveVstMidiEvent"),
53 X_("shellCategorycurID")
55 const int Session::vst_can_do_string_count = sizeof (vst_can_do_strings) / sizeof (char*);
57 intptr_t Session::vst_callback (
66 static VstTimeInfo _timeInfo;
70 if (effect && effect->user) {
71 plug = (VSTPlugin *) (effect->user);
72 session = &plug->session();
73 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("am callback 0x%1%2, opcode = %3%4, plugin = \"%5\" ",
74 std::hex, (void*) DEBUG_THREAD_SELF,
75 std::dec, opcode, plug->name()));
79 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("am callback 0x%1%2, opcode = %3%4",
80 std::hex, (void*) DEBUG_THREAD_SELF,
86 case audioMasterAutomate:
87 SHOW_CALLBACK ("audioMasterAutomate");
88 // index, value, returns 0
90 plug->parameter_changed_externally (index, opt);
94 case audioMasterVersion:
95 SHOW_CALLBACK ("audioMasterVersion");
96 // vst version, currently 2 (0 for older)
99 case audioMasterCurrentId:
100 SHOW_CALLBACK ("audioMasterCurrentId");
101 // returns the unique id of a plug that's currently loading
102 return vst_current_loading_id;
104 case audioMasterIdle:
105 SHOW_CALLBACK ("audioMasterIdle");
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 ("audioMasterPinConnected");
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 // but ardour always connects all buffers, so we're good
128 if (plug->plugin_insert ()) {
130 const ChanMapping& map (plug->plugin_insert ()->input_map (plug->plugin_number ()));
131 map.get (DataType::AUDIO, index, &valid);
132 return valid ? 0 : 1;
134 if (index < plug->plugin()->numInputs) {
139 #if 0 // investigate, the outputs *are* connected to scratch buffers
140 if (plug->plugin_insert ()) {
142 const ChanMapping& map (plug->plugin_insert ()->output_map (plug->plugin_number ()));
143 map.get (DataType::AUDIO, index, &valid);
144 return valid ? 0 : 1;
147 if (index < plug->plugin()->numOutputs) {
156 case audioMasterWantMidi:
157 SHOW_CALLBACK ("audioMasterWantMidi");
158 // <value> is a filter which is currently ignored
159 if (plug && plug->get_info() != NULL) {
160 plug->get_info()->n_inputs.set_midi (1);
164 case audioMasterGetTime:
165 SHOW_CALLBACK ("audioMasterGetTime");
166 // returns const VstTimeInfo* (or 0 if not supported)
167 // <value> should contain a mask indicating which fields are required
168 // (see valid masks above), as some items may require extensive
173 framepos_t now = session->transport_frame();
175 _timeInfo.samplePos = now;
176 _timeInfo.sampleRate = session->frame_rate();
178 const TempoMetric& tm (session->tempo_map().metric_at (now));
180 if (value & (kVstTempoValid)) {
181 const Tempo& t (tm.tempo());
182 _timeInfo.tempo = t.beats_per_minute ();
183 _timeInfo.flags |= (kVstTempoValid);
185 if (value & (kVstTimeSigValid)) {
186 const Meter& m (tm.meter());
187 _timeInfo.timeSigNumerator = m.divisions_per_bar ();
188 _timeInfo.timeSigDenominator = m.note_divisor ();
189 _timeInfo.flags |= (kVstTimeSigValid);
191 if ((value & (kVstPpqPosValid)) || (value & (kVstBarsValid))) {
192 Timecode::BBT_Time bbt;
195 session->tempo_map().bbt_time_rt (now, bbt);
197 /* PPQ = pulse per quarter
198 * VST's "pulse" is our "division".
200 * 8 divisions per bar, 1 division = quarter, so 8 quarters per bar, ppq = 1
201 * 8 divisions per bar, 1 division = eighth, so 4 quarters per bar, ppq = 2
202 * 4 divisions per bar, 1 division = quarter, so 4 quarters per bar, ppq = 1
203 * 4 divisions per bar, 1 division = half, so 8 quarters per bar, ppq = 0.5
204 * 4 divisions per bar, 1 division = fifth, so (4 * 5/4) quarters per bar, ppq = 5/4
206 * general: divs_per_bar / (note_type / 4.0)
208 double ppq_scaling = tm.meter().note_divisor() / 4.0;
210 /* Note that this assumes constant meter/tempo throughout the session. Stupid VST */
211 double ppqBar = double(bbt.bars - 1) * tm.meter().divisions_per_bar();
212 double ppqBeat = double(bbt.beats - 1);
213 double ppqTick = double(bbt.ticks) / Timecode::BBT_Time::ticks_per_beat;
215 ppqBar *= ppq_scaling;
216 ppqBeat *= ppq_scaling;
217 ppqTick *= ppq_scaling;
219 if (value & (kVstPpqPosValid)) {
220 _timeInfo.ppqPos = ppqBar + ppqBeat + ppqTick;
221 _timeInfo.flags |= (kVstPpqPosValid);
224 if (value & (kVstBarsValid)) {
225 _timeInfo.barStartPos = ppqBar;
226 _timeInfo.flags |= (kVstBarsValid);
234 if (value & (kVstSmpteValid)) {
237 session->timecode_time (now, t);
239 _timeInfo.smpteOffset = (t.hours * t.rate * 60.0 * 60.0) +
240 (t.minutes * t.rate * 60.0) +
241 (t.seconds * t.rate) +
245 _timeInfo.smpteOffset *= 80.0; /* VST spec is 1/80th frames */
247 if (session->timecode_drop_frames()) {
248 if (session->timecode_frames_per_second() == 30.0) {
249 _timeInfo.smpteFrameRate = 5;
251 _timeInfo.smpteFrameRate = 4; /* 29.97 assumed, thanks VST */
254 if (session->timecode_frames_per_second() == 24.0) {
255 _timeInfo.smpteFrameRate = 0;
256 } else if (session->timecode_frames_per_second() == 24.975) {
257 _timeInfo.smpteFrameRate = 2;
258 } else if (session->timecode_frames_per_second() == 25.0) {
259 _timeInfo.smpteFrameRate = 1;
261 _timeInfo.smpteFrameRate = 3; /* 30 fps */
264 _timeInfo.flags |= (kVstSmpteValid);
268 //if this is found to be burdensome to plugins,
269 //we should cache the previous state at a global level,
270 //and only set this flag when the transport changes state
271 _timeInfo.flags |= (kVstTransportChanged);
273 if (session->transport_speed() != 0.0f) {
274 _timeInfo.flags |= (kVstTransportPlaying);
277 if (session->get_play_loop()) {
278 _timeInfo.flags |= (kVstTransportCycleActive);
282 _timeInfo.samplePos = 0;
283 _timeInfo.sampleRate = AudioEngine::instance()->sample_rate();
286 return (intptr_t) &_timeInfo;
288 case audioMasterProcessEvents:
289 SHOW_CALLBACK ("audioMasterProcessEvents");
290 // VstEvents* in <ptr>
291 if (plug && plug->midi_buffer()) {
292 VstEvents* v = (VstEvents*)ptr;
293 for (int n = 0 ; n < v->numEvents; ++n) {
294 VstMidiEvent *vme = (VstMidiEvent*) (v->events[n]->dump);
295 if (vme->type == kVstMidiType) {
296 plug->midi_buffer()->push_back(vme->deltaFrames, 3, (uint8_t*)vme->midiData);
302 case audioMasterSetTime:
303 SHOW_CALLBACK ("audioMasterSetTime");
304 // VstTimenfo* in <ptr>, filter in <value>, not supported
306 case audioMasterTempoAt:
307 SHOW_CALLBACK ("audioMasterTempoAt");
308 // returns tempo (in bpm * 10000) at sample frame location passed in <value>
310 const Tempo& t (session->tempo_map().tempo_at (value));
311 return t.beats_per_minute() * 1000;
317 case audioMasterGetNumAutomatableParameters:
318 SHOW_CALLBACK ("audioMasterGetNumAutomatableParameters");
321 case audioMasterGetParameterQuantization:
322 SHOW_CALLBACK ("audioMasterGetParameterQuantization");
323 // returns the integer value for +1.0 representation,
324 // or 1 if full single float precision is maintained
325 // in automation. parameter index in <value> (-1: all, any)
328 case audioMasterIOChanged:
329 SHOW_CALLBACK ("audioMasterIOChanged");
330 // numInputs and/or numOutputs has changed
333 case audioMasterNeedIdle:
334 SHOW_CALLBACK ("audioMasterNeedIdle");
335 // plug needs idle calls (outside its editor window)
337 plug->state()->wantIdle = 1;
341 case audioMasterSizeWindow:
342 SHOW_CALLBACK ("audioMasterSizeWindow");
343 if (plug && plug->state()) {
344 plug->state()->width = index;
345 plug->state()->height = value;
346 plug->state()->want_resize = 1;
350 case audioMasterGetSampleRate:
351 SHOW_CALLBACK ("audioMasterGetSampleRate");
353 return session->frame_rate();
357 case audioMasterGetBlockSize:
358 SHOW_CALLBACK ("audioMasterGetBlockSize");
360 return session->get_block_size();
364 case audioMasterGetInputLatency:
365 SHOW_CALLBACK ("audioMasterGetInputLatency");
368 case audioMasterGetOutputLatency:
369 SHOW_CALLBACK ("audioMasterGetOutputLatency");
372 case audioMasterGetPreviousPlug:
373 SHOW_CALLBACK ("audioMasterGetPreviousPlug");
374 // input pin in <value> (-1: first to come), returns cEffect*
377 case audioMasterGetNextPlug:
378 SHOW_CALLBACK ("audioMasterGetNextPlug");
379 // output pin in <value> (-1: first to come), returns cEffect*
381 case audioMasterWillReplaceOrAccumulate:
382 SHOW_CALLBACK ("audioMasterWillReplaceOrAccumulate");
383 // returns: 0: not supported, 1: replace, 2: accumulate
386 case audioMasterGetCurrentProcessLevel:
387 SHOW_CALLBACK ("audioMasterGetCurrentProcessLevel");
388 // returns: 0: not supported,
389 // 1: currently in user thread (gui)
390 // 2: currently in audio thread (where process is called)
391 // 3: currently in 'sequencer' thread (midi, timer etc)
392 // 4: currently offline processing and thus in user thread
393 // other: not defined, but probably pre-empting user thread.
396 case audioMasterGetAutomationState:
397 SHOW_CALLBACK ("audioMasterGetAutomationState");
398 // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
402 case audioMasterOfflineStart:
403 SHOW_CALLBACK ("audioMasterOfflineStart");
406 case audioMasterOfflineRead:
407 SHOW_CALLBACK ("audioMasterOfflineRead");
408 // ptr points to offline structure, see below. return 0: error, 1 ok
411 case audioMasterOfflineWrite:
412 SHOW_CALLBACK ("audioMasterOfflineWrite");
416 case audioMasterOfflineGetCurrentPass:
417 SHOW_CALLBACK ("audioMasterOfflineGetCurrentPass");
420 case audioMasterOfflineGetCurrentMetaPass:
421 SHOW_CALLBACK ("audioMasterOfflineGetCurrentMetaPass");
424 case audioMasterSetOutputSampleRate:
425 SHOW_CALLBACK ("audioMasterSetOutputSampleRate");
426 // for variable i/o, sample rate in <opt>
429 case audioMasterGetSpeakerArrangement:
430 SHOW_CALLBACK ("audioMasterGetSpeakerArrangement");
431 // (long)input in <value>, output in <ptr>
434 case audioMasterGetVendorString:
435 SHOW_CALLBACK ("audioMasterGetVendorString");
436 // fills <ptr> with a string identifying the vendor (max 64 char)
437 strcpy ((char*) ptr, "Linux Audio Systems");
440 case audioMasterGetProductString:
441 SHOW_CALLBACK ("audioMasterGetProductString");
442 // fills <ptr> with a string with product name (max 64 char)
443 strcpy ((char*) ptr, PROGRAM_NAME);
446 case audioMasterGetVendorVersion:
447 SHOW_CALLBACK ("audioMasterGetVendorVersion");
448 // returns vendor-specific version
451 case audioMasterVendorSpecific:
452 SHOW_CALLBACK ("audioMasterVendorSpecific");
453 // no definition, vendor specific handling
456 case audioMasterSetIcon:
457 SHOW_CALLBACK ("audioMasterSetIcon");
458 // void* in <ptr>, format not defined yet
461 case audioMasterCanDo:
462 SHOW_CALLBACK ("audioMasterCanDo");
463 // string in ptr, (const char*)ptr
464 for (int i = 0; i < vst_can_do_string_count; i++) {
465 if (! strcmp(vst_can_do_strings[i], (const char*)ptr)) {
471 case audioMasterGetLanguage:
472 SHOW_CALLBACK ("audioMasterGetLanguage");
476 case audioMasterOpenWindow:
477 SHOW_CALLBACK ("audioMasterOpenWindow");
478 // returns platform specific ptr
481 case audioMasterCloseWindow:
482 SHOW_CALLBACK ("audioMasterCloseWindow");
483 // close window, platform specific handle in <ptr>
486 case audioMasterGetDirectory:
487 SHOW_CALLBACK ("audioMasterGetDirectory");
488 // get plug directory, FSSpec on MAC, else char*
491 case audioMasterUpdateDisplay:
492 SHOW_CALLBACK ("audioMasterUpdateDisplay");
493 // something has changed, update 'multi-fx' display
495 effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f);
499 case audioMasterBeginEdit:
500 SHOW_CALLBACK ("audioMasterBeginEdit");
501 // begin of automation session (when mouse down), parameter index in <index>
504 case audioMasterEndEdit:
505 SHOW_CALLBACK ("audioMasterEndEdit");
506 // end of automation session (when mouse up), parameter index in <index>
509 case audioMasterOpenFileSelector:
510 SHOW_CALLBACK ("audioMasterOpenFileSelector");
511 // open a fileselector window with VstFileSelect* in <ptr>
515 DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("VST master dispatcher: undefed: %1\n", opcode));