Skip to content

Instantly share code, notes, and snippets.

@chrislopresto
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislopresto/fc319bad50e76388967b to your computer and use it in GitHub Desktop.
Save chrislopresto/fc319bad50e76388967b to your computer and use it in GitHub Desktop.
MIDI Moonlight
// Instruments
int piano = 1;
// Notes
// Add notes as needed from http://www.tonalsoft.com/pub/news/pitch-bend.aspx
int g2 = 43;
int bFlat2 = 46;
int c3 = 48;
int cSharp3 = 49;
int dFlat3 = 49;
int d3 = 50;
int e3 = 52;
int f3 = 53;
int g3 = 55;
int a3 = 57;
int bFlat3 = 58;
int b3 = 59;
int d4 = 62;
int eFlat4 = 63;
int f4 = 65;
int g4 = 67;
// Note Duration Math
// *****************************************************************************
// First version
int sixteenthNote = 1;
int dottedEighthNote = 5;
int quarterNote = 6;
int eighthNoteTriplet = 2;
int halfNote = 12;
int dottedHalfNote = 18;
int wholeNote = 24;
// *****************************************************************************
// *****************************************************************************
// Calculated version
//
// Explanation of subdivisionsPerMeasure
// 24 will make for a good tempo but will cause dottedEighthNote and sixteenthNote durations to be rounded/approximated.
// 48 will make the integer math work throughout but will make things slow.
//
// int subdivisionsPerMeasure = 24;
// int sixteenthNote = subdivisionsPerMeasure / 16; // Will be rounded unless subdivisionsPerMeasure is 48...
// int dottedEighthNote = eighthNote * 3 / 2; // Will be rounded unless subdivisionsPerMeasure is 48
// int quarterNote = subdivisionsPerMeasure / 4;
// int eighthNoteTriplet = subdivisionsPerMeasure / 12;
// int halfNote = subdivisionsPerMeasure / 2;
// int dottedHalfNote = halfNote * 3 / 2;
// int wholeNote = subdivisionsPerMeasure;
// *****************************************************************************
// Voices
DaltonMidi voice1 = new DaltonMidi();
voice1.setInstrument(piano);
DaltonMidi voice2 = new DaltonMidi();
voice2.setInstrument(piano);
DaltonMidi voice3 = new DaltonMidi();
voice3.setInstrument(piano);
DaltonMidi voice4 = new DaltonMidi();
voice4.setInstrument(piano);
// Music
// -----------------------------------
// Measure 1
voice1.addNote(a3, eighthNoteTriplet);
voice1.addNote(d4, eighthNoteTriplet);
voice1.addNote(f4, eighthNoteTriplet);
voice1.addNote(a3, eighthNoteTriplet);
voice1.addNote(d4, eighthNoteTriplet);
voice1.addNote(f4, eighthNoteTriplet);
voice1.addNote(a3, eighthNoteTriplet);
voice1.addNote(d4, eighthNoteTriplet);
voice1.addNote(f4, eighthNoteTriplet);
voice1.addNote(a3, eighthNoteTriplet);
voice1.addNote(d4, eighthNoteTriplet);
voice1.addNote(f4, eighthNoteTriplet);
voice2.addNote(d3, wholeNote);
voice3.addRest(wholeNote);
voice4.addRest(wholeNote);
// -----------------------------------
// Measure 2
voice1.addNote(a3, eighthNoteTriplet);
voice1.addNote(d4, eighthNoteTriplet);
voice1.addNote(f4, eighthNoteTriplet);
voice1.addNote(a3, eighthNoteTriplet);
voice1.addNote(d4, eighthNoteTriplet);
voice1.addNote(f4, eighthNoteTriplet);
voice1.addNote(a3, eighthNoteTriplet);
voice1.addNote(d4, eighthNoteTriplet);
voice1.addNote(f4, eighthNoteTriplet);
voice1.addNote(a3, eighthNoteTriplet);
voice1.addNote(d4, eighthNoteTriplet);
voice1.addNote(f4, eighthNoteTriplet);
voice2.addNote(c3, wholeNote);
voice3.addRest(wholeNote);
voice4.addRest(wholeNote);
// -----------------------------------
// Measure 3
voice1.addNote(bFlat3, eighthNoteTriplet);
voice1.addNote(d4, eighthNoteTriplet);
voice1.addNote(f4, eighthNoteTriplet);
voice1.addNote(bFlat3, eighthNoteTriplet);
voice1.addNote(d4, eighthNoteTriplet);
voice1.addNote(f4, eighthNoteTriplet);
voice1.addNote(bFlat3, eighthNoteTriplet);
voice1.addNote(eFlat4, eighthNoteTriplet);
voice1.addNote(g4, eighthNoteTriplet);
voice1.addNote(bFlat3, eighthNoteTriplet);
voice1.addNote(eFlat4, eighthNoteTriplet);
voice1.addNote(g4, eighthNoteTriplet);
voice2.addNote(bFlat2, halfNote);
voice2.addNote(g2, halfNote);
voice3.addRest(wholeNote);
voice4.addRest(wholeNote);
// -----------------------------------
// Measure 4
voice3.addRest(wholeNote);
// -----------------------------------
// Measure 5
voice3.addNote(a4, dottedEighthNote);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment