or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

components.mdcore.mdeffects.mdevents.mdindex.mdinstruments.mdsignals.mdsources.md

events.mddocs/

0

# Event Scheduling and Sequencing

1

2

Musical event scheduling, loops, sequences, and patterns for creating musical arrangements and synchronized events.

3

4

## Capabilities

5

6

### Event Scheduling

7

8

Core event scheduling for timed musical events.

9

10

```typescript { .api }

11

/**

12

* Single scheduled event

13

*/

14

class ToneEvent {

15

constructor(callback: (time: number, value: any) => void, value?: any);

16

17

/** Event callback function */

18

callback: (time: number, value: any) => void;

19

20

/** Event value */

21

value: any;

22

23

/** Event state */

24

state: "started" | "stopped";

25

26

/** Start the event */

27

start(time?: TransportTime): this;

28

29

/** Stop the event */

30

stop(time?: TransportTime): this;

31

32

/** Cancel the event */

33

cancel(time?: TransportTime): this;

34

}

35

```

36

37

### Looping

38

39

Repeating callback loops synchronized to transport.

40

41

```typescript { .api }

42

/**

43

* Looped callback synchronized to transport

44

*/

45

class Loop {

46

constructor(callback: (time: number) => void, interval: Time);

47

48

/** Loop callback function */

49

callback: (time: number) => void;

50

51

/** Loop interval */

52

interval: Time;

53

54

/** Loop state */

55

state: "started" | "stopped";

56

57

/** Number of iterations (-1 for infinite) */

58

iterations: number;

59

60

/** Playback probability */

61

probability: NormalRange;

62

63

/** Humanization amount */

64

humanize: boolean | Time;

65

66

/** Mute the loop */

67

mute: boolean;

68

69

/** Start the loop */

70

start(time?: TransportTime): this;

71

72

/** Stop the loop */

73

stop(time?: TransportTime): this;

74

75

/** Cancel the loop */

76

cancel(time?: TransportTime): this;

77

}

78

```

79

80

### Sequences

81

82

Step sequencers for playing arrays of musical data.

83

84

```typescript { .api }

85

/**

86

* Step sequencer for playing arrays of events

87

*/

88

class Sequence {

89

constructor(callback: (time: number, note: any) => void, events: any[], subdivision: Time);

90

91

/** Sequence callback */

92

callback: (time: number, note: any) => void;

93

94

/** Events array */

95

events: any[];

96

97

/** Subdivision timing */

98

subdivision: Time;

99

100

/** Playback probability */

101

probability: NormalRange;

102

103

/** Humanization */

104

humanize: boolean | Time;

105

106

/** Mute sequence */

107

mute: boolean;

108

109

/** Loop the sequence */

110

loop: boolean | number;

111

112

/** Loop start point */

113

loopStart: number;

114

115

/** Loop end point */

116

loopEnd: number;

117

118

start(time?: TransportTime, offset?: Time): this;

119

stop(time?: TransportTime): this;

120

121

/** Add event at index */

122

add(index: number, value: any): this;

123

124

/** Remove event at index */

125

remove(index: number): this;

126

127

/** Get event at index */

128

at(index: number): any;

129

}

130

```

131

132

### Patterns

133

134

Algorithmic pattern generation for sequences.

135

136

```typescript { .api }

137

/**

138

* Pattern-based sequence generator

139

*/

140

class Pattern {

141

constructor(callback: (time: number, note: any) => void, values: any[], pattern: PatternType);

142

143

/** Pattern callback */

144

callback: (time: number, note: any) => void;

145

146

/** Values to pattern through */

147

values: any[];

148

149

/** Pattern type */

150

pattern: PatternType;

151

152

/** Pattern index */

153

index: number;

154

155

/** Interval between events */

156

interval: Time;

157

158

/** Playback probability */

159

probability: NormalRange;

160

161

/** Humanization */

162

humanize: boolean | Time;

163

164

start(time?: TransportTime): this;

165

stop(time?: TransportTime): this;

166

}

167

168

type PatternType = "up" | "down" | "upDown" | "downUp" | "alternateUp" | "alternateDown" | "random" | "randomWalk" | "randomOnce";

169

```

170

171

### Musical Parts

172

173

Collections of timed events for complex arrangements.

174

175

```typescript { .api }

176

/**

177

* Collection of timed events

178

*/

179

class Part {

180

constructor(callback: (time: number, value: any) => void, events?: Array<{time: Time, [key: string]: any}>);

181

182

/** Part callback */

183

callback: (time: number, value: any) => void;

184

185

/** Events array */

186

events: Array<{time: Time, [key: string]: any}>;

187

188

/** Loop the part */

189

loop: boolean | number;

190

191

/** Loop start */

192

loopStart: Time;

193

194

/** Loop end */

195

loopEnd: Time;

196

197

/** Playback probability */

198

probability: NormalRange;

199

200

/** Humanization */

201

humanize: boolean | Time;

202

203

start(time?: TransportTime, offset?: Time): this;

204

stop(time?: TransportTime): this;

205

206

/** Add event */

207

add(event: {time: Time, [key: string]: any} | Time, value?: any): this;

208

209

/** Remove event */

210

remove(event: {time: Time, [key: string]: any} | Time, value?: any): this;

211

212

/** Get events at time */

213

at(time: Time): Array<{time: Time, [key: string]: any}>;

214

}

215

```

216

217

**Usage Examples:**

218

219

```typescript

220

import { Loop, Sequence, Part, Synth, getTransport, start } from "tone";

221

222

const synth = new Synth().toDestination();

223

224

await start();

225

226

// Simple loop

227

const loop = new Loop((time) => {

228

synth.triggerAttackRelease("C4", "8n", time);

229

}, "4n");

230

231

// Sequence with notes

232

const seq = new Sequence((time, note) => {

233

synth.triggerAttackRelease(note, "8n", time);

234

}, ["C4", "E4", "G4", "C5"], "8n");

235

236

// Part with timed events

237

const part = new Part((time, event) => {

238

synth.triggerAttackRelease(event.note, event.duration, time);

239

}, [

240

{ time: "0:0:0", note: "C4", duration: "4n" },

241

{ time: "0:1:0", note: "E4", duration: "8n" },

242

{ time: "0:2:0", note: "G4", duration: "4n" }

243

]);

244

245

// Start everything

246

loop.start(0);

247

seq.start("4n");

248

part.start("1m");

249

250

getTransport().start();

251

```

252

253

## Types

254

255

```typescript { .api }

256

type TransportTime = Time | string;

257

258

interface ToneEventOptions {

259

callback: (time: number, value: any) => void;

260

value: any;

261

loop: boolean | number;

262

loopStart: TransportTime;

263

loopEnd: TransportTime;

264

probability: NormalRange;

265

humanize: boolean | Time;

266

mute: boolean;

267

}

268

269

interface LoopOptions {

270

callback: (time: number) => void;

271

interval: Time;

272

iterations: number;

273

probability: NormalRange;

274

humanize: boolean | Time;

275

mute: boolean;

276

}

277

278

interface SequenceOptions {

279

callback: (time: number, note: any) => void;

280

events: any[];

281

subdivision: Time;

282

probability: NormalRange;

283

humanize: boolean | Time;

284

mute: boolean;

285

loop: boolean | number;

286

loopStart: number;

287

loopEnd: number;

288

}

289

```