org.jfugue
Class Pattern

java.lang.Object
  extended by org.jfugue.Pattern

public class Pattern
extends java.lang.Object

This class represents a segment of music. By representing segments of music as patterns, JFugue gives users the opportunity to play around with pieces of music in new and interesting ways. Patterns may be added together, transformed, or otherwise manipulated to expand the possibilities of creative music.

Version:
2.0
Author:
David Koelle

Field Summary
protected  javax.swing.event.EventListenerList listenerList
          List of ParserListeners
 
Constructor Summary
  Pattern()
          Instantiates a new pattern
protected Pattern(java.io.File file)
          Creates a Pattern given a MIDI file
  Pattern(Pattern pattern)
          Copy constructor
  Pattern(java.lang.String musicString)
          Instantiates a new pattern using the given music string
 
Method Summary
 void add(Pattern pattern)
          Adds an additional pattern to the end of this pattern.
 void add(Pattern pattern, int numTimes)
          Adds an additional pattern to the end of this pattern.
 void add(java.lang.String musicString)
          Adds a music string to the end of this pattern.
 void add(java.lang.String musicString, int numTimes)
          Adds a music string to the end of this pattern.
 void addElement(JFugueElement element)
          Adds an individual element to the pattern.
 void addPatternListener(PatternListener l)
          Adds a PatternListener.
protected  void clearPatternListeners()
           
 java.lang.String getMusicString()
          Returns the music string kept in this pattern
 java.lang.String getTitle()
          Returns the title of this Pattern
 java.lang.String[] getTokens()
          Returns an array of strings representing each token in the Pattern.
 void insert(java.lang.String musicString)
          Inserts a MusicString before this music string.
static Pattern loadMusicString(java.io.File file)
           
 void offset(long offsetTime)
          Changes all timestamp values by the offsetTime passed in.
 void removePatternListener(PatternListener l)
          Removes a PatternListener.
 void repeat(int times)
          Returns a new Pattern that repeats the music string in this pattern by the given number of times.
 void repeat(int times, int beginIndex)
          Returns a new Pattern that only repeats the portion of this music string that starts at the string index provided.
 void repeat(int times, int beginIndex, int endIndex)
          Returns a new Pattern that only repeats the portion of this music string that starts and ends at the string indices provided.
 void saveMusicString(java.io.File file)
          Saves the pattern as a text file
 void setMusicString(java.lang.String musicString)
          Sets the music string kept by this pattern.
 void setTitle(java.lang.String title)
          Sets the title for this Pattern
 Pattern subPattern(int beginIndex)
          Returns a new Pattern that is a subpattern of this pattern.
 Pattern subPattern(int beginIndex, int endIndex)
          Returns a new Pattern that is a subpattern of this pattern.
protected  java.lang.String substring(int beginIndex)
           
protected  java.lang.String substring(int beginIndex, int endIndex)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

listenerList

protected javax.swing.event.EventListenerList listenerList
List of ParserListeners

Constructor Detail

Pattern

public Pattern()
Instantiates a new pattern


Pattern

public Pattern(java.lang.String musicString)
Instantiates a new pattern using the given music string

Parameters:
s - the music string

Pattern

public Pattern(Pattern pattern)
Copy constructor


Pattern

protected Pattern(java.io.File file)
           throws java.io.IOException,
                  javax.sound.midi.InvalidMidiDataException
Creates a Pattern given a MIDI file

Parameters:
file -
Throws:
java.io.IOException
javax.sound.midi.InvalidMidiDataException
Method Detail

setMusicString

public void setMusicString(java.lang.String musicString)
Sets the music string kept by this pattern.

Parameters:
s - the music string

getMusicString

public java.lang.String getMusicString()
Returns the music string kept in this pattern

Returns:
the music string

insert

public void insert(java.lang.String musicString)
Inserts a MusicString before this music string. NOTE - this does not call fragmentAdded!

Parameters:
musicString - the string to insert

add

public void add(Pattern pattern)
Adds an additional pattern to the end of this pattern.

Parameters:
pattern - the pattern to add

add

public void add(java.lang.String musicString)
Adds a music string to the end of this pattern.

Parameters:
musicString - the music string to add

add

public void add(Pattern pattern,
                int numTimes)
Adds an additional pattern to the end of this pattern.

Parameters:
pattern - the pattern to add

add

public void add(java.lang.String musicString,
                int numTimes)
Adds a music string to the end of this pattern.

Parameters:
musicString - the music string to add

addElement

public void addElement(JFugueElement element)
Adds an individual element to the pattern. This takes into account the possibility that the element may be a sequential or parallel note, in which case no space is placed before it.

Parameters:
element - the element to add

setTitle

public void setTitle(java.lang.String title)
Sets the title for this Pattern

Parameters:
title - the title for this Pattern

getTitle

public java.lang.String getTitle()
Returns the title of this Pattern

Returns:
the title of this Pattern

repeat

public void repeat(int times)
Returns a new Pattern that repeats the music string in this pattern by the given number of times. Example: If the pattern is "A B", calling repeat(4) will make the pattern "A B A B A B A B".


repeat

public void repeat(int times,
                   int beginIndex)
Returns a new Pattern that only repeats the portion of this music string that starts at the string index provided. This allows some initial header information to only be specified once in a repeated pattern. Example: If the pattern is "T0 A B", calling repeat(4, 3) will make the pattern "T0 A B A B A B A B".


repeat

public void repeat(int times,
                   int beginIndex,
                   int endIndex)
Returns a new Pattern that only repeats the portion of this music string that starts and ends at the string indices provided. This allows some initial header information and trailing information to only be specified once in a repeated pattern. Example: If the pattern is "T0 A B C", calling repeat(4, 3, 5) will make the pattern "T0 A B A B A B A B C".


subPattern

public Pattern subPattern(int beginIndex)
Returns a new Pattern that is a subpattern of this pattern.

Returns:
subpattern of this pattern

subPattern

public Pattern subPattern(int beginIndex,
                          int endIndex)
Returns a new Pattern that is a subpattern of this pattern.

Returns:
subpattern of this pattern

substring

protected java.lang.String substring(int beginIndex)

substring

protected java.lang.String substring(int beginIndex,
                                     int endIndex)

loadMusicString

public static Pattern loadMusicString(java.io.File file)
                               throws java.io.IOException
Throws:
java.io.IOException

saveMusicString

public void saveMusicString(java.io.File file)
                     throws java.io.IOException
Saves the pattern as a text file

Parameters:
filename - the filename to save under
Throws:
java.io.IOException

offset

public void offset(long offsetTime)
Changes all timestamp values by the offsetTime passed in. NOTE: This method is only useful for patterns that have been converted from a MIDI file.

Parameters:
offsetTime -

getTokens

public java.lang.String[] getTokens()
Returns an array of strings representing each token in the Pattern.

Returns:

addPatternListener

public void addPatternListener(PatternListener l)
Adds a PatternListener. The listener will receive events when new parts are added to the pattern.

Parameters:
listener - the listener that is to be notified when new parts are added to the pattern

removePatternListener

public void removePatternListener(PatternListener l)
Removes a PatternListener.

Parameters:
listener - the listener to remove

clearPatternListeners

protected void clearPatternListeners()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object