public class PlayerController
extends java.lang.Object
implements java.awt.event.ActionListener, java.awt.event.WindowListener, javax.swing.event.ChangeListener, javax.swing.event.DocumentListener, java.awt.event.MouseWheelListener, java.awt.event.ItemListener
This class provides the controller of the player window.
It listens and reacts to events in the PlayerView
.
Modifier and Type | Field and Description |
---|---|
private java.io.File |
currentFile |
private ErrorMsgView |
errorMsg |
private SequenceParser |
parser |
private RefresherThread |
refresher |
private PlayerView |
view |
Constructor and Description |
---|
PlayerController(PlayerView view,
SequenceParser parser,
java.io.File currentFile)
Creates a new listener object for the player and a
RefresherThread , refreshing the progress slider. |
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
Handles all action events that have happened in the player window.
|
void |
changedUpdate(javax.swing.event.DocumentEvent e)
Checks text field contents after a change (by calling
handleTextFieldChanges(DocumentEvent) ). |
void |
endOfSequence()
Makes the play/pause button ready to begin playing again - called if the end of the MIDI sequence is reached.
|
private void |
handleTextFieldChanges(javax.swing.event.DocumentEvent e)
Handles change events in text fields by checking the changed content.
|
void |
insertUpdate(javax.swing.event.DocumentEvent e)
Checks text field contents after a change (by calling
handleTextFieldChanges(DocumentEvent) ). |
void |
itemStateChanged(java.awt.event.ItemEvent e)
Handles checkbox changes.
|
void |
mouseWheelMoved(java.awt.event.MouseWheelEvent e)
Handles mouse wheel scrolling over a
MidicaSlider . |
private void |
performControlCommand(java.lang.String cmd)
Handles commands after a player control button has been pushed.
|
void |
refreshProgressBar()
Refreshes the progress slider state automatically according to the sequencer state - called by the
RefresherThread . |
void |
removeUpdate(javax.swing.event.DocumentEvent e)
Checks text field contents after a change (by calling
handleTextFieldChanges(DocumentEvent) ). |
private void |
reparse()
Re-parses the last successfully parsed file again.
|
void |
setChannelActivity(int channel,
boolean active)
Turns the given channel’s activity LED on or off.
|
void |
setChannelInfo(byte channel,
java.lang.String bankNumShort,
java.lang.String bankNumLong,
java.lang.String program,
java.lang.String instrName,
java.lang.String comment)
Updates the channel information labels of the given channel.
|
void |
setLyrics(java.lang.String text)
Writes the given lyrics string into the karaoke area.
|
private void |
setupMidiDevices()
Sets up sequencer, synthesizer and so on.
|
private void |
showErrorMessage(java.lang.Exception e)
Shows an error message based on an exception.
|
void |
showErrorMessage(java.lang.String message)
Shows an error message based on a message string.
|
void |
stateChanged(javax.swing.event.ChangeEvent e)
Handles slider events.
|
void |
windowActivated(java.awt.event.WindowEvent e) |
void |
windowClosed(java.awt.event.WindowEvent e) |
void |
windowClosing(java.awt.event.WindowEvent e)
Stops and closes player-related resources and windows - called, if the window is going to be closed.
|
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)
Initializes resources needed for the player - called, if the window is opened.
|
private PlayerView view
private ErrorMsgView errorMsg
private RefresherThread refresher
private SequenceParser parser
private java.io.File currentFile
public PlayerController(PlayerView view, SequenceParser parser, java.io.File currentFile)
Creates a new listener object for the player and a RefresherThread
, refreshing the progress slider.
view
- The player window.parser
- The parser that has successfully parsed the current file.currentFile
- The last loaded (successfully parsed) file.public void actionPerformed(java.awt.event.ActionEvent e)
Handles all action events that have happened in the player window.
Those are:
actionPerformed
in interface java.awt.event.ActionListener
e
- The invoked action event.public void windowActivated(java.awt.event.WindowEvent e)
windowActivated
in interface java.awt.event.WindowListener
public void windowClosing(java.awt.event.WindowEvent e)
Stops and closes player-related resources and windows - called, if the window is going to be closed.
RefresherThread
to refresh the progress sliderwindowClosing
in interface java.awt.event.WindowListener
e
- Window activation event.public void windowClosed(java.awt.event.WindowEvent e)
windowClosed
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)
Initializes resources needed for the player - called, if the window is opened.
RefresherThread
to refresh the progress sliderwindowOpened
in interface java.awt.event.WindowListener
e
- Window deactivated event.public void refreshProgressBar()
Refreshes the progress slider state automatically according to the sequencer state - called by the RefresherThread
.
public void endOfSequence()
Makes the play/pause button ready to begin playing again - called if the end of the MIDI sequence is reached.
public void setChannelActivity(int channel, boolean active)
Turns the given channel’s activity LED on or off.
channel
- MIDI channel number.active
- true to turn the LED on, false to turn it off.public void setChannelInfo(byte channel, java.lang.String bankNumShort, java.lang.String bankNumLong, java.lang.String program, java.lang.String instrName, java.lang.String comment)
Updates the channel information labels of the given channel.
The following information is updated:
channel
- Channel number (0-15).bankNumShort
- bank number syntax – MSB, if LSB is null; otherwise: MSB and LSB, separated by the currently configured separatorbankNumLong
- full bank number, MSB and LSB in a human-readable formprogram
- program numberinstrName
- instrument namecomment
- channel commentpublic void setLyrics(java.lang.String text)
Writes the given lyrics string into the karaoke area.
text
- HTML-formatted lyrics text.public void itemStateChanged(java.awt.event.ItemEvent e)
Handles checkbox changes.
Channel-independent actions:
Channel-dependent actions:
itemStateChanged
in interface java.awt.event.ItemListener
e
- Event object.public void stateChanged(javax.swing.event.ChangeEvent e)
Handles slider events.
Channel-independent actions:
Channel-dependent actions:
stateChanged
in interface javax.swing.event.ChangeListener
e
- Event object.public void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
Handles mouse wheel scrolling over a MidicaSlider
. Sets the slider to the new position, if possible, or otherwise to the minimum or maximum of the slider’s range.
The following sliders are supported by this method:
mouseWheelMoved
in interface java.awt.event.MouseWheelListener
e
- Event object.private void handleTextFieldChanges(javax.swing.event.DocumentEvent e)
Handles change events in text fields by checking the changed content.
The text is checked against the expected number format and range. The text field’s background will be changed to red, if the check fails, or to green, if it succeeds.
The following text fields are handled by this method:
e
- Event object.public void changedUpdate(javax.swing.event.DocumentEvent e)
Checks text field contents after a change (by calling handleTextFieldChanges(DocumentEvent)
).
changedUpdate
in interface javax.swing.event.DocumentListener
e
- Event object.public void insertUpdate(javax.swing.event.DocumentEvent e)
Checks text field contents after a change (by calling handleTextFieldChanges(DocumentEvent)
).
insertUpdate
in interface javax.swing.event.DocumentListener
e
- Event object.public void removeUpdate(javax.swing.event.DocumentEvent e)
Checks text field contents after a change (by calling handleTextFieldChanges(DocumentEvent)
).
removeUpdate
in interface javax.swing.event.DocumentListener
e
- Event object.private void performControlCommand(java.lang.String cmd)
Handles commands after a player control button has been pushed.
Those buttons are:
cmd
- The pushed button’s command string.private void reparse()
Re-parses the last successfully parsed file again. Then sets up the MIDI devices again and connects them with the new MIDI stream. Re-builds the progress slider because the MIDI stream length could have changed.
Shows an error message if the parsing fails.
private void showErrorMessage(java.lang.Exception e)
Shows an error message based on an exception.
e
- Exception containing the error message to be shown.public void showErrorMessage(java.lang.String message)
Shows an error message based on a message string. This is also called from MidiDevices
if a soundbank file/URL fails to load.
message
- Error message.private void setupMidiDevices() throws java.lang.Exception
Sets up sequencer, synthesizer and so on. This operation may be time consuming if a large soundbank has to be loaded. For this reason this operation is done by a worker in the background while a ‘please wait’ message is displayed.
java.lang.Exception
- if something went wrong.