<< Chapter < Page | Chapter >> Page > |
An previous module titled Jbs2050-Runtime Polymorphism with Java Sound summarized the kinds of things that you have learned in the earlier modules inthe series. As indicated in that module, the program that I will discuss in this module will be significantly different from the code in the earlier modules. Forexample, the code in those modules produced hard-coded sound such as StereoPingpong and FMSweep .
The code in this module will allow you to control the sound based on the contents of a text file that you create. This allows a great deal offlexibility as indicated by the melodies in the above list .
In the late 19th and early 20th century, various companies manufactured pianos that played music automatically. The music was recorded on rolls of perforatedpaper. A pneumatic or electro-mechanical mechanism inside the piano read the holes in the paper and used that information to press the keys on the pianokeyboard in such a way as to cause the piano to play the pre-recorded music. To a sightedobserver, it looked as if an invisible person was playing the piano because the piano keys moved up and down with no hands on the keyboard.
These automated pianos were often referred to as player pianos . The program that I will explain in this module is a player piano simulator . You can "pre-record" a melody in text files (as opposed to rolls of perforated paper) and play those files using the simulator program. As you will learn later, amelody is defined in one (or optionally two) text files using standard musical notation where the notes have names like A, A#, B, C, C#, etc.
I'm an engineer, not a musician. While I understand quite a bit about the physics of sound, I understand very little about how that sound is put togetherto create the pleasing sound that we call music. This module will describe a simulated musical instrument. Therefore, it will be necessary for meto explain the code using musical terminology. I'm sure that the explanation will contain many gaffs insofar as musical terminology is concerned. However, thepurpose is to teach programming and not to teach music. Please bear with me and overlook my musical terminology gaffs.
This program requires access to the following five classes in the same folder :
You will find source code for all of these classes in Listing 24 through Listing 28 .
You are already familiar with the first three classes in the above list because they were used in earlier modules. Therefore, I won't discuss them in this module
The driver class for this program is the class named MusicComposer09 . The player piano simulator is defined in the class named PlayerPiano01 . I will explain those two classes in the next section.
This is the driver class for playing piano melodies. It requires the files in the above list to be in the same folder.
Notification Switch
Would you like to follow the 'Accessible objected-oriented programming concepts for blind students using java' conversation and receive update notifications?