# `tecs.audio.timeline`
## Overview
::: api-overview
**functions**
- [`new`](#tecs.audio.timeline.new)
**types**
- [`Cue`](#tecs.audio.timeline.Cue)
- [`Options`](#tecs.audio.timeline.Options)
- [`Timeline`](#tecs.audio.timeline.Timeline)
**values**
- [`LOOKAHEAD`](#tecs.audio.timeline.LOOKAHEAD)
:::
::: api-group
## Functions
::: api-item tecs.audio.timeline.new
### `new` _function_
```nupp
function(
clock: function(): number,
options: Options?,
player: (function(sound: any, options: any, at: number): integer)?
): Timeline
```
Creates a timeline over a clock.
The mixer makes these, through `Audio.timeline`, and runs their `update`
from its own. A timeline made here directly has to be updated by its maker.
#### Arguments
`clock` - `function(): number`
: reads the audio clock in seconds
`options` - [`Options`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Options)`?`
: the tempo, bar length, lookahead and start, or nil
`player` - `(function(sound: any, options: any, at: number): integer)?`
:
#### Returns
[`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
: the timeline, running unless `options.paused`
#### Raises
| Type | Condition |
| --- | --- |
| `string` | when the tempo is not positive and finite |
:::
:::
::: api-group
## Types
::: api-item tecs.audio.timeline.Cue
### `Cue` _record_
```nupp
record Cue
```
A handle on an event, to cancel it before it is sent.
#### Members
::: api-overview
**instance methods**
- [`cancel`](#tecs.audio.timeline.Cue.cancel)
**fields**
- [`handle`](#tecs.audio.timeline.Cue.handle)
- [`settled`](#tecs.audio.timeline.Cue.settled)
:::
::: api-item tecs.audio.timeline.Cue.settled
#### `settled` _field_
```nupp
settled: boolean
```
Read-only. Reports whether the event has gone to the backend, or been
cancelled, so `cancel` would do nothing.
:::
::: api-item tecs.audio.timeline.Cue.handle
#### `handle` _field_
```nupp
handle: integer
```
Read-only. The voice a `play` cue started once it was sent, zero
before then and for a start the mixer refused.
:::
::: api-item tecs.audio.timeline.Cue.cancel
#### `cancel` _method_
```nupp
function(exclusive self: Cue): boolean
```
##### Arguments
`exclusive self` - [`Cue`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Cue)
:
##### Returns
`boolean`
:
:::
:::
::: api-item tecs.audio.timeline.Options
### `Options` _type_
```nupp
type Options = {
tempo: number?,
beatsPerBar: integer?,
lookahead: number?,
start: number?,
paused: boolean?
}
```
Configures a timeline.
#### Members
::: api-overview
**fields**
- [`beatsPerBar`](#tecs.audio.timeline.Options.beatsPerBar)
- [`lookahead`](#tecs.audio.timeline.Options.lookahead)
- [`paused`](#tecs.audio.timeline.Options.paused)
- [`start`](#tecs.audio.timeline.Options.start)
- [`tempo`](#tecs.audio.timeline.Options.tempo)
:::
::: api-item tecs.audio.timeline.Options.tempo
#### `tempo` _field_
```nupp
tempo: number?
```
Caller-writable. Beats a minute, 60 by default, so a beat is a second.
:::
::: api-item tecs.audio.timeline.Options.beatsPerBar
#### `beatsPerBar` _field_
```nupp
beatsPerBar: integer?
```
Caller-writable. Beats in a bar, four by default, for `nextBar`.
:::
::: api-item tecs.audio.timeline.Options.lookahead
#### `lookahead` _field_
```nupp
lookahead: number?
```
Caller-writable. Seconds ahead events are sent, 0.05 by default.
:::
::: api-item tecs.audio.timeline.Options.start
#### `start` _field_
```nupp
start: number?
```
Caller-writable. The beat the timeline starts at, zero by default.
:::
::: api-item tecs.audio.timeline.Options.paused
#### `paused` _field_
```nupp
paused: boolean?
```
Caller-writable. Starts the timeline paused.
:::
:::
::: api-item tecs.audio.timeline.Timeline
### `Timeline` _record_
```nupp
record Timeline
```
Local time with a tempo and a pause, mapped onto the audio clock.
#### Members
::: api-overview
**instance methods**
- [`at`](#tecs.audio.timeline.Timeline.at)
- [`beatsPerBar`](#tecs.audio.timeline.Timeline.beatsPerBar)
- [`close`](#tecs.audio.timeline.Timeline.close)
- [`closedState`](#tecs.audio.timeline.Timeline.closedState)
- [`follow`](#tecs.audio.timeline.Timeline.follow)
- [`fromClock`](#tecs.audio.timeline.Timeline.fromClock)
- [`nextBar`](#tecs.audio.timeline.Timeline.nextBar)
- [`nextBeat`](#tecs.audio.timeline.Timeline.nextBeat)
- [`now`](#tecs.audio.timeline.Timeline.now)
- [`pause`](#tecs.audio.timeline.Timeline.pause)
- [`paused`](#tecs.audio.timeline.Timeline.paused)
- [`pending`](#tecs.audio.timeline.Timeline.pending)
- [`play`](#tecs.audio.timeline.Timeline.play)
- [`resume`](#tecs.audio.timeline.Timeline.resume)
- [`seek`](#tecs.audio.timeline.Timeline.seek)
- [`setTempo`](#tecs.audio.timeline.Timeline.setTempo)
- [`tempo`](#tecs.audio.timeline.Timeline.tempo)
- [`toClock`](#tecs.audio.timeline.Timeline.toClock)
- [`upcoming`](#tecs.audio.timeline.Timeline.upcoming)
- [`update`](#tecs.audio.timeline.Timeline.update)
:::
::: api-item tecs.audio.timeline.Timeline.now
#### `now` _method_
```nupp
function(borrows self: Timeline): number
```
##### Arguments
`borrows self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
##### Returns
`number`
:
:::
::: api-item tecs.audio.timeline.Timeline.toClock
#### `toClock` _method_
```nupp
function(borrows self: Timeline, beat: number): number
```
##### Arguments
`borrows self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
`beat` - `number`
:
##### Returns
`number`
:
:::
::: api-item tecs.audio.timeline.Timeline.fromClock
#### `fromClock` _method_
```nupp
function(borrows self: Timeline, seconds: number): number
```
##### Arguments
`borrows self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
`seconds` - `number`
:
##### Returns
`number`
:
:::
::: api-item tecs.audio.timeline.Timeline.tempo
#### `tempo` _method_
```nupp
function(borrows self: Timeline): number
```
##### Arguments
`borrows self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
##### Returns
`number`
:
:::
::: api-item tecs.audio.timeline.Timeline.setTempo
#### `setTempo` _method_
```nupp
function(exclusive self: Timeline, beatsPerMinute: number)
```
##### Arguments
`exclusive self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
`beatsPerMinute` - `number`
:
:::
::: api-item tecs.audio.timeline.Timeline.beatsPerBar
#### `beatsPerBar` _method_
```nupp
function(borrows self: Timeline): integer
```
##### Arguments
`borrows self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
##### Returns
`integer`
:
:::
::: api-item tecs.audio.timeline.Timeline.nextBeat
#### `nextBeat` _method_
```nupp
function(borrows self: Timeline): number
```
##### Arguments
`borrows self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
##### Returns
`number`
:
:::
::: api-item tecs.audio.timeline.Timeline.nextBar
#### `nextBar` _method_
```nupp
function(borrows self: Timeline): number
```
##### Arguments
`borrows self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
##### Returns
`number`
:
:::
::: api-item tecs.audio.timeline.Timeline.pause
#### `pause` _method_
```nupp
function(exclusive self: Timeline)
```
##### Arguments
`exclusive self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
:::
::: api-item tecs.audio.timeline.Timeline.resume
#### `resume` _method_
```nupp
function(exclusive self: Timeline)
```
##### Arguments
`exclusive self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
:::
::: api-item tecs.audio.timeline.Timeline.paused
#### `paused` _method_
```nupp
function(borrows self: Timeline): boolean
```
##### Arguments
`borrows self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
##### Returns
`boolean`
:
:::
::: api-item tecs.audio.timeline.Timeline.seek
#### `seek` _method_
```nupp
function(exclusive self: Timeline, beat: number)
```
##### Arguments
`exclusive self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
`beat` - `number`
:
:::
::: api-item tecs.audio.timeline.Timeline.follow
#### `follow` _method_
```nupp
function(exclusive self: Timeline, held: (function(): boolean)?)
```
##### Arguments
`exclusive self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
`held` - `(function(): boolean)?`
:
:::
::: api-item tecs.audio.timeline.Timeline.at
#### `at` _method_
```nupp
function(
exclusive self: Timeline,
beat: number,
run: function(at: number): nil
): Cue
```
##### Arguments
`exclusive self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
`beat` - `number`
:
`run` - `function(at: number): nil`
:
##### Returns
[`Cue`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Cue)
:
:::
::: api-item tecs.audio.timeline.Timeline.play
#### `play` _method_
```nupp
function(exclusive self: Timeline, sound: any, options: {[string]: any}?): Cue
```
##### Arguments
`exclusive self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
`sound` - `any`
:
`options` - `{[string]: any}?`
:
##### Returns
[`Cue`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Cue)
:
:::
::: api-item tecs.audio.timeline.Timeline.pending
#### `pending` _method_
```nupp
function(borrows self: Timeline): integer
```
##### Arguments
`borrows self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
##### Returns
`integer`
:
:::
::: api-item tecs.audio.timeline.Timeline.upcoming
#### `upcoming` _method_
```nupp
function(borrows self: Timeline, limit: integer?): {number}
```
##### Arguments
`borrows self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
`limit` - `integer?`
:
##### Returns
`{number}`
:
:::
::: api-item tecs.audio.timeline.Timeline.update
#### `update` _method_
```nupp
function(exclusive self: Timeline): boolean
```
##### Arguments
`exclusive self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
##### Returns
`boolean`
:
:::
::: api-item tecs.audio.timeline.Timeline.close
#### `close` _method_
```nupp
function(exclusive self: Timeline)
```
##### Arguments
`exclusive self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
:::
::: api-item tecs.audio.timeline.Timeline.closedState
#### `closedState` _method_
```nupp
function(borrows self: Timeline): boolean
```
##### Arguments
`borrows self` - [`Timeline`](../../../../modules/tecs/audio/timeline/index.html#tecs.audio.timeline.Timeline)
:
##### Returns
`boolean`
:
:::
:::
:::
::: api-group
## Values
::: api-item tecs.audio.timeline.LOOKAHEAD
### `LOOKAHEAD` _variable_
```nupp
const LOOKAHEAD: number
```
Seconds of lookahead a timeline schedules by default.
:::
:::