aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/jsyn/ports/InputMixingBlockPart.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/jsyn/ports/InputMixingBlockPart.java')
-rw-r--r--src/com/jsyn/ports/InputMixingBlockPart.java48
1 files changed, 26 insertions, 22 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;