Skip to content

Instantly share code, notes, and snippets.

@rr-codes
Last active January 28, 2021 00:05
Show Gist options
  • Save rr-codes/1289ca8639731009c31c195d64502086 to your computer and use it in GitHub Desktop.
Save rr-codes/1289ca8639731009c31c195d64502086 to your computer and use it in GitHub Desktop.
Jmusic demo
import jm.constants.Instruments;
import jm.constants.Pitches;
import jm.constants.RhythmValues;
import jm.music.data.*;
import jm.util.Play;
import java.util.List;
public class Main {
public static void main(String[] args) {
var notes = List.of(
new Note(Pitches.G3, 0.75 * RhythmValues.TN),
new Note(Pitches.G3, 0.50 * RhythmValues.TN),
new Note(Pitches.A3, RhythmValues.TN),
new Note(Pitches.G3, RhythmValues.TN),
new Note(Pitches.C4, RhythmValues.TN),
new Note(Pitches.B3, 2.00 * RhythmValues.TN)
); // we make a `List` of notes
var phrase = new Phrase(notes.toArray(Note[]::new)); // we covert `notes` into an array, and pass it into the `Phrase` constructor
var part = new Part(phrase);
part.setInstrument(Instruments.GUITAR);
var score = new Score(part, null, 13.0);
Play.midi(score);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment