mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-15 08:17:07 +00:00
removing circular dependencies in types
This commit is contained in:
parent
d866dfe66a
commit
c658980915
4 changed files with 40 additions and 7 deletions
|
@ -34,3 +34,27 @@ export function gainToDb(gain: GainFactor): Decibels {
|
|||
export function intervalToFrequencyRatio(interval: Interval): number {
|
||||
return Math.pow(2, (interval / 12));
|
||||
}
|
||||
|
||||
/**
|
||||
* The Global [concert tuning pitch](https://en.wikipedia.org/wiki/Concert_pitch) which is used
|
||||
* to generate all the other pitch values from notes. A4's values in Hertz.
|
||||
*/
|
||||
let A4: Hertz = 440;
|
||||
|
||||
export function getA4(): Hertz {
|
||||
return A4;
|
||||
}
|
||||
|
||||
export function setA4(freq: Hertz): void {
|
||||
A4 = freq;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a frequency value to a MIDI note.
|
||||
* @param frequency The value to frequency value to convert.
|
||||
* @example
|
||||
* Frequency.ftom(440); // returns 69
|
||||
*/
|
||||
export function ftom(frequency: Hertz): MidiNote {
|
||||
return 69 + Math.round(12 * Math.log2(frequency / A4));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { getContext } from "../Global";
|
||||
import { intervalToFrequencyRatio } from "./Conversions";
|
||||
import { ftom, getA4, setA4 } from "./Conversions";
|
||||
import { TimeClass } from "./Time";
|
||||
import { TypeBaseExpression } from "./TypeBase";
|
||||
|
||||
|
@ -21,7 +22,12 @@ export class FrequencyClass extends TimeClass<Hertz> {
|
|||
* The [concert tuning pitch](https://en.wikipedia.org/wiki/Concert_pitch) which is used
|
||||
* to generate all the other pitch values from notes. A4's values in Hertz.
|
||||
*/
|
||||
static A4: Hertz = 440;
|
||||
static get A4(): Hertz {
|
||||
return getA4();
|
||||
}
|
||||
static set A4(freq: Hertz) {
|
||||
setA4(freq);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// AUGMENT BASE EXPRESSIONS
|
||||
|
@ -202,7 +208,7 @@ export class FrequencyClass extends TimeClass<Hertz> {
|
|||
* Frequency.ftom(440); // returns 69
|
||||
*/
|
||||
static ftom(frequency: Hertz): MidiNote {
|
||||
return 69 + Math.round(12 * Math.log2(frequency / FrequencyClass.A4));
|
||||
return ftom(frequency);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { getContext } from "../Global";
|
||||
import { FrequencyClass } from "./Frequency";
|
||||
import { ftom } from "./Conversions";
|
||||
import { TypeBaseClass, TypeBaseExpression, TypeBaseUnits } from "./TypeBase";
|
||||
|
||||
/**
|
||||
|
@ -124,7 +124,7 @@ export class TimeClass<Type extends Seconds | Ticks = Seconds> extends TypeBaseC
|
|||
* Return the value as a midi note.
|
||||
*/
|
||||
toMidi(): MidiNote {
|
||||
return FrequencyClass.ftom(this.toFrequency());
|
||||
return ftom(this.toFrequency());
|
||||
}
|
||||
|
||||
protected _now(): Type {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import { Tone } from "../../core/Tone";
|
||||
import { Context } from "../context/Context";
|
||||
import { ToneWithContext, ToneWithContextOptions } from "../context/ToneWithContext";
|
||||
import { getContext } from "../Global";
|
||||
import { isDefined, isObject , isString, isUndef } from "../util/TypeCheck";
|
||||
|
||||
interface TypeBaseClassOptions extends ToneWithContextOptions {
|
||||
interface TypeBaseClassOptions {
|
||||
value?: TypeBaseClassValue;
|
||||
units?: TypeBaseUnits;
|
||||
context: Context;
|
||||
}
|
||||
|
||||
type TypeBaseClassValue = string | number | TimeObject | TypeBaseClass<any>;
|
||||
|
@ -60,7 +61,9 @@ export abstract class TypeBaseClass<Type extends Seconds | Hertz | Ticks> extend
|
|||
}
|
||||
|
||||
static getDefaults(): TypeBaseClassOptions {
|
||||
return ToneWithContext.getDefaults();
|
||||
return {
|
||||
context : getContext(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue