From 3526a527ed542ced57a650c67b3175c58d563eb1 Mon Sep 17 00:00:00 2001 From: kevinstadler Date: Fri, 29 Sep 2023 18:13:45 +0200 Subject: [PATCH] Add MultiChannel.connectToOutput() methods --- src/processing/sound/Engine.java | 4 ++++ src/processing/sound/MultiChannel.java | 27 ++++++++++++++++++++++++-- src/processing/sound/Oscillator.java | 19 +++++++++++++++--- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/processing/sound/Engine.java b/src/processing/sound/Engine.java index b99b4ae..f852925 100644 --- a/src/processing/sound/Engine.java +++ b/src/processing/sound/Engine.java @@ -508,6 +508,10 @@ protected void connectToOutput(int channel, UnitSource source, int part) { source.getOutput().connect(part, this.volume[channel].inputA, 0); } + protected void disconnectFromOutput(int channel, UnitSource source) { + this.disconnectFromOutput(channel, source, 0); + } + protected void disconnectFromOutput(int channel, UnitSource source, int part) { source.getOutput().disconnect(part, this.volume[channel].inputA, 0); } diff --git a/src/processing/sound/MultiChannel.java b/src/processing/sound/MultiChannel.java index 77165b9..d7daa63 100644 --- a/src/processing/sound/MultiChannel.java +++ b/src/processing/sound/MultiChannel.java @@ -12,8 +12,8 @@ public abstract class MultiChannel { /** * Controls which output channel sounds will be played back to. * - * After selecting a new output channel, all sounds that start `play()`ing will - * be sent to that channel. + * After selecting a new output channel, all sounds that start `play()`ing + * will be sent to that channel. * * @param channel the channel number to send sounds to * @return the channel number that sounds will be sent to @@ -30,6 +30,29 @@ public static int activeChannel() { return Engine.getEngine().outputChannel; } + /** + * Connect a SoundObject to the given output channel. + * + * Use this only for SoundObjects that are already playing back on some + * channel, which you want to have playing back on another channel at the same + * time. + */ + public static void connectToOutput(SoundObject o, int channel) { + Engine.getEngine().connectToOutput(channel, o.circuit); + } + + /** + * Disconnect a SoundObject from the given output channel. + * + * Only use on SoundObjects that were previously connected using + * connectToOutput() + * + * @see connectToOutput() + */ + public static void disconnectFromOutput(SoundObject o, int channel) { + Engine.getEngine().disconnectFromOutput(channel, o.circuit); + } + /** * Gets the number of output channels available on an output device * diff --git a/src/processing/sound/Oscillator.java b/src/processing/sound/Oscillator.java index fbdca3e..40da3cf 100644 --- a/src/processing/sound/Oscillator.java +++ b/src/processing/sound/Oscillator.java @@ -20,14 +20,22 @@ protected Oscillator(PApplet theParent, JSynOscillator oscillator) { } /** - * Set the frequency of the oscillator in Hz. + * Sets the frequency of the oscillator. * @webref Oscillators:Oscillator - * @param freq A floating point value of the oscillator in Hz. - **/ + * @param freq the desired oscillator frequency in Hertz + */ public void freq(float freq) { // TODO check positive? this.oscillator.frequency.set(freq); } + + /* + * Modulates the frequency of this oscillator using another (low frequency) + * oscillator. + public void modulateFreq(SoundObject modulator) { + this.oscillator.frequency.connect(modulator.circuit.source); + } + */ public void play() { super.play(); @@ -39,6 +47,10 @@ public void play(float freq, float amp) { this.play(); } + /** + * @deprecated + * @nowebref + */ public void play(float freq, float amp, float add) { this.add(add); this.play(freq, amp); @@ -71,6 +83,7 @@ public void set(float freq, float amp, float pos) { /** * @deprecated + * @nowebref */ public void set(float freq, float amp, float add, float pos) { this.freq(freq);