<< 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

calculate molarity of NaOH solution when 25.0ml of NaOH titrated with 27.2ml of 0.2m H2SO4
Gasin Reply
what's Thermochemistry
rhoda Reply
the study of the heat energy which is associated with chemical reactions
Kaddija
How was CH4 and o2 was able to produce (Co2)and (H2o
Edafe Reply
explain please
Victory
First twenty elements with their valences
Martine Reply
what is chemistry
asue Reply
what is atom
asue
what is the best way to define periodic table for jamb
Damilola Reply
what is the change of matter from one state to another
Elijah Reply
what is isolation of organic compounds
IKyernum Reply
what is atomic radius
ThankGod Reply
Read Chapter 6, section 5
Dr
Read Chapter 6, section 5
Kareem
Atomic radius is the radius of the atom and is also called the orbital radius
Kareem
atomic radius is the distance between the nucleus of an atom and its valence shell
Amos
Read Chapter 6, section 5
paulino
Bohr's model of the theory atom
Ayom Reply
is there a question?
Dr
when a gas is compressed why it becomes hot?
ATOMIC
It has no oxygen then
Goldyei
read the chapter on thermochemistry...the sections on "PV" work and the First Law of Thermodynamics should help..
Dr
Which element react with water
Mukthar Reply
Mgo
Ibeh
an increase in the pressure of a gas results in the decrease of its
Valentina Reply
definition of the periodic table
Cosmos Reply
What is the lkenes
Da Reply
what were atoms composed of?
Moses 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