Chord | Notes |
---|---|
CMaj | C E G |
FMaj | F A C |
GMaj | G B D |
Phrase phr = new Phrase("Twinkle twinkle", 0.0); Part treblePart = new Part("PIANO-Right", PIANO, 0); int[] pitchArray = {C4, C4, G4, G4, A4, A4, G4, F4, F4, E4, E4, D4, D4, C4, G4, G4, F4, F4, E4, E4, D4, G4, G4, F4, F4, E4, E4, D4}; double[] rhythmArray = {C, C, C, C, C, C, M, C, C, C, C, C, C, M, C, C, C, C, C, C, M, C, C, C, C, C, C, M}; phr.addNoteList(pitchArray, rhythmArray); treblePart.add(phr);
Note cMaj[] = {new Note(C3, M), new Note(E3, M), new Note(G3, M)}; Note fMaj[] = {new Note(F3, M), new Note(A3, M), new Note(C3, M)}; Note gMaj[] = {new Note(G3, M), new Note(B3, M), new Note(D3, M)};
public static void addChordsPart(Note chrd[]) { CPhrase chord = new CPhrase(); chord.addChord(chrd); bassPart.addCPhrase(chord); }
- Create two parts
- Add the melody to the first part by giving the pitch classes and durations
- Create the types of the chords
- Add each chord to the second part by giving the chord name and their duration per each chord
- Create the Score and add Part one and part two together
- Play/Save the midi
package mymusicapp; import jm.JMC; import jm.music.data.CPhrase; import jm.music.data.Note; import jm.music.data.Part; import jm.music.data.Phrase; import jm.music.data.Score; import jm.util.Play; import jm.util.Write; public class Main implements JMC { static Part bassPart = new Part("PIANO-Left", PIANO, 0); public static void main(String[] args) { Phrase phr = new Phrase("Twinkle twinkle", 0.0); Part treblePart = new Part("PIANO-Right", PIANO, 0); int[] pitchArray = {C4, C4, G4, G4, A4, A4, G4, F4, F4, E4, E4, D4, D4, C4, G4, G4, F4, F4, E4, E4, D4, G4, G4, F4, F4, E4, E4, D4}; double[] rhythmArray = {C, C, C, C, C, C, M, C, C, C, C, C, C, M, C, C, C, C, C, C, M, C, C, C, C, C, C, M}; phr.addNoteList(pitchArray, rhythmArray); treblePart.add(phr); Note cMaj[] = {new Note(C3, M), new Note(E3, M), new Note(G3, M)}; Note fMaj[] = {new Note(F3, M), new Note(A3, M), new Note(C3, M)}; Note gMaj[] = {new Note(G3, M), new Note(B3, M), new Note(D3, M)}; addChordsPart(cMaj); addChordsPart(cMaj); addChordsPart(fMaj); addChordsPart(cMaj); addChordsPart(fMaj); addChordsPart(cMaj); addChordsPart(gMaj); addChordsPart(cMaj); addChordsPart(cMaj); addChordsPart(fMaj); addChordsPart(cMaj); addChordsPart(gMaj); addChordsPart(cMaj); addChordsPart(fMaj); addChordsPart(cMaj); addChordsPart(gMaj); Score score = new Score("Twinkle-Twinkle"); score.addPart(treblePart); score.addPart(bassPart); Play.midi(score); Write.midi(score); } public static void addChordsPart(Note chrd[]) { CPhrase chord = new CPhrase(); chord.addChord(chrd); bassPart.addCPhrase(chord); } }
public static void addbaseNotesPart(Note chrd[]) { Phrase chord = new Phrase(); int[] pitchArray = {chrd[0].getPitch(), chrd[2].getPitch(), chrd[1].getPitch(), chrd[2].getPitch()}; double[] rhythmArray = {Q, Q, Q, Q}; chord.addNoteList(pitchArray, rhythmArray); bassPart.addPhrase(chord); }
We can use the same code, but instead of using addChordsPart, use addbaseNotesPart to get the styling of our chord progression.