<< Chapter < Page
  Accessible objected-oriented     Page 4 / 17
Chapter >> Page >

Because of the code in Listing 3 , the program can be run in default mode without the requirement to enter command-line parameters. This code creates default args data if no parameters are entered on the command line. The code requires that the files named GreensleevesTreble.txt and GreensleevesBass.txt exist in the subfolder named Music .

Get a melody array

The code in Listing 4 is the same as code that you have seen in previous modules. The only thing new is that this program requires a text file containing treble clef data and optionally a filecontaining bass clef data in the subfolder named Music .

Listing 4 . Get a melody array.
AudioSignalGenerator02 sigGen = new PlayerPiano01(audioParams,this.args,melody);melody = sigGen.getMelody();//Play or file the audio data new AudioPlayOrFile01(audioParams,melody,this.args[0]).playOrFileData(); }//end constructor//-------------------------------------------------------------------------// }//end class MusicComposer09.java

Listing 4 also signals the end of the constructor and the end of the class named MusicComposer09 .

The class named PlayerPiano01

This class simulates an old-fashioned player piano and makes it possible to compose a melody by specifying the sequence of notes and the duration of eachnote for both the treble and bass clefs. The program uses text files to store the notes.

The notes are converted to frequencies, which are then used to produce mono or stereo sound.While not perfect, an attempt was made to cause that sound to resemble the sound of a piano.

Treble clef and bass clef

A file containing treble clef notes is required. Bass clef notes are optional. If a file is provided containing bass clef notes, the bass clef melody isemitted from the left speaker and the treble clef melody is emitted from the right speaker.If bass clef notes are not provided, the program defaults to monaural with the treble clef melody being emitted with equal volume from both speakers.

Command-line parameters

Various operating parameters are provided by way of command-line parameters. One ofthe command-line parameters makes it possible to play the music immediately or to write it into an audio file of type AU for playback later.The notes for the melody are specified in one or two text files. As mentioned earlier, a filecontaining treble clef notes is required. A file containing bass clef notes is optional.

The input file names and other parameters are specified on the command line as shown in the comments at the beginning of the source code filefor the class named MusicComposer09 .

Required text file format

Each line in the text file specifies the duration and one or more keys that would be pressed on a piano simultaneously. The items are delimited by commas,and spaces are not allowed. For example, the following lines of text specify four instances of the A-Major chord for quarter, half,three-fourths, and whole notes with a whole note rest in between. (See (External Link) for chord chars.)Note that X is used as the symbol for silence or a musical rest.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Accessible objected-oriented programming concepts for blind students using java. OpenStax CNX. Sep 01, 2014 Download for free at https://legacy.cnx.org/content/col11349/1.17
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Accessible objected-oriented programming concepts for blind students using java' conversation and receive update notifications?

Ask