diff options
author | Phil Burk <[email protected]> | 2016-11-30 19:26:29 -0800 |
---|---|---|
committer | GitHub <[email protected]> | 2016-11-30 19:26:29 -0800 |
commit | 10ffa9acf32c7fb40f084d9cef9a0ff5e608fc0c (patch) | |
tree | c6e70f7a076bb65484f52709864975b21afab75d /src/com/jsyn/util | |
parent | 5cc223574b43d3f72b746e8f0bb4f31cbd2fd52f (diff) | |
parent | cc4bcfe2aa049543ee759823bc0a72282e4a1dc5 (diff) |
Merge pull request #43 from philburk/rc-1678
last minute changes for 16.7.8
Diffstat (limited to 'src/com/jsyn/util')
-rw-r--r-- | src/com/jsyn/util/MultiChannelSynthesizer.java | 60 | ||||
-rw-r--r-- | src/com/jsyn/util/PolyphonicInstrument.java | 2 |
2 files changed, 54 insertions, 8 deletions
diff --git a/src/com/jsyn/util/MultiChannelSynthesizer.java b/src/com/jsyn/util/MultiChannelSynthesizer.java index 6db0790..8027994 100644 --- a/src/com/jsyn/util/MultiChannelSynthesizer.java +++ b/src/com/jsyn/util/MultiChannelSynthesizer.java @@ -52,6 +52,8 @@ public class MultiChannelSynthesizer { private Synthesizer synth; private TwoInDualOut outputUnit; private ChannelContext[] channels; + private final static int MAX_VELOCITY = 127; + private double mMasterAmplitude = 0.25; private class ChannelGroupContext { private VoiceDescription voiceDescription; @@ -83,7 +85,6 @@ public class MultiChannelSynthesizer { private Pan panner; private double vibratoRate = 5.0; private double bendRangeOctaves = 2.0 / 12.0; -// private double bendRangeOctaves = 0.0 / 12.0; private int presetIndex; private ChannelGroupContext groupContext; VoiceOperation voiceOperation = new VoiceOperation() { @@ -120,7 +121,6 @@ public class MultiChannelSynthesizer { volumeMultiplier.output.connect(panner.input); panner.output.connect(0, outputUnit.inputA, 0); // Use MultiPassthrough panner.output.connect(1, outputUnit.inputB, 0); - } private void connectVoice(UnitVoice voice) { @@ -157,13 +157,12 @@ public class MultiChannelSynthesizer { presetIndex = programWrapped; } - void noteOff(int noteNumber, int velocity) { + void noteOff(int noteNumber, double amplitude) { groupContext.allocator.noteOff(noteNumber, synth.createTimeStamp()); } - void noteOn(int noteNumber, int velocity) { + void noteOn(int noteNumber, double amplitude) { double frequency = AudioMath.pitchToFrequency(noteNumber); - double amplitude = velocity / (4 * 128.0); TimeStamp timeStamp = synth.createTimeStamp(); //System.out.println("noteOn(noteNumber) -> " + frequency + " Hz"); groupContext.allocator.noteOn(noteNumber, frequency, amplitude, voiceOperation, timeStamp); @@ -257,14 +256,48 @@ public class MultiChannelSynthesizer { channelContext.programChange(program); } + + /** + * Turn off a note. + * @param channel + * @param noteNumber + * @param velocity between 0 and 127, will be scaled by masterAmplitude + */ public void noteOff(int channel, int noteNumber, int velocity) { + double amplitude = velocity * (1.0 / MAX_VELOCITY); + noteOff(channel, noteNumber, amplitude); + } + + /** + * Turn off a note. + * @param channel + * @param noteNumber + * @param amplitude between 0 and 1.0, will be scaled by masterAmplitude + */ + public void noteOff(int channel, int noteNumber, double amplitude) { ChannelContext channelContext = channels[channel]; - channelContext.noteOff(noteNumber, velocity); + channelContext.noteOff(noteNumber, amplitude * mMasterAmplitude); } + /** + * Turn on a note. + * @param channel + * @param noteNumber + * @param velocity between 0 and 127, will be scaled by masterAmplitude + */ public void noteOn(int channel, int noteNumber, int velocity) { + double amplitude = velocity * (1.0 / MAX_VELOCITY); + noteOn(channel, noteNumber, amplitude); + } + /** + * Turn on a note. + * @param channel + * @param noteNumber + * @param amplitude between 0 and 1.0, will be scaled by masterAmplitude + */ + public void noteOn(int channel, int noteNumber, double amplitude) { ChannelContext channelContext = channels[channel]; - channelContext.noteOn(noteNumber, velocity); + channelContext.noteOn(noteNumber, amplitude * mMasterAmplitude); } /** @@ -321,8 +354,21 @@ public class MultiChannelSynthesizer { channelContext.setPan(pan); } + /** + * @return stereo output port + */ public UnitOutputPort getOutput() { return outputUnit.output; } + /** + * Set amplitude for a single voice when the velocity is 127. + * @param masterAmplitude + */ + public void setMasterAmplitude(double masterAmplitude) { + mMasterAmplitude = masterAmplitude; + } + public double getMasterAmplitude() { + return mMasterAmplitude; + } } diff --git a/src/com/jsyn/util/PolyphonicInstrument.java b/src/com/jsyn/util/PolyphonicInstrument.java index 2cba78f..08460d0 100644 --- a/src/com/jsyn/util/PolyphonicInstrument.java +++ b/src/com/jsyn/util/PolyphonicInstrument.java @@ -86,7 +86,7 @@ public class PolyphonicInstrument extends Circuit implements UnitSource, Instrum * @param portName * @see exportAllInputPorts */ - void exportNamedInputPort(String portName) { + public void exportNamedInputPort(String portName) { UnitInputPort voicePort = null; PassThrough fanout = new PassThrough(); for (UnitVoice voice : voices) { |