SequenceNote : AbstractFunction

SequenceNote is the base class for a set of three classes to allow more intelligent handling of grace notes and chord notes for sequence manipulation.

Important: Some of the implementation will change in the future. The gate, or velocity, parameter needs to be handled specially for Voicers, but currently this is not done well. The changes will simplify the requirements for your code!

It is a subclass of AbstractFunction so that you can do math on a SequenceNote and get a SequenceNote back. This is especially helpful for transposition. Only the freq variable will undergo the math operation; others remain unchanged.

See SeqChordNote and SequenceItem for compound note objects.

*new(freq, dur, length, args)

freq: The pitch value. This may be whatever representation you choose: frequency in Hz, MIDI note number, modal index, etc.

dur: Delta to the next note event (in beats).

length: Sustain time for this note (in beats).

args: An array of key/value pairs with other synthesis parameters that should be sent along with the note event.

gate: Currently, a "virtual" instance variable. Eventually I will change this to a real instance variable; however, there might be code that depends on the current implementation (in which the gate value is stored either in the args instance variable as a simple float, or as a "\gate, value" pair in the args array). So there is a getter and setter that interfaces with the backend data storage.

add(note)

Create a SeqChordNote with the note argument added to the chord note list.

++ notes

Create a SeqChordNote with the note argument array added to the chord note list.

addGraceNotes

Create a SequenceItem with the supplied grace notes.

asPlayableNote

A no-op for this class. For SeqChordNote and SequenceItem, all chord notes will be compacted into one SequenceNote with arrays for the parameters.

asSequenceNote

A no-op for this class. For SeqChordNote and SequenceItem, the main note object will be returned.

asNoteArray

^[this]

asArray

^[freq, dur, length, args]

asPattern

asStream

Assists with streaming notes. The resulting stream returns only one item. For SeqChordNote and SequenceItem, the stream will output all required note objects.

This is the recommended way to use sequence note and the related classes for playing note data back.

Examples:

// middle C, 1 beat

n = SequenceNote(60, 1, 1);

// math operations work on the freq variable -- easy transposition

(n + 1).dump

Instance of SequenceNote { (0F20BD90, gc=3C, fmt=00, flg=00, set=02)

instance variables [4]

freq : Integer 61

dur : Integer 1

length : Integer 1

args : nil

}

n = [60, 62, 64, 65, 67, 69, 71, 72].collect(SequenceNote(_, 1, 1));

[ a SequenceNote, a SequenceNote, a SequenceNote, a SequenceNote, a SequenceNote, a SequenceNote, a SequenceNote, a SequenceNote ]

n.do(_.postln);

[ 60, 1, 1, nil ]

[ 62, 1, 1, nil ]

[ 64, 1, 1, nil ]

[ 65, 1, 1, nil ]

[ 67, 1, 1, nil ]

[ 69, 1, 1, nil ]

[ 71, 1, 1, nil ]

[ 72, 1, 1, nil ]

// whole sequences can be transposed

(n + 5).do(_.postln);

[ 65, 1, 1, nil ]

[ 67, 1, 1, nil ]

[ 69, 1, 1, nil ]

[ 70, 1, 1, nil ]

[ 72, 1, 1, nil ]

[ 74, 1, 1, nil ]

[ 76, 1, 1, nil ]

[ 77, 1, 1, nil ]

// asFloat simplifies conversion to note numbers

n.asFloat;

[ 60, 62, 64, 65, 67, 69, 71, 72 ]

// comparisons are legal

(n[0] < n[1])

true

// works easily with patterns

p = Pseq(n, 1).asStream;

while { p.next.postln.notNil };

[ 60, 1, 1, nil ]

[ 62, 1, 1, nil ]

[ 64, 1, 1, nil ]

[ 65, 1, 1, nil ]

[ 67, 1, 1, nil ]

[ 69, 1, 1, nil ]

[ 71, 1, 1, nil ]

[ 72, 1, 1, nil ]

nil