Created
November 19, 2019 13:24
-
-
Save totalgee/ca7662551228029f93aa996fa0531749 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( | |
// Look for strings like deg"1 2 ~ 4" for a \degree pattern with durations | |
var pattern = "(\\w{3})\"([^\"\n]*)\""; | |
preProcessor = { |code| | |
var curOffset = 0; | |
var pat = code.findRegexp(pattern).clump(3); | |
// pat.debug("pat"); | |
pat.do{ arg p; | |
var fullMatch = p[0]; | |
var patternType = p[1].last; | |
var patternString = p[2].last; | |
var replaceStr; | |
switch (patternType, | |
"deg", { | |
var patternContents = patternString.replace("~", "Rest()"); | |
var patternArray = patternContents.split($ ); | |
replaceStr = "Pbind(\\degree, Pseq(%, 2), \\dur, %)".format(patternArray, patternArray.size.reciprocal); | |
patternString.debug("degree pattern"); | |
} | |
// ... | |
); | |
code = code.replaceAt(replaceStr, fullMatch.first + curOffset, fullMatch.last.size); | |
// code.postln; | |
curOffset = curOffset + replaceStr.size - fullMatch.last.size | |
}; | |
code | |
}; | |
) | |
// To switch it off (useful when debugging): | |
preProcessor = nil; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment