abc4j API Specification

abc.parser
Class TuneBook

java.lang.Object
  extended by abc.parser.TuneBook

public class TuneBook
extends java.lang.Object

This class provides an object representation of a tunebook. It enables you to store tunes ordered by reference number.


Constructor Summary
TuneBook()
          Creates an empty tunebook.
TuneBook(java.io.BufferedReader stream)
          Deprecated. use TuneBook(Reader) instead.
TuneBook(java.io.BufferedReader stream, AbcFileParserListenerInterface listener)
          Deprecated. use TuneBook(Reader, AbcFileParserListenerInterface) instead.
TuneBook(java.io.File abcFile)
          Creates a new tune book from the specified file.
TuneBook(java.io.File abcFile, AbcFileParserListenerInterface listener)
          Creates a new tune book from the specified file and gets feedback from the parsing phasis via the specified listener.
TuneBook(java.io.Reader stream)
          Creates a new tune book from the specified stream.
TuneBook(java.io.Reader stream, AbcFileParserListenerInterface listener)
          Creates a new tune book from the specified stream and gets feedback from the parsing phasis via the specified listener.
 
Method Summary
 void addListener(TuneBookListenerInterface l)
          Adds a listener to this tunebook to be aware of tunes changes.
 java.io.File getFile()
          Returns the file associated to this TuneBook if any.
 int getHighestReferenceNumber()
          Returns the highest reference number from all the reference numbers this tunebook contains.
 int[] getReferenceNumbers()
          Returns the reference numbers of tunes contained in this tunebook.
 Tune getTune(int referenceNumber)
          Returns the tune with the specified reference number
 java.lang.String getTuneHeader(int referenceNumber)
          Returns the text put just before a tune in an ABC file.
 java.lang.String getTuneNotation(int referenceNumber)
          Returns the notation of the tune corresponding to the specified reference number.
 Tune[] getTunesHeaders()
          Returns tunes header information of tunes contained in this tunebook.
 Tune putTune(java.lang.String tuneNotation)
          Puts the specified tune notation in this tunebook.
 void removeListener(TuneBookListenerInterface l)
          Removes a listener from this tunebook.
 Tune removeTune(int referenceNumber)
          Removes the tune with specified reference number.
 void save()
           
 void saveTo(java.io.File file)
          Saves this tunebook to the specified file.
 int size()
          Returns the number of tunes contained in this tunebook.
 java.util.Vector toVector()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TuneBook

public TuneBook(java.io.File abcFile)
         throws java.io.FileNotFoundException
Creates a new tune book from the specified file.

Parameters:
abcFile - The file that contains tunes in abc notation.
Throws:
java.io.FileNotFoundException - Thrown if the specified file doesn't exist.

TuneBook

public TuneBook(java.io.File abcFile,
                AbcFileParserListenerInterface listener)
         throws java.io.FileNotFoundException
Creates a new tune book from the specified file and gets feedback from the parsing phasis via the specified listener.

Parameters:
abcFile - The file that contains tunes in abc notation.
listener - Listener to be informed of the parsing phasis.
Throws:
java.io.FileNotFoundException - Thrown if the specified file doesn't exist.

TuneBook

public TuneBook(java.io.Reader stream)
         throws java.io.IOException
Creates a new tune book from the specified stream.

Parameters:
stream - The stream in abc notation.
Throws:
java.io.IOException - If the stream does not support Reader.mark(int), or if some other I/O error occurs

TuneBook

public TuneBook(java.io.Reader stream,
                AbcFileParserListenerInterface listener)
         throws java.io.IOException
Creates a new tune book from the specified stream and gets feedback from the parsing phasis via the specified listener.

Parameters:
stream - The stream in abc notation.
listener - Listener to be informed of the parsing phasis.
Throws:
java.io.IOException - If the stream does not support Reader.mark(int), or if some other I/O error occurs

TuneBook

public TuneBook()
Creates an empty tunebook.


TuneBook

public TuneBook(java.io.BufferedReader stream)
Deprecated. use TuneBook(Reader) instead.

Creates a new tune book from the specified stream.

Parameters:
stream - The stream in abc notation.

TuneBook

public TuneBook(java.io.BufferedReader stream,
                AbcFileParserListenerInterface listener)
Deprecated. use TuneBook(Reader, AbcFileParserListenerInterface) instead.

Creates a new tune book from the specified stream and gets feedback from the parsing phasis via the specified listener.

Parameters:
stream - The stream in abc notation.
listener - Listener to be informed of the parsing phasis.
Method Detail

saveTo

public void saveTo(java.io.File file)
            throws java.io.IOException
Saves this tunebook to the specified file.

Parameters:
file - The file where all tunes notation should be stored.
Throws:
java.io.IOException - Thrown if the specified file doesn't exist.

getFile

public java.io.File getFile()
Returns the file associated to this TuneBook if any.

Returns:
Returns the file associated to this TuneBook if any. null is returned if this TuneBook has been created from scratch for instance.

save

public void save()
          throws java.io.IOException
Throws:
java.io.IOException

putTune

public Tune putTune(java.lang.String tuneNotation)
Puts the specified tune notation in this tunebook. If a tune with the same reference number was already existing, it updates it. If it's a new tune, it adds it.

Parameters:
tuneNotation - A string that describes a tune using ABC notation.
Returns:
The Tune representation of the tuneNotation parameter.

removeTune

public Tune removeTune(int referenceNumber)
Removes the tune with specified reference number.

Parameters:
referenceNumber - The reference number of the tune that has to be removed.
Returns:
The tune that has been removed, null if no tune with the corresponding reference number has been found.

getTune

public Tune getTune(int referenceNumber)
Returns the tune with the specified reference number

Parameters:
referenceNumber - The reference number of the tune that should be retrieved.
Returns:
The tune corresponding to the specified reference number, null if no tune found.

getTuneHeader

public java.lang.String getTuneHeader(int referenceNumber)
Returns the text put just before a tune in an ABC file. For instance, with a file such as :
 %text 1 before the first tune
 X:5
 T:xxxx
 K:D
 ...
 
the invokation
getTuneHeader(5)
would return the string
"%text 1 before the first tune\n"

Returns:
The text put just before a tune in an ABC file.

getTuneNotation

public java.lang.String getTuneNotation(int referenceNumber)
                                 throws NoSuchTuneException
Returns the notation of the tune corresponding to the specified reference number.

Parameters:
referenceNumber - A reference number.
Returns:
A tune notation in ABC format. null if no tune has been found.
Throws:
NoSuchTuneException - Thrown if the specified reference number doesn't exist in this tunebook.

getTunesHeaders

public Tune[] getTunesHeaders()
Returns tunes header information of tunes contained in this tunebook.

Returns:
An array containing Tune objects representing header information of tunes contained in this tunebook.

getReferenceNumbers

public int[] getReferenceNumbers()
Returns the reference numbers of tunes contained in this tunebook.

Returns:
An array containing the reference numbers of tunes contained in this tunebook, ordered in the way they were added in this tunebook.

getHighestReferenceNumber

public int getHighestReferenceNumber()
Returns the highest reference number from all the reference numbers this tunebook contains.

Returns:
The highest reference number from all the reference numbers this tunebook contains. -1 is returned if no tune is stored in this tunebook

size

public int size()
Returns the number of tunes contained in this tunebook.

Returns:
The number of tunes contained in this tunebook.

toVector

public java.util.Vector toVector()

addListener

public void addListener(TuneBookListenerInterface l)
Adds a listener to this tunebook to be aware of tunes changes.

Parameters:
l - The listener to be added.

removeListener

public void removeListener(TuneBookListenerInterface l)
Removes a listener from this tunebook.

Parameters:
l - The listener to be removed.

abc4j API Specification

Submit a bug or feature