From 72e877ff67549f9da416ed540453bdc371c69959 Mon Sep 17 00:00:00 2001 From: Yotam Mann Date: Mon, 12 Aug 2019 00:13:52 -0400 Subject: [PATCH] hooking up onsilence --- Tone/instrument/Synth.test.ts | 2 ++ Tone/instrument/Synth.ts | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Tone/instrument/Synth.test.ts b/Tone/instrument/Synth.test.ts index 7c318cc9..9d485860 100644 --- a/Tone/instrument/Synth.test.ts +++ b/Tone/instrument/Synth.test.ts @@ -2,6 +2,7 @@ import { expect } from "chai"; import { BasicTests } from "test/helper/Basic"; import { CompareToFile } from "test/helper/CompareToFile"; import { InstrumentTest } from "test/helper/InstrumentTests"; +import { MonophonicTest } from "test/helper/MonophonicTests"; import { Offline } from "test/helper/Offline"; import { Frequency } from "Tone/core/type/Frequency"; import { Synth } from "./Synth"; @@ -10,6 +11,7 @@ describe("Synth", () => { BasicTests(Synth); InstrumentTest(Synth, "C4"); + MonophonicTest(Synth, "C4"); it("matches a file basic", () => { return CompareToFile(() => { diff --git a/Tone/instrument/Synth.ts b/Tone/instrument/Synth.ts index c1c895cf..2b5134ff 100644 --- a/Tone/instrument/Synth.ts +++ b/Tone/instrument/Synth.ts @@ -1,18 +1,27 @@ -import { Signal } from "Tone/signal"; import { AmplitudeEnvelope } from "../component/envelope/AmplitudeEnvelope"; import { Envelope, EnvelopeOptions } from "../component/envelope/Envelope"; +import { ToneAudioNode, ToneAudioNodeOptions } from "../core/context/ToneAudioNode"; import { Cents, Frequency, Time } from "../core/type/Units"; import { omitFromObject, optionsFromArguments } from "../core/util/Defaults"; import { readOnly } from "../core/util/Interface"; import { RecursivePartial } from "../core/util/Interface"; +import { Signal } from "../signal/Signal"; import { OmniOscillator } from "../source/oscillator/OmniOscillator"; import { OmniOscillatorConstructorOptions } from "../source/oscillator/OscillatorInterface"; -import { Source } from "../source/Source"; +import { Source, SourceOptions } from "../source/Source"; import { Monophonic, MonophonicOptions } from "./Monophonic"; +/** + * The settable oscillator options. Does not include optiosn like + * "context" and "frequency" since those are controlled by the synth + */ +type LimitedOscillatorOptions = Omit< + Omit, + "frequency" | "detune">; + export interface SynthOptions extends MonophonicOptions { - oscillator: OmniOscillatorConstructorOptions; - envelope: EnvelopeOptions; + oscillator: LimitedOscillatorOptions; + envelope: Omit; } /** @@ -58,6 +67,7 @@ export class Synth extends Monophonic { this.oscillator = new OmniOscillator(Object.assign({ context: this.context, + onstop: () => this.onsilence(this), }, options.oscillator)); this.frequency = this.oscillator.frequency; @@ -75,7 +85,7 @@ export class Synth extends Monophonic { static getDefaults(): SynthOptions { return Object.assign(Monophonic.getDefaults(), { envelope: Object.assign( - omitFromObject(Envelope.getDefaults(), Object.keys(Source.getDefaults())), + omitFromObject(Envelope.getDefaults(), Object.keys(ToneAudioNode.getDefaults())), { attack : 0.005, decay : 0.1, @@ -84,7 +94,7 @@ export class Synth extends Monophonic { }, ), oscillator: Object.assign( - omitFromObject(OmniOscillator.getDefaults(), Object.keys(Source.getDefaults())), + omitFromObject(OmniOscillator.getDefaults(), [...Object.keys(Source.getDefaults()), "frequency", "detune"]), { type: "triangle", },