XMLVoice holds XMLNote events for a single musical line.


Inherits from: Object


A structure to handle a single voice of XMLNotes. XMLNotes can be added to an XMLVoice for inclusion in an XMLScore and output to a MusicXML file. Notes are added according to beat. For any given voice, where a note isn't given, rests will be filled in for you.


See also: XMLScore and XMLNote as well as MusicXMLOverview


Some Important Issues Regarding XMLVoice (optional)


MusicXML is a VERY complex system, and different notation programs handle the code in different ways. Overall, the MusicXML files created from SuperCollider should open fine in Finale, Sibelius and NoteAbility Pro. Also, while this first version (June 2008) works well, until a number of people have used it there may be some instability in the library. While future changes will attempt to be backwards compatible, this may not always be possible.


ONLY single melodic lines are now possible. This should be remedied soon.


Creation / Class Methods


*new (partName, id, meter, key, clef)

Creates a container for a single voice of XMLNote instances. All creation arguments are optional.

partName - a symbol to be used for the part's name.

id - An integer to be used as an id in the XML file.

meter - An instance of XMLMeter to be used as a global default.

key - An instance of XMLKey to be used as a global default.

clef - An instance of XMLClef to be used as a global default.



Accessing Instance and Class Variables

keySigs

Returns an array consisting of measure numbers and the key signatures associated with the measure.

timeSigs

Returns an array consisting of measure numbers and the time signatures associated with the measure.

clefs

Returns an array consisting of measure numbers and the clefs associated with the measure.

notes

Returns the notes associated with an XMLVoice.

Keeping track of time, beats and a voice's attributes


now

Returns the current beat (as calcualted from the end of the last note's beat). Beats are kept track of with an instance of BeatKeeper that handles rounding, and pays attention to notes that are added in relation to the current meter of an XMLVoice.

now_ (newNow)

Sets the value of 'now' to a new beat value (handy for creating rests).


addMeter (measure, meter)

measure - The measure to add a meter change.

meter - An instance of XMLMeter to take effect at the given measure.



addKey (measure, key)

measure - The measure to add a key change.

key - An instance of XMLKey to take effect at the given measure.



addClef (measure, clef)

measure - The measure to add a key change.

clef - An instance of XMLClef to take effect at the given measure.


add (noteEvents)

Add XMLNotes to an XMLVoice.

noteEvents - one or more instances of XMLNote

getMeasureFromBeat (beat)


Return the measure number from a given beat.

getBeatDurFromBeat (beat)


Return the duration of a given beat (e.g. 0.25 = quarter note)

getMeterForMeasure (measureNum)


Return the XMLMeter for a given measure. 

getMeterFromBeat (beat)


Return the XMLMeter for a given beat. 

Examples


// simple example

(

// create an XMLScore

z = XMLScore.new;

// add a voice to the XMLScore

z.add(y = XMLVoice(meter: XMLMeter(4, 4), key: XMLKey.major(\Bf)));

// create a B-flat major scale in quarter notes

// uses XMLVoice's internal 'clock' to keep track of beats

[58, 60, 62, 63, 65, 67, 69, 70].do({arg keynum;

y.add(XMLNote(keynum, y.now, \e));

y.now_(y.now.ceil);

});

// output the XMLScore

z.output("~/Desktop/test.xml".standardizePath);

);



// a short melodic example with changing meters, and tuplets in simple meters

(

var curkey, notedur, tuplet, curMeter;

// create an XMLScore

z = XMLScore.new;

// add a voice to the XMLScore

z.add(y = XMLVoice(key: XMLKey.major(\Bf)));

y.addMeter(1, XMLMeter(4, 4));

y.addMeter(2, XMLMeter(6, 8, \compound)); // a compound meter

y.addMeter(4, XMLMeter(4, 4));


while({

curkey = [58, 60, 62, 63, 65, 67, 69, 70].choose;

curMeter = y.getMeterFromBeat(y.now);

tuplet = (curMeter.type == \compound).if({1/1}, {3/2});

y.add(XMLNote(curkey, y.now, \e, tuplet));

(y.now < 13)

});

// output the XMLScore

z.output("~/Desktop/test.xml".standardizePath);

)