be.hogent.tarsos.ui.virtualkeyboard
Class VirtualKeyboard

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by be.hogent.tarsos.ui.virtualkeyboard.VirtualKeyboard
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.sound.midi.Receiver
Direct Known Subclasses:
UniversalVirtualKeyboard, VirtualKeyboard12, VirtualKeyboard19

public abstract class VirtualKeyboard
extends javax.swing.JComponent
implements javax.sound.midi.Receiver

An abstract class to represent a keyboard.

Uses refactored code from the gervill package licensed under the GPL with the classpath exception.

Gervill source code

Author:
Joren Six
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int NUMBER_OF_MIDI_KEYS
          The number of MIDI keys in total.
static int VELOCITY
          The velocity of NOTE_ON events.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
VirtualKeyboard(int numberOfKeysInOctave)
          Create a new keyboard that spans 7 octaves and uses the specified number of keys per octave.
VirtualKeyboard(int numberOfKeysInOctave, int totalOfKeys)
          Create a new keyboard that has a number of keys per octave and a specified total number of keys.
 
Method Summary
protected  void allKeysOff()
           
 void close()
           
 void connectToTunedSynth(double[] tuning)
          Connects the virtual keyboard to the default Gervill synthesizer.
static VirtualKeyboard createVirtualKeyboard(int numberOfKeysPerOctave)
          Creates a virtual keyboard using the best representation available.
protected  int getLowestAssignedKey()
           
static java.lang.String getMappedKeys()
           
protected abstract  int getMidiNote(int x, int y)
          Converts x and y coordinate into a MIDI note number.
protected  int getNumberOfKeys()
           
protected  int getNumberOfKeysPerOctave()
           
protected  float getNumberOfOctaves()
           
protected  double[] getTuning()
           
protected  boolean isKeyDown(int midiKey)
           
 void send(javax.sound.midi.MidiMessage message, long timeStamp)
           
protected  void setLowestAssignedKey(int lowestAssignedKey)
           
static void setMappedKeys(java.lang.String mappedKeys)
           
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VELOCITY

public static final int VELOCITY
The velocity of NOTE_ON events.

See Also:
Constant Field Values

NUMBER_OF_MIDI_KEYS

public static final int NUMBER_OF_MIDI_KEYS
The number of MIDI keys in total.

See Also:
Constant Field Values
Constructor Detail

VirtualKeyboard

public VirtualKeyboard(int numberOfKeysInOctave)
Create a new keyboard that spans 7 octaves and uses the specified number of keys per octave.

Parameters:
numberOfKeysInOctave - the number of keys per octave

VirtualKeyboard

public VirtualKeyboard(int numberOfKeysInOctave,
                       int totalOfKeys)
Create a new keyboard that has a number of keys per octave and a specified total number of keys.

Parameters:
numberOfKeysInOctave - the number of keys per octave
totalOfKeys - the total number of keys used. E.g. 12 keys per octave and 4 octaves = 48 keys
Method Detail

isKeyDown

protected final boolean isKeyDown(int midiKey)

getMidiNote

protected abstract int getMidiNote(int x,
                                   int y)
Converts x and y coordinate into a MIDI note number.

Parameters:
x - the x coordinate
y - the y coordinate
Returns:
the corresponding MIDI note number

allKeysOff

protected final void allKeysOff()

send

public final void send(javax.sound.midi.MidiMessage message,
                       long timeStamp)
Specified by:
send in interface javax.sound.midi.Receiver

createVirtualKeyboard

public static VirtualKeyboard createVirtualKeyboard(int numberOfKeysPerOctave)
Creates a virtual keyboard using the best representation available. For the moment there are two special keyboards: one with 12 keys (a normal keyboard) and one with 19 keys. The rest use the UniversalVirtualKeyboard class.

Parameters:
numberOfKeysPerOctave - requested number of keys for each octave.
Returns:
a VirtualKeyboard using the best representation available.

getTuning

protected double[] getTuning()

connectToTunedSynth

public void connectToTunedSynth(double[] tuning)
Connects the virtual keyboard to the default Gervill synthesizer.

Parameters:
tuning - The tuning for one octave defined in cents.

setMappedKeys

public static void setMappedKeys(java.lang.String mappedKeys)

getMappedKeys

public static java.lang.String getMappedKeys()

getNumberOfKeysPerOctave

protected int getNumberOfKeysPerOctave()

setLowestAssignedKey

protected void setLowestAssignedKey(int lowestAssignedKey)

getLowestAssignedKey

protected int getLowestAssignedKey()

getNumberOfKeys

protected int getNumberOfKeys()

getNumberOfOctaves

protected float getNumberOfOctaves()

close

public void close()
Specified by:
close in interface javax.sound.midi.Receiver