| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectworld.sound.SoundWorld
public abstract class SoundWorld
  
  A Class representing an imperative World with sound/music and the related methods for drawing the 
    world and handling various events.  In order to implement a functioning World with sound you
    must extend this class, and implement an onDraw
    method.  Other handler methods (tickRate, onTick, 
    onMouse, onKey, onRelease, 
    stopWhen, and lastScene) are optional, and
    can be overridden to add new functionality.
 
  Each of the interaction methods can add Notes (sounds) to be played
  (e.g., onTick) for a length of time after the event.  There are two tune-collections
  for adding sounds, the first tickTunes, should be added
  to for notes/sounds that should be played for a specified length of time corresponding to a World
  event. The second, keyTunes, should be added to for
  notes/sounds that should be played for as long as the key is pressed;  when the key is released
  the sound will be removed and playing of the note will stop.
 
See the world.sound.tunes package for more details (Notes, Chords, etc.).
Below is a simple example of aVoidWorldthat adds a new point at each mouse click. The world contains aSceneand a newCircleis placed for each"button-down"event received, and aNoteis added to thetickTunesto be played at the currentpitch, which is incremented.import image.*; import world.sound.SoundWorld; import world.sound.tunes.Note; public class MousePointsSoundWorld extends SoundWorld{ // Simple Main Program public static void main(String[] args) { new MousePointsSoundWorld().bigBang(); } // The inner Scene Scene scene = new EmptyScene(200, 200); // The current pitch to be played int pitch = noteDownC; // Create a new World MousePointsSoundWorld(){} // Draw by returning the inner Scene public Scene onDraw(){ return this.scene; } // On a mouse click add a circle to the inner Scene, increment the // current pitch and play a short note public void onMouse(int x, int y, String me){ if(me.equals("button-down")){ this.pitch++; this.tickTunes.addNote(WOOD_BLOCK, new Note(this.pitch, 1)); this.scene = this.scene.placeImage( new Circle(20, "solid", "red") .overlay(new Circle(20, "outline", "black")), x, y); } } }After a few mouse clicks, the window will look something like this, though every mouse click will have a corresponding sound at an increasing pitch:

| Field Summary | |
|---|---|
| static double | DEFAULT_TICK_RATEDefault Tick rate for the world: ~33 frames per second | 
| static java.lang.String | KEY_ARROW_DOWNKey arrow-down event String | 
| static java.lang.String | KEY_ARROW_LEFTKey arrow-left event String | 
| static java.lang.String | KEY_ARROW_RIGHTKey arrow-right event String | 
| static java.lang.String | KEY_ARROW_UPKey arrow-up event String | 
|  TuneCollection | keyTunesThe collection of tunes to start playing when a key is pressed, which will automatically removed when the same key is released. | 
| static java.lang.String | MOUSE_DOWNMouse down (button-down) event String | 
| static java.lang.String | MOUSE_DRAGMouse down & move (drag) event String | 
| static java.lang.String | MOUSE_ENTERMouse window enter (enter) event String | 
| static java.lang.String | MOUSE_LEAVEMouse window leave (leave) event String | 
| static java.lang.String | MOUSE_MOVEMouse motion (move) event String | 
| static java.lang.String | MOUSE_UPMouse up (button-up) event String | 
|  MusicBox | musicBoxA representation of the current state of the MIDI synthesizer. | 
|  TuneCollection | tickTunesThe collection of tunes to play on tick. | 
| Constructor Summary | |
|---|---|
| SoundWorld()Default constructor. | |
| Method Summary | |
|---|---|
|  SoundWorld | bigBang()Kick off the interaction/animation. | 
|  boolean | equals(java.lang.Object o)Overridden equality to method. | 
|  Scene | lastScene()Returns the Scene that should be displayed when the interaction/animation completes ( stopWhen()returns true). | 
| abstract  Scene | onDraw()Return a visualization of this World as a Scene. | 
|  void | onKey(java.lang.String event)Change this World when a key event is triggered. | 
|  void | onMouse(int x,
        int y,
        java.lang.String event)Change this World when a mouse event is triggered. | 
|  void | onRelease(java.lang.String event)Change this World when a key is released. | 
|  void | onTick()Change this World based on the Tick of the clock. | 
|  boolean | stopWhen()Determine if the World/interaction/animation should be stopped. | 
|  double | tickRate()Return the tick rate for this World in seconds. | 
| Methods inherited from class java.lang.Object | 
|---|
| getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
public static double DEFAULT_TICK_RATE
public static java.lang.String MOUSE_DOWN
public static java.lang.String MOUSE_UP
public static java.lang.String MOUSE_ENTER
public static java.lang.String MOUSE_LEAVE
public static java.lang.String MOUSE_MOVE
public static java.lang.String MOUSE_DRAG
public static java.lang.String KEY_ARROW_UP
public static java.lang.String KEY_ARROW_DOWN
public static java.lang.String KEY_ARROW_LEFT
public static java.lang.String KEY_ARROW_RIGHT
public MusicBox musicBox
public TuneCollection tickTunes
public TuneCollection keyTunes
| Constructor Detail | 
|---|
public SoundWorld()
| Method Detail | 
|---|
public abstract Scene onDraw()
Scene.
    See EmptyScene, Scene.placeImage(Image, int, int), and
    Scene.addLine(int, int, int, int, String) for documentation on
    constructing Scenes
public double tickRate()
public void onTick()
Notes) to play starting on the current tick
  may be added to the tickTunes tune-collection
  to be played for a specified length of time.  Notes will stop playing automatically
  when the amount of time corresponding to the note's duration has elapsed.
public void onMouse(int x,
                    int y,
                    java.lang.String event)
Possible Mouse Events
| "button-down" : | The user presses a mouse button in the World window | 
| "button-up" : | The user releases a mouse button in the World window | 
| "move" : | The user moves the mouse in the World window | 
| "drag" : | The user holds a mouse button and moves the mouse in the World window | 
| "enter" : | The user moves the mouse in-to the World window | 
| "leave" : | The user moves the mouse out-of the World window | 
Notes) to play starting when a certain mouse event
  occurs may be added to the tickTunes tune-collection
  to be played for a specified length of time.  Notes will stop playing automatically
  when the amount of time corresponding to the note's duration has elapsed.
public void onKey(java.lang.String event)
Special Key
| "up" : | The user presses the up-arrow key | 
| "down" : | The user presses the down-arrow key | 
| "left" : | The user presses the left-arrow key | 
| "right" : | The user presses the right-arrow key | 
Notes) to play when the given key is pressed
  may be added to the keyTunes tune-collection
  to be played until the same key is released.  Notes will not stop playing until the
  key is released.
 
  Sounds to be played for a specific length of time after a certain key press (i.e., not
  until the key is released) may be added to the tickTunes
  tune-collection (instead of keyTunes) played until
  amount of time corresponding to the note's duration has elapsed.
 
public void onRelease(java.lang.String event)
Special Keys
| "up" : | The user presses the up-arrow key | 
| "down" : | The user presses the down-arrow key | 
| "left" : | The user presses the left-arrow key | 
| "right" : | The user presses the right-arrow key | 
Notes) that were added to the
 keyTunes tune-collection on a previous
 key press will be stopped.
public boolean stopWhen()
lastScene() to be used to draw the final
 Scene.
public Scene lastScene()
stopWhen()
 returns true).
public SoundWorld bigBang()
public boolean equals(java.lang.Object o)
equals in class java.lang.Object| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||