Ableton / LinkKit

iOS SDK for Ableton Link, a new technology that synchronizes musical beat, tempo, and phase across multiple applications running on one or more devices.
http://ableton.github.io/linkkit
Other
147 stars 10 forks source link

Beat time: Is it really beats, or quarter notes? #32

Closed BlipGit closed 7 years ago

BlipGit commented 7 years ago

I'm currently dealing with time signatures and how they may affect Ableton Link integration.

Would I be correct in saying that the timeline's 'beat time' is actually quarter notes rather than beats?

cdi-ableton commented 7 years ago

Yes. The duration of a beat corresponds to the one of a quarter note. If you're dealing with different signatures check out the section about Phase Synchronisation in Link's documentation.

BlipGit commented 7 years ago

Thanks, although that does bring me to my next question ...

I'm using the current time signature's 'beats per bar' to determine the quantum. However, when the 'beats per bar' changes (as a result of a user interaction, or due to an event in the sequence), the beat time returned by LinkKit becomes discontinuous, and the timeline jumps to a different position. I've worked around this by adding a compensation offset when a quantum change occurs, as follows:


    // Has the quantum changed since the last call?
    if (mQuantum != zQuantum)
    {
        // Calculate the beat time using both the old and the new quantum
        f64 OldQuantumBeat = ABLLinkBeatAtTime(mpCapturedTimeline, HostTime, mQuantum);
        f64 NewQuantumBeat = ABLLinkBeatAtTime(mpCapturedTimeline, HostTime, zQuantum);

        // The difference between the two returned beat times must be added as an offset in all future calls
        // to prevent a timeline discontinuity
        mBeatOffset += (OldQuantumBeat - NewQuantumBeat);

        // This is now the new quantum
        mQuantum = zQuantum;
    }

    // Return the beat time, adding our offset to prevent discontinuities when the quantum changes
    return ABLLinkBeatAtTime(mpCapturedTimeline, HostTime, mQuantum) + mBeatOffset;

This seems to work, and the app's bar start (phase) still seems to align with the connected peers when the quanta are a multiple of each other but it still feels like a workaround. Have I handled this correctly?

cdi-ableton commented 7 years ago

Yes. The beat time will be discontinuous when changing the quantum. For Ableton Live we're taking an alternative approach on handling this. We're saving the quantum when starting transport and use this for alignment with Link until transport is stopped. When transport is started again we update the quantum.

BlipGit commented 7 years ago

OK. This is the same alternative approach I thought of last night, so I think I might change it!

Thanks once again for your help.