public class SoundcheckController
extends java.lang.Object
implements java.awt.event.ActionListener, javax.swing.event.ListSelectionListener, java.awt.event.ItemListener, javax.swing.event.ChangeListener, java.awt.event.MouseWheelListener, javax.swing.event.DocumentListener, java.awt.event.WindowListener, javax.swing.event.RowSorterListener
This class provides the controller and event listener for the soundcheck window. It’s implemented as a singleton.
Modifier and Type | Field and Description |
---|---|
private static SoundcheckController |
controller |
private static int |
DEFAULT_NOTE_NUM |
private static int |
DEFAULT_PERCUSSION_NUM |
private static SoundcheckInstrumentModel |
instrumentModel |
private static SoundcheckNoteModel |
noteModel |
private static java.util.TreeMap<java.lang.Integer,java.lang.Integer> |
selectedInstrumentRow |
private static java.util.TreeMap<java.lang.Integer,java.util.TreeMap<java.lang.Boolean,java.lang.Integer>> |
selectedNoteRow |
private static SoundcheckView |
view |
Modifier | Constructor and Description |
---|---|
private |
SoundcheckController()
The actual constructor - private in order to enforce singleton behaviour.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
Action listener for the soundcheck window.
|
void |
changedUpdate(javax.swing.event.DocumentEvent e)
Called if one of the text fields has been changed.
|
private void |
checkDurationField()
Checks if the duration textfield contains a usable string.
|
private void |
checkVolOrVelField(java.lang.String type)
Checks if the volume or velocity textfield contains a usable string.
|
private void |
fillInstrumentsTable()
(Re)fills the instruments/drumkits table according to the currently selected channel.
|
private void |
fillNoteTable()
(Re)fills the note/percussion table according to the currently selected instrument type.
|
static int |
getChannel()
Returns the currently selected channel.
|
static SoundcheckController |
getController()
Returns the singleton
SoundcheckController object. |
static SoundcheckController |
getController(SoundcheckView scView,
SoundcheckNoteModel scNoteModel,
SoundcheckInstrumentModel scInstrModel)
Creates a
SoundcheckController object by calling the private constructor, if not yet done. |
int[] |
getInstrument()
Returns the currently (or last) selected instrument coordinates from the instruments combobox.
|
static int |
getLastSelectedInstrumentTableRow(int channel)
Returns the last (remembered) selected table model index of the given channel.
|
int |
getNote()
Returns the currently selected note (or percussion instrument) from the note/percussion table.
|
private void |
handleTextFieldChanges(javax.swing.event.DocumentEvent e)
Called if a text field value changes by one of the according event handlers.
|
void |
insertUpdate(javax.swing.event.DocumentEvent e)
Called if one of the text fields has been changed.
|
void |
itemStateChanged(java.awt.event.ItemEvent event)
Combobox selection listener for the channel combobox.
|
void |
mouseWheelMoved(java.awt.event.MouseWheelEvent e)
Handles volume or velocity slider scrolls with the mouse wheel.
|
private void |
play()
Plays the customized sound.
|
void |
removeUpdate(javax.swing.event.DocumentEvent e)
Called if one of the text fields has been changed.
|
void |
sorterChanged(javax.swing.event.RowSorterEvent e)
Scrolls to the currently selected instruments table row, if possible.
|
void |
stateChanged(javax.swing.event.ChangeEvent e)
Handles volume or velocity slider changes via mouse clicks.
|
void |
valueChanged(javax.swing.event.ListSelectionEvent event)
Handles selections of instruments or notes.
|
void |
windowActivated(java.awt.event.WindowEvent e) |
void |
windowClosed(java.awt.event.WindowEvent e) |
void |
windowClosing(java.awt.event.WindowEvent e) |
void |
windowDeactivated(java.awt.event.WindowEvent e) |
void |
windowDeiconified(java.awt.event.WindowEvent e) |
void |
windowIconified(java.awt.event.WindowEvent e) |
void |
windowOpened(java.awt.event.WindowEvent e)
Fills the instruments table and the notes list (in the right order) and ensures that in both of them one element is selected.
|
private static final int DEFAULT_NOTE_NUM
private static final int DEFAULT_PERCUSSION_NUM
private static SoundcheckController controller
private static SoundcheckView view
private static SoundcheckNoteModel noteModel
private static SoundcheckInstrumentModel instrumentModel
private static java.util.TreeMap<java.lang.Integer,java.lang.Integer> selectedInstrumentRow
private static java.util.TreeMap<java.lang.Integer,java.util.TreeMap<java.lang.Boolean,java.lang.Integer>> selectedNoteRow
private SoundcheckController()
The actual constructor - private in order to enforce singleton behaviour.
public static SoundcheckController getController(SoundcheckView scView, SoundcheckNoteModel scNoteModel, SoundcheckInstrumentModel scInstrModel)
Creates a SoundcheckController
object by calling the private constructor, if not yet done. Returns the object.
This method is called from outside instead of the constructor itself in order to ensure the singleton behaviour.
scView
- Soundcheck window.scNoteModel
- Note combobox model.scInstrModel
- Instruments table model.SoundcheckController
object.public static SoundcheckController getController()
Returns the singleton SoundcheckController
object.
SoundcheckController
object.public void itemStateChanged(java.awt.event.ItemEvent event)
Combobox selection listener for the channel combobox. Refills the instruments table based on the new channel and pre-selects the last selected row for this channel.
itemStateChanged
in interface java.awt.event.ItemListener
event
- selection change eventpublic void actionPerformed(java.awt.event.ActionEvent e)
Action listener for the soundcheck window.
Handles:
actionPerformed
in interface java.awt.event.ActionListener
e
- The event to be handled.public void sorterChanged(javax.swing.event.RowSorterEvent e)
Scrolls to the currently selected instruments table row, if possible. Called when the table string filter or sorter has been changed.
sorterChanged
in interface javax.swing.event.RowSorterListener
e
- the row sorter eventpublic static int getLastSelectedInstrumentTableRow(int channel)
Returns the last (remembered) selected table model index of the given channel.
channel
- The requested channel.public int[] getInstrument()
Returns the currently (or last) selected instrument coordinates from the instruments combobox.
The returned value consists of the following parts:
If no instrument is selected, all these values are -1.
public int getNote()
Returns the currently selected note (or percussion instrument) from the note/percussion table.
In case of an error, -1 is returned.
private void play()
Plays the customized sound.
private void checkVolOrVelField(java.lang.String type) throws java.lang.NumberFormatException
Checks if the volume or velocity textfield contains a usable string.
If the check succeeds: sets the volume/velocity slider according to the value from the text field.
type
- volume or velocity, depending on the field to be checked.java.lang.NumberFormatException
- if the field cannot be used as a volume/velocity value.private void checkDurationField() throws java.lang.NumberFormatException
Checks if the duration textfield contains a usable string.
java.lang.NumberFormatException
- if the field cannot be used as a duration value.public void stateChanged(javax.swing.event.ChangeEvent e)
Handles volume or velocity slider changes via mouse clicks. Sets the volume or velocity text field’s content to the new value.
stateChanged
in interface javax.swing.event.ChangeListener
e
- The event to be handled.public void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
Handles volume or velocity slider scrolls with the mouse wheel. Sets the volume or velocity text field’s content to the new value.
mouseWheelMoved
in interface java.awt.event.MouseWheelListener
e
- The event to be handled.public void changedUpdate(javax.swing.event.DocumentEvent e)
Called if one of the text fields has been changed.
Passes the event to handleTextFieldChanges(DocumentEvent)
in order to check the content and adjust the background color.
changedUpdate
in interface javax.swing.event.DocumentListener
e
- The event to be handled.public void insertUpdate(javax.swing.event.DocumentEvent e)
Called if one of the text fields has been changed.
Passes the event to handleTextFieldChanges(DocumentEvent)
in order to check the content and adjust the background color.
insertUpdate
in interface javax.swing.event.DocumentListener
e
- The event to be handled.public void removeUpdate(javax.swing.event.DocumentEvent e)
Called if one of the text fields has been changed.
Passes the event to handleTextFieldChanges(DocumentEvent)
in order to check the content and adjust the background color.
removeUpdate
in interface javax.swing.event.DocumentListener
e
- The event to be handled.private void handleTextFieldChanges(javax.swing.event.DocumentEvent e)
Called if a text field value changes by one of the according event handlers. Checks the content of the changed field and adjusts the background color according to the check result.
e
- The event to be handled.public void windowActivated(java.awt.event.WindowEvent e)
windowActivated
in interface java.awt.event.WindowListener
public void windowClosed(java.awt.event.WindowEvent e)
windowClosed
in interface java.awt.event.WindowListener
public void windowClosing(java.awt.event.WindowEvent e)
windowClosing
in interface java.awt.event.WindowListener
public void windowDeactivated(java.awt.event.WindowEvent e)
windowDeactivated
in interface java.awt.event.WindowListener
public void windowDeiconified(java.awt.event.WindowEvent e)
windowDeiconified
in interface java.awt.event.WindowListener
public void windowIconified(java.awt.event.WindowEvent e)
windowIconified
in interface java.awt.event.WindowListener
public void windowOpened(java.awt.event.WindowEvent e)
Fills the instruments table and the notes list (in the right order) and ensures that in both of them one element is selected.
windowOpened
in interface java.awt.event.WindowListener
e
- eventpublic void valueChanged(javax.swing.event.ListSelectionEvent event)
Handles selections of instruments or notes.
Instruments or drumkits are selected from a MidicaTable
. Notes or percussion instruments are selected from a JList
.
valueChanged
in interface javax.swing.event.ListSelectionListener
event
- Table row or list item selection event.public static int getChannel()
Returns the currently selected channel.
private void fillInstrumentsTable()
(Re)fills the instruments/drumkits table according to the currently selected channel.
private void fillNoteTable()
(Re)fills the note/percussion table according to the currently selected instrument type.