Skip to content

Commit

Permalink
Add MultiChannel.connectToOutput() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinstadler committed Sep 29, 2023
1 parent d37fa0d commit 3526a52
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/processing/sound/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
27 changes: 25 additions & 2 deletions src/processing/sound/MultiChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*
Expand Down
19 changes: 16 additions & 3 deletions src/processing/sound/Oscillator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3526a52

Please sign in to comment.