6.005 Elements of Software Construction | Fall 2009
|
The purpose of this exploration is to give you practice coding in Java, and to introduce you to the state machine case study that will be presented in lecture. Your solution will be judged by (1) correctness -- whether it meets the specification, and (2) clarity -- whether your code is well-organized and carefully commented. You are not required to use any of the ideas or patterns that have not yet been taught in lecture.
Your task is to build a program that allows a standard computer keyboard to be used as a (rather crude) electronic piano with the following features:
Your keyboard driver will probably generate repeat presses when a key is held down. On most Linux distributions you can turn this off using the following command: "xset r off" (and "xset r on" to turn it back on). Note that your keyboard driver might behave differently on different operating systems, so our requirement for this exploration is that your application works correctly on Athena when key repeats are turned off.
A slight annoyance: you'll need to click on the applet's panel with your mouse to give it keyboard focus before playing any notes.
Some Java installations do not have a default soundbank installed, causing the Midi code to throw the exception
java.lang.NullPointerException at com.sun.media.sound.AbstractPlayer.loadAllInstruments(Unknown Source) at midi.Midi.This can be corrected by following Sun's instructions here.(Midi.java:43) at piano.PianoApplet.init(PianoApplet.java:24) at sun.applet.AppletPanel.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
If you've successfully completed the exploration, you may want to try this optional challenge. Allow the P key to be pressed during recording, so that recordings can be layered, with new notes played being added to notes that were previously recorded.
Note that this challenge is completely optional, i.e. you can get full credit even without completing it.