Archive for the ‘programming’ tag
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.
Live Coding History Uploads
Hi, I wrote a couple of action into menu items for my SuperCollider and now I can publish my exercises with 2-3 clicks! I’m pushing all this logged session into the live code folder in my SC code GitHub repository. So if you are interested… I’m not yet publishing the music, maybe I’ll modify all the process so I can start History and the recording and so on, but there’s still the disk space problem. The audio files are too big and my server is not that big to support daily 20-40 MB… so… I was thinking about the possibility of using one of those music hosting sites like SoundCloud or something like that, but that would be for the future. For the moment I’ll be happy to be able to record the history and publish it from SuperCollider and that easy. If you are interested in the menu items, you can see the code here but probably you’ll have to modify it, and don’t forget, this should be in the startup file so you have these items in your menu every time you start SuperCollider.
Programming, meet music [BBC about livecoding]
Some weeks ago the SuperCollider and livecoding mailing lists were quite active talking about this article in the BBC.
I personally, not being a big live coder to talk about this theme, see some positive things about in all this. Not only the article, but the scene in general. The only thing I still don’t like from the BBC side are the journalists, why do they always try to be so funny when they talk about things they don’t even know? I could sense some ‘joke’ in the tone of this woman in the video like: “yeah, don’t know what livecoding is, but I thing you have to be a ‘freak’ to do this crazy stuff”. Anyway, it’s just my subjective opinion about this interviewer.
I was quite happy to see some people on the screen I normally only see their names in the e-mail list. And really, the scene is evolving at a fast pace, so that people can say anymore: “live coding, yeah, but it’s always so ‘shitty’ music”. One example is the recently published work by Miquel Parera nx001_LiveCode. It was all done with the JitLib in SuperCollider and just some editing in Audacity. Hearing the music without knowing the process done is as interesting as viewing the code he also published on his site.
It’s going to be interesting the next few years in the developing of this ‘on the go’ programming for music. Impromptu 2.0 also recently published is also strongly orientated for this, using LLVM and practically compiling DSP code on the fly.
Live coding has also some disadvantages, but hey… this is quite a newborn, so we have to give it a little bit more time to mature. But at the moment one can see and hear some amazing examples an performances in YouTube.