Hey Geoff, It's absolutely
possible. I'm working on a pretty ambitious live rewriting
system right now myself. :-) As has been said before, all scd files are just text files. And SC has plenty of string manipulation options. Here's one way you might do it. ( a = 2; b = 3; c = a + b + 20; c.postln; ); ( var str, matches; str = Document.current.string; // Do your text parsing on str here matches = str.findRegexp("[0-9]+"); matches.do {|match| var idx = match[0], val = match[1]; str = str[0..(idx-1)] ++ (val.asInt + 1) ++ str[(idx+val.size)..]; }; Document.current.string_(str, rangesize: str.size); );
best, Jonathan
On 24/09/2018 06:28,
geoffbaltan@xxxxxxxxx wrote:
"I'm curious about what you're trying to do. There are a million ways to randomize numbers, what it's your goal here?" Long-term, I'm interested in the idea of using SuperCollider code to "write itself" - to see if it can look at its own code, and then pick out and classify parts of itself. In the short-term, I was thinking it would be nice to go back over bits of code I've written over the years and transform it quickly, without rewriting it. On Sun, Sep 23, 2018 at 1:12 AM, <dpalkowski@xxxxxxxxx> wrote:Sounds like the idea is to do something like the good old Galaxy Editor Librarian (Opcode) from yesteryear. With that you could generate a 'factory' of thousands of variants on a given patch. Of course, it only works well if the device being cloned/modified has a consistent structure, e.g. innards of a dx-7 On Sat, Sep 22, 2018 at 9:13 PM <grahams@xxxxxxxxxxxx> wrote:I'm curious about what you're trying to do. There are a million ways to randomize numbers, what it's your goal here? On Sat, Sep 22, 2018, 18:44 <sludgefree@xxxxxxxxx> wrote:Ever since switching to OSX, when experimenting I always add a .softclip to ensure outputs do not blow out my ears or speakers a la: Out.ar(0, audio.softclip); But for your purposes, I would add a method to Float like scramble(), which will return a random number so you could decide which numbers get scrambled and which don't (ie output buses shouldn't be scrambled). var audio = SinOsc.ar(440.0.scramble); Out.ar(0, audio.softclip); and then maybe in yr extensions folder, extend the Float class like: + Float { scramble { ^ 1000.0.rand2; }; } You could even get fancy and scramble within a range of the original value. On Fri, Sep 21, 2018 at 7:01 PM <josh@xxxxxxxxxxxxxxxxx> wrote:Well - this could be quite dangerous. Imagine a filter parameter getting changed to something that causes it to blow up and destroy your hearing? Otherwise, at the SynthDef level, all inputs are numbers. But they don’t require a number to go into it. Detecting what should be a number and what isn’t would be pretty difficult (especially since SC isn’t strongly typed). E.g: s = Server.default; // s is a Server instance s = 10.0; // s is a Float s = ‘aString’; // s is a String s = \aSymbol; // etc. … s = s + 10; // valid, but doesn’t result in a number! {BPF.ar(WhiteNoise.ar(1.0), s}.play; // s won’t be a good filter parameter At one point, s was a number, but it isn’t any longer… it could be possible to build a parser that finds numbers and replaces them, but what would be more idiomatic would be storing the result of random selection to variables, seeding the random number generator in the language, then changing the seed for new variations. This way, you can build in some reasonable limits to your numbers. The attached file is updated to use a seed passed in… and you can test with this example: this.executeFile("~/Desktop/test.scd".standardizePath).value(1); this.executeFile("~/Desktop/test.scd".standardizePath).value(1); // same this.executeFile("~/Desktop/test.scd".standardizePath).value(1); // same this.executeFile("~/Desktop/test.scd".standardizePath).value(2); // new values1On Sep 21, 2018, at 3:14 PM, geoffbaltan@xxxxxxxxx wrote: Oh, I'm sorry - I think I was being unclear: I was just imagining, instead of identifying and labelling hundreds of arguments, it would be interesting if there was some sort of parsing that could just tell when numerical data was in the text file and replace it with different data. On Fri, Sep 21, 2018 at 5:36 PM, <josh@xxxxxxxxxxxxxxxxx> wrote:SCD files are just text files. And there are even functions in the File class for reading the string in a text file. However - Interpreter can also execute a file, which will read the file at a path and pass in arguments. So, if the file you have is wrapped as a function, you can pass in new numbers as arguments and have the Function run. So - if you put the attached file on your Desktop, you can run it like this: this.executeFile("~/Desktop/test.scd".standardizePath).value(700) this.executeFile("~/Desktop/test.scd".standardizePath).value(800) Or - a better route may be passing in a Dictionary of key / value pairs that your file interprets as needed. Hope that helps. JoshOn Sep 21, 2018, at 2:11 PM, geoffbaltan@xxxxxxxxx wrote: Recently, I was thinking it would be nice to change all of the fixed numerical values in an SCD file. Maybe just specify a random range of values and re-parse the document. Is such a thing possible within SuperCollider, or would that be more functional in the purview of something like _javascript_? _______________________________________________ sc-users mailing list info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx archive: https://listarc.bham.ac.uk/marchives/sc-users/ search: https://listarc.bham.ac.uk/lists/sc-users/search/_______________________________________________ sc-users mailing list info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx archive: https://listarc.bham.ac.uk/marchives/sc-users/ search: https://listarc.bham.ac.uk/lists/sc-users/search/_______________________________________________ sc-users mailing list info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx archive: https://listarc.bham.ac.uk/marchives/sc-users/ search: https://listarc.bham.ac.uk/lists/sc-users/search/ --
JC Reus WEB: jonathanreus.com |