m4 expansion for sample libraries hack
Sample librarians, This is a stupid hack as a holdover for string ops. (if you can think of an idiomatic way to do this, lemme know) I have a local sample library in a file called drum.ck that formerly used relative paths like so: //a sampling UGen to compile all my drums public class Drum { ["drums/kick.wav", "drums/kick1h.wav","drums/kick2h.wav", "drums/kick3h.wav","drums/kick4h.wav", "drums/kick5h.wav","drums/kick6h.wav", "drums/kick7h.wav","drums/kick8h.wav", "drums/kick9h.wav","drums/kick10h.wav", "drums/C_Kick.wav"] @=> string kicks[]; ... } Problem with this arrangement is that executing a file not in the same directory would change the current directory. Hereafter referring to Drum in another shred would return the same relative path, but would fail to load the sample as a result of the change in current directory. To make sure my samples always loaded, I thought of using a macro processing language. I first tried the C preprocessor, but the one on my system (all of them?) did not want to expand macros inside double quotes. Next, I tried m4, of which I was able to find a windows port: http://gnuwin32.sourceforge.net/packages/m4.htm So, I made a variant of the drum sample library (drum.ck.m4): define(`DRUMPATH', `C:/Documents and Settings/Graham/My Documents/chuck/drums') //a sampling UGen to compile all my drums public class Drum { ["DRUMPATH()/kick.wav", "DRUMPATH/kick1h.wav","DRUMPATH/kick2h.wav", "DRUMPATH/kick3h.wav","DRUMPATH/kick4h.wav", "DRUMPATH/kick5h.wav","DRUMPATH/kick6h.wav", "DRUMPATH/kick7h.wav","DRUMPATH/kick8h.wav", "DRUMPATH/kick9h.wav","DRUMPATH/kick10h.wav", "DRUMPATH/C_Kick.wav"] @=> string kicks[]; ... } And ran an expansion command:
m4 < drum.ck.m4 > drum2.ck
To get the expanded form: //a sampling UGen to compile all my drums public class Drum { ["C:/Documents and Settings/Graham/My Documents/chuck/drums/kick.wav", "C:/Documents and Settings/Graham/My Documents/chuck/drums/kick1h.wav","C:/Documents and Settings/Graham/My Documents/chuck/drums/kick2h.wav", "C:/Documents and Settings/Graham/My Documents/chuck/drums/kick3h.wav","C:/Documents and Settings/Graham/My Documents/chuck/drums/kick4h.wav", ... } Any other thoughts on doing this sort of thing? Making the world safe for samples, Graham
On Thu, 21 Sep 2006, Graham Coleman wrote:
Problem with this arrangement is that executing a file not in the same directory would change the current directory. Hereafter referring to Drum in another shred would return the same relative path, but would fail to load the sample as a result of the change in current directory.
I should specify that I was executing code by Ctrl-F in Audicle and selecting the file via GUI. This is why the current directory changed. Graham
participants (1)
-
Graham Coleman