> Programming > Java > Methods for musical manipulation | |||||||||||||
Methods for musical manipulationAs well as providing a way of storing your music in a score, jMusic provides
ways of manipulating that stored music. Making modification to the jMusic data (processes such as repeating,
reversing and copying) is done using the
Mod class. In this tutorial many of the methods will be outlined - for a more comprehensive list check out the documentation, and examine the source code to see how the methods are implemented.
Note Methods In the Note class the most important task is setting the notes attributes,
such as pitch, rhythm value, dynamic, pan position, duration, and so on.
The get and set methods form the basis for all higher level manipulations.
Apart from get and set methods for each note attribute, the note (and
all other music data classes in jMusic) have a copy()
method, which does the obvious thing. This allows the duplication of notes
for repetitions, or as the starting point for minor modifications. One useful method is print()
which will display the numerical values of each note attribute to the
standard output.
Phrase/CPhrase Methods We will deal with these two classes in the one breath because every attempt has been made in jMusic design to have the same functionality in Phrases and Chord Phrases. Phrases have particular attributes of their own with get and set methods, including startTime and title. i.e., getStartTime(), setTitle(), copy() and so on. Getting notes into phrases is achieved one by one with the addNote() method, or as a group with the addNoteList() method.
The chord phrase class adds several notes at one time as a chord using the addChord() methods which usually take arrays of values for pitch, rhythm, dynamic, etc. but can take an array of Notes.
Part Methods There are attributes associated with a Part which have get and set methods, including title, progChg, and midiChannel. Continuing the score metaphor, it is common for all Notes in a Part to be played by the same instrument which is why the MIDI program change and channel are Part attributes.
Most importantly, a Part has methods to add Phrases to it; addPhrase(); and addCPhrase(); Many of the Phrase methods (above) have equivalents in the Part class. This means that all the Phrases in a Part can be changed with a call to the Part method.
Score Methods The Score class contains all the notes for a piece of music (or at least a section of a piece of music) and as a result it does not have many unique methods. A score has a title with methods to get and set it. The Score call can add parts using the addPart() method and delete them using the removePart() and removeLastPart() methods.
Mod class The Mod class is in the jm.music.tools package, and you need to import this package in order to access these methods. import jm.music.tools.*; Most Mod methods apply to phrases, but many apply to all data types. Check the documentation for a detailed description. The Mod class is a 'static' class, meaning that you don't instantiate a new Mod object. It is used similar to the Math class, such as x = Math.random(); The Mod class copy would be p = Mod.copy(part); Phrase manipulations are widely used in western composition, and this
is reflected in the jMusic Mod class having more methods than other data
classes. loop(); - play the phrase a number of times through transpose(); - shift the pitch of the phrase by a certain number of semitones palindrome(); - extend the phrase to add all the notes in reverse order * retrograde(); - reverse the order of the notes * inversion(); - flip the pitch of notes in relation to the first note's pitch * shuffle(); - randomly reorganise the order of the notes in a phrase * elongate(); - change the rhythm values of the notes in the phrase by a certain scaling factor * accents(); - add a sense of meter by emphasising the dynamic of regular beats fadeIn(); - starting at zero volume, add a crescendo to the current loudness over a certain number of beats fadeOut(); - starting at the current loudness, add a decrescendo down to zero volume over a certain number of beats getEndTime(); - report the beat number following this phrase (where a subsequent phrase might start) append(); - extend a phrase by adding another phrase to the end of it empty();
- remove all notes from this phrase These
are provided by the Mod class. Lets see some examples of this class
in action.
The first example quantises phrase1 to multiples of semi-quavers, the second repeats phrase1, and the third appends phrase2 to the end of phrase1. This begins to show some of the power of the jMusic libraries. All the hard work is done behind the scenes, and all you need to access them are these lines. All the methods in the Mod class follow the pattern of the examples.
The first parameter is always the musical data that gets modified. So, for the method call:
The second parameter, phrase2, remains the same. It is phrase1 that gets updated to include the melody stored in phrase2. Most of the methods are overloaded. This is programming
term to meaning that the same call can be used with different types of
arguments.
This framework can be used with all the methods of the Mod class. Modifications effect existng jMusic objects. So remember to create a phrase, chordPhrase, part, score before modifying it.
Part modification methods include: fadeIn(); - starting at zero volume, add a crescendo to the current loudness over a certain number of beats fadeOut(); - starting at the current loudness, add a decrescendo down to zero volume over a certain number of beats repeat(); - play the part a number of times over quantise(); - round the rhythmValues (thus start times) of the notes to a specified beat value (e.g., 0.25) accents(); - add a sense of meter by emphasising the dynamic of regular beats empty(); - remove all phrases from this part
There are a few useful Score modification methods in the Mod class including; append(); - extend a score by adding another score to the end of it fadeIn(); - starting at zero volume, add a crescendo to the current loudness over a certain number of beats fadeOut(); - starting at the current loudness, add a decrescendo down to zero volume over a certain number of beats quantise(); - round the rhythmValues (thus start times) of the notes to a specified beat value (e.g., 0.25) accents(); - add a sense of meter by emphasising the dynamic of regular beats empty(); - remove all parts from this score
While this tutorial introduces the music manipulation methods in jMusic remember that a more comprehensive list of the methods and the arguments taken by each one is maintained in the jMusic documentation. And always remember that these methods are the basic functionality provided with jMusic, but much of the fun and creativity in algorithmic composition is writing your own music manipulation methods - so get to it!
|
|||||||||||||