Mod

Mod provides functions for modifying, or varying, phrases, parts and scores. These functions modify the data given to them.

For example, Mod.repeat() creates repetitions of the given musical material:

This will modify phrase to contain a total of 41 copies of what it originally contained.

Below are the available Mod functions.  They are organized in terms of their functionality – Pitch, Duration, Dynamic, and Randomness. They are also presented in alphabetical order.

You may use these functions in any sequence to achieve a desired effect.

Modifying Pitch

The following functions modify the pitch of musical material in various ways.

Function Description
Mod.invert(material) Mirror the pitch of notes in the material around the first note’s pitch. The order of the notes is not affected it is only the pitches that are mirrored.  That is, notes which are n semitones above the first pitch will be changed to be n semitones below. Material may be a Phrase,Part, or Score.
Mod.mutate(phrase) Mutate phrase by changing one pitch and one duration value.  The new pitch is selected randomly between the lowest and the highest note of phrase.  The random duration is selected from those in the existing notes.
Mod.randomize(material, pitchVariation, durationVariation, dynamicVariation) Randomly adjusts every note’s pitch, duration, and dynamic values to a random value within the range plus or minus the specified amount; pitchVariation is an int (make sure result stays within 0-127); durationVariation is a float (e.g., 1.0 is a quarter note); dynamicVariation is an int (make sure result stays within 0-127). Material may be a Phrase,Part, or Score.
Mod.retrograde(material) Reverse the order of notes in the material. Material may be a Phrase,Part, or Score.
Mod.rotate(material) Move the notes around the material, first becoming second, second becoming third, … and last becoming first. Material may be a Phrase,Part, or Score.
Mod.shuffle(material) Randomize the order of notes in the material without repeating any note. Material may be a Phrase,Part, or Score.
Mod.tiePitches(material) Joins consecutive notes in material that have the same pitch, creating one longer note. This is similar to the musical function of a tie. This will reduce the overall note count. Material may be a Phrase,Part, or Score.
Mod.transpose(material, semitones) Chromatic transposition. It shift the pitch of every note in the material by the given number of semitones. Material may be a Phrase,Part, or Score.
Mod.transpose(material, steps, scale, key) Diatonic transposition. It shift the pitch of every note in the material by the given number of scale degrees (steps), given the scale and key. Material may be a Phrase,Part, or Score.  Key is an integer (0 means the key of C, a positive integer indicates the number of sharps, whereas a negative integer indicates the number of flats).   See Appendix A for a list of available scales.

Modifying Duration

The following functions modify the length of musical material in various ways.

Function Description
Mod.append(material1, material2) Appends material2 to material1. Works with notes, phrases, parts, and scores.  In the case of notes, it extends the duration value of the first note (without changing its pitch).
Mod.changeLength(phrase, newLength) Alters the phrase so that its notes are stretched or compressed until the phrase is the specified length (number of beats – a float).  It works in the same manner as elongate(), except it takes an absolute length parameter not a ratio.
Mod.cycle(material, numberOfNotes) Repeats the material until it contains the specified number of notes.  The repetitions work in the same manner as Mod.repeat(), except that the final repetition will not be a complete copy of the original if the note count is reached before the repetition is completed.  Material may be a Phrase,Part, or Score.
Mod.elongate(material, scaleFactor) Stretch the time of each note in the phrase by scaleFactor (a float). Material may be a Phrase,Part, or Score.
Mod.fillRests(material) Lengthens notes followed by a rest in material by creating one longer note and deleting the rest. This will reduce the overall note count. Material may be a Phrase,Part, or Score.
Mod.mutate(phrase) Mutate phrase by changing one pitch and one duration value.  The new pitch is selected randomly between the lowest and the highest note of phrase.  The random duration is selected from those in the existing notes.
Mod.palindrome(material) Extend the phrase by adding all notes backwards, repeating the last note of the material. Material may be a Phrase,Part, or Score.
Mod.quantize(phrase, quantum) Rounds (quantizes) the start time and duration of each note in phrase to fit multiples of quantum. The smallest the quantum, the least the amount of change. A large quantum results in music that sounds mechanical.
Mod.randomize(material, pitchVariation, durationVariation, dynamicVariation) Randomly adjusts every note’s pitch, duration, and dynamic values to a random value within the range plus or minus the specified amount; pitchVariationis an int (make sure result stays within 0-127); durationVariation is a float (e.g., 1.0 is a quarter note); dynamicVariationis an int (make sure result stays within 0-127). Material may be a Phrase,Part, or Score.
Mod.repeat(material, number) Repeat the material a number of times.  Material may be a Phrase,Part, or Score. For example, Mod.repeat(phrase, 2) will play phrase two times.
Mod.retrograde(material) Reverse the order of notes in the material. Material may be a Phrase,Part, or Score.
Mod.rotate(material) Move the notes around the material, first becoming second, second becoming third, … and last becoming first. Material may be a Phrase,Part, or Score.
Mod.shuffle(material) Randomize the order of notes in the material without repeating any note. Material may be a Phrase,Part, or Score.
Mod.tiePitches(material) Joins consecutive notes in material that have the same pitch, creating one longer note. This is similar to the musical function of a tie. This will reduce the overall note count. Material may be a Phrase,Part, or Score.
Mod.tieRests(material) Joins consecutive rests in material creating a longer note. This is similar to the musical function of a tie. This will reduce the overall note count. Material may be a Phrase,Part, or Score.

Modifying Dynamic

The following functions modify the dynamic (or volume) of musical material in various ways.

Function Description
Mod.accent(material, beats) Accents the first beat of each measure in material.Beats(a float) is the number of beats per measure.  Material may be a Phrase,Part, or Score.
Mod.accent(material, meter, accentedBeats, accentAmount) Accents by accentAmount (an int) at the accentedBeatslocations (a list of floats, denoting time in quarter notes). Meter(a float) is the number of beats per measure.  Material may be a Phrase,Part, or Score.
Mod.compress(material, ratio) Compresses (or expands) the material. Compression ratio numbers between 0 and 1.  Values larger than 1 expand.  Negative values invert the volume about the mean. This compression applies only to the volume of the notes.  It will multiply the difference between each note’s volume and the volume, by the compression ratio.  Thus, a ratio of 0 will change every note’s volume to the average volume; 1 will leave every note unchanged; and 2 will make every note’s volume twice as far from the mean. Negative values will have a similar affect but leave the volume of each note on the other side of the mean. Material may be a Phrase,Part, or Score.
Mod.crescendo(phrase, time1, time2, vol1, vol2) Increase volume in phrase from vol1 at time time1, to vol2 at time time2.
Mod.fadeIn(material, fadeLength) Linearly fades in the material (fadeLength is quarter notes). Material may be a Phrase,Part, or Score.
Mod.fadeOut(material, fadeLength) Linearly fades out the material (fadeLength is quarter notes). Material may be a Phrase,Part, or Score.
Mod.normalize(phrase) Increase note volumes proportionally in phrase, so the loudest note is at maximum level.
Mod.randomize(material, pitchVariation, durationVariation, dynamicVariation) Randomly adjusts every note’s pitch, duration, and dynamic values to a random value within the range plus or minus the specified amount; pitchVariationis an int (make sure result stays within 0-127); durationVariation is a float (e.g., 1.0 is a quarter note); dynamicVariationis an int (make sure result stays within 0-127). Material may be a Phrase,Part, or Score.
Mod.shake(material) Randomly adjusts the volume of notes to create uneven loudness. Material may be a Phrase,Part, or Score.
Mod.shake(material, amount) Randomly adjusts the volume of notes to create uneven loudness. Amount (an int) denotes how strong the effect will be, e.g., 5 will be +/-5 from the current volume. Material may be a Phrase,Part, or Score.

Modifying Panning

The following functions modify the panning (stereo position) of musical material in various ways.

Function Description
Mod.bounce(material) Adjusts the pan values of all notes in material to alternate between extreme left and right from note to note. Material may be a Phrase,Part, or Score.
Mod.spread(material) Randomly adjusts the pan values of all notes in material to create an even spread across the stereo spectrum. Material may be a Phrase,Part, or Score.

Modifying with Randomness

The following functions transform musical material using randomness in various ways.

Function Description
Mod.mutate(phrase) Mutate phrase by changing one pitch and one duration value.  The new pitch is selected randomly between the lowest and the highest note of phrase.  The random duration is selected from those in the existing notes.
Mod.randomize(material, pitchVariation, durationVariation, dynamicVariation) Randomly adjusts every note’s pitch, duration, and dynamic values to a random value within the range plus or minus the specified amount; pitchVariationis an int (make sure result stays within 0-127); durationVariation is a float (e.g., 1.0 is a quarter note); dynamicVariationis an int (make sure result stays within 0-127). Material may be a Phrase,Part, or Score.
Mod.shake(material) Randomly adjusts the volume of notes to create uneven loudness. Material may be a Phrase,Part, or Score.
Mod.shake(material, amount) Randomly adjusts the volume of notes to create uneven loudness. Amount (an int) denotes how strong the effect will be, e.g., 5 will be +/-5 from the current volume. Material may be a Phrase,Part, or Score.
Mod.shuffle(material) Randomise the order of notes in the material without repeating any note. Material may be a Phrase,Part, or Score.
Mod.spread(material) Randomly adjusts the pan values of all notes in material to create an even spread across the stereo spectrum. Material may be a Phrase,Part, or Score.

Mod Functions in Alphabetical Order

Here is the list of Mod functions in alphabetical order.

Function Description
Mod.accent(material, beats) Accents the first beat of each measure in material.Beats(a float) is the number of beats per measure.  Material may be a Phrase,Part, or Score.
Mod.accent(material, meter, accentedBeats, accentAmount) Accents by accentAmount (an int) at the accentedBeatslocations (a list of floats, denoting time in quarter notes). Meter(a float) is the number of beats per measure.  Material may be a Phrase,Part, or Score.
Mod.append(material1, material2) Appends material2 to material1. Works with notes, phrases, parts, and scores.  In the case of notes, it extends the duration value of the first note (without changing its pitch).
Mod.bounce(material) Adjusts the pan values of all notes in material  to alternate between extreme left and right from note to note. Material may be a Phrase,Part, or Score.
Mod.changeLength(phrase, newLength) Alters the phrase so that its notes are stretched or compressed until the phrase is the specified length (number of beats – a float).  It works in the same manner as elongate(), except it takes an absolute length parameter not a ratio.
Mod.compress(material, ratio) Compresses (or expands) the material. Compression ratio numbers between 0 and 1.  Values larger than 1 expand.  Negative values invert the volume about the mean. This compression applies only to the volume of the notes.  It will multiply the difference between each note’s volume and the volume, by the compression ratio.  Thus, a ratio of 0 will change every note’s volume to the average volume; 1 will leave every note unchanged; and 2 will make every note’s volume twice as far from the mean. Negative values will have a similar affect but leave the volume of each note on the other side of the mean. Material may be a Phrase,Part, or Score.
Mod.consolidate(part) Merges part’s phrases into one phrase.  This works well with View.notate(part), so that notate() can display all the notes in the part (View.notate() works only with a single phrase).
Mod.cycle(material, numberOfNotes) Repeats the material until it contains the specified number of notes.  The repetitions work in the same manner as Mod.repeat(), except that the final repetition will not be a complete copy of the original if the note count is reached before the repetition is completed.  Material may be a Phrase,Part, or Score.
Mod.elongate(material, scaleFactor) Stretch the time of each note in the phrase by scaleFactor (a float). Material may be a Phrase,Part, or Score.
Mod.fadeIn(material, fadeLength) Linearly fades in the material (fadeLength is quarter notes). Material may be a Phrase,Part, or Score.
Mod.fadeOut(material, fadeLength) Linearly fades out the material (fadeLength is quarter notes). Material may be a Phrase,Part, or Score.
Mod.fillRests(material) Lengthens notes followed by a rest in material by creating one longer note and deleting the rest. This will reduce the overall note count. Material may be a Phrase,Part, or Score.
Mod.invert(material) Mirror the pitch of notes in the material around the first note’s pitch. The order of the notes is not affected it is only the pitches that are mirrored.  That is, notes which are n semitones above the first pitch will be changed to be n semitones below. Material may be a Phrase,Part, or Score.
Mod.mutate(phrase) Mutate phrase by changing one pitch and one duration value.  The new pitch is selected randomly between the lowest and the highest note of phrase.  The random duration is selected from those in the existing notes.
Mod.normalize(phrase) Increase note volumes proportionally in phrase, so the loudest note is at maximum level.
Mod.palindrome(material) Extend the phrase by adding all notes backwards, repeating the last note of the material. Material may be a Phrase,Part, or Score.
Mod.quantize(phrase, quantum) Rounds (quantizes) the start time and duration of each note in phrase to fit multiples of quantum. The smallest the quantum, the least the amount of change. A large quantum results in music that sounds mechanical.
Mod.randomize(material, pitchVariation, durationVariation, dynamicVariation) Randomly adjusts every note’s pitch, duration, and dynamic values to a random value within the range plus or minus the specified amount; pitchVariationis an int (make sure result stays within 0-127); durationVariation is a float (e.g., 1.0 is a quarter note); dynamicVariationis an int (make sure result stays within 0-127). Material may be a Phrase,Part, or Score.
Mod.repeat(material, number) Repeat the material a number of times.  Material may be a Phrase,Part, or Score. For example, Mod.repeat(phrase, 2) will play phrase two times.
Mod.retrograde(material) Reverse the order of notes in the material. Material may be a Phrase,Part, or Score.
Mod.rotate(material) Move the notes around the material, first becoming second, second becoming third, … and last becoming first. Material may be a Phrase,Part, or Score.
Mod.shake(material) Randomly adjusts the volume of notes to create uneven loudness. Material may be a Phrase,Part, or Score.
Mod.shake(material, amount) Randomly adjusts the volume of notes to create uneven loudness. Amount (an int) denotes how strong the effect will be, e.g., 5 will be +/-5 from the current volume. Material may be a Phrase,Part, or Score.
Mod.shuffle(material) Randomise the order of notes in the material without repeating any note. Material may be a Phrase,Part, or Score.
Mod.spread(material) Randomly adjusts the pan values of all notes in material to create an even spread across the stereo spectrum. Material may be a Phrase,Part, or Score.
Mod.tiePitches(material) Joins consecutive notes in material that have the same pitch, creating one longer note. This is similar to the musical function of a tie. This will reduce the overall note count. Material may be a Phrase,Part, or Score.
Mod.tieRests(material) Joins consecutive rests in material creating a longer note. This is similar to the musical function of a tie. This will reduce the overall note count. Material may be a Phrase,Part, or Score.
Mod.transpose(material, semitones) Chromatic transposition. It shift the pitch of every note in the material by the given number of semitones. Material may be a Phrase,Part, or Score.
Mod.transpose(material, steps, scale, key) Diatonic transposition. It shift the pitch of every note in the material by the given number of scale degrees (steps), given the scale and key. Material may be a Phrase,Part, or Score.  Key is an integer (0 means the key of C, a positive integer indicates the number of sharps, whereas a negative integer indicates the number of flats).   See Appendix A for a list of available scales.