org.pealfactory.compose.halfleadspliced
Class Elf

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by org.pealfactory.compose.halfleadspliced.Elf
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, javax.accessibility.Accessible, ComposerHost, StandardMethods

public class Elf
extends java.applet.Applet
implements ComposerHost, java.lang.Runnable, StandardMethods

Elf, the Online Half-lead Spliced Composing Engine. The Elf applet provides a public API, accessible from client-side javascript, to manage method libraries, music and composition parameters, and to initiate and monitor searches. The search algorithm itself is handled by the Composer class.

Note that the applet should be scripted with a 0x0 visible size, since it doesn't provide any external user interface. The UI is the sole responsibility of DHTML in the Elf website. All Elf functionality is accessed from Javascript on the invoking web page via calls to public methods in the applet. For this to function correctly a Javascript to Java communication protocol must be supported by the browser, such as LiveConnect. Browsers such as IE for the Macintosh and Netscape 6.0 do not support such communication.

Many methods in this class are public so that they can be accessed from script.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
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
 boolean available
          Used by the website to check Java VM with LiveConnect available
private  int fBalanceScore
           
private  int fBestBalance
           
private  int fBestCOM
           
private  java.util.Vector fBestComps
           
private  int fBestMusic
           
private  int fBestScore
           
private  Composer fComposer
           
private  int fCompsPerSec
           
private  int fCOMScore
           
private  java.util.Vector fMethodLibrary
           
private  java.util.Vector fMethods
           
private  java.util.Vector fMusic
           
private  int fNComps
           
private  int fNCompsToKeep
           
private  int fNodesPerSec
           
private  java.lang.String fOutput
           
private  boolean fOutputChanged
           
private  Tables fTables
           
private  java.lang.String fTimeLeft
           
private  Tracker fTracker
           
static java.lang.String kHEAD_LINE
           
static int kMAX_NAME
           
static java.lang.String kNEWLINE
           
static java.lang.String kOPEN_SOURCE_ANNOUNCE
           
static char kSEPARATOR
           
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface org.pealfactory.compose.halfleadspliced.StandardMethods
kASHTEAD, kBELFAST, kBRISTOL, kCAMBRIDGE, kCASSIOBURY, kGLASGOW, kLINCOLNSHIRE, kLONDON, kPUDSEY, kRUTLAND, kSUPERLATIVE, kUXBRIDGE, kYORKSHIRE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Elf()
          Made public for use with Java plugin (Undomiel build).
 
Method Summary
 void addMethod(int i)
          Parameter i is index in method library
 java.lang.String addMethodToLibrary(java.lang.String name, java.lang.String abbrev, java.lang.String pn)
          Returns empty string if successful, otherwise an error message.
 java.lang.String addMusic(java.lang.String name, int score, java.lang.String matches)
           
 boolean compose(int nleads, int nparts, boolean tenorsTogether, boolean nicePE, boolean optimumBalance, boolean maxCOM, int calls, boolean LHonly)
          Start composition, using the passed parameter values.
 boolean compose(int nleads, int nparts, boolean tenorsTogether, boolean nicePE, boolean optimumBalance, boolean maxCOM, int calls, boolean LHonly, int minPartLength, int maxPartLength)
          Start composition, using the passed parameter values, including min and max part length.
private  java.lang.String deAccent(java.lang.String s)
          Converts any HTML accent characters (e.g.
 void destroy()
           
 java.lang.String getAllComps()
           
 int getBalanceScore()
          Allows method balance score to be configured from the website
private  java.lang.String getComp(int i)
           
 int getCOMScore()
          Allows COM score to be configured from the website
 java.lang.String getErrorMsg()
           
 java.lang.String getLibraryMethod(int i)
          Returns one String with name, abbreviation, PN and leadhead separated by '|' characters
 int getLibrarySize()
           
 int getLongestLead()
          Return the lead length of the longest method in the current composition method list.
 java.lang.String getMethod(int i)
           
 java.lang.String getMusic(int i)
           
 int getNCompsToKeep()
          Allows number of comps in "top ten" list to be configured from the website
 int getNMethods()
           
 int getNMusicDefs()
           
 java.lang.String getOutput()
          Now just gets the one best composition - see getAllComps().
 int getShortestLead()
          Return the lead length of the shortest method in the current composition method list.
 java.lang.String getStatus()
           
 java.lang.String getVersionString()
          Part of the public script interface.
 void init()
           
 boolean isError()
          Returns true if a (non-abort) error occurred.
 boolean isFinished()
           
 boolean isMethodInComp(java.lang.String name)
           
 boolean isPaused()
           
 boolean isThereNewOutput()
           
private  void methodsChanged()
           
private  void musicChanged()
           
private  void newLibraryMethod(Method newMethod)
          Inserts new method into library, sorted on abbreviation.
 void outputComp(OutputComp latest)
          Called by the Composer when a new composition meeting the score minimums is produced.
 boolean pause()
           
 void removeMethod(int i)
           
 void removeMethodFromLibrary(int i)
           
 void removeMusic(int i)
           
 void resetLibrary()
           
 void resetMusic()
           
 void resume()
           
 void run()
          Pass 1 is table build (methods - only if method table dirty).
 void setBalanceScore(int balanceScore)
          Allows method balance score to be configured from the website
 void setCOMScore(int COMScore)
          Allows COM score to be configured from the website
 void setNCompsToKeep(int NCompsToKeep)
          Allows number of comps in "top ten" list to be configured from the website
 void start()
           
 void stop()
           
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, 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

kOPEN_SOURCE_ANNOUNCE

public static final java.lang.String kOPEN_SOURCE_ANNOUNCE
See Also:
Constant Field Values

kHEAD_LINE

public static final java.lang.String kHEAD_LINE
See Also:
Constant Field Values

kMAX_NAME

public static final int kMAX_NAME
See Also:
Constant Field Values

kNEWLINE

public static final java.lang.String kNEWLINE
See Also:
Constant Field Values

kSEPARATOR

public static final char kSEPARATOR
See Also:
Constant Field Values

available

public boolean available
Used by the website to check Java VM with LiveConnect available


fComposer

private Composer fComposer

fTracker

private Tracker fTracker

fMethodLibrary

private java.util.Vector fMethodLibrary

fMethods

private java.util.Vector fMethods

fMusic

private java.util.Vector fMusic

fCOMScore

private int fCOMScore

fBalanceScore

private int fBalanceScore

fTables

private Tables fTables

fBestComps

private java.util.Vector fBestComps

fNCompsToKeep

private int fNCompsToKeep

fNComps

private int fNComps

fCompsPerSec

private int fCompsPerSec

fNodesPerSec

private int fNodesPerSec

fBestScore

private int fBestScore

fBestMusic

private int fBestMusic

fBestCOM

private int fBestCOM

fBestBalance

private int fBestBalance

fTimeLeft

private java.lang.String fTimeLeft

fOutputChanged

private boolean fOutputChanged

fOutput

private java.lang.String fOutput
Constructor Detail

Elf

public Elf()
Made public for use with Java plugin (Undomiel build).

Method Detail

init

public void init()
Overrides:
init in class java.applet.Applet

start

public void start()
Overrides:
start in class java.applet.Applet

getVersionString

public java.lang.String getVersionString()
Part of the public script interface.


deAccent

private java.lang.String deAccent(java.lang.String s)
Converts any HTML accent characters (e.g. ú) into normal unaccented 7-bit ASCII (e.g. 'u').

Since:
Tinuviel

getNCompsToKeep

public int getNCompsToKeep()
Allows number of comps in "top ten" list to be configured from the website

Since:
Tinuviel B

setNCompsToKeep

public void setNCompsToKeep(int NCompsToKeep)
Allows number of comps in "top ten" list to be configured from the website

Since:
Tinuviel B

getCOMScore

public int getCOMScore()
Allows COM score to be configured from the website

Since:
Tinuviel

setCOMScore

public void setCOMScore(int COMScore)
Allows COM score to be configured from the website

Since:
Tinuviel

getBalanceScore

public int getBalanceScore()
Allows method balance score to be configured from the website

Since:
Tinuviel

setBalanceScore

public void setBalanceScore(int balanceScore)
Allows method balance score to be configured from the website

Since:
Tinuviel

resetMusic

public void resetMusic()

getNMusicDefs

public int getNMusicDefs()

getMusic

public java.lang.String getMusic(int i)

removeMusic

public void removeMusic(int i)

addMusic

public java.lang.String addMusic(java.lang.String name,
                                 int score,
                                 java.lang.String matches)

musicChanged

private void musicChanged()

resetLibrary

public void resetLibrary()

getLibrarySize

public int getLibrarySize()

getLibraryMethod

public java.lang.String getLibraryMethod(int i)
Returns one String with name, abbreviation, PN and leadhead separated by '|' characters


addMethodToLibrary

public java.lang.String addMethodToLibrary(java.lang.String name,
                                           java.lang.String abbrev,
                                           java.lang.String pn)
Returns empty string if successful, otherwise an error message. Also updates existing methods if "name" already in use.


newLibraryMethod

private void newLibraryMethod(Method newMethod)
Inserts new method into library, sorted on abbreviation. Method must not already exist.


removeMethodFromLibrary

public void removeMethodFromLibrary(int i)

getNMethods

public int getNMethods()

getShortestLead

public int getShortestLead()
Return the lead length of the shortest method in the current composition method list.

Returns:
Since:
Undomiel-B

getLongestLead

public int getLongestLead()
Return the lead length of the longest method in the current composition method list.

Returns:
Since:
Undomiel-B

isMethodInComp

public boolean isMethodInComp(java.lang.String name)

getMethod

public java.lang.String getMethod(int i)

removeMethod

public void removeMethod(int i)

addMethod

public void addMethod(int i)
Parameter i is index in method library


methodsChanged

private void methodsChanged()

compose

public boolean compose(int nleads,
                       int nparts,
                       boolean tenorsTogether,
                       boolean nicePE,
                       boolean optimumBalance,
                       boolean maxCOM,
                       int calls,
                       boolean LHonly)
Start composition, using the passed parameter values. Returns false if composer fails to start for some reason (usually because tables are still building).


compose

public boolean compose(int nleads,
                       int nparts,
                       boolean tenorsTogether,
                       boolean nicePE,
                       boolean optimumBalance,
                       boolean maxCOM,
                       int calls,
                       boolean LHonly,
                       int minPartLength,
                       int maxPartLength)
Start composition, using the passed parameter values, including min and max part length. Returns false if composer fails to start for some reason (usually because tables are still building).

Since:
Undomiel-B

getStatus

public java.lang.String getStatus()

isFinished

public boolean isFinished()

isError

public boolean isError()
Returns true if a (non-abort) error occurred.


getErrorMsg

public java.lang.String getErrorMsg()

isThereNewOutput

public boolean isThereNewOutput()

getOutput

public java.lang.String getOutput()
Now just gets the one best composition - see getAllComps().


getAllComps

public java.lang.String getAllComps()

getComp

private java.lang.String getComp(int i)

run

public void run()
Pass 1 is table build (methods - only if method table dirty). Pass 2 is music preparation (only if music table dirty). Pass 3 is lead-music prep (always) Pass 4 is the search!

Specified by:
run in interface java.lang.Runnable

outputComp

public void outputComp(OutputComp latest)
Called by the Composer when a new composition meeting the score minimums is produced. We compare it against the current top ten to see whether it is worth keeping. If it is, we may also update the Composer's minimum score values to implement "heuristic pruning".

Specified by:
outputComp in interface ComposerHost

isPaused

public boolean isPaused()

pause

public boolean pause()

resume

public void resume()

stop

public void stop()
Overrides:
stop in class java.applet.Applet

destroy

public void destroy()
Overrides:
destroy in class java.applet.Applet