X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsession_vst.cc;h=7f13d3e18bfebf47fd74d08b25a82caeee9b68a5;hb=50131b3751e6ed5c9ed7450406049b2195ea9ecf;hp=16233feba23f3a528dc79caaaf09cc2112039b82;hpb=45d3ec1437cf661533bc7750c623865def4424df;p=ardour.git diff --git a/libs/ardour/session_vst.cc b/libs/ardour/session_vst.cc index 16233feba2..7f13d3e18b 100644 --- a/libs/ardour/session_vst.cc +++ b/libs/ardour/session_vst.cc @@ -21,17 +21,19 @@ #include #include -#include +#include -#include -#include +#include "ardour/session.h" +#include "ardour/tempo.h" +#include "ardour/vst_plugin.h" #include "i18n.h" -// #define DEBUG_CALLBACKS +#define DEBUG_CALLBACKS +static int debug_callbacks = -1; #ifdef DEBUG_CALLBACKS -#define SHOW_CALLBACK printf +#define SHOW_CALLBACK if (debug_callbacks) printf #else #define SHOW_CALLBACK(...) #endif @@ -49,14 +51,18 @@ long Session::vst_callback (AEffect* effect, VSTPlugin* plug; Session* session; - SHOW_CALLBACK ("am callback, opcode = %d", opcode); - + if (debug_callbacks < 0) { + debug_callbacks = (getenv ("ARDOUR_DEBUG_VST_CALLBACKS") != 0); + } + if (effect && effect->user) { - plug = static_cast (effect->user); + plug = (VSTPlugin*) (effect->user); session = &plug->session(); + SHOW_CALLBACK ("am callback 0x%x, opcode = %ld, plugin = \"%s\" ", pthread_self(), opcode, plug->name()); } else { plug = 0; session = 0; + SHOW_CALLBACK ("am callback 0x%x, opcode = %ld", pthread_self(), opcode); } switch(opcode){ @@ -74,22 +80,22 @@ long Session::vst_callback (AEffect* effect, // vst version, currently 2 (0 for older) return 2; - case audioMasterCurrentId: + case audioMasterCurrentId: SHOW_CALLBACK ("amc: audioMasterCurrentId\n"); // returns the unique id of a plug that's currently // loading return 0; - + case audioMasterIdle: SHOW_CALLBACK ("amc: audioMasterIdle\n"); // call application idle routine (this will - // call effEditIdle for all open editors too) + // call effEditIdle for all open editors too) if (effect) { effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f); } return 0; - case audioMasterPinConnected: + case audioMasterPinConnected: SHOW_CALLBACK ("amc: audioMasterPinConnected\n"); // inquire if an input or output is beeing connected; // index enumerates input or output counting from zero: @@ -113,7 +119,25 @@ long Session::vst_callback (AEffect* effect, if (session) { _timeInfo.samplePos = session->transport_frame(); _timeInfo.sampleRate = session->frame_rate(); + _timeInfo.flags = 0; + + if (value & (kVstTempoValid)) { + const Tempo& t (session->tempo_map().tempo_at (session->transport_frame())); + _timeInfo.tempo = t.beats_per_minute (); + _timeInfo.flags |= (kVstTempoValid); + } + if (value & (kVstBarsValid)) { + const Meter& m (session->tempo_map().meter_at (session->transport_frame())); + _timeInfo.timeSigNumerator = m.beats_per_bar (); + _timeInfo.timeSigDenominator = m.note_divisor (); + _timeInfo.flags |= (kVstBarsValid); + } + + if (session->transport_speed() != 0.0f) { + _timeInfo.flags |= kVstTransportPlaying; + } } + return (long)&_timeInfo; case audioMasterProcessEvents: @@ -128,13 +152,19 @@ long Session::vst_callback (AEffect* effect, case audioMasterTempoAt: SHOW_CALLBACK ("amc: audioMasterTempoAt\n"); // returns tempo (in bpm * 10000) at sample frame location passed in - return 0; + if (session) { + const Tempo& t (session->tempo_map().tempo_at (value)); + return t.beats_per_minute() * 1000; + } else { + return 0; + } + break; case audioMasterGetNumAutomatableParameters: SHOW_CALLBACK ("amc: audioMasterGetNumAutomatableParameters\n"); return 0; - case audioMasterGetParameterQuantization: + case audioMasterGetParameterQuantization: SHOW_CALLBACK ("amc: audioMasterGetParameterQuantization\n"); // returns the integer value for +1.0 representation, // or 1 if full single float precision is maintained @@ -148,7 +178,10 @@ long Session::vst_callback (AEffect* effect, case audioMasterNeedIdle: SHOW_CALLBACK ("amc: audioMasterNeedIdle\n"); - // plug needs idle calls (outside its editor window) + // plug needs idle calls (outside its editor window) + if (plug) { + plug->fst()->wantIdle = 1; + } return 0; case audioMasterSizeWindow: @@ -158,10 +191,16 @@ long Session::vst_callback (AEffect* effect, case audioMasterGetSampleRate: SHOW_CALLBACK ("amc: audioMasterGetSampleRate\n"); + if (session) { + return session->frame_rate(); + } return 0; case audioMasterGetBlockSize: SHOW_CALLBACK ("amc: audioMasterGetBlockSize\n"); + if (session) { + return session->get_block_size(); + } return 0; case audioMasterGetInputLatency: @@ -195,7 +234,7 @@ long Session::vst_callback (AEffect* effect, // 4: currently offline processing and thus in user thread // other: not defined, but probably pre-empting user thread. return 0; - + case audioMasterGetAutomationState: SHOW_CALLBACK ("amc: audioMasterGetAutomationState\n"); // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write @@ -246,42 +285,42 @@ long Session::vst_callback (AEffect* effect, SHOW_CALLBACK ("amc: audioMasterGetVendorVersion\n"); // returns vendor-specific version return 900; - + case audioMasterVendorSpecific: SHOW_CALLBACK ("amc: audioMasterVendorSpecific\n"); // no definition, vendor specific handling return 0; - + case audioMasterSetIcon: SHOW_CALLBACK ("amc: audioMasterSetIcon\n"); // void* in , format not defined yet return 0; - + case audioMasterCanDo: SHOW_CALLBACK ("amc: audioMasterCanDo\n"); // string in ptr, see below return 0; - + case audioMasterGetLanguage: SHOW_CALLBACK ("amc: audioMasterGetLanguage\n"); // see enum return 0; - + case audioMasterOpenWindow: SHOW_CALLBACK ("amc: audioMasterOpenWindow\n"); // returns platform specific ptr return 0; - + case audioMasterCloseWindow: SHOW_CALLBACK ("amc: audioMasterCloseWindow\n"); // close window, platform specific handle in return 0; - + case audioMasterGetDirectory: SHOW_CALLBACK ("amc: audioMasterGetDirectory\n"); // get plug directory, FSSpec on MAC, else char* return 0; - + case audioMasterUpdateDisplay: SHOW_CALLBACK ("amc: audioMasterUpdateDisplay\n"); // something has changed, update 'multi-fx' display @@ -289,27 +328,27 @@ long Session::vst_callback (AEffect* effect, effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f); } return 0; - + case audioMasterBeginEdit: SHOW_CALLBACK ("amc: audioMasterBeginEdit\n"); // begin of automation session (when mouse down), parameter index in return 0; - + case audioMasterEndEdit: SHOW_CALLBACK ("amc: audioMasterEndEdit\n"); // end of automation session (when mouse up), parameter index in return 0; - + case audioMasterOpenFileSelector: SHOW_CALLBACK ("amc: audioMasterOpenFileSelector\n"); // open a fileselector window with VstFileSelect* in return 0; - + default: - SHOW_CALLBACK ("VST master dispatcher: undefed: %d, %d\n", opcode, effKeysRequired); + SHOW_CALLBACK ("VST master dispatcher: undefed: %d\n", opcode); break; - } - + } + return 0; }