X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsession_vst.cc;h=b4a584b1831dfa0277b54c03f2abb67c81fae933;hb=5fa05b403ca21a6573d07b921dc14f0769dc9fc7;hp=a9f404fcb21695330e9842ad3a078b26f186b98d;hpb=ccf558f482afbe593f5ffd04456fa9e8bbb47168;p=ardour.git diff --git a/libs/ardour/session_vst.cc b/libs/ardour/session_vst.cc index a9f404fcb2..b4a584b183 100644 --- a/libs/ardour/session_vst.cc +++ b/libs/ardour/session_vst.cc @@ -26,18 +26,19 @@ #include "ardour/debug.h" #include "ardour/session.h" #include "ardour/tempo.h" +#include "ardour/plugin_insert.h" #include "ardour/windows_vst_plugin.h" -#include "ardour/vestige/aeffectx.h" +#include "ardour/vestige/vestige.h" #include "ardour/vst_types.h" #ifdef WINDOWS_VST_SUPPORT #include #endif -#include "i18n.h" +#include "pbd/i18n.h" using namespace ARDOUR; -#define SHOW_CALLBACK(MSG) DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose (MSG " val = %1 idx = %2", index, value)) +#define SHOW_CALLBACK(MSG) DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose (MSG " val = %1 idx = %2\n", index, value)) int Session::vst_current_loading_id = 0; const char* Session::vst_can_do_strings[] = { @@ -49,7 +50,8 @@ const char* Session::vst_can_do_strings[] = { X_("receiveVstMidiEvent"), X_("supportShell"), X_("shellCategory"), - X_("shellCategorycurID") + X_("shellCategorycurID"), + X_("sizeWindow") }; const int Session::vst_can_do_string_count = sizeof (vst_can_do_strings) / sizeof (char*); @@ -62,20 +64,24 @@ intptr_t Session::vst_callback ( float opt ) { - static VstTimeInfo _timeInfo; VSTPlugin* plug; Session* session; + static VstTimeInfo _timeinfo; // only uses as fallback + VstTimeInfo* timeinfo; + int32_t newflags = 0; - if (effect && effect->user) { - plug = (VSTPlugin *) (effect->user); + if (effect && effect->ptr1) { + plug = (VSTPlugin *) (effect->ptr1); session = &plug->session(); - DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("am callback 0x%1%2, opcode = %3%4, plugin = \"%5\" ", + timeinfo = plug->timeinfo (); + DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("am callback 0x%1%2, opcode = %3%4, plugin = \"%5\"\n", std::hex, (void*) DEBUG_THREAD_SELF, std::dec, opcode, plug->name())); } else { plug = 0; session = 0; - DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("am callback 0x%1%2, opcode = %3%4", + timeinfo = &_timeinfo; + DEBUG_TRACE (PBD::DEBUG::VSTCallbacks, string_compose ("am callback 0x%1%2, opcode = %3%4\n", std::hex, (void*) DEBUG_THREAD_SELF, std::dec, opcode)); } @@ -86,7 +92,7 @@ intptr_t Session::vst_callback ( SHOW_CALLBACK ("audioMasterAutomate"); // index, value, returns 0 if (plug) { - plug->set_parameter (index, opt); + plug->parameter_changed_externally (index, opt); } return 0; @@ -124,11 +130,25 @@ intptr_t Session::vst_callback ( } switch (value) { case 0: + if (plug->plugin_insert ()) { + bool valid; + const ChanMapping& map (plug->plugin_insert ()->input_map (plug->plugin_number ())); + map.get (DataType::AUDIO, index, &valid); + return valid ? 0 : 1; + } if (index < plug->plugin()->numInputs) { return 0; } break; case 1: +#if 0 // investigate, the outputs *are* connected to scratch buffers + if (plug->plugin_insert ()) { + bool valid; + const ChanMapping& map (plug->plugin_insert ()->output_map (plug->plugin_number ())); + map.get (DataType::AUDIO, index, &valid); + return valid ? 0 : 1; + } +#endif if (index < plug->plugin()->numOutputs) { return 0; } @@ -148,67 +168,46 @@ intptr_t Session::vst_callback ( case audioMasterGetTime: SHOW_CALLBACK ("audioMasterGetTime"); - // returns const VstTimeInfo* (or 0 if not supported) - // should contain a mask indicating which fields are required - // (see valid masks above), as some items may require extensive - // conversions - _timeInfo.flags = 0; + newflags = kVstNanosValid | kVstAutomationWriting | kVstAutomationReading; - if (session) { - framepos_t now = session->transport_frame(); + timeinfo->nanoSeconds = g_get_monotonic_time () * 1000; - _timeInfo.samplePos = now; - _timeInfo.sampleRate = session->frame_rate(); + if (plug && session) { + samplepos_t now = plug->transport_sample(); - const TempoMetric& tm (session->tempo_map().metric_at (now)); + timeinfo->samplePos = now; + timeinfo->sampleRate = session->sample_rate(); if (value & (kVstTempoValid)) { - const Tempo& t (tm.tempo()); - _timeInfo.tempo = t.beats_per_minute (); - _timeInfo.flags |= (kVstTempoValid); + const Tempo& t (session->tempo_map().tempo_at_sample (now)); + timeinfo->tempo = t.quarter_notes_per_minute (); + newflags |= (kVstTempoValid); } if (value & (kVstTimeSigValid)) { - const Meter& m (tm.meter()); - _timeInfo.timeSigNumerator = m.divisions_per_bar (); - _timeInfo.timeSigDenominator = m.note_divisor (); - _timeInfo.flags |= (kVstTimeSigValid); + const MeterSection& ms (session->tempo_map().meter_section_at_sample (now)); + timeinfo->timeSigNumerator = ms.divisions_per_bar (); + timeinfo->timeSigDenominator = ms.note_divisor (); + newflags |= (kVstTimeSigValid); } if ((value & (kVstPpqPosValid)) || (value & (kVstBarsValid))) { Timecode::BBT_Time bbt; try { - session->tempo_map().bbt_time_rt (now, bbt); - - /* PPQ = pulse per quarter - * VST's "pulse" is our "division". - * - * 8 divisions per bar, 1 division = quarter, so 8 quarters per bar, ppq = 1 - * 8 divisions per bar, 1 division = eighth, so 4 quarters per bar, ppq = 2 - * 4 divisions per bar, 1 division = quarter, so 4 quarters per bar, ppq = 1 - * 4 divisions per bar, 1 division = half, so 8 quarters per bar, ppq = 0.5 - * 4 divisions per bar, 1 division = fifth, so (4 * 5/4) quarters per bar, ppq = 5/4 - * - * general: divs_per_bar / (note_type / 4.0) - */ - double ppq_scaling = tm.meter().note_divisor() / 4.0; - - /* Note that this assumes constant meter/tempo throughout the session. Stupid VST */ - double ppqBar = double(bbt.bars - 1) * tm.meter().divisions_per_bar(); - double ppqBeat = double(bbt.beats - 1); - double ppqTick = double(bbt.ticks) / Timecode::BBT_Time::ticks_per_beat; - - ppqBar *= ppq_scaling; - ppqBeat *= ppq_scaling; - ppqTick *= ppq_scaling; - + bbt = session->tempo_map().bbt_at_sample_rt (now); + bbt.beats = 1; + bbt.ticks = 0; + /* exact quarter note */ + double ppqBar = session->tempo_map().quarter_note_at_bbt_rt (bbt); + /* quarter note at sample position (not rounded to note subdivision) */ + double ppqPos = session->tempo_map().quarter_note_at_sample_rt (now); if (value & (kVstPpqPosValid)) { - _timeInfo.ppqPos = ppqBar + ppqBeat + ppqTick; - _timeInfo.flags |= (kVstPpqPosValid); + timeinfo->ppqPos = ppqPos; + newflags |= kVstPpqPosValid; } if (value & (kVstBarsValid)) { - _timeInfo.barStartPos = ppqBar; - _timeInfo.flags |= (kVstBarsValid); + timeinfo->barStartPos = ppqBar; + newflags |= kVstBarsValid; } } catch (...) { @@ -221,47 +220,67 @@ intptr_t Session::vst_callback ( session->timecode_time (now, t); - _timeInfo.smpteOffset = (t.hours * t.rate * 60.0 * 60.0) + + timeinfo->smpteOffset = (t.hours * t.rate * 60.0 * 60.0) + (t.minutes * t.rate * 60.0) + (t.seconds * t.rate) + (t.frames) + (t.subframes); - _timeInfo.smpteOffset *= 80.0; /* VST spec is 1/80th frames */ + timeinfo->smpteOffset *= 80.0; /* VST spec is 1/80th samples */ if (session->timecode_drop_frames()) { if (session->timecode_frames_per_second() == 30.0) { - _timeInfo.smpteFrameRate = 5; + timeinfo->smpteFrameRate = 5; } else { - _timeInfo.smpteFrameRate = 4; /* 29.97 assumed, thanks VST */ + timeinfo->smpteFrameRate = 4; /* 29.97 assumed, thanks VST */ } } else { if (session->timecode_frames_per_second() == 24.0) { - _timeInfo.smpteFrameRate = 0; + timeinfo->smpteFrameRate = 0; } else if (session->timecode_frames_per_second() == 24.975) { - _timeInfo.smpteFrameRate = 2; + timeinfo->smpteFrameRate = 2; } else if (session->timecode_frames_per_second() == 25.0) { - _timeInfo.smpteFrameRate = 1; + timeinfo->smpteFrameRate = 1; } else { - _timeInfo.smpteFrameRate = 3; /* 30 fps */ + timeinfo->smpteFrameRate = 3; /* 30 fps */ } } - _timeInfo.flags |= (kVstSmpteValid); + newflags |= (kVstSmpteValid); + } + + if (session->actively_recording ()) { + newflags |= kVstTransportRecording; } - if (session->transport_speed() != 0.0f) { - _timeInfo.flags |= (kVstTransportPlaying); + if (plug->transport_speed () != 0.0f) { + newflags |= kVstTransportPlaying; } - if (session->get_play_loop()) { + if (session->get_play_loop ()) { + newflags |= kVstTransportCycleActive; + Location * looploc = session->locations ()->auto_loop_location (); + if (looploc) try { + timeinfo->cycleStartPos = session->tempo_map ().quarter_note_at_sample_rt (looploc->start ()); + timeinfo->cycleEndPos = session->tempo_map ().quarter_note_at_sample_rt (looploc->end ()); + + newflags |= kVstCyclePosValid; + } catch (...) { } } } else { - _timeInfo.samplePos = 0; - _timeInfo.sampleRate = AudioEngine::instance()->sample_rate(); + timeinfo->samplePos = 0; + timeinfo->sampleRate = AudioEngine::instance()->sample_rate(); } - return (intptr_t) &_timeInfo; + if ((timeinfo->flags & (kVstTransportPlaying | kVstTransportRecording | kVstTransportCycleActive)) + != + (newflags & (kVstTransportPlaying | kVstTransportRecording | kVstTransportCycleActive))) + { + newflags |= kVstTransportChanged; + } + + timeinfo->flags = newflags; + return (intptr_t) timeinfo; case audioMasterProcessEvents: SHOW_CALLBACK ("audioMasterProcessEvents"); @@ -271,7 +290,7 @@ intptr_t Session::vst_callback ( for (int n = 0 ; n < v->numEvents; ++n) { VstMidiEvent *vme = (VstMidiEvent*) (v->events[n]->dump); if (vme->type == kVstMidiType) { - plug->midi_buffer()->push_back(vme->deltaFrames, 3, (uint8_t*)vme->midiData); + plug->midi_buffer()->push_back(vme->deltaSamples, 3, (uint8_t*)vme->midiData); } } } @@ -280,13 +299,14 @@ intptr_t Session::vst_callback ( case audioMasterSetTime: SHOW_CALLBACK ("audioMasterSetTime"); // VstTimenfo* in , filter in , not supported + return 0; case audioMasterTempoAt: SHOW_CALLBACK ("audioMasterTempoAt"); - // returns tempo (in bpm * 10000) at sample frame location passed in + // returns tempo (in bpm * 10000) at sample sample location passed in if (session) { - const Tempo& t (session->tempo_map().tempo_at (value)); - return t.beats_per_minute() * 1000; + const Tempo& t (session->tempo_map().tempo_at_sample (value)); + return t.quarter_notes_per_minute() * 1000; } else { return 0; } @@ -318,13 +338,22 @@ intptr_t Session::vst_callback ( case audioMasterSizeWindow: SHOW_CALLBACK ("audioMasterSizeWindow"); - // index: width, value: height - return 0; + if (plug && plug->state()) { + if (plug->state()->width != index || plug->state()->height != value) { + plug->state()->width = index; + plug->state()->height = value; +#ifndef NDEBUG + printf ("audioMasterSizeWindow %d %d\n", plug->state()->width, plug->state()->height); +#endif + plug->VSTSizeWindow (); /* EMIT SIGNAL */ + } + } + return 1; case audioMasterGetSampleRate: SHOW_CALLBACK ("audioMasterGetSampleRate"); if (session) { - return session->frame_rate(); + return session->sample_rate(); } return 0; @@ -351,6 +380,7 @@ intptr_t Session::vst_callback ( case audioMasterGetNextPlug: SHOW_CALLBACK ("audioMasterGetNextPlug"); // output pin in (-1: first to come), returns cEffect* + return 0; case audioMasterWillReplaceOrAccumulate: SHOW_CALLBACK ("audioMasterWillReplaceOrAccumulate"); @@ -409,13 +439,13 @@ intptr_t Session::vst_callback ( SHOW_CALLBACK ("audioMasterGetVendorString"); // fills with a string identifying the vendor (max 64 char) strcpy ((char*) ptr, "Linux Audio Systems"); - return 0; + return 1; case audioMasterGetProductString: SHOW_CALLBACK ("audioMasterGetProductString"); // fills with a string with product name (max 64 char) strcpy ((char*) ptr, PROGRAM_NAME); - return 0; + return 1; case audioMasterGetVendorVersion: SHOW_CALLBACK ("audioMasterGetVendorVersion"); @@ -465,19 +495,32 @@ intptr_t Session::vst_callback ( case audioMasterUpdateDisplay: SHOW_CALLBACK ("audioMasterUpdateDisplay"); // something has changed, update 'multi-fx' display - if (effect) { - effect->dispatcher(effect, effEditIdle, 0, 0, NULL, 0.0f); + /* TODO: consider emitting ParameterChangedExternally() for each ctrl input */ + if (session) { + session->set_dirty (); } return 0; case audioMasterBeginEdit: SHOW_CALLBACK ("audioMasterBeginEdit"); // begin of automation session (when mouse down), parameter index in + if (plug && plug->plugin_insert ()) { + boost::shared_ptr ac = plug->plugin_insert ()->automation_control (Evoral::Parameter (PluginAutomation, 0, index)); + if (ac) { + ac->start_touch (ac->session().transport_sample()); + } + } return 0; case audioMasterEndEdit: SHOW_CALLBACK ("audioMasterEndEdit"); // end of automation session (when mouse up), parameter index in + if (plug && plug->plugin_insert ()) { + boost::shared_ptr ac = plug->plugin_insert ()->automation_control (Evoral::Parameter (PluginAutomation, 0, index)); + if (ac) { + ac->stop_touch (ac->session().transport_sample()); + } + } return 0; case audioMasterOpenFileSelector: @@ -492,4 +535,3 @@ intptr_t Session::vst_callback ( return 0; } -