UNPKG

3.25 kBTypeScriptView Raw
1import { Tone } from "../Tone.js";
2/**
3 * An IntervalTimeline event must have a time and duration
4 */
5export interface IntervalTimelineEvent {
6 time: number;
7 duration: number;
8 [propName: string]: any;
9}
10type IteratorCallback = (event: IntervalTimelineEvent) => void;
11/**
12 * Similar to Tone.Timeline, but all events represent
13 * intervals with both "time" and "duration" times. The
14 * events are placed in a tree structure optimized
15 * for querying an intersection point with the timeline
16 * events. Internally uses an [Interval Tree](https://en.wikipedia.org/wiki/Interval_tree)
17 * to represent the data.
18 * @internal
19 */
20export declare class IntervalTimeline extends Tone {
21 readonly name: string;
22 /**
23 * The root node of the inteval tree
24 */
25 private _root;
26 /**
27 * Keep track of the length of the timeline.
28 */
29 private _length;
30 /**
31 * The event to add to the timeline. All events must
32 * have a time and duration value
33 * @param event The event to add to the timeline
34 */
35 add(event: IntervalTimelineEvent): this;
36 /**
37 * Remove an event from the timeline.
38 * @param event The event to remove from the timeline
39 */
40 remove(event: IntervalTimelineEvent): this;
41 /**
42 * The number of items in the timeline.
43 * @readOnly
44 */
45 get length(): number;
46 /**
47 * Remove events whose time time is after the given time
48 * @param after The time to query.
49 */
50 cancel(after: number): this;
51 /**
52 * Set the root node as the given node
53 */
54 private _setRoot;
55 /**
56 * Replace the references to the node in the node's parent
57 * with the replacement node.
58 */
59 private _replaceNodeInParent;
60 /**
61 * Remove the node from the tree and replace it with
62 * a successor which follows the schema.
63 */
64 private _removeNode;
65 /**
66 * Rotate the tree to the left
67 */
68 private _rotateLeft;
69 /**
70 * Rotate the tree to the right
71 */
72 private _rotateRight;
73 /**
74 * Balance the BST
75 */
76 private _rebalance;
77 /**
78 * Get an event whose time and duration span the give time. Will
79 * return the match whose "time" value is closest to the given time.
80 * @return The event which spans the desired time
81 */
82 get(time: number): IntervalTimelineEvent | null;
83 /**
84 * Iterate over everything in the timeline.
85 * @param callback The callback to invoke with every item
86 */
87 forEach(callback: IteratorCallback): this;
88 /**
89 * Iterate over everything in the array in which the given time
90 * overlaps with the time and duration time of the event.
91 * @param time The time to check if items are overlapping
92 * @param callback The callback to invoke with every item
93 */
94 forEachAtTime(time: number, callback: IteratorCallback): this;
95 /**
96 * Iterate over everything in the array in which the time is greater
97 * than or equal to the given time.
98 * @param time The time to check if items are before
99 * @param callback The callback to invoke with every item
100 */
101 forEachFrom(time: number, callback: IteratorCallback): this;
102 /**
103 * Clean up
104 */
105 dispose(): this;
106}
107export {};