Tone.js/Tone/core/clock/TickSignal.ts

94 lines
2.4 KiB
TypeScript
Raw Normal View History

import { Signal, SignalOptions } from "../../signal/Signal";
import { BPM, Hertz, Seconds, Ticks, Time } from "../type/Units";
2019-05-22 03:37:03 +00:00
import { optionsFromArguments } from "../util/Defaults";
import { TickParam } from "./TickParam";
2019-05-22 03:37:03 +00:00
interface TickSignalOptions<T> extends SignalOptions<T> {
value: T;
2019-05-22 03:37:03 +00:00
multiplier: number;
}
/**
* TickSignal extends Tone.Signal, but adds the capability
* to calculate the number of elapsed ticks. exponential and target curves
* are approximated with multiple linear ramps.
*
* Thank you Bruno Dias, H. Sofia Pinto, and David M. Matos,
* for your [WAC paper](https://smartech.gatech.edu/bitstream/handle/1853/54588/WAC2016-49.pdf)
* describing integrating timing functions for tempo calculations.
2019-08-21 20:59:01 +00:00
* @category Core
2019-05-22 03:37:03 +00:00
*/
export class TickSignal<Type extends Hertz | BPM> extends Signal<Type> {
2019-05-22 03:37:03 +00:00
2019-09-04 23:18:44 +00:00
readonly name: string = "TickSignal";
2019-05-22 03:37:03 +00:00
/**
* The param which controls the output signal value
*/
protected _param: TickParam<Type>;
2019-05-22 03:37:03 +00:00
2019-08-21 20:59:01 +00:00
/**
* @param value The initial value of the signal
*/
constructor(value?: Type);
constructor(options: Partial<TickSignalOptions<Type>>);
2019-05-22 03:37:03 +00:00
constructor() {
super(optionsFromArguments(TickSignal.getDefaults(), arguments, ["value"]));
const options = optionsFromArguments(TickSignal.getDefaults(), arguments, ["value"]);
this._param = new TickParam({
context: this.context,
convert: options.convert,
multiplier : options.multiplier,
param: this._constantSource.offset,
units: options.units,
value: options.value,
2019-05-22 03:37:03 +00:00
});
}
static getDefaults(): TickSignalOptions<any> {
return Object.assign(Signal.getDefaults(), {
2019-05-22 03:37:03 +00:00
multiplier: 1,
units: "hertz",
value: 1,
});
}
ticksToTime(ticks: Ticks, when: Time): Seconds {
return this._param.ticksToTime(ticks, when);
2019-05-22 03:37:03 +00:00
}
timeToTicks(duration: Time, when: Time): Ticks {
return this._param.timeToTicks(duration, when);
2019-05-22 03:37:03 +00:00
}
getTimeOfTick(tick: Ticks): Seconds {
return this._param.getTimeOfTick(tick);
2019-05-22 03:37:03 +00:00
}
getDurationOfTicks(ticks: Ticks, time: Time): Seconds {
return this._param.getDurationOfTicks(ticks, time);
2019-05-22 03:37:03 +00:00
}
getTicksAtTime(time: Time): Ticks {
return this._param.getTicksAtTime(time);
2019-05-22 03:37:03 +00:00
}
/**
* A multiplier on the bpm value. Useful for setting a PPQ relative to the base frequency value.
*/
get multiplier(): number {
return this._param.multiplier;
2019-05-22 03:37:03 +00:00
}
set multiplier(m: number) {
this._param.multiplier = m;
2019-05-22 03:37:03 +00:00
}
2019-07-11 03:33:12 +00:00
dispose(): this {
super.dispose();
this._param.dispose();
2019-07-11 03:33:12 +00:00
return this;
}
2019-05-22 03:37:03 +00:00
}