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

The code in Listing 8 ignores:

  • Blank lines that result in a string with a zero length
  • Comments that begin with a forward slash character (/)
  • Lines that begin with a space

By ignore, I mean that they are not used to create an array that is added to the end of the ArrayList object.

The text file with the given name in the subfolder named Music is opened for reading by one of the early statements in Listing 8 . It is closed by the last statement in Listing 8 .

Get and save bass clef note data

Listing 9 does essentially the same thing for the bass clef note data if a bass clef text file is specified on the command line.

Listing 9 . Get and save bass clef note data.
if(bassFileName != null){ //A file was specified for bass cleft data. Need to process it.bassClef = new ArrayList(); in = new BufferedReader(new FileReader("Music/" + bassFileName));while ((str = in.readLine()) != null) { String[]strArr = str.split(",");//Ignore: // Blank lines that result in a string with a zero length// Comments that begin with a / // Lines that begin with a spaceif(strArr[0].length() != 0&&!(strArr[0].substring(0,1).equals("/"))&&!(strArr[0].substring(0,1).equals(" "))){bassClef.add(strArr); }//end if}//end while}//end if }catch(Exception ex){ex.printStackTrace(); }//end catch

Compute the length of each clef in beats

Later on in the program, we will need to relate the notes from the text file to real time in seconds. We will also need to know the total length ofthe melody in seconds in order to create an array object of sufficient length to contain the audio data at a specified sampling rate.

In preparation for that requirement, Listing 10 uses an iterator to extract and add the number of beats for each note for each clef in order to get the totallength of the melody in beats. (Hopefully you are familiar with the use of an iterator as a result of your studies of the Collections Framework )

Listing 10 . Compute the length of each clef in beats.
//Compute length of trebleClef in beats //Get an iterator on the trebleClefIterator iter = trebleClef.iterator(); while(iter.hasNext()){//Extract the next array of notes from the ArrayList. String[]array = (String[])iter.next();//Get the duration in beats and add to the total. trebleLengthInBeats += Integer.parseInt(array[0]); }//end whileif(bassFileName != null){//Compute length of bassClef in beats //Get an iterator on the trebleClefiter = bassClef.iterator(); while(iter.hasNext()){//Extract the next array of notes from the ArrayList String[]array = (String[])iter.next();//Get the duration in beats and add to the total. bassLengthInBeats += Integer.parseInt(array[0]); }//end while

Check for treble and bass clefs of different lengths

Listing 11 continues the if statement that began in Listing 10 .

Given that the two text files were created separately and probably manually, there is a good possibility that the total length in beats of the treble clefdata and the total length of the bass clef data are not exactly the same. Listing 11 checks for that possibility and prints out a warning if the lengths don't match. As you will see later, if they don't match, the longer of the twowill be truncated to the length of the shorter one. (This might cause you to edit the files and add some musical rests to the end of the shorter one to make themmatch or, find and fix a problem somewhere within the melody.)

Questions & Answers

discuss how the following factors such as predation risk, competition and habitat structure influence animal's foraging behavior in essay form
Burnet Reply
location of cervical vertebra
KENNEDY Reply
What are acid
Sheriff Reply
define biology infour way
Happiness Reply
What are types of cell
Nansoh Reply
how can I get this book
Gatyin Reply
what is lump
Chineye Reply
what is cell
Maluak Reply
what is biology
Maluak
what's cornea?
Majak Reply
what are cell
Achol
Explain the following terms . (1) Abiotic factors in an ecosystem
Nomai Reply
Abiotic factors are non living components of ecosystem.These include physical and chemical elements like temperature,light,water,soil,air quality and oxygen etc
Qasim
Define the term Abiotic
Marial
what is biology
daniel Reply
what is diffusion
Emmanuel Reply
passive process of transport of low-molecular weight material according to its concentration gradient
AI-Robot
what is production?
Catherine
hello
Marial
Pathogens and diseases
how did the oxygen help a human being
Achol Reply
how did the nutrition help the plants
Achol Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

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