A substitute clock that follows MIDI clock messages from an external source, with some caveats.
If it is absolutely necessary to follow an external source, use this class.
Recommended procedure:
MIDIIn.connectAll
. (I believe sysrt
messages are received from any available port. If SC fails to respond, you might try connecting incoming port 0 to the device from which clock messages are coming: MIDIIn: *connect. In theory this should be unnecessary).The clock source should begin by sending a MIDI clock "start" message, resetting MIDISyncClock to beat 0. This is essential for beat sync. If you start the clock source first, and then initialize MIDISyncClock, the beats will probably not line up.
A manual scheduling offset may be given by hand.
In theory, the number of ticks to offset should be server_latency.neg * tempo * ticksPerBeat
(where the last is usually 24). But, you may need to add some amount for audio driver latency (making the offset closer to 0). Because audio driver latency is unknown within the language client, it is up to you to tune the scheduling offset by hand. (Important: Offset should be negative!)
Limitation: The offset depends on tempo. So, if the clock source's tempo changes, the offset will be incorrect. It is difficult to compensate for this (and, to be honest, I'm not that interested in the problem). So, for now, if you expect tempo changes, it's advised not to use schedOffset
; instead, set server latency to nil and the soundcard to the smallest possible buffer size, to try to reduce the impact of latency.
Most of the methods of MIDISyncClock attempt compatibility with TempoClock. Consult TempoClock documentation for details on scheduling events and managing metrical position.
One exception is TempoClock: -tempo. MIDISyncClock derives its tempo from the external source; for obvious reasons, then, you cannot override the tempo by tempo_
.
Initialize MIDISyncClock's internal state. Must be called before starting the external clock source.
Change the MIDI clock's scheduling offset.
newOffset |
An number of ticks by which to offset (recommended to be an integer). A negative offset shifts scheduling earlier. This is the normal case for latency compensation. |
reschedule |
A Boolean indicating whether or not to reschedule items currently on the clock to account for the new scheduling offset. The default is true, so that you should hear the result of the offset immediately. |
This demonstration will generate MIDI clock messages within SuperCollider.