Archive for the ‘programming’ Category
Live coding practice
I haven’t posted anything in the last weeks, so here’s some live coding practice I did this night trying some new stuff I saw on the SC users list. Basically nothing new, but it makes the workflow easier when playing with Pbind or similar with SynthDefs but also in the ProxySpace. Basically the PatternStreamPlayer has to be somewhere in the NodeProxy chain but it has to be played externally:
~node = Pbind(); ~node.play
Maybe like that it will set the outputs to the right buses? Anyway, using
~node = Pbind().play
didn’t worked (well it worked, but one can’t route the signal of that pattern player to other nodes or filter it via ProxyChain. Anyway, here is the result. I forgot to turn on the History, so you’ll have to conform with the result only.
EDIT: I also uploaded a second part a little bit more “beaty”. Hope you like it.
SuperCollider on Twitter (or how I learned to love the sc-tweets)
Just a quick one.
Dan Stowell curated an album made out of compositions that aren’t longer than 140 charactes in SuperCollider code (sc140). The pieces aren’t only great, the code is pretty ingenious. A lot of recursions, syntax shortcuts and tricks to generate a great sound or piece. The album and code are free to download and view, but if you want more of these tweet that didn’t make it to the album,there are lots of code snippets that are also really good. One can find them on twitter by #sc or #supercollider or searching for ‘play{‘ or ‘.play‘. There’s a Yahoo Pipe to facilitate this search, but not all the ‘sc-tweets‘ are there. Another library of sc tweets is the swiki. Great stuff, great sounds, nice code, nice ideas… just digg into it. If you are into SuperCollider, there’s a lot one can learn from these pieces.
Controlling a QuartzComposer Composition in a Cocoa App
There is a way to set controllers directly from within Interface Builder to the published inputs of a Quartz Composition (QCView in the IB). This is nice, if you just want to do an animation that you control from the GUI elements. I’m working on an animation controlled within the program, and I really need to get to those published inputs to send the decisions made in the application.
This little solution may not be world changing, but I’ve searched for this little piece of code for a couple of minutes. so just as a reminder:
IBOutlet QCView * qcAnimation;
[qcAnimation setValue: (id) forInputKey: @"myKey"];
Yes… so easy! but Why it isn’t in the documentation? Well it is, but it won’t appear on the QCView or QCComposition or the quick help if you need. So, how to search for this kind of methods very quick? I found it was nicer to take a look at the header files than the documentation. If one goes to the QCView header it says:
@interface QCView : NSView <QCCompositionRenderer>
Tricky Random Numbers in a Range
I’m working on a learn project to know more about Objective C, the Cocoa Framework and just for fun. I think only from the praxis I’ll be able to solve little problems that one does not have in the Theory.
Yesterday was the problem: how can I generate random numbers? and this within a range? well for the C/C++ people this wouldn’t be a problem. In fact one can use the same functions as in C/C++ but I thought there would be a more ‘cocoay’ version for that, like:
[NSNumber randomIntFrom:(int)a to:(int)b ];
Well, there is not such a thing. However, I knew I was able with a tutorial I made a couple of months ago, that random numbers was possible and with a very easy way, rather than calling random() or rand() an dividing and scaling, etc… I looked at an old ScreenSaver Tutorial and I found the answer there. I still was a little bit ‘disappointed’ there wasn’t like an NSValue or NSNumber that does this job, but well, the ScreenSaver framework has a fix for that…
#import <ScreenSaver/ScreenSaver.h>
SSRandomIntBetween(0, 100);
SSRandomFloatBetween(0.0, 1.0);
Well that was the kind of easy function I was looking for, but I couldn’t expect it to be in the ScreenSaver Framework!
Anyway it’s just a C function call that looks like this:
static __inline__ int SSRandomIntBetween(int a, int b)
{
int range = b – a < 0 ? b – a – 1 : b – a + 1;
int value = (int)(range * ((float) random() / (float) RAND_MAX));
return value == range ? a : a + value;
}
I think I’ll stay with the ScreenSaver solution, even if it isn’t beautiful to call a ScreenSaver function in your app, but well… it’s a lot more understandable and they made a much better and elegant solution than my first try. I guess one could copy also the code in that function and make it your own… but the ScreenSaver Framework has everybody so… why not use it? At least for little projects should do the job.