Resume playback where stopped

I have a small test project on Linux that uses Tracktion Engine with the command line application template. The goal is just to play a loop for some time, pause playback and then resume playback from the current position. The problem is that the sound is always played from start. Is that behavior intended?

Here is the code from Main.cpp:

#include <JuceHeader.h>
#include <iostream>

namespace te = tracktion;

int main (int argc, char* argv[])
{   
    //Setup engine and edit with 1 track
    te::Engine engine(ProjectInfo::projectName);
    te::Edit edit(engine, te::createEmptyEdit(engine), te::Edit::EditRole::forEditing, nullptr, 0);
    edit.ensureNumberOfAudioTracks(1);
    
    //Setup transport for looping 
    te::TransportControl& transport = edit.getTransport();
    transport.looping = true;
    
    //Load sound from file to track 0 as clip and loop around that clip
    juce::File loopFile(PATH-TO-SOME-WAV-FILE);
    te::AudioFile audioFile(edit.engine, loopFile);      
    te::AudioTrack* track = te::getAudioTracks(edit)[0];    
    juce::ReferenceCountedObjectPtr<te::WaveAudioClip> newClip = track->insertWaveClip (loopFile.getFileNameWithoutExtension(), loopFile,
                                                          { { {}, te::TimeDuration::fromSeconds (audioFile.getLength()) }, {} }, false);
    transport.setLoopRange(newClip->getEditTimeRange());
    
    //User presses buttons to trigger actions: play, stop, play, exit 
    std::cout << "Play";
    std::cin.get(); 
    transport.play(false);
    std::cout << "Stop";
    std::cin.get();    
    transport.stop(true, false);
    std::cout << "Play";
    std::cin.get();     
    transport.play(false); //HERE THE SOUND IS PLAYED FROM BEGINNING, NOT FROM POSITION WHERE STOPPED
    std::cout << "Exit";
    std::cin.get();
    
    return 0;
}

JuceHeader and AppConfig:
JuceHeader.h (2.0 KB)
AppConfig.h (10.3 KB)

That shouldn’t be the default behaviour, the only place I can think of that would change the playhead position would be on line 1537 of tracktion_TransportControl.cpp during perform stop:

    if ((transportState->invertReturnToStartPosSelection ^ bool (engine.getPropertyStorage().getProperty (SettingID::resetCursorOnStop, false)))
         && transportState->cursorPosAtPlayStart >= 0_tp)
        setPosition (transportState->cursorPosAtPlayStart);

But as you can see, the default is false there.


If I were you I’d put a breakpoint in TransportControl::setPosition to see if its hit and where the change is coming from.


TBH, looking a bit more closely at your code I see it’s a console app. It doesn’t look like you’ve initialised JUCE correctly and Tracktion Engine needs an unblocked message loop to work correctly.
You might need to refactor this to avoid lots of problems.