com.groovemanager.gui.custom.mc909
Class Mc909KeyComposite

java.lang.Object
  extended by com.groovemanager.gui.custom.CustomComposite
      extended by com.groovemanager.gui.custom.mc909.Mc909KeyComposite
All Implemented Interfaces:
KeyboardKeyListener, MIDIListener

public class Mc909KeyComposite
extends CustomComposite
implements MIDIListener, KeyboardKeyListener

A Mc909KeyComposite contains a number of Mc909Keys aligned as on the MC-909 itself. It can send and receive MIDI note on/off events

Author:
Manu Robledo

Nested Class Summary
private  class Mc909KeyComposite.NumCanvas
          This class is used drawing the pad numbers above the Mc909Keys
 
Field Summary
private static int[] ACCEPT_TYPES
          Array of MIDI message types accepted
private  int channel
          The channel to send the MIDI data to
private  int firstKey
          Note value of the first key to be displayed in this composite from 0 to 127
protected static int KEY_HEIGHT
          Constant for the width of one key in pixels
protected static int KEY_WIDTH
          Constant for the width of one key in pixels
protected  Mc909Key[] keys
          The Mc909Keys contained in this Composite
private  int lastKey
          Note value of the last key to be displayed in this composite from 0 to 127
private  java.util.ArrayList listeners
          List of KeyboardKeyListeners registered with this Composite
private  MIDIManager midiManager
          The MIDIManager used for sending and receiving MIDI events
private  long[] noteOnIds
          The note on ids from the last sent note on events for each key
private  boolean receiveMIDI
          Indicates whether this Composite should react to incoming MIDI messages or not
private  java.lang.Runnable receiver
          Runnable for thread-safe reaction to incoming MIDI events
private  boolean sendMIDI
          Indicates whether this Composite should send MIDI events when the keys are being pressed or not
private  javax.sound.midi.ShortMessage sm
          Last received ShortMessage
private  int velocity
          The velocity used for sending MIDI note on events
 
Constructor Summary
Mc909KeyComposite(org.eclipse.swt.widgets.Composite parent, int lowKey, int highKey)
          Construct a new Mc909KeyComposite using the default MIDIManager
Mc909KeyComposite(org.eclipse.swt.widgets.Composite parent, int lowKey, int highKey, MIDIManager manager)
          Construct a new Mc909KeyComposite using the specified MIDIManager
 
Method Summary
 void addKeyListener(KeyboardKeyListener listener)
          Add a KeyboardKeyListener that will be notified when one this composite´s keys is pressed.
protected  org.eclipse.swt.widgets.Composite createComposite(org.eclipse.swt.widgets.Composite parent, int style)
          This method is to be overwritten by concrete subclasses to create the real contents of this CustomComposite
protected  Mc909Key[] createKeys(org.eclipse.swt.widgets.Composite parent, int firstKey, int lastKey)
          Internal method for creating the Mc909Keys
protected  org.eclipse.swt.widgets.Composite createPadComp(org.eclipse.swt.widgets.Composite parent)
          Internal method for creating the composite containing the keys
protected  org.eclipse.swt.widgets.Composite createTopComp(org.eclipse.swt.widgets.Composite parent)
          Internal method for creating the top method which contains the pad numbers for the keys 59 to 74
 int getChannel()
          Get the channel used for sending MIDI events
protected  int[] getListenerTypes()
          For all types of listeners that should be possible to add to this Composite directly, the corresponding SWT.* constant should be contained in the returned Array.
protected  int getPossibleStyles()
          Get a combination of all allowed SWT.* style constants
 int getVelocity()
          Gete the velocity value used for sending MIDI notes
 void keyPressed(int key)
          Notification that a KeyboardKey has been pressed
 void keyReleased(int key)
          Notification that a KeyboardKey has been released
 void processMessage(javax.sound.midi.MidiMessage m)
          Notification about an incoming MIDI event
 void removeKeyListener(KeyboardKeyListener listener)
          Remove a registered KeyboardKeyListener from this composite
 void setChannel(int channel)
          Set the channel used for sending MIDI events
 void setHold(boolean hold)
          Set the hold behaviour for all keys
 void setNotesVisible(boolean visible)
          Set the visibility of the note name on all keys
 void setReceiveMidi(boolean receive)
          Set, if this composite should react to incoming MIDI note on/off events
 void setSendMIDI(boolean send)
          Set, if this compopsite´s keys should send MIDI events when pressed or released
 void setVelocity(int vel)
          Set the velocity for sending MIDI notes
 
Methods inherited from class com.groovemanager.gui.custom.CustomComposite
addListener, checkStyle, getComposite, getData, getListeners, getParent, removeListener, setData, setLayoutData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACCEPT_TYPES

private static final int[] ACCEPT_TYPES
Array of MIDI message types accepted


channel

private int channel
The channel to send the MIDI data to


firstKey

private final int firstKey
Note value of the first key to be displayed in this composite from 0 to 127


KEY_HEIGHT

protected static final int KEY_HEIGHT
Constant for the width of one key in pixels

See Also:
Constant Field Values

KEY_WIDTH

protected static final int KEY_WIDTH
Constant for the width of one key in pixels

See Also:
Constant Field Values

keys

protected Mc909Key[] keys
The Mc909Keys contained in this Composite


lastKey

private final int lastKey
Note value of the last key to be displayed in this composite from 0 to 127


listeners

private java.util.ArrayList listeners
List of KeyboardKeyListeners registered with this Composite


midiManager

private MIDIManager midiManager
The MIDIManager used for sending and receiving MIDI events


noteOnIds

private long[] noteOnIds
The note on ids from the last sent note on events for each key


receiveMIDI

private boolean receiveMIDI
Indicates whether this Composite should react to incoming MIDI messages or not


receiver

private java.lang.Runnable receiver
Runnable for thread-safe reaction to incoming MIDI events


sendMIDI

private boolean sendMIDI
Indicates whether this Composite should send MIDI events when the keys are being pressed or not


sm

private javax.sound.midi.ShortMessage sm
Last received ShortMessage


velocity

private int velocity
The velocity used for sending MIDI note on events

Constructor Detail

Mc909KeyComposite

public Mc909KeyComposite(org.eclipse.swt.widgets.Composite parent,
                         int lowKey,
                         int highKey)
Construct a new Mc909KeyComposite using the default MIDIManager

Parameters:
parent - The parent composite
lowKey - The note value of the lowest key to display from 0 to 127
highKey - The note value of the highest key to display from 0 to 127

Mc909KeyComposite

public Mc909KeyComposite(org.eclipse.swt.widgets.Composite parent,
                         int lowKey,
                         int highKey,
                         MIDIManager manager)
Construct a new Mc909KeyComposite using the specified MIDIManager

Parameters:
parent - The parent composite
lowKey - The note value of the lowest key to display from 0 to 127
highKey - The note value of the highest key to display from 0 to 127
manager - The MIDIManager to use for in- and output
Method Detail

addKeyListener

public void addKeyListener(KeyboardKeyListener listener)
Add a KeyboardKeyListener that will be notified when one this composite´s keys is pressed.

Parameters:
listener - The KeyboardKeyListener to add

createComposite

protected org.eclipse.swt.widgets.Composite createComposite(org.eclipse.swt.widgets.Composite parent,
                                                            int style)
Description copied from class: CustomComposite
This method is to be overwritten by concrete subclasses to create the real contents of this CustomComposite

Specified by:
createComposite in class CustomComposite
Parameters:
parent - The parent Composite under which this Composite should be created
style - Combination of valid SWT.* style constants
Returns:
The new created main composite
See Also:
CustomComposite.createComposite(org.eclipse.swt.widgets.Composite, int)

createKeys

protected Mc909Key[] createKeys(org.eclipse.swt.widgets.Composite parent,
                                int firstKey,
                                int lastKey)
Internal method for creating the Mc909Keys

Parameters:
parent - The parent Composite
firstKey - Note value of the lowest key from 0 to 127
lastKey - Note value of the highest key from 0 to 127
Returns:
The created Mc909Keys

createPadComp

protected org.eclipse.swt.widgets.Composite createPadComp(org.eclipse.swt.widgets.Composite parent)
Internal method for creating the composite containing the keys


createTopComp

protected org.eclipse.swt.widgets.Composite createTopComp(org.eclipse.swt.widgets.Composite parent)
Internal method for creating the top method which contains the pad numbers for the keys 59 to 74

Parameters:
parent - The parent composite
Returns:
The created top composite

getChannel

public int getChannel()
Get the channel used for sending MIDI events

Returns:
The currently used channel between 0 and 15

getListenerTypes

protected int[] getListenerTypes()
Description copied from class: CustomComposite
For all types of listeners that should be possible to add to this Composite directly, the corresponding SWT.* constant should be contained in the returned Array.

Specified by:
getListenerTypes in class CustomComposite
Returns:
An Array of SWT.* constants defining the set of listeners types applicable to this Composite
See Also:
CustomComposite.getListenerTypes()

getPossibleStyles

protected int getPossibleStyles()
Description copied from class: CustomComposite
Get a combination of all allowed SWT.* style constants

Specified by:
getPossibleStyles in class CustomComposite
Returns:
A combination of all allowed style constants, for example SWT.BORDER | SWT.LEFT | SWT.BORDER
See Also:
CustomComposite.getPossibleStyles()

getVelocity

public int getVelocity()
Gete the velocity value used for sending MIDI notes

Returns:
The velocity from 0 to 127

keyPressed

public void keyPressed(int key)
Description copied from interface: KeyboardKeyListener
Notification that a KeyboardKey has been pressed

Specified by:
keyPressed in interface KeyboardKeyListener
Parameters:
key - The note value of the key that has been pressed in the range from 0 to 127
See Also:
KeyboardKeyListener.keyPressed(int)

keyReleased

public void keyReleased(int key)
Description copied from interface: KeyboardKeyListener
Notification that a KeyboardKey has been released

Specified by:
keyReleased in interface KeyboardKeyListener
Parameters:
key - The note value of the key that has been released in the range from 0 to 127
See Also:
KeyboardKeyListener.keyReleased(int)

processMessage

public void processMessage(javax.sound.midi.MidiMessage m)
Description copied from interface: MIDIListener
Notification about an incoming MIDI event

Specified by:
processMessage in interface MIDIListener
Parameters:
m - The MidiMessage that just came in
See Also:
MIDIListener.processMessage(javax.sound.midi.MidiMessage)

removeKeyListener

public void removeKeyListener(KeyboardKeyListener listener)
Remove a registered KeyboardKeyListener from this composite

Parameters:
listener - The KeyboardKeyListener to remove

setChannel

public void setChannel(int channel)
Set the channel used for sending MIDI events

Parameters:
channel - The channel to send MIDI messages on between 0 and 15

setHold

public void setHold(boolean hold)
Set the hold behaviour for all keys

Parameters:
hold - The new hold behaviour

setNotesVisible

public void setNotesVisible(boolean visible)
Set the visibility of the note name on all keys

Parameters:
visible - true, if the note name and octave should be displayed on each key, false otherwise

setReceiveMidi

public void setReceiveMidi(boolean receive)
Set, if this composite should react to incoming MIDI note on/off events

Parameters:
receive - true, if incoming MIDI events should be handled, false otherwise

setSendMIDI

public void setSendMIDI(boolean send)
Set, if this compopsite´s keys should send MIDI events when pressed or released

Parameters:
send - true, if the keys should send MIDI, false otherwise

setVelocity

public void setVelocity(int vel)
Set the velocity for sending MIDI notes

Parameters:
vel - The new velocity form 0 to 127