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

Preparation and Applications of Nanomaterial for Drug Delivery
Hafiz Reply
Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
hi
Loga
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





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