cmajor-lang/cmajor

VSCode Extension bug: TimeSignature and Tempo objects are "null" after clicking "Reset patch"

atamocius opened this issue · 1 comments

When running a patch within VSCode, if the patch has input events for the TimeSignature and Tempo objects, and the Reset patch button is clicked, Tempo.bpm, TimeSignature.numerator, and TimeSignature.denominator all become 0 (along with every member method returning 0, and Infinity for TimeSignature.quarterNotePerBeat because of the denominator being 0).

Used this code to check:

processor Demo [[main]]
{
    input event
    {
        std::timeline::TimeSignature    timeSigIn;
        std::timeline::Tempo            tempoIn;
    }

    output stream int out;

    event timeSigIn (std::timeline::TimeSignature t) { timeSig = t; }
    event tempoIn   (std::timeline::Tempo t)         { tempo = t; }

    void main()
    {
        console <- "timeSig.numerator: ";
        console <- timeSig.numerator;
        console <- "\n";

        console <- "timeSig.denominator: ";
        console <- timeSig.denominator;
        console <- "\n";

        console <- "timeSig.beatsPerQuarterNote: ";
        console <- timeSig.beatsPerQuarterNote();
        console <- "\n";

        console <- "timeSig.quarterNotesPerBeat: ";
        console <- timeSig.quarterNotesPerBeat();
        console <- "\n";

        console <- "processor.frequency: ";
        console <- processor.frequency;
        console <- "\n";

        console <- "tempo.bpm: ";
        console <- tempo.bpm;
        console <- "\n";

        console <- "tempo.secondsPerBeat: ";
        console <- tempo.secondsPerBeat();
        console <- "\n";

        console <- "tempo.framesPerBeat: ";
        console <- tempo.framesPerBeat(processor.frequency);
        console <- "\n";

        console <- "tempo.secondsPerQuarterNote: ";
        console <- tempo.secondsPerQuarterNote(timeSig);
        console <- "\n";

        console <- "tempo.framesPerQuarterNote: ";
        console <- tempo.framesPerQuarterNote(timeSig, processor.frequency);
        console <- "\n";

        advance();
    }

    std::timeline::TimeSignature timeSig;
    std::timeline::Tempo tempo;
}

Output on first run of the patch:

timeSig.numerator: 4
timeSig.denominator: 4
timeSig.beatsPerQuarterNote: 1
timeSig.quarterNotesPerBeat: 1
processor.frequency: 44100
tempo.bpm: 120
tempo.secondsPerBeat: 0.5
tempo.framesPerBeat: 22050
tempo.secondsPerQuarterNote: 0.5
tempo.framesPerQuarterNote: 22050

Output right after clicking Reset patch:

timeSig.numerator: 0
timeSig.denominator: 0
timeSig.beatsPerQuarterNote: 0
timeSig.quarterNotesPerBeat: Infinity
processor.frequency: 44100
tempo.bpm: 0
tempo.secondsPerBeat: 0
tempo.framesPerBeat: 0
tempo.secondsPerQuarterNote: 0
tempo.framesPerQuarterNote: 0

Thanks for reporting this. The patch player caches the current patch transport state to avoid sending multiple messages when nothing has changed. It's state was not being reset when the patch was reset, so the patch was not receiving these events after reset. I've fixed this, and it'll be included in the next release.