SuperCollider Forum
December 11, 2013, 06:09:01 AM
 News: The SuperCollider forum is currently experiencing a rash of spambot registrations. New user requests may not be approved quickly as a result -- and if your email address looks like spam, it might not be approved at all. We are working to improve the security of the registration process, and to provide alternate means to contact the administrators to get a new account. Thanks for your patience.
 Home Help Search Calendar Login Register
 Show Posts Pages: [1] 2 3 ... 13
 1 Howto / Synths / Re: controlling synth on: April 02, 2009, 09:03:49 PM The only way to get new values into a running Synth is using a Control input. Controls are automatically created from arguments of the SynthDef function.The code you posted looks of the value of d.at("name") once when building the SynthDef. After that, it's hard coded and can't be changed (without rebuilding the SynthDef).I'd suggest, keep the dictionary on the client side and send the new value as needed using .set --Code:d = Dictionary.new;d.put("cfreq", 90);(SynthDef("name", { |cfreq = 440|   var instr;   instr = SinOsc.ar(freq);   Out.ar(0, instr);}).send(s))y = Synth("name", [\cfreq, d.at("cfreq")]);d["cfreq"] = 900;y.set("cfreq", d["cfreq"]);hjh
 2 General Discussion / General Discussion / Re: loading buffers automatically with Pbind on: February 16, 2009, 05:33:53 PM Very tricky one. Pproto creates a separate environment that exists only within the pattern while it's executing. The function that you give at the start of Pproto executes within this separate environment. But, your wavetable functions exist in the main environment. Environments don't share values - there's no kind of nested scope like you have with functions. So, when {arg a; ~sin2.(a) } executes, ~sin2 is nil because the function is running inside an environment that knows nothing about ~sin2.A workaround is to use topEnvironment[\sin2] in place of ~sin2. Or, put inEnvir in front of the function:Pdef(\toto, ~mkbuf.(inEnvir {arg a; ~sin2.(a); a.postln; }, Pbind(\instrument, \wavetable)));This connects the function to the outer environment.Quote from: grirgz on February 12, 2009, 06:34:54 PMCode:~mkbuf = {    arg fun, pat;    Pproto({        var cc;        cc = Signal.newClear(512);        fun.(cc);        ~buf = Buffer.loadCollection(s, cc.asWavetable);    }, Pset(\bufnum, Pkey(\buf), pat))};Note also that using Buffer.loadCollection in Pproto means that the buffer will not get freed automatically at the end of the pattern. Pproto depends on the event types defined in EventTypesWithCleanup -- if resources are created by other means, Pproto doesn't know what to do with them afterward. The \table event type should suit this purpose.Code:        ~buf = (type: \table, amps: cc.asWavetable).yield;I recently added a cleanup func to Pfset, which might be more intuitive.Code:p = Pfset({ ... ~buf = Buffer.loadCollection(...);}, pattern, { ~buf.free;});QuotePdef(\toto, ~mkbuf.({arg a; ~sinx.(_,3) }, Pbind(\instrument, \wavetable)));The last one isn't right because _ is not a substitute for a.{arg a; ~sinx.(a, 3) } is the same as ~sinx.(_, 3) -- but if you call .value on {arg a; ~sinx.(_,3) }, the result will be a Function that is supposed to call ~sinx - but this function will not actually be called.James
 3 Howto / Language questions / Re: Reading parts from a text file on: February 16, 2009, 04:54:01 PM Quote from: tedor2 on February 11, 2009, 05:15:09 PMDear James, 1, I am ok,  if I use a text file with just the lines of useful data "simple_lines16.txt". (copy and paste from the original). TabFileReader seems to make things easier for a dummy like me. I still would like to use the original file "leftandright16ch.txt", where both channels (Left CH1 and Right CH2) could be read in arrays. Well, I think I just have to find out how to get the line number of where "Left CH1" and "Right CH2" is positioned. Then I could add and minus the numbers, and get the array to be read in from these new parameters. Do you have an idea how to get this line position?http://tedor2.extra.hu/mix/ReadintoArray.zipThe easiest way to find the line numbers is to use a proper text editor (not the one built into sc.app). A lot of programmers swear by text mate, but there are a bunch of freeware choices. Many editors, especially programming-oriented ones, have the option of showing line numbers in the left margin.But, looking at the tab file reader class definition, I don't see an easy way to tell it to stop after a given number of lines. I don't have a quick answer to that problem (except that I probably would write my own reader and parser using the outline in my earlier post, especially if this is something I expect to do a lot).Quote2, I wanted to send you an email on your site concerning the CD with your music, there is an error message after clicking on send. I wonder whether you would send it to the UK as well? ($?) Sure, I'll send to the UK. What was the error message? I can't help you much with the error if I don't know what the error is. (Unfortunately this is all too common in the computer world -- people think it's enough to say "there was an error." So then it takes longer to solve the problem because it's necessary to do another back-and-forth to find out what the problem really was. Sorry to go on about this -- it is a major peeve of mine.)I can tell you that I've had horrible problems with spam from that page, so I block actually rather a lot of phrases. I also had to put in a timer because a lot of spammers submit the input form instantaneously after visiting the page. The side effect is that if you write the message to me in another editor, then go to my page, paste it in quickly and hit "send," as far as the website is concerned, you look like a spammer. Try waiting at least 15 seconds before sending.Or, if all else fails, send me a PM here.James  4 Howto / Language questions / Re: Reading parts from a text file on: January 27, 2009, 03:00:53 PM Quote from: tedor2 on January 26, 2009, 03:46:25 PMthank you for clearing the haze! Do you think I should try learning C? Or which would be the best way to learn the language? Are the help files enough?Nah, don't waste your time with C. (C is still useful for a lot of things, but most of the programming world has moved on to C++ or Java. C is not object-oriented, so it won't teach you much about SC.)I can't think of a "general programming concepts for SC users" guide... maybe look at the Ruby language. It is somewhat similar to SC in some ways.QuoteThere is one major issue concerning this project. There are some invisible characters in the text file:http://www.tedor2.extra.hu/mix/scpostmicro.jpgOh, this is interesting. Yeah, you sometimes have to dig into the raw data to see what's really there before writing the final code. Sometimes I do this to look at the raw data:Code:f = File(p, "r");z = Int8Array.newClear(200);f.read(z);z.clump(8).do({ |row| row.do({ |item| Post << item.asHexString(2) << " "; }); "\t".post; row.do({ |item| item = item.asAscii; Post << if(item.isPrint) { item } { "." }; }); Post <<$\n;});f.close;// prints:0D 54 69 74 6C 65 20 6F    .Title o66 20 74 68 65 20 45 78    f the Ex70 6F 72 74 20 42 72 61    port Bra69 6E 20 44 61 74 61 3A    in Data:09 09 09 45 78 70 6F 72    ...Expor74 20 42 72 61 69 6E 20    t Brain 44 61 74 61 0D 0D 4D 61    Data..Ma78 20 62 75 66 66 65 72    x buffer20 73 69 7A 65 3A 09 09     size:..09 20 30 31 3A 30 30 3A    . 01:00:30 30 2E 30 30 30 0D 53    00.000.S74 61 72 74 20 54 69 6D    tart Tim65 20 69 6E 20 62 75 66    e in buf66 65 72 3A 09 09 09 20    fer:... 30 30 3A 30 30 3A 30 30    00:00:002E 30 30 30 0D 45 6E 64    .000.End20 54 69 6D 65 20 69 6E     Time in20 62 75 66 66 65 72 3A     buffer:09 09 09 20 30 30 3A 30    ... 00:032 3A 34 37 2E 35 39 31    2:47.5910D 0D 49 42 56 41 34 20    ..IBVA4 61 6E 64 20 63 75 72 72    and curr65 6E 74 20 66 69 6C 65    ent file20 69 6E 66 6F 72 6D 61     informa74 69 6F 6E 3A 09 09 09    tion:...The first thing I see from this is that 0D represents a line break in this file, and getLine doesn't recognize it as a line break. (How do I know this is the line break? By comparing the raw output to the appearance in a text editor.)The bad characters show up as NUL in notepad++ on my windows machine, meaning ascii code 0. That is a fairly serious data problem that is harder to correct in SC. Since SC's underbelly is C, the C-style rule for strings apply where a 0 byte means the end of the string. Probably the string in memory has all the characters, but they are ignored past 0 because of the C rule.SC doesn't have a built-in method to strip 0 bytes, so you'll have to write your own getLine function.Code:~getLine = { |file, endChar(13.asAscii)| var char = file.getChar, str = String.new; if(char.isNil) { nil } { while { char.notNil and: { char != endChar } } { if(char.ascii > 0) { str = str.add(char) }; char = file.getChar; }; }; str};Sorry this is such a pain... working with files you didn't create yourself is sometimes hard.James