The architecture of the isdraw package
The isdraw package extends the functionality of the idraw package
by providing an interface to the tunes package. The World comes
with two TuneBuckets for carrying the tunes that should be played.
Tick events
On each tick event the World starts playing all Tunes currently in the
tickTunes bucket and clears the tickTunes bucket. It also decreases the
duration of all notes that have been placed in the tickTunes bucket during the previous tick events,
and stops playing those that have gone silent (have duration equal to zero). However, the programmer cannot
see or change what is playing after the tunes in the tickTune bucket started playing.
Key events
The programmer has to implement the method onKeyEvent. Here the programmer can add
tunes to the keyTunes bucket. The world plays all the tunes associated with the key event that
has been handled and plays them until the corresponding key is released. The programmer has no control over the
duration of these tunes other than pressing and releasing the keys. For longer durations of keypresses the notes
may be restarted, sounding as if the key has been pressed again.
The World defines a method onKeyReleased that can be overridden by the
programmer. It does not give the programmer control over the tunes played. It is included so that the program
can provide clues to the user that the key has been released. For example, one of our demo programs shows
a piano keyboard and annotated with the computer keyboard keys to
be played (a s d f g h j k - covering one octave). When a key is played, the label for that key is shown in red.
Program change
The programmer can change the selection of the MIDI instruments in response to a mouse
click or in response to a key event, by invoking the programChange method and providing the
new selection of instruments.
Drawing text on a Canvas
The method drawString now allows the programmer to define the color of the text that is
displayed. If no color is given, the text is shown in black as has been done in the idraw
library.
Mouse actions
The World class includes the methods onMouseClicked(Posn p),
onMouseEntered(Posn p), onMouseExited(Posn p),
onMousePressed(Posn p), onMouseReleased(Posn p). Programmer can override
any of these methods. The value of the Posn p is the location of the mouse when the mouse event
has been signalled.
We have used the onMouseClicked method in our samples, but have not yet used the other
methods in out examples. Please, report any problems, as well as examples of use of these features.