com.soundhelix.misc
Class Sequence

java.lang.Object
  extended by com.soundhelix.misc.Sequence

public class Sequence
extends Object

Represents a sequence, i.e., the notes and pauses of a single voice. A note consists of a pitch (with 0 being c', 1 being c#' and so on), a velocity (between 0 and Short.MAX_VALUE) and a positive length in ticks. A pause is represented by an arbitrary pitch, a velocity of -1 and a positive length in ticks. The velocity can be used to represent a note's volume, but after all, it is up to the playback device how it interprets the velocity. For example, a device might always play a note at its full volume and use the velocity to control filter cut-off instead.

Author:
Thomas Schuerger (thomas@schuerger.com)

Nested Class Summary
static class Sequence.SequenceEntry
          A container for a sequence entry.
 
Constructor Summary
Sequence()
           
 
Method Summary
 void addNote(int pitch, int ticks)
          Calls addNote(pitch,ticks,Short.MAX_VALUE).
 void addNote(int pitch, int ticks, short velocity)
          Calls addNote(pitch,Short.MAX_VALUE,ticks,false).
 void addNote(int pitch, int ticks, short velocity, boolean legato)
          Appends a new note with the given pitch, velocity and number of ticks, which logically means a note-down for the given number of ticks and a note-up afterwards.
 void addPause(int ticks)
          Appends a pause with the given number of ticks.
 void extendNote(int ticks)
          Extends the previous sequence entry (which must be note) by the given number of ticks.
 Sequence.SequenceEntry get(int index)
          Returns the sequence entry with the given index.
 int getTicks()
          Returns the total number of ticks this sequence spans.
 void replaceEntry(int tick, Sequence.SequenceEntry entry)
          Replaces the entry at the given tick by the given entry.
 int size()
          Returns the number of sequence entries this sequence contains.
 String toString()
           
 void transpose(int halftones)
          Transposes all notes of this sequence up by the given number of halftones.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Sequence

public Sequence()
Method Detail

addNote

public void addNote(int pitch,
                    int ticks)
Calls addNote(pitch,ticks,Short.MAX_VALUE).

Parameters:
pitch - the pitch
ticks - the ticks

addNote

public void addNote(int pitch,
                    int ticks,
                    short velocity)
Calls addNote(pitch,Short.MAX_VALUE,ticks,false).

Parameters:
pitch - the pitch
ticks - the ticks
velocity - the velocity

addNote

public void addNote(int pitch,
                    int ticks,
                    short velocity,
                    boolean legato)
Appends a new note with the given pitch, velocity and number of ticks, which logically means a note-down for the given number of ticks and a note-up afterwards. This method does nothing if ticks is 0. If velocity is 0, an equivalently sized pause is added.

Parameters:
pitch - the pitch
velocity - the velocity (between 0 and 32767)
ticks - the ticks
legato - the legato flag

addPause

public void addPause(int ticks)
Appends a pause with the given number of ticks. If the previous sequence entry already was a pause, that pause is extended by the number of ticks instead of adding another pause. The method does nothing if ticks is 0.

Parameters:
ticks - the ticks

extendNote

public void extendNote(int ticks)
Extends the previous sequence entry (which must be note) by the given number of ticks. An IllegalStateException will be thrown if the sequence is empty or if the previous entry is not a note.

Parameters:
ticks - the number of ticks

getTicks

public int getTicks()
Returns the total number of ticks this sequence spans.

Returns:
the number of ticks
See Also:
size()

get

public Sequence.SequenceEntry get(int index)
Returns the sequence entry with the given index.

Parameters:
index - the index
Returns:
the sequence entry at that index

size

public int size()
Returns the number of sequence entries this sequence contains.

Returns:
the size of the sequence
See Also:
getTicks()

toString

public String toString()
Overrides:
toString in class Object

transpose

public void transpose(int halftones)
Transposes all notes of this sequence up by the given number of halftones.

Parameters:
halftones - the number of halftones (positive or negative)

replaceEntry

public void replaceEntry(int tick,
                         Sequence.SequenceEntry entry)
Replaces the entry at the given tick by the given entry. The tick can be any tick within the sequence and any note can be given. Note that this is an expensive operation, because the runtime grows linearly with the number of entries in the sequence.

Parameters:
tick - the tick where the replacement should take place
entry - the SequenceEntry to insert