Diatonic Transposition

This tutorial shows how to use the transposition modification class that does a diatonic transposition. This means it is useful for melodic 'sequences' where the same riff is repeated slightly higher or lower than the original, but still within the key. The Mod.transpose(phrase, 4, MAJOR_SCALE, C4) line will shift the phrase up four scale degrees (from C to G for example).

This is in contrast to the simple transpose method, Mod.transpose(phrase, 4), that would simply shift all notes up four semitones (from C to E).

View / Download source

Here is avisual example of the result of Mod.transpose(phrase, 4, MAJOR_SCALE, C4);

Original

Transposition

The Mod method for a diatonic trasnpose has four arguments:

Mod.transpose(Note note, final int transposition, final int[] mode, int key)

Where

@param note                     Note to be transposed
@param transposition          the amount to transpose in semitones
@param mode                    the scale to use for the transposition (the JMC has some scale constants)
@param key                       the chromatic note to be used as the root of the mode. i.e., 0 = C, 1 = C# etc.

Let's have a closer look at the code that produced the above scores.
import jm.JMC;
import jm.music.data.*;
import jm.music.tools.Mod;
import jm.util.*;
 
public class TransposeDiatonicTest implements JMC {;
	public static void main(String[] args) {;
		Phrase original = new Phrase(0.0);
		for(int i=0;i<10;i++) {
		    Note n = new Note((int)(Math.random() * 12) + 60, 0.25);
		    original.addNote(n);
		}
		
		View.notate(original);
 
		Phrase trans = original.copy();
		Mod.transpose(trans, 4, MAJOR_SCALE, C4);
		
		View.notate(trans, 10, 300);
	}
}

It is important to copy the phrase before transposing it if you want both the original and transposed version for your music. If you simply assign a new phrase to the old one, as in Phrase trans = original, then when you transpose trans the original will also be transposed (Java references objects by default - duplicating jmusic objects is done by copying them).


jMusic Tutorial Index

© 2001 Andrew Brown