/* For License see bottom */
/*
* AmpPanel.java
*
* Created on 15. Juli 2007, 13:37
*/
package jrackattack.gui;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ResourceBundle;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import jonkoshare.util.VersionInformation;
import jrackattack.midi.MidiThread;
import jrackattack.midi.RackAttack;
import jrackattack.midi.SoundParameter;
import org.jdesktop.layout.GroupLayout;
/**
*
* @author methke01
*/
@VersionInformation (
lastChanged="$LastChangedDate: 2009-09-15 14:15:46 -0500 (Tue, 15 Sep 2009) $",
authors={"Alexander Methke"},
revision="$LastChangedRevision: 15 $",
lastEditor="$LastChangedBy: onkobu $",
id="$Id"
)
public class AmpPanel extends JPanel {
/** Creates new form AmpPanel */
public AmpPanel() {
initComponents();
initValues();
}
protected void initValues() {
initiating=true;
panKnob.setIntValue(64);
((SpinnerNumberModel)panSpinner.getModel()).setMinimum(-64);
((SpinnerNumberModel)panSpinner.getModel()).setMaximum(63);
panSpinner.setValue(new Integer(0));
panModKnob.setIntValue(64);
((SpinnerNumberModel)panModSpinner.getModel()).setMinimum(-64);
((SpinnerNumberModel)panModSpinner.getModel()).setMaximum(63);
panModSpinner.setValue(new Integer(0));
panCtrlKnob.setIntValue(64);
((SpinnerNumberModel)panCtrlSpinner.getModel()).setMinimum(-64);
((SpinnerNumberModel)panCtrlSpinner.getModel()).setMaximum(63);
panCtrlSpinner.setValue(new Integer(0));
volumeKnob.setIntValue(0);
((SpinnerNumberModel)volumeSpinner.getModel()).setMinimum(0);
((SpinnerNumberModel)volumeSpinner.getModel()).setMaximum(127);
volumeSpinner.setValue(new Integer(0));
volumeModKnob.setIntValue(64);
((SpinnerNumberModel)volumeModSpinner.getModel()).setMinimum(-64);
((SpinnerNumberModel)volumeModSpinner.getModel()).setMaximum(63);
volumeModSpinner.setValue(new Integer(0));
volumeCtrlKnob.setIntValue(64);
((SpinnerNumberModel)volumeCtrlSpinner.getModel()).setMinimum(-64);
((SpinnerNumberModel)volumeCtrlSpinner.getModel()).setMaximum(63);
volumeCtrlSpinner.setValue(new Integer(0));
volumeModBox.removeAllItems();
panModBox.removeAllItems();
for(String src:RackAttack.MOD_SOURCE) {
volumeModBox.addItem(src);
panModBox.addItem(src);
}
volumeCtrlBox.removeAllItems();
panCtrlBox.removeAllItems();
for(String ctrl:RackAttack.CTRL_SOURCE) {
volumeCtrlBox.addItem(ctrl);
panCtrlBox.addItem(ctrl);
}
initiating=false;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
GridBagConstraints gridBagConstraints;
jKnob1 = new JKnob();
volumeKnob = new JKnob();
volumeModKnob = new JKnob();
volumeCtrlKnob = new JKnob();
panKnob = new JKnob();
panModKnob = new JKnob();
panCtrlKnob = new JKnob();
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jLabel3 = new JLabel();
jLabel4 = new JLabel();
jLabel5 = new JLabel();
jLabel6 = new JLabel();
volumeModBox = new JComboBox();
volumeCtrlBox = new JComboBox();
panModBox = new JComboBox();
panCtrlBox = new JComboBox();
volumeSpinner = new JSpinner();
volumeModSpinner = new JSpinner();
volumeCtrlSpinner = new JSpinner();
panSpinner = new JSpinner();
panModSpinner = new JSpinner();
panCtrlSpinner = new JSpinner();
GroupLayout jKnob1Layout = new GroupLayout(jKnob1);
jKnob1.setLayout(jKnob1Layout);
jKnob1Layout.setHorizontalGroup(
jKnob1Layout.createParallelGroup(GroupLayout.LEADING)
.add(0, 80, Short.MAX_VALUE)
);
jKnob1Layout.setVerticalGroup(
jKnob1Layout.createParallelGroup(GroupLayout.LEADING)
.add(0, 80, Short.MAX_VALUE)
);
setLayout(new GridBagLayout());
volumeKnob.setIntValue(0);
volumeKnob.setMaximumValue(127);
volumeKnob.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
volumeKnobStateChanged(evt);
}
});
GroupLayout volumeKnobLayout = new GroupLayout(volumeKnob);
volumeKnob.setLayout(volumeKnobLayout);
volumeKnobLayout.setHorizontalGroup(
volumeKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 40, Short.MAX_VALUE)
);
volumeKnobLayout.setVerticalGroup(
volumeKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 40, Short.MAX_VALUE)
);
add(volumeKnob, new GridBagConstraints());
volumeModKnob.setMaximumValue(127);
volumeModKnob.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
volumeModKnobStateChanged(evt);
}
});
GroupLayout volumeModKnobLayout = new GroupLayout(volumeModKnob);
volumeModKnob.setLayout(volumeModKnobLayout);
volumeModKnobLayout.setHorizontalGroup(
volumeModKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 40, Short.MAX_VALUE)
);
volumeModKnobLayout.setVerticalGroup(
volumeModKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 40, Short.MAX_VALUE)
);
add(volumeModKnob, new GridBagConstraints());
volumeCtrlKnob.setMaximumValue(127);
volumeCtrlKnob.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
volumeCtrlKnobStateChanged(evt);
}
});
GroupLayout volumeCtrlKnobLayout = new GroupLayout(volumeCtrlKnob);
volumeCtrlKnob.setLayout(volumeCtrlKnobLayout);
volumeCtrlKnobLayout.setHorizontalGroup(
volumeCtrlKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 40, Short.MAX_VALUE)
);
volumeCtrlKnobLayout.setVerticalGroup(
volumeCtrlKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 40, Short.MAX_VALUE)
);
add(volumeCtrlKnob, new GridBagConstraints());
panKnob.setMaximumValue(127);
panKnob.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
panKnobStateChanged(evt);
}
});
GroupLayout panKnobLayout = new GroupLayout(panKnob);
panKnob.setLayout(panKnobLayout);
panKnobLayout.setHorizontalGroup(
panKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 40, Short.MAX_VALUE)
);
panKnobLayout.setVerticalGroup(
panKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 40, Short.MAX_VALUE)
);
add(panKnob, new GridBagConstraints());
panModKnob.setMaximumValue(127);
panModKnob.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
panModKnobStateChanged(evt);
}
});
GroupLayout panModKnobLayout = new GroupLayout(panModKnob);
panModKnob.setLayout(panModKnobLayout);
panModKnobLayout.setHorizontalGroup(
panModKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 40, Short.MAX_VALUE)
);
panModKnobLayout.setVerticalGroup(
panModKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 40, Short.MAX_VALUE)
);
add(panModKnob, new GridBagConstraints());
panCtrlKnob.setMaximumValue(127);
panCtrlKnob.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
panCtrlKnobStateChanged(evt);
}
});
GroupLayout panCtrlKnobLayout = new GroupLayout(panCtrlKnob);
panCtrlKnob.setLayout(panCtrlKnobLayout);
panCtrlKnobLayout.setHorizontalGroup(
panCtrlKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 40, Short.MAX_VALUE)
);
panCtrlKnobLayout.setVerticalGroup(
panCtrlKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 40, Short.MAX_VALUE)
);
add(panCtrlKnob, new GridBagConstraints());
ResourceBundle bundle = ResourceBundle.getBundle("jrackattack/gui");
jLabel1.setText(bundle.getString("label.volume"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
add(jLabel1, gridBagConstraints);
jLabel2.setText(bundle.getString("label.mod"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridy = 2;
add(jLabel2, gridBagConstraints);
jLabel3.setText(bundle.getString("label.ctrl"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridy = 2;
add(jLabel3, gridBagConstraints);
jLabel4.setText(bundle.getString("label.pan"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridy = 2;
add(jLabel4, gridBagConstraints);
jLabel5.setText(bundle.getString("label.mod"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridy = 2;
add(jLabel5, gridBagConstraints);
jLabel6.setText(bundle.getString("label.ctrl"));
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridy = 2;
add(jLabel6, gridBagConstraints);
volumeModBox.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
volumeModBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent evt) {
volumeModBoxItemStateChanged(evt);
}
});
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 3;
add(volumeModBox, gridBagConstraints);
volumeCtrlBox.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
volumeCtrlBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent evt) {
volumeCtrlBoxItemStateChanged(evt);
}
});
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 3;
add(volumeCtrlBox, gridBagConstraints);
panModBox.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
panModBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent evt) {
panModBoxItemStateChanged(evt);
}
});
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 3;
add(panModBox, gridBagConstraints);
panCtrlBox.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
panCtrlBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent evt) {
panCtrlBoxItemStateChanged(evt);
}
});
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 5;
gridBagConstraints.gridy = 3;
add(panCtrlBox, gridBagConstraints);
volumeSpinner.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
volumeSpinnerStateChanged(evt);
}
});
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
add(volumeSpinner, gridBagConstraints);
volumeModSpinner.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
volumeModSpinnerStateChanged(evt);
}
});
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = GridBagConstraints.BOTH;
add(volumeModSpinner, gridBagConstraints);
volumeCtrlSpinner.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
volumeCtrlSpinnerStateChanged(evt);
}
});
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = GridBagConstraints.BOTH;
add(volumeCtrlSpinner, gridBagConstraints);
panSpinner.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
panSpinnerStateChanged(evt);
}
});
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = GridBagConstraints.BOTH;
add(panSpinner, gridBagConstraints);
panModSpinner.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
panModSpinnerStateChanged(evt);
}
});
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = GridBagConstraints.BOTH;
add(panModSpinner, gridBagConstraints);
panCtrlSpinner.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
panCtrlSpinnerStateChanged(evt);
}
});
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 5;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = GridBagConstraints.BOTH;
add(panCtrlSpinner, gridBagConstraints);
}// </editor-fold>
private void panCtrlBoxItemStateChanged(ItemEvent evt) {
if (initiating) {
return;
}
SoundParameter sp=getSoundBuffer().getActiveSoundParameter();
MidiThread.getInstance().emitParamChange(this, getSoundBuffer().getActiveSoundNumber(),
RackAttack.PAN_CTRL_SRC, panCtrlBox.getSelectedIndex());
sp.setAmpPanCtrlSrcIndex(panCtrlBox.getSelectedIndex());
}
private void panModBoxItemStateChanged(ItemEvent evt) {
if (initiating) {
return;
}
SoundParameter sp=getSoundBuffer().getActiveSoundParameter();
MidiThread.getInstance().emitParamChange(this, getSoundBuffer().getActiveSoundNumber(),
RackAttack.PAN_MOD_SRC, panModBox.getSelectedIndex());
sp.setAmpPanModSrcIndex(panModBox.getSelectedIndex());
}
private void volumeCtrlBoxItemStateChanged(ItemEvent evt) {
if (initiating) {
return;
}
SoundParameter sp=getSoundBuffer().getActiveSoundParameter();
MidiThread.getInstance().emitParamChange(this, getSoundBuffer().getActiveSoundNumber(),
RackAttack.VOLUME_CTRL_SRC, volumeCtrlBox.getSelectedIndex());
sp.setAmpVolumeCtrlSrcIndex(volumeCtrlBox.getSelectedIndex());
}
private void volumeModBoxItemStateChanged(ItemEvent evt) {
if (initiating) {
return;
}
SoundParameter sp=getSoundBuffer().getActiveSoundParameter();
MidiThread.getInstance().emitParamChange(this, getSoundBuffer().getActiveSoundNumber(),
RackAttack.VOLUME_MOD_SRC, volumeModBox.getSelectedIndex());
sp.setAmpVolumeModSrcIndex(volumeModBox.getSelectedIndex());
}
public void soundParameterChanged(SoundParameter sp) {
initiating=true;
volumeKnob.setIntValue(sp.getAmpVolume());
volumeModKnob.setIntValue(sp.getAmpVolumeMod());
volumeCtrlKnob.setIntValue(sp.getAmpVolumeCtrl());
volumeModBox.setSelectedIndex(sp.getAmpVolumeModSrcIndex());
volumeCtrlBox.setSelectedIndex(sp.getAmpVolumeCtrlSrcIndex());
panKnob.setIntValue(sp.getAmpPan());
panModKnob.setIntValue(sp.getAmpPanMod());
panCtrlKnob.setIntValue(sp.getAmpPanCtrl());
panModBox.setSelectedIndex(sp.getAmpPanModSrcIndex());
panCtrlBox.setSelectedIndex(sp.getAmpPanCtrlSrcIndex());
syncSpinner();
initiating=false;
}
protected void syncSpinner() {
volumeSpinner.setValue(new Integer(volumeKnob.getIntValue()));
volumeModSpinner.setValue(new Integer(volumeModKnob.getIntValue()-64));
volumeCtrlSpinner.setValue(new Integer(volumeCtrlKnob.getIntValue()-64));
panSpinner.setValue(new Integer(panKnob.getIntValue()-64));
panModSpinner.setValue(new Integer(panModKnob.getIntValue()-64));
panCtrlSpinner.setValue(new Integer(panCtrlKnob.getIntValue()-64));
}
// Component events
private void panCtrlSpinnerStateChanged(ChangeEvent evt) {
if (initiating) {
return;
}
panCtrlKnob.setIntValue(((Integer)panCtrlSpinner.getValue()).intValue()+64);
}
private void panModSpinnerStateChanged(ChangeEvent evt) {
if (initiating) {
return;
}
panModKnob.setIntValue(((Integer)panModSpinner.getValue()).intValue()+64);
}
private void panSpinnerStateChanged(ChangeEvent evt) {
if (initiating) {
return;
}
panKnob.setIntValue(((Integer)panSpinner.getValue()).intValue()+64);
}
private void volumeCtrlSpinnerStateChanged(ChangeEvent evt) {
if (initiating) {
return;
}
volumeCtrlKnob.setIntValue(((Integer)volumeCtrlSpinner.getValue()).intValue()+64);
}
private void volumeModSpinnerStateChanged(ChangeEvent evt) {
if (initiating) {
return;
}
volumeModKnob.setIntValue(((Integer)volumeModSpinner.getValue()).intValue()+64);
}
private void volumeSpinnerStateChanged(ChangeEvent evt) {
if (initiating) {
return;
}
volumeKnob.setIntValue(((Integer)volumeSpinner.getValue()).intValue());
}
private void panCtrlKnobStateChanged(ChangeEvent evt) {
if (initiating) {
return;
}
panCtrlSpinner.setValue(new Integer(panCtrlKnob.getIntValue()-64));
MidiThread.getInstance().emitParamChange(this,
getSoundBuffer().getActiveSoundNumber(),
RackAttack.PAN_CTRL,
panCtrlKnob.getIntValue());
}
private void panModKnobStateChanged(ChangeEvent evt) {
if (initiating) {
return;
}
panModSpinner.setValue(new Integer(panModKnob.getIntValue()-64));
MidiThread.getInstance().emitParamChange(this,
getSoundBuffer().getActiveSoundNumber(),
RackAttack.PAN_MOD,
panModKnob.getIntValue());
}
private void panKnobStateChanged(ChangeEvent evt) {
panSpinner.setValue(new Integer(panKnob.getIntValue()-64));
if (initiating) {
return;
}
MidiThread.getInstance().emitPanChange(this, getSoundBuffer().getActiveSoundNumber(),
panKnob.getIntValue());
}
private void volumeCtrlKnobStateChanged(ChangeEvent evt) {
volumeCtrlSpinner.setValue(new Integer(volumeCtrlKnob.getIntValue()-64));
if (initiating) {
return;
}
MidiThread.getInstance().emitParamChange(this,
getSoundBuffer().getActiveSoundNumber(),
RackAttack.VOLUME_CTRL,
volumeCtrlKnob.getIntValue());
}
private void volumeModKnobStateChanged(ChangeEvent evt) {
volumeModSpinner.setValue(new Integer(volumeModKnob.getIntValue()-64));
if (initiating) {
return;
}
MidiThread.getInstance().emitParamChange(this,
getSoundBuffer().getActiveSoundNumber(),
RackAttack.VOLUME_MOD,
volumeModKnob.getIntValue());
}
private void volumeKnobStateChanged(ChangeEvent evt) {
volumeSpinner.setValue(new Integer(volumeKnob.getIntValue()));
if (initiating) {
return;
}
MidiThread.getInstance().emitVolumeChange(this, getSoundBuffer().getActiveSoundNumber(),
volumeKnob.getIntValue());
}
private boolean initiating;
// Variables declaration - do not modify
private JKnob jKnob1;
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel6;
private JComboBox panCtrlBox;
private JKnob panCtrlKnob;
private JSpinner panCtrlSpinner;
private JKnob panKnob;
private JComboBox panModBox;
private JKnob panModKnob;
private JSpinner panModSpinner;
private JSpinner panSpinner;
private JComboBox volumeCtrlBox;
private JKnob volumeCtrlKnob;
private JSpinner volumeCtrlSpinner;
private JKnob volumeKnob;
private JComboBox volumeModBox;
private JKnob volumeModKnob;
private JSpinner volumeModSpinner;
private JSpinner volumeSpinner;
// End of variables declaration
/**
* Holds value of property soundBuffer.
*/
private SoundBuffer soundBuffer;
/**
* Getter for property soundBuffer.
* @return Value of property soundBuffer.
*/
public SoundBuffer getSoundBuffer() {
return this.soundBuffer;
}
/**
* Setter for property soundBuffer.
* @param soundBuffer New value of property soundBuffer.
*/
public void setSoundBuffer(SoundBuffer soundBuffer) {
this.soundBuffer = soundBuffer;
}
}
/*
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).
*/