Package jrackattack.gui

Source Code of jrackattack.gui.FXEditPanel$FXDescription

/* For License see bottom */
/*
* FXEditPanel.java
*
* Created on 27. Juli 2007, 21:35
*/

package jrackattack.gui;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.HashMap;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import jonkoshare.util.VersionInformation;
import jrackattack.event.FXParameterEvent;
import jrackattack.event.FXParameterListener;
import jrackattack.midi.FXParameter;
import jrackattack.midi.MidiThread;
import jrackattack.midi.ParameterChange;
import jrackattack.midi.RackAttack;

import org.apache.log4j.Logger;
import org.jdesktop.layout.GroupLayout;

/**
* Panel to edit a single FX setting.
*
* @since 0.7
* @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 FXEditPanel extends JPanel implements
    FXParameterListener {
  private static final Logger log = Logger.getLogger(FXEditPanel.class);

  /** Creates new form FXEditPanel */
  public FXEditPanel() {
    if (descriptionMap == null) {
      descriptionMap = new HashMap<String, FXDescription>();
      for (int i = 0; i < RackAttack.FX_TYPES1_2.length; i++) {
        descriptionMap.put(RackAttack.FX_TYPES1_2[i],
            new FXDescription(RackAttack.FX_TYPES1_2[i],
                CONTROL_MATRIX[i], RackAttack.FX_RANGES[i],
                RackAttack.FX_AH_AL[i],
                RackAttack.FX_DESCRIPTIONS[i]));
      }
    }
    initComponents();
    initValues();
  }

  /**
   * 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();
    jKnob2 = new JKnob();
    jKnob3 = new JKnob();
    jKnob4 = new JKnob();
    jKnob5 = new JKnob();
    jKnob6 = new JKnob();
    jKnob7 = new JKnob();
    jSpinner1 = new JSpinner();
    jSpinner2 = new JSpinner();
    jSpinner3 = new JSpinner();
    jSpinner4 = new JSpinner();
    jSpinner5 = new JSpinner();
    jSpinner6 = new JSpinner();
    jSpinner7 = new JSpinner();
    typeBox = new JComboBox();
    jLabel1 = new JLabel();
    jLabel2 = new JLabel();
    jLabel3 = new JLabel();
    jLabel4 = new JLabel();
    jLabel5 = new JLabel();
    jLabel6 = new JLabel();
    jLabel7 = new JLabel();
    syncBox = new JComboBox();
    posButton = new JRadioButton();
    negButton = new JRadioButton();
    outBox = new JComboBox();
    autoPanBox = new JCheckBox();
    loadButton = new JButton();
    jKnob8 = new JKnob();
    jSpinner8 = new JSpinner();
    jLabel8 = new JLabel();

    setLayout(new GridBagLayout());

    jKnob1.setIntValue(0);
    jKnob1.setMaximumValue(127);
    jKnob1.setPreferredSize(new Dimension(60, 60));
    jKnob1.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jKnob1StateChanged(evt);
      }
    });

    GroupLayout jKnob1Layout = new GroupLayout(
        jKnob1);
    jKnob1.setLayout(jKnob1Layout);
    jKnob1Layout.setHorizontalGroup(jKnob1Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    jKnob1Layout.setVerticalGroup(jKnob1Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jKnob1, gridBagConstraints);

    jKnob2.setIntValue(0);
    jKnob2.setMaximumValue(127);
    jKnob2.setPreferredSize(new Dimension(60, 60));
    jKnob2.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jKnob2StateChanged(evt);
      }
    });

    GroupLayout jKnob2Layout = new GroupLayout(
        jKnob2);
    jKnob2.setLayout(jKnob2Layout);
    jKnob2Layout.setHorizontalGroup(jKnob2Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    jKnob2Layout.setVerticalGroup(jKnob2Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jKnob2, gridBagConstraints);

    jKnob3.setIntValue(0);
    jKnob3.setMaximumValue(127);
    jKnob3.setPreferredSize(new Dimension(60, 60));
    jKnob3.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jKnob3StateChanged(evt);
      }
    });

    GroupLayout jKnob3Layout = new GroupLayout(
        jKnob3);
    jKnob3.setLayout(jKnob3Layout);
    jKnob3Layout.setHorizontalGroup(jKnob3Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    jKnob3Layout.setVerticalGroup(jKnob3Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jKnob3, gridBagConstraints);

    jKnob4.setIntValue(0);
    jKnob4.setMaximumValue(127);
    jKnob4.setPreferredSize(new Dimension(60, 60));
    jKnob4.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jKnob4StateChanged(evt);
      }
    });

    GroupLayout jKnob4Layout = new GroupLayout(
        jKnob4);
    jKnob4.setLayout(jKnob4Layout);
    jKnob4Layout.setHorizontalGroup(jKnob4Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    jKnob4Layout.setVerticalGroup(jKnob4Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jKnob4, gridBagConstraints);

    jKnob5.setIntValue(0);
    jKnob5.setMaximumValue(127);
    jKnob5.setPreferredSize(new Dimension(60, 60));
    jKnob5.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jKnob5StateChanged(evt);
      }
    });

    GroupLayout jKnob5Layout = new GroupLayout(
        jKnob5);
    jKnob5.setLayout(jKnob5Layout);
    jKnob5Layout.setHorizontalGroup(jKnob5Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    jKnob5Layout.setVerticalGroup(jKnob5Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 4;
    gridBagConstraints.gridheight = 3;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jKnob5, gridBagConstraints);

    jKnob6.setIntValue(0);
    jKnob6.setMaximumValue(127);
    jKnob6.setPreferredSize(new Dimension(60, 60));
    jKnob6.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jKnob6StateChanged(evt);
      }
    });

    GroupLayout jKnob6Layout = new GroupLayout(
        jKnob6);
    jKnob6.setLayout(jKnob6Layout);
    jKnob6Layout.setHorizontalGroup(jKnob6Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    jKnob6Layout.setVerticalGroup(jKnob6Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 4;
    gridBagConstraints.gridheight = 3;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jKnob6, gridBagConstraints);

    jKnob7.setIntValue(0);
    jKnob7.setMaximumValue(127);
    jKnob7.setPreferredSize(new Dimension(60, 60));
    jKnob7.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jKnob7StateChanged(evt);
      }
    });

    GroupLayout jKnob7Layout = new GroupLayout(
        jKnob7);
    jKnob7.setLayout(jKnob7Layout);
    jKnob7Layout.setHorizontalGroup(jKnob7Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    jKnob7Layout.setVerticalGroup(jKnob7Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 4;
    gridBagConstraints.gridheight = 3;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jKnob7, gridBagConstraints);

    jSpinner1.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jSpinner1StateChanged(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 2;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jSpinner1, gridBagConstraints);

    jSpinner2.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jSpinner2StateChanged(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 2;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jSpinner2, gridBagConstraints);

    jSpinner3.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jSpinner3StateChanged(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 2;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jSpinner3, gridBagConstraints);

    jSpinner4.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jSpinner4StateChanged(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 2;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jSpinner4, gridBagConstraints);

    jSpinner5.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jSpinner5StateChanged(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 7;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jSpinner5, gridBagConstraints);

    jSpinner6.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jSpinner6StateChanged(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 7;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jSpinner6, gridBagConstraints);

    jSpinner7.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        jSpinner7StateChanged(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 7;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jSpinner7, gridBagConstraints);

    typeBox.setModel(new DefaultComboBoxModel(new String[] {
        "Item 1", "Item 2", "Item 3", "Item 4" }));
    typeBox.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent evt) {
        typeBoxItemStateChanged(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 4;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = 2;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(typeBox, gridBagConstraints);

    java.util.ResourceBundle bundle = java.util.ResourceBundle
        .getBundle("jrackattack/gui"); // NOI18N
    jLabel1.setText(bundle.getString("label.disabled")); // NOI18N
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 3;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jLabel1, gridBagConstraints);

    jLabel2.setText(bundle.getString("label.disabled")); // NOI18N
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 3;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jLabel2, gridBagConstraints);

    jLabel3.setText(bundle.getString("label.disabled")); // NOI18N
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 3;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jLabel3, gridBagConstraints);

    jLabel4.setText(bundle.getString("label.disabled")); // NOI18N
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 3;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jLabel4, gridBagConstraints);

    jLabel5.setText(bundle.getString("label.disabled")); // NOI18N
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 8;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jLabel5, gridBagConstraints);

    jLabel6.setText(bundle.getString("label.disabled")); // NOI18N
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 8;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jLabel6, gridBagConstraints);

    jLabel7.setText(bundle.getString("label.disabled")); // NOI18N
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridy = 8;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jLabel7, gridBagConstraints);

    syncBox.setModel(new DefaultComboBoxModel(new String[] {
        "Item 1", "Item 2", "Item 3", "Item 4" }));
    syncBox.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent evt) {
        syncBoxItemStateChanged(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 4;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(syncBox, gridBagConstraints);

    posButton.setText(bundle.getString("radio.pos")); // NOI18N
    posButton.setBorder(BorderFactory.createEmptyBorder(0, 0,
        0, 0));
    posButton.setMargin(new Insets(0, 0, 0, 0));
    posButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        posButtonActionPerformed(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 4;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(posButton, gridBagConstraints);

    negButton.setText(bundle.getString("radio.neg_polarity")); // NOI18N
    negButton.setBorder(BorderFactory.createEmptyBorder(0, 0,
        0, 0));
    negButton.setMargin(new Insets(0, 0, 0, 0));
    negButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        negButtonActionPerformed(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 4;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(negButton, gridBagConstraints);

    outBox.setModel(new DefaultComboBoxModel(new String[] {
        "Item 1", "Item 2", "Item 3", "Item 4" }));
    outBox.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent evt) {
        outBoxItemStateChanged(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 4;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(outBox, gridBagConstraints);

    autoPanBox.setText(bundle.getString("checkbox.auto_pan")); // NOI18N
    autoPanBox.setBorder(BorderFactory.createEmptyBorder(0, 0,
        0, 0));
    autoPanBox.setMargin(new Insets(0, 0, 0, 0));
    autoPanBox.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        autoPanBoxActionPerformed(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 4;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(autoPanBox, gridBagConstraints);

    loadButton.setText(bundle.getString("button.load")); // NOI18N
    loadButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        loadButtonActionPerformed(evt);
      }
    });

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 4;
    gridBagConstraints.gridy = 7;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(loadButton, gridBagConstraints);

    jKnob8.setIntValue(0);
    jKnob8.setMaximumValue(127);
    jKnob8.setPreferredSize(new Dimension(60, 60));
    GroupLayout jKnob8Layout = new GroupLayout(
        jKnob8);
    jKnob8.setLayout(jKnob8Layout);
    jKnob8Layout.setHorizontalGroup(jKnob8Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    jKnob8Layout.setVerticalGroup(jKnob8Layout.createParallelGroup(
        GroupLayout.LEADING).add(0, 60,
        Short.MAX_VALUE));
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.gridheight = 3;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jKnob8, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 7;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jSpinner8, gridBagConstraints);

    jLabel8.setText(bundle.getString("label.disabled")); // NOI18N
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 3;
    gridBagConstraints.gridy = 8;
    gridBagConstraints.insets = new Insets(2, 2, 2, 2);
    add(jLabel8, gridBagConstraints);

  }

  private void loadButtonActionPerformed(ActionEvent evt) {
    MidiThread.getInstance().loadFXParameter(getFxNumber(), true);
  }

  private void autoPanBoxActionPerformed(ActionEvent evt) {
    if (initiating) {
      return;
    }
    if (autoPanBox.isSelected()) {
      MidiThread.getInstance().emitFxChange(this, getFxNumber(),
          RackAttack.FX_AUTO_PAN, 1);
    } else {
      MidiThread.getInstance().emitFxChange(this, getFxNumber(),
          RackAttack.FX_AUTO_PAN, 0);
    }
  }

  private void negButtonActionPerformed(ActionEvent evt) {
    if (initiating) {
      return;
    }
    MidiThread.getInstance().emitFxChange(this, getFxNumber(),
        RackAttack.FX_POLARITY, 1);
  }

  private void posButtonActionPerformed(ActionEvent evt) {
    if (initiating) {
      return;
    }
    MidiThread.getInstance().emitFxChange(this, getFxNumber(),
        RackAttack.FX_POLARITY, 0);
  }

  private void syncBoxItemStateChanged(ItemEvent evt) {
    if (initiating) {
      return;
    }
    if (evt.getStateChange() != ItemEvent.SELECTED) {
      return;
    }
    if (typeBox.getSelectedItem().equals("Delay")) {
      MidiThread.getInstance().emitFxChange(this, getFxNumber(),
          RackAttack.FX_DELAY_SYNC, syncBox.getSelectedIndex());
    } else {
      MidiThread.getInstance().emitFxChange(this, getFxNumber(),
          RackAttack.FX_SYNC, syncBox.getSelectedIndex());
    }
  }

  private void outBoxItemStateChanged(ItemEvent evt) {
    if (initiating) {
      return;
    }
    if (evt.getStateChange() != ItemEvent.SELECTED) {
      return;
    }
    MidiThread.getInstance().emitFxChange(this, getFxNumber(),
        RackAttack.FX_OUTPUT, outBox.getSelectedIndex());
  }

  private void typeBoxItemStateChanged(ItemEvent evt) {
    if (initiating) {
      return;
    }
    if (evt.getStateChange() != ItemEvent.SELECTED) {
      return;
    }
    if (getFxNumber() > 1) {
      if (typeBox.getSelectedIndex() > 4
          && typeBox.getSelectedIndex() < 8) {
        // do nothing, efx disabled
      } else if (typeBox.getSelectedIndex() <= 4) {
        MidiThread.getInstance().emitFxChange(this, getFxNumber(),
            RackAttack.FX_TYPE, typeBox.getSelectedIndex());
      } else {
        MidiThread.getInstance().emitFxChange(this, getFxNumber(),
            RackAttack.FX_TYPE, typeBox.getSelectedIndex() - 3);
      }
    } else {
      MidiThread.getInstance().emitFxChange(this, getFxNumber(),
          RackAttack.FX_TYPE, typeBox.getSelectedIndex());
    }
    enableForType();
  }

  protected void enableForType() {
    boolean polarityFlag = false;
    boolean syncFlag = false;
    boolean autoPanFlag = false;
    if (typeBox.getSelectedIndex() == 0
        || (getFxNumber() > 1 && typeBox.getSelectedIndex() > 4 && typeBox
            .getSelectedIndex() < 8)) {
      for (int i = 0; i < knobs.length; i++) {
        knobs[i].setEnabled(false);
        labels[i].setEnabled(false);
        spinner[i].setEnabled(false);
      }
      posButton.setEnabled(false);
      negButton.setEnabled(false);
      syncBox.setEnabled(false);
      outBox.setEnabled(false);
      return;
    }
    // the following effects are not available for FX 3 & 4
    //
    outBox.setEnabled(true);
    java.util.ResourceBundle bundle = java.util.ResourceBundle
        .getBundle("jrackattack/gui");
    int spinnerIdx = 0;
    String[] descs = getActiveDescription().getDescriptions();
    for (int i = 0; i < 9; i++) {
      if (i >= descs.length) {
        if (spinnerIdx < 8) {
          knobs[spinnerIdx].setEnabled(false);
          labels[spinnerIdx].setEnabled(false);
          spinner[spinnerIdx].setEnabled(false);
          labels[spinnerIdx].setText(bundle
              .getString("label.disabled"));
          spinnerIdx++;
          continue;
        } else {
          break;
        }
      } else if (descs[i].equals("Sync")) {
        syncBox.setEnabled(true);
        syncFlag = true;
        continue;
      } else if (descs[i].equals("Polarity")) {
        posButton.setEnabled(true);
        negButton.setEnabled(true);
        polarityFlag = true;
        continue;
      } else if (descs[i].equals("Auto Pan")) {
        autoPanBox.setEnabled(true);
        autoPanFlag = true;
        continue;
      }
      labels[spinnerIdx].setText(descs[i]);
      labels[spinnerIdx].setEnabled(true);
      spinner[spinnerIdx].setEnabled(true);
      knobs[spinnerIdx].setEnabled(true);
      knobOffsets[spinnerIdx] = i;
      spinnerIdx++;
    }
    if (!syncFlag) {
      syncBox.setEnabled(false);
    }
    if (!polarityFlag) {
      posButton.setEnabled(false);
      negButton.setEnabled(false);
    }
    if (!autoPanFlag) {
      autoPanBox.setEnabled(false);
    }
  }

  protected int getTypeNumber() {
    if (getFxNumber() > 1 && typeBox.getSelectedIndex() > 4) {
      return typeBox.getSelectedIndex() - 3;
    } else {
      return typeBox.getSelectedIndex();
    }
  }

  private void jKnob7StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jSpinner7.setValue(jKnob7.getIntValue());
    MidiThread.getInstance().emitFxChange(this, getFxNumber(),
        RackAttack.FX_AH_AL[getTypeNumber()][knobOffsets[6]],
        jKnob7.getIntValue());
  }

  private void jKnob6StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jSpinner6.setValue(jKnob6.getIntValue());
    MidiThread.getInstance().emitFxChange(this, getFxNumber(),
        RackAttack.FX_AH_AL[getTypeNumber()][knobOffsets[5]],
        jKnob6.getIntValue());
  }

  private void jKnob5StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jSpinner5.setValue(jKnob5.getIntValue());
    MidiThread.getInstance().emitFxChange(this, getFxNumber(),
        RackAttack.FX_AH_AL[getTypeNumber()][knobOffsets[4]],
        jKnob5.getIntValue());
  }

  private void jKnob4StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jSpinner4.setValue(jKnob4.getIntValue());
    MidiThread.getInstance().emitFxChange(this, getFxNumber(),
        RackAttack.FX_AH_AL[getTypeNumber()][knobOffsets[3]],
        jKnob4.getIntValue());
  }

  private void jKnob3StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jSpinner3.setValue(jKnob3.getIntValue());
    MidiThread.getInstance().emitFxChange(this, getFxNumber(),
        RackAttack.FX_AH_AL[getTypeNumber()][knobOffsets[2]],
        jKnob3.getIntValue());
  }

  private void jKnob2StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jSpinner2.setValue(jKnob2.getIntValue());
    MidiThread.getInstance().emitFxChange(this, getFxNumber(),
        RackAttack.FX_AH_AL[getTypeNumber()][knobOffsets[1]],
        jKnob2.getIntValue());
  }

  private void jKnob1StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jSpinner1.setValue(jKnob1.getIntValue());
    MidiThread.getInstance().emitFxChange(this, getFxNumber(),
        RackAttack.FX_AH_AL[getTypeNumber()][knobOffsets[0]],
        jKnob1.getIntValue());
  }

  private void jSpinner7StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jKnob7.setIntValue(((Integer) jSpinner7.getValue()).intValue());
  }

  private void jSpinner6StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jKnob6.setIntValue(((Integer) jSpinner6.getValue()).intValue());
  }

  private void jSpinner5StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jKnob5.setIntValue(((Integer) jSpinner5.getValue()).intValue());
  }

  private void jSpinner4StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jKnob4.setIntValue(((Integer) jSpinner4.getValue()).intValue());
  }

  private void jSpinner3StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jKnob3.setIntValue(((Integer) jSpinner3.getValue()).intValue());
  }

  private void jSpinner2StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jKnob2.setIntValue(((Integer) jSpinner2.getValue()).intValue());
  }

  private void jSpinner1StateChanged(ChangeEvent evt) {
    if (initiating) {
      return;
    }
    jKnob1.setIntValue(((Integer) jSpinner1.getValue()).intValue());
  }

  protected void initValues() {
    initiating = true;
    typeBox.removeAllItems();
    if (getFxNumber() > 1) {
      for (String t : RackAttack.FX_TYPES3_4) {
        typeBox.addItem(t);
      }
    } else {
      for (String t : RackAttack.FX_TYPES1_2) {
        typeBox.addItem(t);
      }
    }
    syncBox.removeAllItems();
    for (String t : RackAttack.FX_SYNCS) {
      syncBox.addItem(t);
    }
    outBox.removeAllItems();
    for (String t : RackAttack.DRY_OUTS) {
      outBox.addItem(t);
    }
    ((SpinnerNumberModel) jSpinner1.getModel()).setMinimum(0);
    ((SpinnerNumberModel) jSpinner1.getModel()).setMaximum(127);
    ((SpinnerNumberModel) jSpinner2.getModel()).setMinimum(0);
    ((SpinnerNumberModel) jSpinner2.getModel()).setMaximum(127);
    ((SpinnerNumberModel) jSpinner3.getModel()).setMinimum(0);
    ((SpinnerNumberModel) jSpinner3.getModel()).setMaximum(127);
    ((SpinnerNumberModel) jSpinner4.getModel()).setMinimum(0);
    ((SpinnerNumberModel) jSpinner4.getModel()).setMaximum(127);
    ((SpinnerNumberModel) jSpinner5.getModel()).setMinimum(0);
    ((SpinnerNumberModel) jSpinner5.getModel()).setMaximum(127);
    ((SpinnerNumberModel) jSpinner6.getModel()).setMinimum(0);
    ((SpinnerNumberModel) jSpinner6.getModel()).setMaximum(127);
    ((SpinnerNumberModel) jSpinner7.getModel()).setMinimum(0);
    ((SpinnerNumberModel) jSpinner7.getModel()).setMaximum(127);
    ((SpinnerNumberModel) jSpinner8.getModel()).setMinimum(0);
    ((SpinnerNumberModel) jSpinner8.getModel()).setMaximum(127);

    spinner[0] = jSpinner1;
    spinner[1] = jSpinner2;
    spinner[2] = jSpinner3;
    spinner[3] = jSpinner4;
    spinner[4] = jSpinner5;
    spinner[5] = jSpinner6;
    spinner[6] = jSpinner7;
    spinner[7] = jSpinner8;
    labels[0] = jLabel1;
    labels[1] = jLabel2;
    labels[2] = jLabel3;
    labels[3] = jLabel4;
    labels[4] = jLabel5;
    labels[5] = jLabel6;
    labels[6] = jLabel7;
    labels[7] = jLabel8;
    knobs[0] = jKnob1;
    knobs[1] = jKnob2;
    knobs[2] = jKnob3;
    knobs[3] = jKnob4;
    knobs[4] = jKnob5;
    knobs[5] = jKnob6;
    knobs[6] = jKnob7;
    knobs[7] = jKnob8;
    ButtonGroup bg = new ButtonGroup();
    bg.add(posButton);
    bg.add(negButton);
    reset();
    initiating = false;
  }

  protected void reset() {
    typeBox.setSelectedIndex(0);
    syncBox.setSelectedIndex(0);
    outBox.setSelectedIndex(0);

    for (int i = 0; i < knobs.length; i++) {
      knobs[i].setEnabled(false);
      knobs[i].setIntValue(0);
      labels[i].setEnabled(false);
      spinner[i].setEnabled(false);
      spinner[i].setValue(new Integer(0));
    }
    posButton.setSelected(true);
    negButton.setEnabled(false);
    posButton.setEnabled(false);
    syncBox.setEnabled(false);
    outBox.setEnabled(false);
    autoPanBox.setEnabled(false);
  }

  // FXParameterListener
  public void parameterChanged(FXParameter sp) {
    if (sp.getFxNumber() != getFxNumber()) {
      return;
    }
    initiating = true;
    reset();
    if (sp.getType() == FXParameter.FXType.BYPASS) {
      initiating = false;
      return;
    }
    if (getFxNumber() > 1 && sp.getTypeNumber() > 4) {
      typeBox.setSelectedIndex(sp.getTypeNumber() + 3);
    } else {
      typeBox.setSelectedIndex(sp.getTypeNumber());
    }
    log("parameter changed to :" + typeBox.getSelectedItem());
    enableForType();
    int[] controls = getActiveDescription().getControls();
    for (int i = 0; i < 18; i++) {
      if (i >= controls.length) {
        log("finished (" + i + ")");
        break;
      }
      int val = sp.getByte(i + 7);
      log("applying byte #" + i + ", value=" + val);
      applyValue(controls[i], val);
    }
    outBox.setSelectedIndex(sp.getOutput());
    syncSpinner();
    initiating = false;
  }

  protected void syncSpinner() {
    for (int i = 0; i < spinner.length; i++) {
      spinner[i].setValue(new Integer(knobs[i].getIntValue()));
    }
  }

  protected void applyValue(int idx, int val) {
    switch (idx) {
    // if it has no controller assigned, we don't need to
    // act in any way --Alexander Methke
    case -1: {
      log("no control assigned to " + idx);
      return;
    }
    case 0: {
      log("" + idx + " refers to knob 1");
      jKnob1.setIntValue(val);
    }
      break;
    case 1: {
      log("" + idx + " refers to knob 2");
      jKnob2.setIntValue(val);
    }
      break;
    case 2: {
      log("" + idx + " refers to knob 3");
      jKnob3.setIntValue(val);
    }
      break;
    case 3: {
      log("" + idx + " refers to knob 4");
      jKnob4.setIntValue(val);
    }
      break;
    case 4: {
      log("" + idx + " refers to knob 5");
      jKnob5.setIntValue(val);
    }
      break;
    case 5: {
      log("" + idx + " refers to knob 6");
      jKnob6.setIntValue(val);
    }
      break;
    case 6: {
      log("" + idx + " refers to knob 7");
      jKnob7.setIntValue(val);
    }
      break;
    case 7: {
      log("" + idx + " refers to knob 8");
      jKnob8.setIntValue(val);
    }
      break;
    case 8: {
      log("" + idx + " refers to polarity");
      if (val == 0) {
        posButton.setSelected(true);
      } else {
        negButton.setSelected(true);
      }
    }
      break;
    case 9: {
      log("" + idx + " refers to sync box");
      syncBox.setSelectedIndex(val);
    }
      break;
    case 10: {
      log("" + idx + " refers to auto pan");
      if (val == 0) {
        autoPanBox.setSelected(false);
      } else {
        autoPanBox.setSelected(true);
      }
    }
      break;
    default: {
      log("" + idx + " is forbidden");
    }
    }
  }

  /**
   * Change of a single parameter within a FX.
   */
  public void parameterChanged(ParameterChange pc) {
    if (pc.getFxNumber() != getFxNumber()) {
      return;
    }
    initiating = true;
    int[] controls = getActiveDescription().getControls();
    log("" + controls.length + " controls available for "
        + getActiveDescription());
    applyValue(controls[pc.getAL()], pc.getChange());
    syncSpinner();
    initiating = false;
  }

  public void parameterChanged(FXParameterEvent spe) {
    if (spe.getFxNumber() != getFxNumber() || spe.getSource() == this) {
      return;
    }
    initiating = true;

    initiating = false;
  }

  private boolean initiating;

  // Variables declaration - do not modify
  private JCheckBox autoPanBox;
  private JKnob jKnob1;
  private JKnob jKnob2;
  private JKnob jKnob3;
  private JKnob jKnob4;
  private JKnob jKnob5;
  private JKnob jKnob6;
  private JKnob jKnob7;
  private JKnob jKnob8;
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JLabel jLabel4;
  private JLabel jLabel5;
  private JLabel jLabel6;
  private JLabel jLabel7;
  private JLabel jLabel8;
  private JSpinner jSpinner1;
  private JSpinner jSpinner2;
  private JSpinner jSpinner3;
  private JSpinner jSpinner4;
  private JSpinner jSpinner5;
  private JSpinner jSpinner6;
  private JSpinner jSpinner7;
  private JSpinner jSpinner8;
  private JButton loadButton;
  private JRadioButton negButton;
  private JComboBox outBox;
  private JRadioButton posButton;
  private JComboBox syncBox;
  private JComboBox typeBox;
  // End of variables declaration

  private JSpinner[] spinner = new JSpinner[8];
  private JLabel[] labels = new JLabel[8];
  private JKnob[] knobs = new JKnob[8];

  /**
   * Holds value of property fxNumber.
   */
  private int fxNumber;

  /**
   * Getter for property fxNumber.
   *
   * @return Value of property fxNumber.
   */
  public int getFxNumber() {
    return this.fxNumber;
  }

  /**
   * Setter for property fxNumber.
   *
   * @param fxNumber
   *            New value of property fxNumber.
   */
  public void setFxNumber(int fxNumber) {
    this.fxNumber = fxNumber;
  }

  protected FXDescription getActiveDescription() {
    return descriptionMap.get(typeBox.getSelectedItem().toString());
  }

  /**
   * Description of how to map AL-values to controls. Whereas -1 means no
   * control, 0-7 knobs, 8=polarity, 9=sync map, 10=auto pan.
   */
  private static final int[][] CONTROL_MATRIX = {
  // Bypass
      {},
      // Chorus
      { -1, -1, 0, 1, -1, 2 },
      // Flanger
      { -1, -1, 0, 1, -1, -1, 2, -1, -1, -1, 8 },
      // Phaser
      { -1, -1, 0, 1, -1, -1, 2, 3, 4, -1, 8 },
      // Overdrive
      { -1, -1, -1, 0, 1, -1, -1, 2 },
      // Delay
      { -1, -1, -1, -1, -1, 0, 1, 2, -1, -1, 8, 10, 9 },
      // Mod Delay
      { -1, -1, 0, 1, 9, 2, 3, 4, 5, 6 },
      // Reverb
      { -1, -1, 0, 1, 2, 3, -1, 4, 5, 6, 7 },
      // Low Fi
      { -1, -1, -1, -1, -1, -1, 0, 1, 2 } };

  protected void log(String msg) {
    log.debug(msg);
  }

  public static class FXDescription {
    public FXDescription(String name, int[] ctrlMatrix, int[] rangeMatrix,
        byte[][] ahAl, String[] descMatrix) {
      this.name = name;
      this.controlMatrix = ctrlMatrix;
      this.rangeMatrix = rangeMatrix;
      this.descriptionMatrix = descMatrix;
      this.ahAl = ahAl;
    }

    public String getName() {
      return name;
    }

    public int[] getControls() {
      return controlMatrix;
    }

    public int[] getRanges() {
      return rangeMatrix;
    }

    public String[] getDescriptions() {
      return descriptionMatrix;
    }

    public byte[][] getAHAL() {
      return ahAl;
    }

    @Override
    public String toString() {
      return super.toString() + "; name=" + getName();
    }

    private String name;

    private byte[][] ahAl;
    private int[] controlMatrix;
    private int[] rangeMatrix;
    private String[] descriptionMatrix;
  }

  private int[] knobOffsets = new int[8];

  private static HashMap<String, FXDescription> descriptionMap;
}
/*
* 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).
*/
TOP

Related Classes of jrackattack.gui.FXEditPanel$FXDescription

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.