//Public class for processing lilypond chords. //Stores chords in a table: /* - each row is a new chords - first column is the length of the note (relative to the whole note) - second column is the base note (in case of inversions) - third to sixth columns contains the notes of the chord (if there are only 3 notes, the last column will contain 0) - accepted chord variations: - all inversions - major triads, minor triads - augmented triads, diminished triads - dominant seventh - suspended second, suspended fourth - NOTE: Chords' base note (before inversion) must not contain double sharps or flats. White notes (on keyboards) must not be expressed with accidentals. (i.e. no f-flat or c-flat or b-sharp or e-sharp) For lilypond notations of the chords, refer to http://lilypond.org/doc/v2.12/Documentation/user/lilypond/Common-chord-modifiers#Common-chord-modifiers For lilypond inversions syntax in chordmode, refer to http://www.rosegardenmusic.com/tutorials/supplemental/chordnames/index.html */ public class chordPro { //instance variables int chordTable[100][6]; int chordCount; int fullBar; //this processes the chords in lilypond string form sequentially and fills up the table fun int[][] process(string raw[], int num, string timeSig) { for(0 => int i; i < num; i++) { raw[i] => string curr; findSemiColon(curr)=> int colonMarker; //index of the marker curr.length() => int befColon; //length of the string before the semicolon (full length if there is no colon) if(colonMarker > 0) { colonMarker => befColon; } //retrieving note of the chord if(befColon >= 3 && curr.get_at(2)=="s") { strToMidi(curr.get_at(0) + curr.get_at(1) + curr.get_at(2))=>chordTable[i][2]; } else { strToMidi(curr.get_at(0))=>chordTable[i][2]; } //retrieving chord length 4=>chordTable[i][0]; //lilypond default is a quarter note or crotchet if(curr.get_at(befColon-1) == ".") { Std.atoi(curr.get_at(befColon-2))+ 1 =>chordTable[i][0]; } if(Std.atoi(curr.get_at(befColon-1)) != 0 ) { Std.atoi(curr.get_at(befColon-1)) =>chordTable[i][0]; } //retrieving other notes of the chord chordTable[i][2] => chordTable[i][1]; //base note - set first change later //default major scale chordTable[i][1] + 4 => chordTable[i][3]; chordTable[i][3] + 3 => chordTable[i][4]; 0 => chordTable[i][5]; if(colonMarker > 0) { //chord qualities if(curr.get_at(colonMarker+1) == "m") { chordTable[i][2] + 3 => chordTable[i][3]; chordTable[i][3] + 4 => chordTable[i][4]; 0 => chordTable[i][5]; } if(curr.get_at(colonMarker+1) == "a") { chordTable[i][2] + 4 => chordTable[i][3]; chordTable[i][3] + 4 => chordTable[i][4]; 0 => chordTable[i][5]; } if(curr.get_at(colonMarker+1) == "d") { chordTable[i][2] + 3 => chordTable[i][3]; chordTable[i][3] + 3 => chordTable[i][4]; 0 => chordTable[i][5]; } if(curr.get_at(colonMarker+1) == "7") //dominant 7 { chordTable[i][2] + 4 => chordTable[i][3]; chordTable[i][3] + 3 => chordTable[i][4]; chordTable[i][4] + 3 => chordTable[i][5]; } if(curr.get_at(colonMarker+1) == "s" && curr.get_at(colonMarker+4) == "2") //sus2 { chordTable[i][2] + 2 => chordTable[i][3]; chordTable[i][2] + 7 => chordTable[i][4]; 0 => chordTable[i][5]; } if(curr.get_at(colonMarker+1) == "s" && curr.get_at(colonMarker+4) == "4") //sus4 { chordTable[i][2] + 6 => chordTable[i][3]; chordTable[i][2] + 7 => chordTable[i][4]; 0 => chordTable[i][5]; } //inversions if(curr.get_at(curr.length()-2) == "\\") { strToMidi(curr.get_at(curr.length()-1))=> chordTable[i][1]; //base note } if(curr.length()> 5 && curr.get_at(curr.length()-4) == "\\") { strToMidi(curr.get_at(curr.length()-3) + curr.get_at(curr.length()-2) + curr.get_at(curr.length()-1)) => chordTable[i][1]; //base note } } } return chordTable; } //converts alphabetical string to midi number fun static int strToMidi(string alpha) { if(alpha == "c") return 24; if(alpha == "cis" || alpha == "des") return 25; if(alpha == "d") return 26; if(alpha == "dis" || alpha == "ees") return 27; if(alpha == "e") return 28; if(alpha == "f") return 29; if(alpha == "fis" || alpha == "ges") return 30; if(alpha == "g") return 31; if(alpha == "gis" || alpha == "aes") return 32; if(alpha == "a") return 33; if(alpha == "ais" || alpha == "bes") return 34; if(alpha == "b") return 35; } //finds index of the semicolon modifier in the string (if it exists) fun static int findSemiColon(string chord) { for(0 => int i; i