openpiano.control
Class MidiTimer

java.lang.Object
  extended by openpiano.control.MidiTimer
All Implemented Interfaces:
Runnable

public class MidiTimer
extends Object
implements Runnable

MidiTimer is the central clock of the application. It controls the speed of notes and sets their position

Version:
1.0, 07/30/08
Author:
Sascha Westermann

Constructor Summary
MidiTimer(Controller controller, SlidePanel slidePanel, LinkedList<Bpm> bpmList, int tpb, float factor)
          Constructs a new MidiTimer based on conditions from a MIDI file
 
Method Summary
 float getBeatsPerMinuteFactor()
          Returns the current beats per minute factor
 long getElapsedTicks()
          Returns the elapsed ticks of the current MIDI file
 long getTicksPerBeat()
          Returns the ticks per beat defined in the MIDI file
 long getTicksPerSecond()
          Returns the ticks per second defined in the MIDI file
 void initTimer()
          Initializes the MidiTimer
 boolean isRunning()
          Returns true if the MidiTimer thread is running
 void run()
          Updates the application according to the time passed by.
 void seek(boolean seek, float factor)
          Sets the seek mode and speed.
 void setElapsedTicks(float ticks)
          Sets the actual position in the MIDI file
 void startTimer()
          Starts the MidiTimer
 void stopTimer()
          Stops the MidiTimer
 void updateBpm()
          Updates beats per minutes according to the position
 void updateBpm(float factor)
          Updates beats per minutes according to the position based on a given factor
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MidiTimer

public MidiTimer(Controller controller,
                 SlidePanel slidePanel,
                 LinkedList<Bpm> bpmList,
                 int tpb,
                 float factor)
Constructs a new MidiTimer based on conditions from a MIDI file

Parameters:
controller - the main controller of the application
slidePanel - the panel containing the position slider
bpmList - a list of timed speed-changing events according to the MIDI file
tpb - the amount of ticks per beat according to the MIDI file
factor - a speed factor for beats per minute
Method Detail

getBeatsPerMinuteFactor

public float getBeatsPerMinuteFactor()
Returns the current beats per minute factor

Returns:
the current beats per minute factor

getElapsedTicks

public long getElapsedTicks()
Returns the elapsed ticks of the current MIDI file

Returns:
the elapsed ticks

getTicksPerBeat

public long getTicksPerBeat()
Returns the ticks per beat defined in the MIDI file

Returns:
the ticks per beat

getTicksPerSecond

public long getTicksPerSecond()
Returns the ticks per second defined in the MIDI file

Returns:
the ticks per second

initTimer

public void initTimer()
Initializes the MidiTimer


isRunning

public boolean isRunning()
Returns true if the MidiTimer thread is running

Returns:
true if the MidiTimer thread is running

run

public void run()
Updates the application according to the time passed by. This is the central clock dealing with timed events like moving blocks and the slider position

Specified by:
run in interface Runnable

seek

public void seek(boolean seek,
                 float factor)
Sets the seek mode and speed. Used for rewind and fast forward

Parameters:
seek - true if seeking, false if resume
factor - speed-factor of seeking

setElapsedTicks

public void setElapsedTicks(float ticks)
Sets the actual position in the MIDI file

Parameters:
ticks - current tick position

startTimer

public void startTimer()
Starts the MidiTimer


stopTimer

public void stopTimer()
Stops the MidiTimer


updateBpm

public void updateBpm()
Updates beats per minutes according to the position


updateBpm

public void updateBpm(float factor)
Updates beats per minutes according to the position based on a given factor

Parameters:
factor - speed-factor