/* For License see bottom */
/*
* LFOPanel.java
*
* Created on 13. Juli 2007, 20:50
*/
package jrackattack.gui;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JPanel;
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 13:46:50 -0500 (Tue, 15 Sep 2009) $",
authors={"Alexander Methke"},
revision="$LastChangedRevision: 14 $",
lastEditor="$LastChangedBy: onkobu $",
id="$Id"
)
public class LFOPanel extends JPanel {
public enum Mode {
LFO1,
LFO2
};
/** Creates new form LFOPanel */
public LFOPanel() {
initComponents();
initValues();
}
protected void initValues() {
initiating=true;
syncBox.removeAllItems();
for (String syn:RackAttack.LFO_SYNC) {
syncBox.addItem(syn);
}
shapeBox.removeAllItems();
for (String sh:RackAttack.LFO_SHAPE) {
shapeBox.addItem(sh);
}
modSrcBox.removeAllItems();
for (String md:RackAttack.MOD_SOURCE) {
modSrcBox.addItem(md);
}
((SpinnerNumberModel)speedSpinner.getModel()).setMinimum(0);
((SpinnerNumberModel)speedSpinner.getModel()).setMaximum(127);
speedSpinner.setValue(new Integer(0));
((SpinnerNumberModel)modSpinner.getModel()).setMinimum(-64);
((SpinnerNumberModel)modSpinner.getModel()).setMaximum(63);
modSpinner.setValue(new Integer(0));
modKnob.setIntValue(64);
initiating=false;
}
public void soundParameterChanged(SoundParameter sp) {
initiating=true;
if (getMode()==Mode.LFO1) {
speedKnob.setIntValue(sp.getLFO1Speed());
shapeBox.setSelectedIndex(sp.getLFO1ShapeIndex());
syncBox.setSelectedIndex(sp.getLFO1Sync());
oneShotCheckBox.setSelected(sp.getLFO1OneShot()>0);
} else {
speedKnob.setIntValue(sp.getLFO2Speed());
modKnob.setValue(sp.getLFO2Mod());
modSrcBox.setSelectedIndex(sp.getLFO2ModSrcIndex());
shapeBox.setSelectedIndex(sp.getLFO2ShapeIndex());
syncBox.setSelectedIndex(sp.getLFO2Sync());
modKnob.setIntValue(sp.getLFO2Mod());
modSrcBox.setSelectedIndex(sp.getLFO2ModSrcIndex());
}
syncSpinner();
initiating=false;
}
protected void syncSpinner() {
speedSpinner.setValue(new Integer(speedKnob.getIntValue()));
modSpinner.setValue(new Integer(modKnob.getIntValue()-64));
}
/** 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 ">//GEN-BEGIN:initComponents
private void initComponents() {
GridBagConstraints gridBagConstraints;
speedKnob = new jrackattack.gui.JKnob();
shapeBox = new javax.swing.JComboBox();
speedLabel = new javax.swing.JLabel();
oneShotCheckBox = new javax.swing.JCheckBox();
modKnob = new jrackattack.gui.JKnob();
modSpinner = new javax.swing.JSpinner();
speedSpinner = new javax.swing.JSpinner();
modLabel = new javax.swing.JLabel();
modSrcBox = new javax.swing.JComboBox();
syncBox = new javax.swing.JComboBox();
setLayout(new GridBagLayout());
speedKnob.setIntValue(0);
speedKnob.setMaximumValue(127);
speedKnob.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
speedKnobStateChanged(evt);
}
});
GroupLayout speedKnobLayout = new GroupLayout(speedKnob);
speedKnob.setLayout(speedKnobLayout);
speedKnobLayout.setHorizontalGroup(
speedKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 80, Short.MAX_VALUE)
);
speedKnobLayout.setVerticalGroup(
speedKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 80, Short.MAX_VALUE)
);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridheight = 2;
add(speedKnob, gridBagConstraints);
shapeBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
shapeBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
shapeBoxItemStateChanged(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(shapeBox, gridBagConstraints);
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("jrackattack/gui"); // NOI18N
speedLabel.setText(bundle.getString("label.speed")); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridy = 3;
add(speedLabel, gridBagConstraints);
oneShotCheckBox.setText(bundle.getString("checkbox.one_shot")); // NOI18N
oneShotCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
oneShotCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
oneShotCheckBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oneShotCheckBoxActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 3;
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
add(oneShotCheckBox, gridBagConstraints);
modKnob.setIntValue(0);
modKnob.setMaximumValue(127);
modKnob.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
modKnobStateChanged(evt);
}
});
GroupLayout modKnobLayout = new GroupLayout(modKnob);
modKnob.setLayout(modKnobLayout);
modKnobLayout.setHorizontalGroup(
modKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 80, Short.MAX_VALUE)
);
modKnobLayout.setVerticalGroup(
modKnobLayout.createParallelGroup(GroupLayout.LEADING)
.add(0, 80, Short.MAX_VALUE)
);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridheight = 2;
add(modKnob, gridBagConstraints);
modSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
modSpinnerStateChanged(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
add(modSpinner, gridBagConstraints);
speedSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
speedSpinnerStateChanged(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
add(speedSpinner, gridBagConstraints);
modLabel.setText(bundle.getString("label.mod")); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 3;
add(modLabel, gridBagConstraints);
modSrcBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
modSrcBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
modSrcBoxItemStateChanged(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(modSrcBox, gridBagConstraints);
syncBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
syncBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
syncBoxItemStateChanged(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
add(syncBox, gridBagConstraints);
}// </editor-fold>//GEN-END:initComponents
private void syncBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_syncBoxItemStateChanged
// TODO add your handling code here:
if (initiating) {
return;
}
if (getMode()==Mode.LFO1) {
MidiThread.getInstance().emitParamChange(this,
getSoundBuffer().getActiveSoundNumber(),
RackAttack.LFO1_SYNC,
syncBox.getSelectedIndex());
} else {
MidiThread.getInstance().emitParamChange(this,
getSoundBuffer().getActiveSoundNumber(),
RackAttack.LFO2_SYNC,
syncBox.getSelectedIndex());
}
}//GEN-LAST:event_syncBoxItemStateChanged
private void oneShotCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oneShotCheckBoxActionPerformed
// TODO add your handling code here:
if (initiating) {
return;
}
if (getMode()==Mode.LFO1) {
MidiThread.getInstance().emitParamChange(this,
getSoundBuffer().getActiveSoundNumber(),
RackAttack.LFO1_ONE_SHOT,
oneShotCheckBox.isEnabled()?1:0);
}
}//GEN-LAST:event_oneShotCheckBoxActionPerformed
private void modSrcBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_modSrcBoxItemStateChanged
// TODO add your handling code here:
if (initiating) {
return;
}
if (getMode()==Mode.LFO2) {
MidiThread.getInstance().emitParamChange(this,
getSoundBuffer().getActiveSoundNumber(),
RackAttack.LFO2_MOD_SRC,
modSrcBox.getSelectedIndex());
}
}//GEN-LAST:event_modSrcBoxItemStateChanged
private void shapeBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_shapeBoxItemStateChanged
// TODO add your handling code here:
if (initiating) {
return;
}
if (getMode()==Mode.LFO1) {
MidiThread.getInstance().emitParamChange(this,
getSoundBuffer().getActiveSoundNumber(),
RackAttack.LFO1_SHAPE,
shapeBox.getSelectedIndex());
} else {
MidiThread.getInstance().emitParamChange(this,
getSoundBuffer().getActiveSoundNumber(),
RackAttack.LFO2_SHAPE,
shapeBox.getSelectedIndex());
}
}//GEN-LAST:event_shapeBoxItemStateChanged
private void modSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_modSpinnerStateChanged
// TODO add your handling code here:
if (initiating) {
return;
}
modKnob.setIntValue(((Integer)modSpinner.getValue()).intValue()+64);
}//GEN-LAST:event_modSpinnerStateChanged
private void speedSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_speedSpinnerStateChanged
// TODO add your handling code here:
if (initiating) {
return;
}
speedKnob.setIntValue(((Integer)speedSpinner.getValue()).intValue());
}//GEN-LAST:event_speedSpinnerStateChanged
private void modKnobStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_modKnobStateChanged
// TODO add your handling code here:
if (initiating) {
return;
}
modSpinner.setValue(new Integer(modKnob.getIntValue()-64));
if (getMode()==Mode.LFO2) {
MidiThread.getInstance().emitParamChange(this,
getSoundBuffer().getActiveSoundNumber(),
RackAttack.LFO2_MOD,
modKnob.getIntValue());
}
}//GEN-LAST:event_modKnobStateChanged
private void speedKnobStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_speedKnobStateChanged
// TODO add your handling code here:
if (initiating) {
return;
}
speedSpinner.setValue(new Integer(speedKnob.getIntValue()));
if (getMode()==Mode.LFO1) {
MidiThread.getInstance().emitParamChange(this,
getSoundBuffer().getActiveSoundNumber(),
RackAttack.LFO1_SPEED,
speedKnob.getIntValue());
} else {
MidiThread.getInstance().emitParamChange(this,
getSoundBuffer().getActiveSoundNumber(),
RackAttack.LFO2_SPEED,
speedKnob.getIntValue());
}
}//GEN-LAST:event_speedKnobStateChanged
/**
* Getter for property mode.
* @return Value of property mode.
*/
public Mode getMode() {
return this.mode;
}
/**
* Setter for property mode.
* @param mode New value of property mode.
*/
public void setMode(Mode mode) {
this.mode = mode;
if (mode==Mode.LFO1) {
modKnob.setEnabled(false);
modSpinner.setEnabled(false);
modSrcBox.setEnabled(false);
oneShotCheckBox.setEnabled(true);
} else {
modKnob.setEnabled(true);
modSpinner.setEnabled(true);
modSrcBox.setEnabled(true);
oneShotCheckBox.setEnabled(false);
}
}
/**
* 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;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private jrackattack.gui.JKnob modKnob;
private javax.swing.JLabel modLabel;
private javax.swing.JSpinner modSpinner;
private javax.swing.JComboBox modSrcBox;
private javax.swing.JCheckBox oneShotCheckBox;
private javax.swing.JComboBox shapeBox;
private jrackattack.gui.JKnob speedKnob;
private javax.swing.JLabel speedLabel;
private javax.swing.JSpinner speedSpinner;
private javax.swing.JComboBox syncBox;
// End of variables declaration//GEN-END:variables
/**
* Holds value of property mode.
*/
private Mode mode;
private boolean initiating;
/**
* Holds value of property soundBuffer.
*/
private 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).
*/