1 | import { Tone } from "../Tone.js";
|
2 | import { Seconds } from "../type/Units.js";
|
3 | type TimelineSearchParam = "ticks" | "time";
|
4 | /**
|
5 | * The options object for Timeline
|
6 | */
|
7 | interface TimelineOptions {
|
8 | memory: number;
|
9 | increasing: boolean;
|
10 | }
|
11 | /**
|
12 | * An event must have a time number
|
13 | */
|
14 | export interface TimelineEvent {
|
15 | time: number;
|
16 | }
|
17 | /**
|
18 | * A Timeline class for scheduling and maintaining state
|
19 | * along a timeline. All events must have a "time" property.
|
20 | * Internally, events are stored in time order for fast
|
21 | * retrieval.
|
22 | * @internal
|
23 | */
|
24 | export declare class Timeline<GenericEvent extends TimelineEvent> extends Tone {
|
25 | readonly name: string;
|
26 | /**
|
27 | * The memory of the timeline, i.e.
|
28 | * how many events in the past it will retain
|
29 | */
|
30 | memory: number;
|
31 | /**
|
32 | * The array of scheduled timeline events
|
33 | */
|
34 | protected _timeline: GenericEvent[];
|
35 | /**
|
36 | * If the time value must always be greater than or equal to the last
|
37 | * element on the list.
|
38 | */
|
39 | increasing: boolean;
|
40 | /**
|
41 | * @param memory The number of previous events that are retained.
|
42 | */
|
43 | constructor(memory?: number);
|
44 | constructor(options?: Partial<TimelineOptions>);
|
45 | static getDefaults(): TimelineOptions;
|
46 | /**
|
47 | * The number of items in the timeline.
|
48 | */
|
49 | get length(): number;
|
50 | /**
|
51 | * Insert an event object onto the timeline. Events must have a "time" attribute.
|
52 | * @param event The event object to insert into the timeline.
|
53 | */
|
54 | add(event: GenericEvent): this;
|
55 | /**
|
56 | * Remove an event from the timeline.
|
57 | * @param {Object} event The event object to remove from the list.
|
58 | * @returns {Timeline} this
|
59 | */
|
60 | remove(event: GenericEvent): this;
|
61 | /**
|
62 | * Get the nearest event whose time is less than or equal to the given time.
|
63 | * @param time The time to query.
|
64 | */
|
65 | get(time: number, param?: TimelineSearchParam): GenericEvent | null;
|
66 | /**
|
67 | * Return the first event in the timeline without removing it
|
68 | * @returns {Object} The first event object
|
69 | */
|
70 | peek(): GenericEvent | undefined;
|
71 | /**
|
72 | * Return the first event in the timeline and remove it
|
73 | */
|
74 | shift(): GenericEvent | undefined;
|
75 | /**
|
76 | * Get the event which is scheduled after the given time.
|
77 | * @param time The time to query.
|
78 | */
|
79 | getAfter(time: number, param?: TimelineSearchParam): GenericEvent | null;
|
80 | /**
|
81 | * Get the event before the event at the given time.
|
82 | * @param time The time to query.
|
83 | */
|
84 | getBefore(time: number): GenericEvent | null;
|
85 | /**
|
86 | * Cancel events at and after the given time
|
87 | * @param after The time to query.
|
88 | */
|
89 | cancel(after: number): this;
|
90 | /**
|
91 | * Cancel events before or equal to the given time.
|
92 | * @param time The time to cancel before.
|
93 | */
|
94 | cancelBefore(time: number): this;
|
95 | /**
|
96 | * Returns the previous event if there is one. null otherwise
|
97 | * @param event The event to find the previous one of
|
98 | * @return The event right before the given event
|
99 | */
|
100 | previousEvent(event: GenericEvent): GenericEvent | null;
|
101 | /**
|
102 | * Does a binary search on the timeline array and returns the
|
103 | * nearest event index whose time is after or equal to the given time.
|
104 | * If a time is searched before the first index in the timeline, -1 is returned.
|
105 | * If the time is after the end, the index of the last item is returned.
|
106 | */
|
107 | protected _search(time: number, param?: TimelineSearchParam): number;
|
108 | /**
|
109 | * Internal iterator. Applies extra safety checks for
|
110 | * removing items from the array.
|
111 | */
|
112 | private _iterate;
|
113 | /**
|
114 | * Iterate over everything in the array
|
115 | * @param callback The callback to invoke with every item
|
116 | */
|
117 | forEach(callback: (event: GenericEvent) => void): this;
|
118 | /**
|
119 | * Iterate over everything in the array at or before the given time.
|
120 | * @param time The time to check if items are before
|
121 | * @param callback The callback to invoke with every item
|
122 | */
|
123 | forEachBefore(time: Seconds, callback: (event: GenericEvent) => void): this;
|
124 | /**
|
125 | * Iterate over everything in the array after the given time.
|
126 | * @param time The time to check if items are before
|
127 | * @param callback The callback to invoke with every item
|
128 | */
|
129 | forEachAfter(time: Seconds, callback: (event: GenericEvent) => void): this;
|
130 | /**
|
131 | * Iterate over everything in the array between the startTime and endTime.
|
132 | * The timerange is inclusive of the startTime, but exclusive of the endTime.
|
133 | * range = [startTime, endTime).
|
134 | * @param startTime The time to check if items are before
|
135 | * @param endTime The end of the test interval.
|
136 | * @param callback The callback to invoke with every item
|
137 | */
|
138 | forEachBetween(startTime: number, endTime: number, callback: (event: GenericEvent) => void): this;
|
139 | /**
|
140 | * Iterate over everything in the array at or after the given time. Similar to
|
141 | * forEachAfter, but includes the item(s) at the given time.
|
142 | * @param time The time to check if items are before
|
143 | * @param callback The callback to invoke with every item
|
144 | */
|
145 | forEachFrom(time: number, callback: (event: GenericEvent) => void): this;
|
146 | /**
|
147 | * Iterate over everything in the array at the given time
|
148 | * @param time The time to check if items are before
|
149 | * @param callback The callback to invoke with every item
|
150 | */
|
151 | forEachAtTime(time: number, callback: (event: GenericEvent) => void): this;
|
152 | /**
|
153 | * Clean up.
|
154 | */
|
155 | dispose(): this;
|
156 | }
|
157 | export {};
|