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

How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
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
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
How can I make nanorobot?
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
how can I make nanorobot?
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
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
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?