Skip to content

Commit

Permalink
Keep some stopped SoundObjects in synth network (closes #95)
Browse files Browse the repository at this point in the history
Keep stopped SoundObjects in the synth network as long as they're still
connected to some non-output unit (typically an analyzer)

(This can re-introduce some memory leakage.)
  • Loading branch information
kevinstadler committed Mar 20, 2024
1 parent efe6524 commit 6110595
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/processing/sound/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,15 @@ protected void disconnectFromOutput(int channel, UnitSource source, int part) {
source.getOutput().disconnect(part, this.volume[channel].inputA, 0);
}

protected void disconnectFromOutput(UnitSource source) {
for (Multiply o : this.volume) {
// keep it generic: disconnect all parts from all outputs
for (int i = 0; i < source.getOutput().getNumParts(); i++) {
source.getOutput().disconnect(i, o.inputA, 0);
}
}
}

protected void play(UnitSource source) {
// add unit to synth
UnitGenerator generator = source.getUnitGenerator();
Expand All @@ -544,13 +553,12 @@ protected void play(UnitSource source) {

protected void stop(UnitSource source) {
if (this.addedUnits.contains(source.getUnitGenerator())) {
// this is usually just the two-part output of a JSynCircuit, but let's
// keep it generic just in case
for (int i : IntStream.range(0, source.getOutput().getNumParts()).toArray()) {
source.getOutput().disconnectAll(i);
// disconnect from any and all outputs
this.disconnectFromOutput(source);
// don't remove if it's still connected (typically to an analyzer)
if (!source.getOutput().isConnected()) {
this.remove(source.getUnitGenerator());
}
// removal happens inside
this.remove(source.getUnitGenerator());
}
}

Expand Down

0 comments on commit 6110595

Please sign in to comment.