ModelInstrument.java revision 2362
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * This code is free software; you can redistribute it and/or modify it
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * under the terms of the GNU General Public License version 2 only, as
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * published by the Free Software Foundation. Oracle designates this
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * particular file as subject to the "Classpath" exception as provided
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * by Oracle in the LICENSE file that accompanied this code.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * This code is distributed in the hope that it will be useful, but WITHOUT
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * version 2 for more details (a copy is included in the LICENSE file that
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * accompanied this code).
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * You should have received a copy of the GNU General Public License version
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * 2 along with this work; if not, write to the Free Software Foundation,
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * or visit www.oracle.com if you need additional information or have any
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * questions.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * The model instrument class.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * <p>The main methods to override are:<br>
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * getPerformer, getDirector, getChannelMixer.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * <p>Performers are used to define what voices which will
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * playback when using the instrument.<br>
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * ChannelMixer is used to add channel-wide processing
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * on voices output or to define non-voice oriented instruments.<br>
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * Director is used to change how the synthesizer
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * chooses what performers to play on midi events.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * @author Karl Helgason
869a36e2649ae064c98063cf1e55198488d78d12Allan Fosterpublic abstract class ModelInstrument extends Instrument {
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster protected ModelInstrument(Soundbank soundbank, Patch patch, String name,
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster public ModelDirector getDirector(ModelPerformer[] performers,
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster MidiChannel channel, ModelDirectedPlayer player) {
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster return new ModelStandardDirector(performers, player);
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster public ModelChannelMixer getChannelMixer(MidiChannel channel,
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster // Get General MIDI 2 Alias patch for this instrument.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster boolean percussion = false;
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster percussion = ((ModelPatch)getPatch()).isPercussion();
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster // Return name of all the keys.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster // This information is generated from ModelPerformer.getName()
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster // returned from getPerformers().
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster for (ModelPerformer performer : getPerformers()) {
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster for (int k = performer.getKeyFrom(); k <= performer.getKeyTo(); k++) {
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster // Return what channels this instrument will probably response
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster // on General MIDI synthesizer.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster public boolean[] getChannels() {
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster boolean percussion = false;
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster percussion = ((ModelPatch)getPatch()).isPercussion();
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster // Check if instrument is percussion.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster // Check if instrument uses General MIDI 2 default banks.