UNPKG

4.1 kBTypeScriptView Raw
1import { NormalRange, Positive, Seconds, Ticks, Time, TransportTime } from "../core/type/Units.js";
2import { ToneEvent, ToneEventCallback, ToneEventOptions } from "./ToneEvent.js";
3type SequenceEventDescription<T> = Array<T | SequenceEventDescription<T>>;
4interface SequenceOptions<T> extends Omit<ToneEventOptions<T>, "value"> {
5 loopStart: number;
6 loopEnd: number;
7 subdivision: Time;
8 events: SequenceEventDescription<T>;
9}
10/**
11 * A sequence is an alternate notation of a part. Instead
12 * of passing in an array of [time, event] pairs, pass
13 * in an array of events which will be spaced at the
14 * given subdivision. Sub-arrays will subdivide that beat
15 * by the number of items are in the array.
16 * Sequence notation inspiration from [Tidal Cycles](http://tidalcycles.org/)
17 * @example
18 * const synth = new Tone.Synth().toDestination();
19 * const seq = new Tone.Sequence((time, note) => {
20 * synth.triggerAttackRelease(note, 0.1, time);
21 * // subdivisions are given as subarrays
22 * }, ["C4", ["E4", "D4", "E4"], "G4", ["A4", "G4"]]).start(0);
23 * Tone.Transport.start();
24 * @category Event
25 */
26export declare class Sequence<ValueType = any> extends ToneEvent<ValueType> {
27 readonly name: string;
28 /**
29 * The subdivison of each note
30 */
31 private _subdivision;
32 /**
33 * The object responsible for scheduling all of the events
34 */
35 private _part;
36 /**
37 * private reference to all of the sequence proxies
38 */
39 private _events;
40 /**
41 * The proxied array
42 */
43 private _eventsArray;
44 /**
45 * @param callback The callback to invoke with every note
46 * @param events The sequence of events
47 * @param subdivision The subdivision between which events are placed.
48 */
49 constructor(callback?: ToneEventCallback<ValueType>, events?: SequenceEventDescription<ValueType>, subdivision?: Time);
50 constructor(options?: Partial<SequenceOptions<ValueType>>);
51 static getDefaults(): SequenceOptions<any>;
52 /**
53 * The internal callback for when an event is invoked
54 */
55 private _seqCallback;
56 /**
57 * The sequence
58 */
59 get events(): any[];
60 set events(s: any[]);
61 /**
62 * Start the part at the given time.
63 * @param time When to start the part.
64 * @param offset The offset index to start at
65 */
66 start(time?: TransportTime, offset?: number): this;
67 /**
68 * Stop the part at the given time.
69 * @param time When to stop the part.
70 */
71 stop(time?: TransportTime): this;
72 /**
73 * The subdivision of the sequence. This can only be
74 * set in the constructor. The subdivision is the
75 * interval between successive steps.
76 */
77 get subdivision(): Seconds;
78 /**
79 * Create a sequence proxy which can be monitored to create subsequences
80 */
81 private _createSequence;
82 /**
83 * When the sequence has changed, all of the events need to be recreated
84 */
85 private _eventsUpdated;
86 /**
87 * reschedule all of the events that need to be rescheduled
88 */
89 private _rescheduleSequence;
90 /**
91 * Get the time of the index given the Sequence's subdivision
92 * @param index
93 * @return The time of that index
94 */
95 private _indexTime;
96 /**
97 * Clear all of the events
98 */
99 clear(): this;
100 dispose(): this;
101 get loop(): boolean | number;
102 set loop(l: boolean | number);
103 /**
104 * The index at which the sequence should start looping
105 */
106 get loopStart(): number;
107 set loopStart(index: number);
108 /**
109 * The index at which the sequence should end looping
110 */
111 get loopEnd(): number;
112 set loopEnd(index: number);
113 get startOffset(): Ticks;
114 set startOffset(start: Ticks);
115 get playbackRate(): Positive;
116 set playbackRate(rate: Positive);
117 get probability(): NormalRange;
118 set probability(prob: NormalRange);
119 get progress(): NormalRange;
120 get humanize(): boolean | Time;
121 set humanize(variation: boolean | Time);
122 /**
123 * The number of scheduled events
124 */
125 get length(): number;
126}
127export {};