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, 4.0 - added Pattern Properties
Author:
David Koelle

Field Summary
static java.lang.String TITLE
           
 
Constructor Summary
Pattern()
          Instantiates a new pattern
Pattern(Pattern... patterns)
          This constructor creates a new Pattern that contains each of the given patterns
Pattern(Pattern pattern)
          Copy constructor
Pattern(java.lang.String musicString)
          Instantiates a new pattern using the given music string
 
Method Summary
 void add(Pattern... patterns)
          Adds a number of patterns sequentially
 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... musicStrings)
          Adds a number of patterns sequentially
 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.
 java.lang.String getMusicString()
          Returns the music string kept in this pattern
 java.util.Map<java.lang.String,java.lang.String> getProperties()
          Get all properties set on this pattern, such as "author" or "date".
 java.lang.String getPropertiesAsParagraph()
          Returns a String containing key-value pairs stored in this object's properties, separated by newline characters.
 java.lang.String getPropertiesAsSentence()
          Returns a String containing key-value pairs stored in this object's properties, separated by semicolons and spaces.
 java.lang.String getProperty(java.lang.String key)
          Get a property on this pattern, such as "author" or "date".
 java.lang.String getTitle()
          Returns the title of this Pattern As of JFugue 4.0, the title is set as a property with the key Pattern.TITLE
 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 loadPattern(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)
          Repeats the music string in this pattern by the given number of times.
 void repeat(int times, int beginIndex)
          Only repeats the portion of this music string that starts at the string index provided.
 void repeat(int times, int beginIndex, int endIndex)
          Only repeats the portion of this music string that starts and ends at the string indices provided.
 void savePattern(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 setProperty(java.lang.String key, java.lang.String value)
          Set a property on this pattern, such as "author" or "date".
 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.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TITLE

public static final java.lang.String TITLE
See Also:
Constant Field Values
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

public Pattern(Pattern... patterns)
This constructor creates a new Pattern that contains each of the given patterns

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

add

public void add(Pattern... patterns)
Adds a number of patterns sequentially

Parameters:
musicString - the music string to add

add

public void add(java.lang.String... musicStrings)
Adds a number of patterns sequentially

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. As of JFugue 4.0, the title is set as a property with the key Pattern.TITLE

Parameters:
title - the title for this Pattern

getTitle

public java.lang.String getTitle()
Returns the title of this Pattern As of JFugue 4.0, the title is set as a property with the key Pattern.TITLE

Returns:
the title of this Pattern

getProperty

public java.lang.String getProperty(java.lang.String key)
Get a property on this pattern, such as "author" or "date".


setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)
Set a property on this pattern, such as "author" or "date".


getProperties

public java.util.Map<java.lang.String,java.lang.String> getProperties()
Get all properties set on this pattern, such as "author" or "date".


repeat

public void repeat(int times)
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)
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)
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

loadPattern

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

savePattern

public void savePattern(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

getPropertiesAsSentence

public java.lang.String getPropertiesAsSentence()
Returns a String containing key-value pairs stored in this object's properties, separated by semicolons and spaces. Values are returned in the following form: key1: value1; key2: value2; key3: value3

Returns:
a String containing key-value pairs stored in this object's properties, separated by semicolons and spaces

getPropertiesAsParagraph

public java.lang.String getPropertiesAsParagraph()
Returns a String containing key-value pairs stored in this object's properties, separated by newline characters. Values are returned in the following form: key1: value1\n key2: value2\n key3: value3\n

Returns:
a String containing key-value pairs stored in this object's properties, separated by newline characters

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

toString

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