|
Java example source code file (SoftPerformer.java)
The SoftPerformer.java Java example source code
/*
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.media.sound;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* This class decodes information from ModelPeformer for use in SoftVoice.
* It also adds default connections if they where missing in ModelPerformer.
*
* @author Karl Helgason
*/
public final class SoftPerformer {
static ModelConnectionBlock[] defaultconnections
= new ModelConnectionBlock[42];
static {
int o = 0;
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("noteon", "on", 0),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
1, new ModelDestination(new ModelIdentifier("eg", "on", 0)));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("noteon", "on", 0),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
1, new ModelDestination(new ModelIdentifier("eg", "on", 1)));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("eg", "active", 0),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
1, new ModelDestination(new ModelIdentifier("mixer", "active", 0)));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("eg", 0),
ModelStandardTransform.DIRECTION_MAX2MIN,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
-960, new ModelDestination(new ModelIdentifier("mixer", "gain")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("noteon", "velocity"),
ModelStandardTransform.DIRECTION_MAX2MIN,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_CONCAVE),
-960, new ModelDestination(new ModelIdentifier("mixer", "gain")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi", "pitch"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_BIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
new ModelSource(new ModelIdentifier("midi_rpn", "0"),
new ModelTransform() {
public double transform(double value) {
int v = (int) (value * 16384.0);
int msb = v >> 7;
int lsb = v & 127;
return msb * 100 + lsb;
}
}),
new ModelDestination(new ModelIdentifier("osc", "pitch")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("noteon", "keynumber"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
12800, new ModelDestination(new ModelIdentifier("osc", "pitch")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_cc", "7"),
ModelStandardTransform.DIRECTION_MAX2MIN,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_CONCAVE),
-960, new ModelDestination(new ModelIdentifier("mixer", "gain")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_cc", "8"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
1000, new ModelDestination(new ModelIdentifier("mixer", "balance")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_cc", "10"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
1000, new ModelDestination(new ModelIdentifier("mixer", "pan")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_cc", "11"),
ModelStandardTransform.DIRECTION_MAX2MIN,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_CONCAVE),
-960, new ModelDestination(new ModelIdentifier("mixer", "gain")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_cc", "91"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
1000, new ModelDestination(new ModelIdentifier("mixer", "reverb")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_cc", "93"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
1000, new ModelDestination(new ModelIdentifier("mixer", "chorus")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_cc", "71"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_BIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
200, new ModelDestination(new ModelIdentifier("filter", "q")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_cc", "74"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_BIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
9600, new ModelDestination(new ModelIdentifier("filter", "freq")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_cc", "72"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_BIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
6000, new ModelDestination(new ModelIdentifier("eg", "release2")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_cc", "73"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_BIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
2000, new ModelDestination(new ModelIdentifier("eg", "attack2")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_cc", "75"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_BIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
6000, new ModelDestination(new ModelIdentifier("eg", "decay2")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_cc", "67"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_SWITCH),
-50, new ModelDestination(ModelDestination.DESTINATION_GAIN));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_cc", "67"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_UNIPOLAR,
ModelStandardTransform.TRANSFORM_SWITCH),
-2400, new ModelDestination(ModelDestination.DESTINATION_FILTER_FREQ));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_rpn", "1"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_BIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
100, new ModelDestination(new ModelIdentifier("osc", "pitch")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("midi_rpn", "2"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_BIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
12800, new ModelDestination(new ModelIdentifier("osc", "pitch")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("master", "fine_tuning"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_BIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
100, new ModelDestination(new ModelIdentifier("osc", "pitch")));
defaultconnections[o++] = new ModelConnectionBlock(
new ModelSource(
new ModelIdentifier("master", "coarse_tuning"),
ModelStandardTransform.DIRECTION_MIN2MAX,
ModelStandardTransform.POLARITY_BIPOLAR,
ModelStandardTransform.TRANSFORM_LINEAR),
12800, new ModelDestination(new ModelIdentifier("osc", "pitch")));
defaultconnections[o++] = new ModelConnectionBlock(13500,
new ModelDestination(new ModelIdentifier("filter", "freq", 0)));
defaultconnections[o++] = new ModelConnectionBlock(
Float.NEGATIVE_INFINITY, new ModelDestination(
new ModelIdentifier("eg", "delay", 0)));
defaultconnections[o++] = new ModelConnectionBlock(
Float.NEGATIVE_INFINITY, new ModelDestination(
new ModelIdentifier("eg", "attack", 0)));
defaultconnections[o++] = new ModelConnectionBlock(
Float.NEGATIVE_INFINITY, new ModelDestination(
new ModelIdentifier("eg", "hold", 0)));
defaultconnections[o++] = new ModelConnectionBlock(
Float.NEGATIVE_INFINITY, new ModelDestination(
new ModelIdentifier("eg", "decay", 0)));
defaultconnections[o++] = new ModelConnectionBlock(1000,
new ModelDestination(new ModelIdentifier("eg", "sustain", 0)));
defaultconnections[o++] = new ModelConnectionBlock(
Float.NEGATIVE_INFINITY, new ModelDestination(
new ModelIdentifier("eg", "release", 0)));
defaultconnections[o++] = new ModelConnectionBlock(1200.0
* Math.log(0.015) / Math.log(2), new ModelDestination(
new ModelIdentifier("eg", "shutdown", 0))); // 15 msec default
defaultconnections[o++] = new ModelConnectionBlock(
Float.NEGATIVE_INFINITY, new ModelDestination(
new ModelIdentifier("eg", "delay", 1)));
defaultconnections[o++] = new ModelConnectionBlock(
Float.NEGATIVE_INFINITY, new ModelDestination(
new ModelIdentifier("eg", "attack", 1)));
defaultconnections[o++] = new ModelConnectionBlock(
Float.NEGATIVE_INFINITY, new ModelDestination(
new ModelIdentifier("eg", "hold", 1)));
defaultconnections[o++] = new ModelConnectionBlock(
Float.NEGATIVE_INFINITY, new ModelDestination(
new ModelIdentifier("eg", "decay", 1)));
defaultconnections[o++] = new ModelConnectionBlock(1000,
new ModelDestination(new ModelIdentifier("eg", "sustain", 1)));
defaultconnections[o++] = new ModelConnectionBlock(
Float.NEGATIVE_INFINITY, new ModelDestination(
new ModelIdentifier("eg", "release", 1)));
defaultconnections[o++] = new ModelConnectionBlock(-8.51318,
new ModelDestination(new ModelIdentifier("lfo", "freq", 0)));
defaultconnections[o++] = new ModelConnectionBlock(
Float.NEGATIVE_INFINITY, new ModelDestination(
new ModelIdentifier("lfo", "delay", 0)));
defaultconnections[o++] = new ModelConnectionBlock(-8.51318,
new ModelDestination(new ModelIdentifier("lfo", "freq", 1)));
defaultconnections[o++] = new ModelConnectionBlock(
Float.NEGATIVE_INFINITY, new ModelDestination(
new ModelIdentifier("lfo", "delay", 1)));
}
public int keyFrom = 0;
public int keyTo = 127;
public int velFrom = 0;
public int velTo = 127;
public int exclusiveClass = 0;
public boolean selfNonExclusive = false;
public boolean forcedVelocity = false;
public boolean forcedKeynumber = false;
public ModelPerformer performer;
public ModelConnectionBlock[] connections;
public ModelOscillator[] oscillators;
public Map<Integer, int[]> midi_rpn_connections = new HashMap
Other Java examples (source code examples)Here is a short list of links related to this Java SoftPerformer.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.