Skip to content

Commit

Permalink
Merge pull request surge-synthesizer#156 from baconpaul/freerun-146
Browse files Browse the repository at this point in the history
Make Freerun work Standalone in AU

Former-commit-id: 69b2435
Former-commit-id: 384cf8088fcde58ad1894d6f30cf48ac8956067f
  • Loading branch information
kurasu authored Dec 27, 2018
2 parents 20b558b + 1231a0b commit 1c22425
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/au/aulayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ void aulayer::InitializePlugin()

// FIXME: The VST uses a std::unique_ptr<> and we probably should here also
plugin_instance = new SurgeSynthesizer( this );
}

// 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);
}

Expand Down Expand Up @@ -335,13 +338,39 @@ ComponentResult aulayer::Render( AudioUnitRenderActionFlags & ioActionFlags, con
}
}

// Get the transport status
Boolean isPlaying;

if(CallHostTransportState( &isPlaying,
NULL, // &isTransportStateChanged,
NULL, // &currentSampleInTimeline,
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
{
Expand Down

0 comments on commit 1c22425

Please sign in to comment.