diff options
author | Phil Burk <[email protected]> | 2016-08-02 07:52:17 -0700 |
---|---|---|
committer | Phil Burk <[email protected]> | 2016-10-24 08:29:20 -0700 |
commit | 580fea450ec0982d0bd8be589f00566267e7b0d1 (patch) | |
tree | 0420f768fc7c63208b1720232c447e17af9017af /src/com/jsyn/ports/InputMixingBlockPart.java | |
parent | a6583e89166f7477a675cf3094a91b303ba7850a (diff) |
Instruments: add better synth, pitch control
Diffstat (limited to 'src/com/jsyn/ports/InputMixingBlockPart.java')
-rw-r--r-- | src/com/jsyn/ports/InputMixingBlockPart.java | 48 |
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; |