tecs.audio.sequencer#
Overview#
Functions#
checkOptionsfunction#
function(name: string, options: PlayOptions?)Raises unless play options are in range.
Arguments#
name-stringoptions-PlayOptions?
Raises#
| Type | Condition |
|---|---|
string |
when tempo, lookahead or start is out of range |
newPlayerfunction#
function(
mixer: audio.Audio,
driver: Driver,
handle: assets.Handle?,
options: PlayOptions?
): PlayerStarts a player on a driver and registers it with the mixer's update.
What the format modules' play functions end in, and what a game with a format of its own calls with a driver it wrote.
Arguments#
mixer-audio.Audio- the mixer whose
updateadvances the player driver-Driver- the song and its voices, which the player now owns
handle-assets.Handle?- the song's handle, which the player retains until it stops and watches for a reload, or nil for a song held some other way
options-PlayOptions?- the loop, tempo, lookahead and start, or nil for the defaults.
groupandgainare the driver's to apply.
Returns#
Player-
the playing player
Raises#
| Type | Condition |
|---|---|
string |
when an option is out of range |
Types#
Driverrecord#
record DriverWhat a format module supplies to a Player: the voices a song plays on and the song's events, behind the operations a player needs.
Song time is seconds from the start of the song at a tempo of one. Clock time is seconds on the voices' own clock, which now reads. A player maps one to the other with an anchor: song time song is clock time clock, and tempo song seconds pass for each clock second.
Members#
constructorconstructor#
function(
duration: number,
loopStart: number?,
loopEnd: number?,
tail: number,
now: function(): number,
schedule: function(to: number, song: number, clock: number, tempo: number): number,
pending: function(): number?,
jump: function(target: number, at: number): nil,
seek: function(target: number, at: number): nil,
reload: function(payload: any): (boolean, string?),
pause: function(): nil,
resume: function(): nil,
setGain: function(gain: number): nil,
setMuted: function(index: integer, muted: boolean): nil,
stop: function(fadeOut: number?): nil
): tecs.audio.sequencer.DriverConstructs an instance from named fields. Optional fields may be omitted.
Arguments#
duration-number- Required. Read-only. Reports the song's length in seconds.
loopStart-number?- Optional. Defaults to
nil. Read-only. Reports where the song loops back to, in seconds, or nil for a song without a loop. loopEnd-number?- Optional. Defaults to
nil. Read-only. Reports where a loop ends and the song goes back toloopStart, in seconds, or nil for the end of the song. tail-number- Required. Read-only. Reports the seconds a voice keeps sounding after the last event, for releases and reverb, before a finished song frees it.
now-function(): number- Required. Read-only. Reports the mixer's clock in seconds, which every
atthe driver sends is on. schedule-function(to: number, song: number, clock: number, tempo: number): number- Required. Read-only. Sends every event due at or after the driver's cursor and before song time
to, each at clock timeclock + (time - song) / tempo, and returns the song time it reached,to. An event a voice refuses is skipped rather than retried. pending-function(): number?- Required. Read-only. Reports the song time of the first event the cursor has not sent, or nil when every event has gone.
jump-function(target: number, at: number): nil- Required. Read-only. Moves the cursor back to song time
targetfor a loop, after ending what still sounds at clock timeat. seek-function(target: number, at: number): nil- Required. Read-only. Moves the cursor to song time
targetfrom anywhere, putting the voices in the state the song had there, at clock timeat. reload-function(payload: any): (boolean, string?)- Required. Read-only. Replaces the song with the payload of a reloaded handle, and returns false and a reason when it cannot.
pause-function(): nil- Required. Read-only. Pauses every voice, which stops its clock.
resume-function(): nil- Required. Read-only. Resumes every voice.
setGain-function(gain: number): nil- Required. Read-only. Sets the gain of every voice.
setMuted-function(index: integer, muted: boolean): nil- Required. Read-only. Mutes or unmutes one part of the song: a MIDI channel or a chip, numbered from zero.
stop-function(fadeOut: number?): nil- Required. Read-only. Stops and frees every voice, over
fadeOutseconds when that is given.
Returns#
tecs.audio.sequencer.Driver-
the constructed instance
Examples#
Using values of the argument types above:
local value = require("tecs.audio.sequencer").Driver(
duration = duration,
tail = tail,
now = now,
schedule = schedule,
pending = pending,
jump = jump,
seek = seek,
reload = reload,
pause = pause,
resume = resume,
setGain = setGain,
setMuted = setMuted,
stop = stop
)durationfield#
duration: numberRead-only. Reports the song's length in seconds.
loopStartfield#
loopStart: number?Read-only. Reports where the song loops back to, in seconds, or nil for a song without a loop.
loopEndfield#
loopEnd: number?Read-only. Reports where a loop ends and the song goes back to loopStart, in seconds, or nil for the end of the song.
tailfield#
tail: numberRead-only. Reports the seconds a voice keeps sounding after the last event, for releases and reverb, before a finished song frees it.
nowmethod#
function(): numberRead-only. Reports the mixer's clock in seconds, which every at the driver sends is on.
Returns#
number
schedulemethod#
function(to: number, song: number, clock: number, tempo: number): numberRead-only. Sends every event due at or after the driver's cursor and before song time to, each at clock time clock + (time - song) / tempo, and returns the song time it reached, to. An event a voice refuses is skipped rather than retried.
Arguments#
to-numbersong-numberclock-numbertempo-number
Returns#
number
pendingmethod#
function(): number?Read-only. Reports the song time of the first event the cursor has not sent, or nil when every event has gone.
Returns#
number?
jumpmethod#
function(target: number, at: number)Read-only. Moves the cursor back to song time target for a loop, after ending what still sounds at clock time at.
Arguments#
target-numberat-number
seekmethod#
function(target: number, at: number)Read-only. Moves the cursor to song time target from anywhere, putting the voices in the state the song had there, at clock time at.
Arguments#
target-numberat-number
reloadmethod#
function(payload: any): (boolean, string?)Read-only. Replaces the song with the payload of a reloaded handle, and returns false and a reason when it cannot.
Arguments#
payload-any
Returns#
booleanstring?
pausemethod#
function()Read-only. Pauses every voice, which stops its clock.
resumemethod#
function()Read-only. Resumes every voice.
setGainmethod#
function(gain: number)Read-only. Sets the gain of every voice.
Arguments#
gain-number
setMutedmethod#
function(index: integer, muted: boolean)Read-only. Mutes or unmutes one part of the song: a MIDI channel or a chip, numbered from zero.
Arguments#
index-integermuted-boolean
stopmethod#
function(fadeOut: number?)Read-only. Stops and frees every voice, over fadeOut seconds when that is given.
Arguments#
fadeOut-number?
Playerrecord#
record PlayerA song playing on voices of its own.
Made by tecs.gm.midi.play, tecs.ymfm.music.play or newPlayer, advanced by the mixer's update, and finished with stop. Nothing here raises for a player that has stopped: every call on one does nothing.
Members#
stopmethod#
function(exclusive self: Player, fadeOut: number?)Arguments#
exclusive self-PlayerfadeOut-number?
pausemethod#
function(exclusive self: Player)Arguments#
exclusive self-Player
resumemethod#
function(exclusive self: Player)Arguments#
exclusive self-Player
statusmethod#
function(borrows self: Player): StateArguments#
borrows self-Player
Returns#
playingmethod#
function(borrows self: Player): booleanArguments#
borrows self-Player
Returns#
boolean
pausedmethod#
function(borrows self: Player): booleanArguments#
borrows self-Player
Returns#
boolean
finishedmethod#
function(borrows self: Player): booleanArguments#
borrows self-Player
Returns#
boolean
positionmethod#
function(borrows self: Player): numberArguments#
borrows self-Player
Returns#
number
durationmethod#
function(borrows self: Player): numberArguments#
borrows self-Player
Returns#
number
seekmethod#
function(exclusive self: Player, seconds: number)Arguments#
exclusive self-Playerseconds-number
setLoopmethod#
function(exclusive self: Player, loop: boolean)Arguments#
exclusive self-Playerloop-boolean
loopingmethod#
function(borrows self: Player): booleanArguments#
borrows self-Player
Returns#
boolean
loopsmethod#
function(borrows self: Player): integerArguments#
borrows self-Player
Returns#
integer
setTempomethod#
function(exclusive self: Player, scale: number)Arguments#
exclusive self-Playerscale-number
tempomethod#
function(borrows self: Player): numberArguments#
borrows self-Player
Returns#
number
setGainmethod#
function(exclusive self: Player, gain: number)Arguments#
exclusive self-Playergain-number
setMutedmethod#
function(exclusive self: Player, index: integer, muted: boolean)Arguments#
exclusive self-Playerindex-integermuted-boolean
reloadFailuremethod#
function(borrows self: Player): string?Arguments#
borrows self-Player
Returns#
string?
updatemethod#
function(exclusive self: Player): booleanArguments#
exclusive self-Player
Returns#
boolean
PlayOptionstype#
type PlayOptions = {
group: string?,
gain: number?,
loop: boolean?,
tempo: number?,
lookahead: number?,
start: number?,
track: tecs.audio.Track?,
timeline: tecs.audio.timeline.Timeline?
}Configures a player. The format modules' play functions take it too.
Members#
groupfield#
group: string?Caller-writable. Selects the group the player's voices join, so the group's gain, mute and pause apply to them. Defaults to none.
gainfield#
gain: number?Caller-writable. Sets the linear gain of the player's voices, before group and master gain, and defaults to one.
loopfield#
loop: boolean?Caller-writable. Repeats the song from its loop point. Defaults to true when the song has one, and is ignored when it has none.
tempofield#
tempo: number?Caller-writable. Scales the speed, from 0.01 to 100, and defaults to one.
lookaheadfield#
lookahead: number?Caller-writable. Sets the seconds the player schedules ahead, from 0.005 to 2, and defaults to 0.05.
startfield#
start: number?Caller-writable. Sets where in the song playback starts, in seconds, and defaults to zero.
trackfield#
track: tecs.audio.Track?
Caller-writable. The Track the player's voices sound on, which a driver passes on. Omitted, their group's.
timelinefield#
timeline: tecs.audio.timeline.Timeline?
Caller-writable. A Timeline the song follows: it pauses while the Timeline is paused, and its speed is its own tempo times the Timeline's tempo over 60, so a song on a scene's Timeline stops with the scene and slows with it.
Statetype#
type State = "playing" | "paused" | "finished" | "stopped"Where a player stands.