UNPKG

2.57 kBTypeScriptView Raw
1import { TimeBaseClass, TimeBaseUnit, TimeExpression, TimeValue } from "./TimeBase.js";
2import { BarsBeatsSixteenths, MidiNote, Seconds, Subdivision, Ticks, Time } from "./Units.js";
3/**
4 * TimeClass is a primitive type for encoding and decoding Time values.
5 * TimeClass can be passed into the parameter of any method which takes time as an argument.
6 * @param val The time value.
7 * @param units The units of the value.
8 * @example
9 * const time = Tone.Time("4n"); // a quarter note
10 * @category Unit
11 */
12export declare class TimeClass<Type extends Seconds | Ticks = Seconds, Unit extends string = TimeBaseUnit> extends TimeBaseClass<Type, Unit> {
13 readonly name: string;
14 protected _getExpressions(): TimeExpression<Type>;
15 /**
16 * Quantize the time by the given subdivision. Optionally add a
17 * percentage which will move the time value towards the ideal
18 * quantized value by that percentage.
19 * @param subdiv The subdivision to quantize to
20 * @param percent Move the time value towards the quantized value by a percentage.
21 * @example
22 * Tone.Time(21).quantize(2); // returns 22
23 * Tone.Time(0.6).quantize("4n", 0.5); // returns 0.55
24 */
25 quantize(subdiv: Time, percent?: number): Type;
26 /**
27 * Convert a Time to Notation. The notation values are will be the
28 * closest representation between 1m to 128th note.
29 * @return {Notation}
30 * @example
31 * // if the Transport is at 120bpm:
32 * Tone.Time(2).toNotation(); // returns "1m"
33 */
34 toNotation(): Subdivision;
35 /**
36 * Return the time encoded as Bars:Beats:Sixteenths.
37 */
38 toBarsBeatsSixteenths(): BarsBeatsSixteenths;
39 /**
40 * Return the time in ticks.
41 */
42 toTicks(): Ticks;
43 /**
44 * Return the time in seconds.
45 */
46 toSeconds(): Seconds;
47 /**
48 * Return the value as a midi note.
49 */
50 toMidi(): MidiNote;
51 protected _now(): Type;
52}
53/**
54 * Create a TimeClass from a time string or number. The time is computed against the
55 * global Tone.Context. To use a specific context, use {@link TimeClass}
56 * @param value A value which represents time
57 * @param units The value's units if they can't be inferred by the value.
58 * @category Unit
59 * @example
60 * const time = Tone.Time("4n").toSeconds();
61 * console.log(time);
62 * @example
63 * const note = Tone.Time(1).toNotation();
64 * console.log(note);
65 * @example
66 * const freq = Tone.Time(0.5).toFrequency();
67 * console.log(freq);
68 */
69export declare function Time(value?: TimeValue, units?: TimeBaseUnit): TimeClass<Seconds>;