// Scala Tuning File Parser public class Scala { static FileIO @ scale; static int tuningDiasponOffSet; static int tuningKeyOffSet; static float tuningKey[]; static float tuningMap[]; static int initstatus; public static void read(string filename) { scale.open( filename , FileIO.READ ); if ( scale.good() ) { <<< "Scale read successfully." >>>; } else <<< "Something went wrong." >>>; 0 => initstatus; } public static void init() { string line; int pos; 392 => float base; // set tuning note (to be corrected with tuningDiasponOffSet and tuningKeyOffSet) float num, den; string tuningName; int tuningSize; tuningKey << base; -1 => num => den; // initialize the num and den, in case of cents or no data do { scale.readLine() => line; if ( commentCheck(line) ) <<< "Comm: ", line >>>; } while ( commentCheck(line) ); line => tuningName; scale.readInt() => tuningSize; if ( scale.more() ) scale.readLine(); <<< "Name: ", tuningName, "\nSize: ", tuningSize >>>; while ( scale.more() ) { scale.tell() => pos; scale.readLine() @=> line; if ( commentCheck(line) ) { <<< "Comm: ", line >>>; } // if commentCheck else { scale.seek(pos); if (scale.more()) { scale.readFloat() => num; //<<< "Num: ", num >>>; } if (scale.more() && scale.read(1) == "/") { if (scale.more()) { scale.readFloat() => den; //<<< "Den: ", den >>>; } } if (scale.more()) scale.readLine(); if (den != -1) { tuningKey << (num / den) * base; } else if (den == -1 && num != -1) { tuningKey << Math.pow(2, num / 1200) * base; } else if (den == -1 && num == -1) break; -1 => num => den; // reset both for next round } // else } // while // fills the tuningMap for (int i; i < tuningMap.size(); i++) { tuningKey[ ( i + tuningKeyOffSet ) % (tuningKey.size() - 1) ] * Math.pow(2, tuningDiasponOffSet + Math.floor( ( ( i + tuningKeyOffSet ) / (tuningKey.size() - 1) ) ) ) => tuningMap[i]; } //for (int i; i < tuningMap.size(); i++) // <<< "MIDI note", i, "tuned to freq", tuningMap[i] >>>; //<<< "And that's all." >>>; 1 => initstatus; } fun static int commentCheck(string s) { "!" @=> string comment; StringTokenizer t; t.set(s); if (t.next() == "!") return (1); else return (0); } public static float mtof(int key) { if (scale.good() && initstatus == 1) return tuningMap[key]; else <<< "Either your scale did not load or you must call Scala.init()" >>>; } } // public class Scala new FileIO @=> Scala.scale; new float[0] @=> Scala.tuningKey; new float[128] @=> Scala.tuningMap; -6 => Scala.tuningDiasponOffSet; 5 => Scala.tuningKeyOffSet; // the following two lines are unnecessary for the class itself, // but some form of both functions must be called before Scala.mtof is used. Scala.read("ji_12.scl"); Scala.init();