diff options
author | Phil Burk <[email protected]> | 2016-11-29 08:50:45 -0800 |
---|---|---|
committer | GitHub <[email protected]> | 2016-11-29 08:50:45 -0800 |
commit | 69568a0ab6aaba08eb366b63ce8748fc3a7f256d (patch) | |
tree | a3a9d56ae6001dd80b8633e2781467024e532391 /src/com/jsyn/ports | |
parent | bcd89345103f895b2b5fd508fca4cbe7af033861 (diff) | |
parent | c081ad0ff9f10c0ab530088dc73c1e7f6735c600 (diff) |
Merge pull request #41 from philburk/instruments
Instruments
Diffstat (limited to 'src/com/jsyn/ports')
-rw-r--r-- | src/com/jsyn/ports/InputMixingBlockPart.java | 48 | ||||
-rw-r--r-- | src/com/jsyn/ports/UnitGatePort.java | 8 | ||||
-rw-r--r-- | src/com/jsyn/ports/UnitInputPort.java | 35 |
3 files changed, 57 insertions, 34 deletions
diff --git a/src/com/jsyn/ports/InputMixingBlockPart.java b/src/com/jsyn/ports/InputMixingBlockPart.java index 3211342..5b54b99 100644 --- a/src/com/jsyn/ports/InputMixingBlockPart.java +++ b/src/com/jsyn/ports/InputMixingBlockPart.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,16 +23,18 @@ import com.jsyn.unitgen.UnitGenerator; /** * A UnitInputPort has an array of these, one for each part. - * + * * @author Phil Burk 2009 Mobileer Inc */ public class InputMixingBlockPart extends PortBlockPart { private double[] mixer = new double[Synthesizer.FRAMES_PER_BLOCK]; private double current; + private UnitInputPort unitInputPort; - InputMixingBlockPart(UnitBlockPort unitBlockPort, double defaultValue) { - super(unitBlockPort, defaultValue); + InputMixingBlockPart(UnitInputPort unitInputPort, double defaultValue) { + super(unitInputPort, defaultValue); + this.unitInputPort = unitInputPort; } @Override @@ -52,30 +54,32 @@ public class InputMixingBlockPart extends PortBlockPart { int numConnections = getConnectionCount(); // System.out.println("numConnection = " + numConnections + " for " + // this ); - if (numConnections == 0) - // No connection so just use our own data. - { + if (numConnections == 0) { + // No connection so just use our own data. result = super.getValues(); - } else if (numConnections == 1) - // Grab values from one connected port. - { - PortBlockPart otherPart = getConnection(0); - result = otherPart.getValues(); - } else - // Mix all of the inputs. - { - PortBlockPart otherPart = getConnection(0); - double[] inputs = otherPart.getValues(); + } else { + // Mix all of the connected ports. + double[] inputs; + int jCon = 0; + PortBlockPart otherPart; + // Choose value to initialize the mixer array. + if (unitInputPort.isValueAdded()) { + inputs = super.getValues(); // prime mixer with the set() values + jCon = 0; + } else { + otherPart = getConnection(jCon); + inputs = otherPart.getValues(); // prime mixer with first connected + jCon = 1; + } for (int i = 0; i < mixer.length; i++) { - mixer[i] = inputs[i]; // set directly instead of zeroing first + mixer[i] = inputs[i]; } // Now mix in the remaining inputs. - for (int jCon = 1; jCon < numConnections; jCon++) { + for (; jCon < numConnections; jCon++) { otherPart = getConnection(jCon); - inputs = otherPart.getValues(); for (int i = 0; i < mixer.length; i++) { - mixer[i] += inputs[i]; // mix with previous inputs + mixer[i] += inputs[i]; } } result = mixer; diff --git a/src/com/jsyn/ports/UnitGatePort.java b/src/com/jsyn/ports/UnitGatePort.java index 43d5e7f..700aef8 100644 --- a/src/com/jsyn/ports/UnitGatePort.java +++ b/src/com/jsyn/ports/UnitGatePort.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -97,7 +97,7 @@ public class UnitGatePort extends UnitInputPort { /** * This is called by UnitGenerators. It sets the off value that can be tested using isOff(). - * + * * @param i * @return true if triggered by a positive edge. */ @@ -129,7 +129,7 @@ public class UnitGatePort extends UnitInputPort { /** * Request the containing UnitGenerator be disabled when checkAutoDisabled() is called. This can * be used to reduce CPU load. - * + * * @param autoDisableEnabled */ public void setAutoDisableEnabled(boolean autoDisableEnabled) { diff --git a/src/com/jsyn/ports/UnitInputPort.java b/src/com/jsyn/ports/UnitInputPort.java index 93a7f7a..3eda1f6 100644 --- a/src/com/jsyn/ports/UnitInputPort.java +++ b/src/com/jsyn/ports/UnitInputPort.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,15 +23,15 @@ import com.softsynth.shared.time.TimeStamp; /** * A port that is used to pass values into a UnitGenerator. - * + * * @author Phil Burk 2009 Mobileer Inc */ public class UnitInputPort extends UnitBlockPort implements ConnectableInput, SettablePort { private double minimum = 0.0; private double maximum = 1.0; private double defaultValue = 0.0; - private double[] setValues; + private boolean valueAdded = false; /** * @param numParts typically 1, use 2 for stereo ports @@ -69,7 +69,7 @@ public class UnitInputPort extends UnitBlockPort implements ConnectableInput, Se /** * This is used internally by the SynthesisEngine to execute units based on their connections. - * + * * @param frameCount * @param start * @param limit @@ -128,7 +128,7 @@ public class UnitInputPort extends UnitBlockPort implements ConnectableInput, Se /** * Value of a port based on the set() calls. Not affected by connected ports. - * + * * @param partNum * @return value as set */ @@ -144,7 +144,7 @@ public class UnitInputPort extends UnitBlockPort implements ConnectableInput, Se /** * The minimum and maximum are only used when setting up knobs or other control systems. The * internal values are not clipped to this range. - * + * * @param maximum */ public void setMaximum(double maximum) { @@ -170,7 +170,7 @@ public class UnitInputPort extends UnitBlockPort implements ConnectableInput, Se /** * Convenience function for setting limits on a port. These limits are recommended values when * setting up a GUI. It is possible to set a port to a value outside these limits. - * + * * @param minimum * @param value default value, will be clipped to min/max * @param maximum @@ -187,6 +187,25 @@ public class UnitInputPort extends UnitBlockPort implements ConnectableInput, Se setup(other.getMinimum(), other.getDefault(), other.getMaximum()); } + public boolean isValueAdded() { + return valueAdded; + } + + /** + * If set false then the set() value will be ignored when other ports are connected to this port. + * The sum of the connected port values will be used instead. + * + * If set true then the set() value will be added to the sum of the connected port values. + * This is useful when you want to modulate the set value. + * + * The default is false. + * + * @param valueAdded + */ + public void setValueAdded(boolean valueAdded) { + this.valueAdded = valueAdded; + } + public void connect(int thisPartNum, UnitOutputPort otherPort, int otherPartNum, TimeStamp timeStamp) { otherPort.connect(otherPartNum, this, thisPartNum, timeStamp); |