From 5379137180999987bf6ca1973db1db7ffdb2ee94 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Wed, 26 Dec 2018 13:21:46 -0500 Subject: [PATCH] Make Freerun work Standalone in AU Per issue #146, this diff makes the AU query the transport status and if the host is not in transport mode, then don't reset the song position to zero every time. This means freerun works in performance mode. Former-commit-id: ee6e4f48d28f818c546535b80c83bff1a49c917b Former-commit-id: 9a6bed0bdaf334f0097618c7f81750eefed7cbd4 --- src/au/aulayer.cpp | 38 ++++++++++++++++++++++++++++++-------- src/au/aulayer.h | 31 ------------------------------- src/au/aulayer_cocoaui.mm | 3 --- 3 files changed, 30 insertions(+), 42 deletions(-) diff --git a/src/au/aulayer.cpp b/src/au/aulayer.cpp index d29cf7631b2..404f2dbaea9 100644 --- a/src/au/aulayer.cpp +++ b/src/au/aulayer.cpp @@ -7,10 +7,6 @@ typedef SurgeSynthesizer sub3_synth; -#ifdef GENERATE_AU_LOG -FILE* AULOG::lf = NULL; -#endif - //---------------------------------------------------------------------------------------------------- aulayer::aulayer (AudioUnit au) : AUInstrumentBase (au,1,1) @@ -112,14 +108,14 @@ void aulayer::InitializePlugin() { if(!plugin_instance) { - AULOG::log( "SURGE:>> Constructing new plugin\n" ); - AULOG::log( " :>> BUILD %s on %s\n", __TIME__, __DATE__ ); //sub3_synth* synth = (sub3_synth*)_aligned_malloc(sizeof(sub3_synth),16); //new(synth) sub3_synth(this); // FIXME: The VST uses a std::unique_ptr<> and we probably should here also plugin_instance = new SurgeSynthesizer( this ); - AULOG::log( " :>> Plugin Created\n" ); + + // This allows us standalone performance mode. See issue #146 and comment below tagged with issue number + plugin_instance->time_data.ppqPos = 0; } assert(plugin_instance); } @@ -342,13 +338,39 @@ ComponentResult aulayer::Render( AudioUnitRenderActionFlags & ioActionFlags, con } } + // Get the transport status + Boolean isPlaying; + + if(CallHostTransportState( &isPlaying, + NULL, // &isTransportStateChanged, + NULL, // ¤tSampleInTimeline, + NULL, // &isCycling, + NULL, // &cycleStartBeat, + NULL // &cycleEndBeat + ) < 0 ) + { + isPlaying = false; + } + + // do each buffer Float64 CurrentBeat,CurrentTempo; if(CallHostBeatAndTempo (&CurrentBeat, &CurrentTempo) >= 0) { plugin_instance->time_data.tempo = CurrentTempo; - plugin_instance->time_data.ppqPos = CurrentBeat; + + // If the engine isn't playing, so CurrentBeat is a constant, then result here is + // resetting time_data.ppqPos to the same thing over and over. That means the lfo_freerun + // mode basically acts like keypress mode since time_data.ppqPos - which maps to songpos + // is always reset to zero or a frame or so beyond. If instead we only reset it when + // playing then exactly what we want occurs. In playback mode we get perfectly predictable + // oscillator start and stop; but in performance mode we get freerun working off the internal clock + // which we synthesize by running the "move clock" block below. + // + // See github issue #146 + if( isPlaying ) + plugin_instance->time_data.ppqPos = CurrentBeat; } else { diff --git a/src/au/aulayer.h b/src/au/aulayer.h index 5a2d5dcd9a8..7003ee9b2b1 100644 --- a/src/au/aulayer.h +++ b/src/au/aulayer.h @@ -12,37 +12,6 @@ class SurgeGUIEditor; class SurgeSynthesizer; typedef SurgeSynthesizer plugin; -#define GENERATE_AU_LOG -struct AULOG -{ -#ifdef GENERATE_AU_LOG - static FILE* lf; - - static void log( const char* format, ... ) - { - if( lf == NULL ) - { - char fname[ 1024 ]; - sprintf( fname, "%s/Library/Logs/Surge.log", getenv( "HOME" ) ); - lf = fopen( fname, "a" ); - } - va_list args; - va_start( args, format ); - vfprintf( stderr, format, args ); - va_end( args ); - if( lf != NULL ) - { - va_start( args, format ); - vfprintf( lf, format, args ); - va_end( args ); - fflush( lf ); - } - - } -#else - static void log( const char* format, ... ) { } -#endif -}; //------------------------------------------------------------------------------------------------------- const CFStringRef rawchunkname = CFSTR("VmbA_chunk"); diff --git a/src/au/aulayer_cocoaui.mm b/src/au/aulayer_cocoaui.mm index d4689854bfb..70b8b66b135 100644 --- a/src/au/aulayer_cocoaui.mm +++ b/src/au/aulayer_cocoaui.mm @@ -66,9 +66,6 @@ - (NSView *) uiViewForAudioUnit: (AudioUnit) inAudioUnit withSize: (NSSize) inPreferredSize { // Remember we end up being called here because that's what AUCocoaUIView does in the initiation collaboration with hosts - AULOG::log( "uiViewForAudioUnit %s on %s\n", __TIME__, __DATE__ ); - AULOG::log( "prefSize is %f %f\n", inPreferredSize.width, inPreferredSize.height ); - SurgeGUIEditor* editController = 0; UInt32 size = sizeof (SurgeGUIEditor *); if (AudioUnitGetProperty (inAudioUnit, kVmbAAudioUnitProperty_GetEditPointer, kAudioUnitScope_Global, 0, &editController, &size) != noErr)