/* For License see bottom */
/*
* SoundParameter.java
*
* Created on 1. Juli 2007, 20:15
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package jrackattack.midi;
import java.io.Serializable;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiMessage;
import javax.sound.midi.SysexMessage;
import jonkoshare.util.VersionInformation;
import jrackattack.event.SoundParameterEvent;
/**
* Wrapper class for Sound Parameters.
*
* @author methke01
* @since 0.1
*/
@VersionInformation(lastChanged = "$LastChangedDate: 2009-09-15 13:46:50 -0500 (Tue, 15 Sep 2009) $", authors = { "Alexander Methke" }, revision = "$LastChangedRevision: 14 $", lastEditor = "$LastChangedBy: onkobu $", id = "$Id")
public class SoundParameter extends RackAttackParameter implements Serializable {
/** Creates a new instance of SoundParameter */
public SoundParameter() {
super(RackAttack.SNDD_SYSEX_LENGTH);
initValues();
}
private void initValues() {
setOsc1PitchMod(64);
setOsc1PitchCtrl(64);
setOsc1FMMod(64);
setOsc1FMCtrl(64);
setOsc2PitchMod(64);
setOsc2PitchCtrl(64);
setAmpPan(64);
setAmpPanMod(64);
setAmpPanCtrl(64);
setAmpVolume(100);
setAmpVolumeMod(64);
setAmpVolumeCtrl(64);
setLFO2Mod(64);
setFxSend(0);
setFxIndex(0);
setFilterCutoff(127);
setFilterKeyTrack(64);
setFilterCutoffCtrl1(64);
setFilterCutoffCtrl2(64);
setFilterCutoffMod1(64);
setFilterCutoffMod2(64);
setDryOutput(1);
}
/**
*
* @param buffer
* @return Can be <code>null</code>, if something goes wrong during
* {@link MidiMessage} creation.
*/
public MidiMessage createMessage(boolean buffer) {
byte[] bytes = null;
bytes = new byte[118];
bytes[0] = (byte) SysexMessage.SYSTEM_EXCLUSIVE; // SysEx (SOX)
bytes[1] = 0x3e; // Waldorf (IDW)
bytes[2] = 0x11; // RackAttack (IDM)
bytes[3] = 0x00; // Default ID (IDD)
byte cksum = 0;
bytes[4] = RackAttack.SOUND_DUMP; // CMD (SNDD)
cksum += bytes[4];
if (buffer) {
bytes[5] = RackAttack.EDIT_BUFFER;
} else {
bytes[5] = RackAttack.ASSEMBLY_BUFFER;
}
cksum += bytes[5];
bytes[6] = (byte) (getSoundNumber() & 0xFF); // SNDN
cksum += bytes[6];
for (int i = 7; i < 109; i++) {
bytes[i] = getByte(i);
cksum += bytes[i];
}
bytes[116] = (byte) (cksum & 0x7F); // CKSUM
bytes[117] = (byte) 0xF7; // EOX
SysexMessage sms = new SysexMessage();
try {
sms.setMessage(bytes, bytes.length);
} catch (InvalidMidiDataException e) {
return null;
}
return sms;
}
@Override
public void applyChange(ParameterChange pc) {
setByte(RackAttack.AH_AL_IDX_MATRIX[pc.getAH()][pc.getAL()] + 7,
(byte) (pc.getChange() & 0xff));
}
public void applyChange(SoundParameterEvent spe) {
setByte(RackAttack.AH_AL_IDX_MATRIX[spe.getAH()][spe.getAL()] + 7,
(byte) (spe.getChange() & 0xff));
}
/**
* Inits all values randomly.
*/
public void randomize() {
for (int i = 1; i < RackAttack.RANGES.length; i++) {
// exclude some values from being randomized
switch (i) {
case 85: // Dry Output
case 88: // Tuned Channel
case 89: // Tuned Transpose
case 90: // Tuned Low Key
case 91: // Tuned High Key
case 92: // Tuned Low Velocity
case 93: // Tuned High Velocity
case 94: { // XOR Group
continue;
}
}
// use the following line to find range check violations
// dataBytes[i+7]=(byte)(Math.round((Math.random()*127.0))&0xff);
if (RackAttack.RANGES[i] == -1) {
setByte(i + 7, getRandomByte());
} else {
setByte(i + 7, getRandomByte(RackAttack.RANGES[i]));
}
}
rangeCheck();
}
public void rangeCheck() {
// System.out.println(getClass().getName()+" range checking");
for (int i = 1; i < RackAttack.RANGES.length; i++) {
// usual 0..127-value
if (RackAttack.RANGES[i] == -1) {
// System.out.println("\t #"+i+" is unlimited or unused");
continue;
}
if (getByte(i + 7) > RackAttack.RANGES[i]) {
// System.out.println("\tlimiting #"+i+" from "+dataBytes[i+7]+" to "+RackAttack.RANGES[i]);
setByte(i + 7, (byte) RackAttack.RANGES[i]);
}
}
}
public SoundParameter copy() {
SoundParameter sp = new SoundParameter();
sp.setBytes(copyBytes());
return sp;
}
/**
* Getter for property bufferNumber.
*
* @return Value of property bufferNumber.
*/
public int getBufferNumber() {
return getByte(5);
}
/**
* Setter for property bufferNumber.
*
* @param bufferNumber
* New value of property bufferNumber.
*/
public void setBufferNumber(int bufferNumber) {
setByte(5, (byte) (bufferNumber & 0x7f));
}
/**
* Getter for property soundNumber.
*
* @return Value of property soundNumber.
*/
public int getSoundNumber() {
return getByte(6);
}
/**
* Setter for property soundNumber.
*
* @param soundNumber
* New value of property soundNumber.
*/
public void setSoundNumber(int soundNumber) {
setByte(6, (byte) (soundNumber & 0x7f));
}
/**
* Getter for property soundLabelIndex.
*
* @return Value of property soundLabelIndex.
*/
public int getSoundLabelIndex() {
return getByte(7);
}
/**
* Setter for property soundLabelIndex.
*
* @param soundLabelIndex
* New value of property soundLabelIndex.
*/
public void setSoundLabelIndex(int soundLabelIndex) {
setByte(7, (byte) (soundLabelIndex & 0x7f));
}
public int getOsc1ShapeIndex() {
return getByte(8);
}
public void setOsc1ShapeIndex(int val) {
setByte(8, (byte) (val & 0x7f));
}
public int getOsc1Pitch() {
return getByte(9);
}
public void setOsc1Pitch(int val) {
setByte(9, (byte) (val & 0x7f));
}
public int getOsc1Detune() {
return getByte(10);
}
public void setOsc1Detune(int val) {
setByte(10, (byte) (val & 0x7f));
}
public int getOsc1StartPhaseIndex() {
return getByte(11);
}
public void setOsc1StartPhaseIndex(int val) {
setByte(11, (byte) (val & 0x7f));
}
public int getOsc1PitchMod() {
return getByte(12);
}
public void setOsc1PitchMod(int val) {
setByte(12, (byte) (val & 0x7f));
}
public int getOsc1PitchCtrl() {
return getByte(13);
}
public void setOsc1PitchCtrl(int val) {
setByte(13, (byte) (val & 0x7f));
}
public int getOsc1PitchModSrcIndex() {
return getByte(14);
}
public void setOsc1PitchModSrcIndex(int val) {
setByte(14, (byte) (val & 0x7f));
}
public int getOsc1PitchCtrlSrcIndex() {
return getByte(15);
}
public void setOsc1PitchCtrlSrcIndex(int val) {
setByte(15, (byte) (val & 0x7f));
}
public int getOsc1FMDepth() {
return getByte(16);
}
public void setOsc1FMDepth(int val) {
setByte(16, (byte) (val & 0x7f));
}
public int getOsc1FMMod() {
return getByte(17);
}
public void setOsc1FMMod(int val) {
setByte(17, (byte) (val & 0x7f));
}
public int getOsc1FMCtrl() {
return getByte(18);
}
public void setOsc1FMCtrl(int val) {
setByte(18, (byte) (val & 0x7f));
}
public int getOsc1FMModSrcIndex() {
return getByte(19);
}
public void setOsc1FMModSrcIndex(int val) {
setByte(19, (byte) (val & 0x7f));
}
public int getOsc1FMCtrlSrcIndex() {
return getByte(20);
}
public void setOsc1FMCtrlSrcIndex(int val) {
setByte(20, (byte) (val & 0x7f));
}
// 21 and 22 are unused
public int getOsc2ShapeIndex() {
return getByte(23);
}
public void setOsc2ShapeIndex(int val) {
setByte(23, (byte) (val & 0x7f));
}
public int getOsc2Pitch() {
return getByte(24);
}
public void setOsc2Pitch(int val) {
setByte(24, (byte) (val & 0x7f));
}
public int getOsc2Detune() {
return getByte(25);
}
public void setOsc2Detune(int val) {
setByte(25, (byte) (val & 0x7f));
}
public int getOsc2StartPhaseIndex() {
return getByte(26);
}
public void setOsc2StartPhaseIndex(int val) {
setByte(26, (byte) (val & 0x7f));
}
public int getOsc2PitchMod() {
return getByte(27);
}
public void setOsc2PitchMod(int val) {
setByte(27, (byte) (val & 0x7f));
}
public int getOsc2PitchCtrl() {
return getByte(28);
}
public void setOsc2PitchCtrl(int val) {
setByte(28, (byte) (val & 0x7f));
}
public int getOsc2PitchModSrcIndex() {
return getByte(29);
}
public void setOsc2PitchModSrcIndex(int val) {
setByte(29, (byte) (val & 0x7f));
}
public int getOsc2PitchCtrlSrcIndex() {
return getByte(30);
}
public void setOsc2PitchCtrlSrcIndex(int val) {
setByte(30, (byte) (val & 0x7f));
}
// 31 and 32 are unused
public int getOsc1Level() {
return getByte(33);
}
public void setOsc1Level(int val) {
setByte(33, (byte) (val & 0x7f));
}
public int getOsc2Level() {
return getByte(34);
}
public void setOsc2Level(int val) {
setByte(34, (byte) (val & 0x7f));
}
public int getRingModLevel() {
return getByte(35);
}
public void setRingModLevel(int val) {
setByte(35, (byte) (val & 0x7f));
}
public int getCrackLevel() {
return getByte(36);
}
public void setCrackLevel(int val) {
setByte(36, (byte) (val & 0x7f));
}
public int getOsc2LevelMod() {
return getByte(37);
}
public void setOsc2LevelMod(int val) {
setByte(37, (byte) (val & 0x7f));
}
public int getOsc2LevelCtrl() {
return getByte(38);
}
public void setOsc2LevelCtrl(int val) {
setByte(38, (byte) (val & 0x7f));
}
public int getOsc2LevelModSrcIndex() {
return getByte(39);
}
public void setOsc2LevelModSrcIndex(int val) {
setByte(39, (byte) (val & 0x7f));
}
public int getOsc2LevelCtrlSrcIndex() {
return getByte(40);
}
public void setOsc2LevelCtrlSrcIndex(int val) {
setByte(40, (byte) (val & 0x7f));
}
public int getExternalLevel() {
return getByte(41);
}
public void setExternalLevel(int val) {
setByte(41, (byte) (val & 0x7f));
}
public int getExternalMod() {
return getByte(42);
}
public void setExternalMod(int val) {
setByte(42, (byte) (val & 0x7f));
}
// Crack Generator
public int getCrackSpeed() {
return getByte(43);
}
public void setCrackSpeed(int val) {
setByte(43, (byte) (val & 0x7f));
}
public int getCrackLength() {
return getByte(44);
}
public void setCrackLength(int val) {
setByte(44, (byte) (val & 0x7f));
}
// Filter Section
public int getFilterTypeIndex() {
return getByte(45);
}
public void setFilterTypeIndex(int val) {
setByte(45, (byte) (val & 0x7f));
}
public int getFilterCutoff() {
return getByte(46);
}
public void setFilterCutoff(int val) {
setByte(46, (byte) (val & 0x7f));
}
public int getFilterResonance() {
return getByte(47);
}
public void setFilterResonance(int val) {
setByte(47, (byte) (val & 0x7f));
}
public int getFilterDrive() {
return getByte(48);
}
public void setFilterDrive(int val) {
setByte(48, (byte) (val & 0x7f));
}
public int getFilterKeyTrack() {
return getByte(49);
}
public void setFilterKeyTrack(int val) {
setByte(49, (byte) (val & 0x7f));
}
public int getFilterCutoffMod1() {
return getByte(50);
}
public void setFilterCutoffMod1(int val) {
setByte(50, (byte) (val & 0x7f));
}
public int getFilterCutoffCtrl1() {
return getByte(51);
}
public void setFilterCutoffCtrl1(int val) {
setByte(51, (byte) (val & 0x7f));
}
public int getFilterCutoffMod1SrcIndex() {
return getByte(52);
}
public void setFilterCutoffMod1SrcIndex(int val) {
setByte(52, (byte) (val & 0x7f));
}
public int getFilterCutoffCtrl1SrcIndex() {
return getByte(53);
}
public void setFilterCutoffCtrl1SrcIndex(int val) {
setByte(53, (byte) (val & 0x7f));
}
public int getFilterCutoffMod2() {
return getByte(54);
}
public void setFilterCutoffMod2(int val) {
setByte(54, (byte) (val & 0x7f));
}
public int getFilterCutoffCtrl2() {
return getByte(55);
}
public void setFilterCutoffCtrl2(int val) {
setByte(55, (byte) (val & 0x7f));
}
public int getFilterCutoffMod2SrcIndex() {
return getByte(56);
}
public void setFilterCutoffMod2SrcIndex(int val) {
setByte(56, (byte) (val & 0x7f));
}
public int getFilterCutoffCtrl2SrcIndex() {
return getByte(57);
}
public void setFilterCutoffCtrl2SrcIndex(int val) {
setByte(57, (byte) (val & 0x7f));
}
// 58 and 59 are unused
// Amplifier Section
public int getAmpVolume() {
return getByte(60);
}
public void setAmpVolume(int val) {
setByte(60, (byte) (val & 0x7f));
}
public int getAmpVolumeMod() {
return getByte(61);
}
public void setAmpVolumeMod(int val) {
setByte(61, (byte) (val & 0x7f));
}
public int getAmpVolumeCtrl() {
return getByte(62);
}
public void setAmpVolumeCtrl(int val) {
setByte(62, (byte) (val & 0x7f));
}
public int getAmpVolumeModSrcIndex() {
return getByte(63);
}
public void setAmpVolumeModSrcIndex(int val) {
setByte(63, (byte) (val & 0x7f));
}
public int getAmpVolumeCtrlSrcIndex() {
return getByte(64);
}
public void setAmpVolumeCtrlSrcIndex(int val) {
setByte(64, (byte) (val & 0x7f));
}
public int getAmpPan() {
return getByte(65);
}
public void setAmpPan(int val) {
setByte(65, (byte) (val & 0x7f));
}
public int getAmpPanMod() {
return getByte(66);
}
public void setAmpPanMod(int val) {
setByte(66, (byte) (val & 0x7f));
}
public int getAmpPanCtrl() {
return getByte(67);
}
public void setAmpPanCtrl(int val) {
setByte(67, (byte) (val & 0x7f));
}
public int getAmpPanModSrcIndex() {
return getByte(68);
}
public void setAmpPanModSrcIndex(int val) {
setByte(68, (byte) (val & 0x7f));
}
public int getAmpPanCtrlSrcIndex() {
return getByte(69);
}
public void setAmpPanCtrlSrcIndex(int val) {
setByte(69, (byte) (val & 0x7f));
}
// Envelope 1 Section
public int getEnv1Attack() {
return getByte(70);
}
public void setEnv1Attack(int val) {
setByte(70, (byte) (val & 0x7f));
}
public int getEnv1Decay() {
return getByte(71);
}
public void setEnv1Decay(int val) {
setByte(71, (byte) (val & 0x7f));
}
public int getEnv1Sustain() {
return getByte(72);
}
public void setEnv1Sustain(int val) {
setByte(72, (byte) (val & 0x7f));
}
public int getEnv1Release() {
return getByte(73);
}
public void setEnv1Release(int val) {
setByte(73, (byte) (val & 0x7f));
}
public int getEnv1ShapeIndex() {
return getByte(74);
}
public void setEnv1ShapeIndex(int val) {
setByte(74, (byte) (val & 0x7f));
}
// 75 is unused
// Envelop 2 Section
public int getEnv2Attack() {
return getByte(76);
}
public void setEnv2Attack(int val) {
setByte(76, (byte) (val & 0x7f));
}
public int getEnv2Decay() {
return getByte(77);
}
public void setEnv2Decay(int val) {
setByte(77, (byte) (val & 0x7f));
}
public int getEnv2Sustain() {
return getByte(78);
}
public void setEnv2Sustain(int val) {
setByte(78, (byte) (val & 0x7f));
}
public int getEnv2Release() {
return getByte(79);
}
public void setEnv2Release(int val) {
setByte(79, (byte) (val & 0x7f));
}
public int getEnv2ShapeIndex() {
return getByte(80);
}
public void setEnv2ShapeIndex(int val) {
setByte(80, (byte) (val & 0x7f));
}
// 81 is unused
// LFO1 Section
public int getLFO1Speed() {
return getByte(82);
}
public void setLFO1Speed(int val) {
setByte(82, (byte) (val & 0x7f));
}
public int getLFO1ShapeIndex() {
return getByte(83);
}
public void setLFO1ShapeIndex(int val) {
setByte(83, (byte) (val & 0x7f));
}
public int getLFO1Sync() {
return getByte(84);
}
public void setLFO1Sync(int val) {
setByte(84, (byte) (val & 0x7f));
}
public int getLFO1OneShot() {
return getByte(85);
}
public void setLFO1OneShot(int val) {
setByte(85, (byte) (val & 0x7f));
}
// LFO2 Section
public int getLFO2Speed() {
return getByte(86);
}
public void setLFO2Speed(int val) {
setByte(86, (byte) (val & 0x7f));
}
public int getLFO2ShapeIndex() {
return getByte(87);
}
public void setLFO2ShapeIndex(int val) {
setByte(87, (byte) (val & 0x7f));
}
public int getLFO2Sync() {
return getByte(88);
}
public void setLFO2Sync(int val) {
setByte(88, (byte) (val & 0x7f));
}
public int getLFO2Mod() {
return getByte(89);
}
public void setLFO2Mod(int val) {
setByte(89, (byte) (val & 0x7f));
}
public int getLFO2ModSrcIndex() {
return getByte(90);
}
public void setLFO2ModSrcIndex(int val) {
setByte(90, (byte) (val & 0x7f));
}
// 91 is unused
// Output Section
public int getDryOutput() {
return getByte(92);
}
public void setDryOutput(int val) {
setByte(92, (byte) (val & 0x7f));
}
public int getFxIndex() {
return getByte(93);
}
public void setFxIndex(int val) {
setByte(93, (byte) (val & 0x7f));
}
public int getFxSend() {
return getByte(94);
}
public void setFxSend(int val) {
setByte(94, (byte) (val & 0x7f));
}
public int getTunedChannel() {
return getByte(95);
}
public void setTunedChannel(int val) {
setByte(95, (byte) (val & 0x7f));
}
public int getTunedTranspose() {
return getByte(96);
}
public void setTunedTranspose(int val) {
setByte(96, (byte) (val & 0x7f));
}
public int getTunedLowKey() {
return getByte(97);
}
public void setTunedLowKey(int val) {
setByte(97, (byte) (val & 0x7f));
}
public int getTunedHighKey() {
return getByte(98);
}
public void setTunedHighKey(int val) {
setByte(98, (byte) (val & 0x7f));
}
public int getTunedLowVelocity() {
return getByte(99);
}
public void setTunedLowVelocity(int val) {
setByte(99, (byte) (val & 0x7f));
}
public int getTunedHighVelocity() {
return getByte(100);
}
public void setTunedHighVelocity(int val) {
setByte(100, (byte) (val & 0x7f));
}
public int getXORGroup() {
return getByte(101);
}
public void setXORGroup(int val) {
setByte(101, (byte) (val & 0x7f));
}
// 101-114 unused
// Pattern Section
public int getPatternMode() {
return getByte(115);
}
public void setPatternMode(int val) {
setByte(115, (byte) (val & 0x7f));
}
}
/*
* Copyright (C) 2008 Alexander Methke
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program 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 for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program (gplv3.txt).
*/