{
   "labels" : [
      "tuning",
      "parser",
      "scala"
   ],
   "code" : "// read all scales provided at\r\n// https://www.huygens-fokker.org/microtonality/scales.html\r\n// turn into a dictionary with keys equal to filenames\r\n\r\n// a \"parser\" based on description at\r\n// https://www.huygens-fokker.org/scala/seq_format.html\r\n// 2023, Till Bovermann | https://tai-studio.org\r\n\r\n\r\n// download scl files from https://www.huygens-fokker.org/docs/scales.zip\r\n// unzip with\r\n// unzip -aa scales.zip to a directory\r\n\r\n// example path:\r\nvar path = \"/Users/tboverma/Downloads/scl\";\r\n\r\nt = \"%/*.scl\".format(path).pathMatch.collectAs({|path|\r\n\tvar rawContents, description, numKeys, degrees, octaveRatio, tuning, a, b;\r\n\r\n\t// read file, ignore comments\r\n\trawContents = File.readAllString(path).split($\\n).select{|row| row.first != $! };\r\n\r\n\r\n\t// description is in first line\r\n\tdescription = rawContents[0].replace(13.asAscii, \"\");\r\n\t// number of elements is in second line\r\n\tnumKeys = rawContents[1].asInteger;\r\n\r\n\t// read only numKeys elements\r\n\tdegrees = numKeys.collect{|i|\r\n\t\t// strip leading white space and ignore everything after first white space\r\n\t\tvar val = rawContents[2 + i].stripWhiteSpace.split($ ).first;\r\n\r\n\t\tval.includes($.).if({\r\n\t\t\t// we see cents\r\n\t\t\tval.asFloat/100\r\n\t\t}, {\r\n\t\t\t// we see fractions\r\n\t\t\tval.includes($/).if({\r\n\t\t\t\t#a, b = val.split($/).collect(_.asInteger);\r\n\t\t\t\ta/b\r\n\t\t\t}, {\r\n\t\t\t\tval.asInteger\r\n\t\t\t}) - 1 * 12\r\n\t\t})\r\n\t};\r\n\r\n\t// octave ratio is last element\r\n\toctaveRatio = degrees.last / 12 + 1;\r\n\r\n\t// a Tuning object requires a leading 0 and omits the octave jump\r\n\tdegrees = [0] ++ degrees.drop(-1);\r\n\r\n\t// create a Tuning object\r\n\ttuning = Tuning(degrees, octaveRatio, description);\r\n\t\r\n\tpath.basename.splitext.first.asSymbol -> tuning\r\n}, Event);",
   "id" : "1-5hj",
   "is_private" : null,
   "name" : "parse scale files into Tuning",
   "author" : "LFSaw",
   "description" : "A \"parser\" for Scala tunings as suggested here: https://scsynth.org/t/scales-and-tunings-without-scale-or-tuning/8014/7",
   "ancestor_list" : []
}
