829N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
829N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
829N/A *
829N/A * This code is free software; you can redistribute it and/or modify it
829N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
829N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
829N/A *
829N/A * This code is distributed in the hope that it will be useful, but WITHOUT
829N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
829N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
829N/A * version 2 for more details (a copy is included in the LICENSE file that
829N/A * accompanied this code).
829N/A *
829N/A * You should have received a copy of the GNU General Public License version
829N/A * 2 along with this work; if not, write to the Free Software Foundation,
829N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
829N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
829N/A */
829N/Apackage com.sun.media.sound;
829N/A
829N/Aimport java.util.ArrayList;
829N/Aimport java.util.HashMap;
829N/Aimport java.util.List;
829N/Aimport java.util.Map;
829N/A
829N/A/**
829N/A * Soundfont general region.
829N/A *
829N/A * @author Karl Helgason
829N/A */
829N/Apublic class SF2Region {
829N/A
829N/A public final static int GENERATOR_STARTADDRSOFFSET = 0;
829N/A public final static int GENERATOR_ENDADDRSOFFSET = 1;
829N/A public final static int GENERATOR_STARTLOOPADDRSOFFSET = 2;
829N/A public final static int GENERATOR_ENDLOOPADDRSOFFSET = 3;
829N/A public final static int GENERATOR_STARTADDRSCOARSEOFFSET = 4;
829N/A public final static int GENERATOR_MODLFOTOPITCH = 5;
829N/A public final static int GENERATOR_VIBLFOTOPITCH = 6;
829N/A public final static int GENERATOR_MODENVTOPITCH = 7;
829N/A public final static int GENERATOR_INITIALFILTERFC = 8;
829N/A public final static int GENERATOR_INITIALFILTERQ = 9;
829N/A public final static int GENERATOR_MODLFOTOFILTERFC = 10;
829N/A public final static int GENERATOR_MODENVTOFILTERFC = 11;
829N/A public final static int GENERATOR_ENDADDRSCOARSEOFFSET = 12;
829N/A public final static int GENERATOR_MODLFOTOVOLUME = 13;
829N/A public final static int GENERATOR_UNUSED1 = 14;
829N/A public final static int GENERATOR_CHORUSEFFECTSSEND = 15;
829N/A public final static int GENERATOR_REVERBEFFECTSSEND = 16;
829N/A public final static int GENERATOR_PAN = 17;
829N/A public final static int GENERATOR_UNUSED2 = 18;
829N/A public final static int GENERATOR_UNUSED3 = 19;
829N/A public final static int GENERATOR_UNUSED4 = 20;
829N/A public final static int GENERATOR_DELAYMODLFO = 21;
829N/A public final static int GENERATOR_FREQMODLFO = 22;
829N/A public final static int GENERATOR_DELAYVIBLFO = 23;
829N/A public final static int GENERATOR_FREQVIBLFO = 24;
829N/A public final static int GENERATOR_DELAYMODENV = 25;
829N/A public final static int GENERATOR_ATTACKMODENV = 26;
829N/A public final static int GENERATOR_HOLDMODENV = 27;
829N/A public final static int GENERATOR_DECAYMODENV = 28;
829N/A public final static int GENERATOR_SUSTAINMODENV = 29;
829N/A public final static int GENERATOR_RELEASEMODENV = 30;
829N/A public final static int GENERATOR_KEYNUMTOMODENVHOLD = 31;
829N/A public final static int GENERATOR_KEYNUMTOMODENVDECAY = 32;
829N/A public final static int GENERATOR_DELAYVOLENV = 33;
829N/A public final static int GENERATOR_ATTACKVOLENV = 34;
829N/A public final static int GENERATOR_HOLDVOLENV = 35;
829N/A public final static int GENERATOR_DECAYVOLENV = 36;
829N/A public final static int GENERATOR_SUSTAINVOLENV = 37;
829N/A public final static int GENERATOR_RELEASEVOLENV = 38;
829N/A public final static int GENERATOR_KEYNUMTOVOLENVHOLD = 39;
829N/A public final static int GENERATOR_KEYNUMTOVOLENVDECAY = 40;
829N/A public final static int GENERATOR_INSTRUMENT = 41;
829N/A public final static int GENERATOR_RESERVED1 = 42;
829N/A public final static int GENERATOR_KEYRANGE = 43;
829N/A public final static int GENERATOR_VELRANGE = 44;
829N/A public final static int GENERATOR_STARTLOOPADDRSCOARSEOFFSET = 45;
829N/A public final static int GENERATOR_KEYNUM = 46;
829N/A public final static int GENERATOR_VELOCITY = 47;
829N/A public final static int GENERATOR_INITIALATTENUATION = 48;
829N/A public final static int GENERATOR_RESERVED2 = 49;
829N/A public final static int GENERATOR_ENDLOOPADDRSCOARSEOFFSET = 50;
829N/A public final static int GENERATOR_COARSETUNE = 51;
829N/A public final static int GENERATOR_FINETUNE = 52;
829N/A public final static int GENERATOR_SAMPLEID = 53;
829N/A public final static int GENERATOR_SAMPLEMODES = 54;
829N/A public final static int GENERATOR_RESERVED3 = 55;
829N/A public final static int GENERATOR_SCALETUNING = 56;
829N/A public final static int GENERATOR_EXCLUSIVECLASS = 57;
829N/A public final static int GENERATOR_OVERRIDINGROOTKEY = 58;
829N/A public final static int GENERATOR_UNUSED5 = 59;
829N/A public final static int GENERATOR_ENDOPR = 60;
829N/A protected Map<Integer, Short> generators = new HashMap<Integer, Short>();
829N/A protected List<SF2Modulator> modulators = new ArrayList<SF2Modulator>();
829N/A
829N/A public Map<Integer, Short> getGenerators() {
829N/A return generators;
829N/A }
829N/A
829N/A public boolean contains(int generator) {
829N/A return generators.containsKey(generator);
829N/A }
829N/A
829N/A static public short getDefaultValue(int generator) {
829N/A if (generator == 8) return (short)13500;
829N/A if (generator == 21) return (short)-12000;
829N/A if (generator == 23) return (short)-12000;
829N/A if (generator == 25) return (short)-12000;
829N/A if (generator == 26) return (short)-12000;
829N/A if (generator == 27) return (short)-12000;
829N/A if (generator == 28) return (short)-12000;
829N/A if (generator == 30) return (short)-12000;
829N/A if (generator == 33) return (short)-12000;
829N/A if (generator == 34) return (short)-12000;
829N/A if (generator == 35) return (short)-12000;
829N/A if (generator == 36) return (short)-12000;
829N/A if (generator == 38) return (short)-12000;
829N/A if (generator == 43) return (short)0x7F00;
829N/A if (generator == 44) return (short)0x7F00;
829N/A if (generator == 46) return (short)-1;
829N/A if (generator == 47) return (short)-1;
829N/A if (generator == 56) return (short)100;
829N/A if (generator == 58) return (short)-1;
829N/A return 0;
829N/A }
829N/A
829N/A public short getShort(int generator) {
829N/A if (!contains(generator))
829N/A return getDefaultValue(generator);
829N/A return generators.get(generator);
829N/A }
829N/A
829N/A public void putShort(int generator, short value) {
829N/A generators.put(generator, value);
829N/A }
829N/A
829N/A public byte[] getBytes(int generator) {
829N/A int val = getInteger(generator);
829N/A byte[] bytes = new byte[2];
829N/A bytes[0] = (byte) (0xFF & val);
829N/A bytes[1] = (byte) ((0xFF00 & val) >> 8);
829N/A return bytes;
829N/A }
829N/A
829N/A public void putBytes(int generator, byte[] bytes) {
829N/A generators.put(generator, (short) (bytes[0] + (bytes[1] << 8)));
829N/A }
829N/A
829N/A public int getInteger(int generator) {
829N/A return 0xFFFF & getShort(generator);
829N/A }
829N/A
829N/A public void putInteger(int generator, int value) {
829N/A generators.put(generator, (short) value);
829N/A }
829N/A
829N/A public List<SF2Modulator> getModulators() {
829N/A return modulators;
829N/A }
829N/A}