Class HostClock
- Namespace
- Sigil.Sound
- Assembly
- Sigil.Sound.dll
The host's notion of "now": how many frames it has rendered and where it is on a musical grid. Put one on Sigil.Sound.RenderContext.Clock and time no longer starts over each time a sound is compiled, which is what keeps a live-coded LFO in phase and a looping pattern on the beat when the sound under them is swapped for another.
public sealed class HostClockInheritance
Inherited Members
Remarks
Without a clock every sound counts time from its own first frame, which is right for rendering a file and for one-shot
demos. With one, these follow the clock instead: Sigil.Sound.Sounds.Fn(System.Func{System.Double,System.Double}) and function parameters read host time,
sines, saws and pulses with a constant frequency continue the phase they would have had, and
Pattern.Play without an explicit tempo follows Sigil.Sound.HostClock.Bpm and Sigil.Sound.HostClock.Beats.
Notes played by a voice keep their own time, starting at zero with each note.
The renderer owns the clock: it calls Sigil.Sound.HostClock.Advance(System.Int32) after rendering each block (a Sigil.Sound.SoundContext given a clock does this itself) and Sigil.Sound.HostClock.Seek(System.Int64,System.Double) when the transport jumps. Only Sigil.Sound.HostClock.Bpm may be changed from another thread. Reading the clock is real-time safe.
Constructors
HostClock(int, double)
public HostClock(int sampleRate, double bpm = 120)Parameters
sampleRateint-
Frames per second; must equal the sample rate of every Sigil.Sound.RenderContext that uses the clock.
bpmdouble-
Beats (quarter notes) per minute. Defaults to 120.
Properties
Beats
The musical position, in beats, of the first frame of the block being rendered.
public double Beats { get; }Property Value
Bpm
The tempo in beats per minute. Takes effect from the next block; safe to set from any thread.
public double Bpm { get; set; }Property Value
Running
Whether the musical position moves. A host sets it to false while its transport is paused or stopped: Sigil.Sound.HostClock.Beats then
stays where it is while Sigil.Sound.HostClock.SamplePosition keeps counting, so sounds that read host time (a live-coded LFO, an
oscillator's phase) are not disturbed. Pattern.Play starts no new notes while the clock is held and carries on from the same
beat, without repeating or skipping one, when it runs again. Notes already sounding finish. Safe to set from any thread.
public bool Running { get; set; }Property Value
SamplePosition
The frame number of the first frame of the block being rendered.
public long SamplePosition { get; }Property Value
SampleRate
Frames per second the clock counts in.
public int SampleRate { get; }Property Value
Seconds
Seconds at Sigil.Sound.HostClock.SamplePosition.
public double Seconds { get; }Property Value
Methods
Advance(int)
Moves the clock past a rendered block of frames, advancing the beat position at the current tempo
(unless Sigil.Sound.HostClock.Running is false, which advances only the sample position).
public void Advance(int frames)Parameters
framesint
Seek(long, double)
Jumps to another place, as a transport locate does.
public void Seek(long samplePosition, double beats)