Saturday, January 31, 2009

Python 3.0 / Hex On!

This week, I've started playing with Python 3.0 (aka Py3k). The final 3.0 version had been released in December, so there is only a release candidate available in the Intrepid repositories, but I didn't care. In fact, it was dead easy to install - simply apt-get install python3 and you're all set!

Among the things, that amazed me the most, is a new fractions module (actually existing since Python 2.6), that provides support for rational numbers! What are rational numbers good for? Well, they're invaluable for pretty much anything, that involves just intonation, to say the least!

For example, here's how I've managed to code a simple Hexany generator in almost no time! Roughly speaking, a hexany is created from several prime (or not so prime) numbers, that are multiplied together in pairs to form a set. To get a scale out of it, the resulting numbers should be divided by a chosen "base note" and reduced to the octave range. So, first of all, we'll need a simple octave reduction function:
def octave_range(fr):
    if fr <= 0: raise ValueError("Invalid frequency ratio")
    elif fr > 2: return octave_range(fr / 2)
    elif fr < 1: return octave_range(fr * 2)
    else: return fr
Now, let's define a "base note" and use set comprehension (another Py3k feature) to fill the CPS with permutations of numbers from the Wikipedia example:
nums = [2, 3, 5, 7]
base = 5 * 7
cmps = {a * b for a in nums for b in nums if a != b}
And thanks to the fractions support, the final step is also going to be the easiest:
from fractions import Fraction
hexany = [octave_range(Fraction(note, base)) for note in cmps]
hexany.sort()
The code is also suitable for producing dekanies and other scales, based on Wilson's combination product sets. I still have to figure out the proper ways of using them in music though :P

Monday, January 26, 2009

Updates

There's not much to write about, but here are several quick updates to keep this feed alive... First of all, Sced source code has been moved to the SuperCollider SVN tree, so any further development is going to continue out there... Another good news is that our favourite text editor - gedit is probably going to have some kind of D-Bus interface for the 2.26 release. So things like ScedDocument (and other means of feedback from sclang) could be finally made possible.

I have moved the few Russian posts in this blog into ratzez.blogspot.com, thanks to the Blogger import and export feature. It means, that from now on, I shall continue writing in English here and the secondary blog will be in Russian. Looks like it also makes the Blogger interface more convenient, 'cause the engine does not seem to respect the browser language anyway...

And yet one more thing, just in case you'd like to add a little Human look to your code... It can be done with a couple of Ubuntu-coloured themes for GtkSourceView. They're not quite polished yet, but already seem to nicely fit an all-human environment...

Sunday, November 23, 2008

Back in Black

There are several big changes in Sced expected in the near future, so today I'm releasing the latest stable 0.4 version, that does not introduce any new features, but has fixes for a couple of long-standing bugs.

It's worth mentioning however, that this version is a lot more compatible with stock and third-party style schemes for Gedit. That means, that your SuperCollider code is going to look cool and stylish, even with the darkest of them... Oh, and quite a number of themes is already available through this page at GNOME Live. Go and check them out!



One more thing. In order to make your Gedit even more great and powerful, make sure you also get the fullscreen plugin and the gedit-plugins package from your distro. The former enables the fullscreen mode for the distraction-free coding (or some live demos, perhaps), and the latter has some neat extensions like bracket completion and tabbar-disabler for an even cleaner workspace!

The Sced tarball itself is available through the usual location and the Debian/Ubuntu packages should be already in the PPA at the time of writing. Just in case you missed the installation instructions, check the following post for a short tutorial. And, of course, your feedback is much appreciated.

Wednesday, October 15, 2008

They did it!

Yeah, I'm now running my Intrepid setup with a shiny new fglrx-8.543. It installs, it runs, it works with Jockey! Right in time, when I've started to lose my hope...

And I can even watch the video and play games - something I've been missing since I have installed Intrepid back in August :) My huge thanks to all the AMD/ATi and Ubuntu developers who have brought the driver back to us!

Friday, October 3, 2008

Time for some colliding under Ibex...

Dang, it looks like I write in this blog, only when I publish the new SuperCollider binaries... Anyway, if you're interested in trying the latest (7803) SVN snapshot the easy way, it's now available (for Intrepid as well)!

The instructions for installing the SuperCollider debs (and making some sounds) may be found in an earlier howto, but I also think of writing another introductory tutorial on Synths and SynthDefs in the next few days...

And most importantly, I'm probably going to perform a bit of live SC noise by the end of October. So any comments and tips, esp. from those of you, who have played live with SC/Linux are kindly welcome :)

Sunday, September 14, 2008

Just couldn't resist...

For the meme:
  • teaquetzl
  • roppongi
  • carthax
All of 'em are named after places (real and fictional) :)

Wednesday, May 21, 2008

SuperCollider for Human Beings

This time with gedit support!!!

And here's a short hands-on tutorial, just in case anyone would like to try out this extremely efficient synthesis environment for the first time...

UPDATE:The best way to get semi-official SuperCollider packages is the SuperCollider PPA. Check its page for instructions on adding the repository.

After you've successfully added the PPA to your software sources, install supercollider and supercollider-gedit packages.



Then start gedit and open Edit->Preferences. Enable Sced plugin from the Plugins tab:


Okay, now we can try the interpreter. Select Tools->SuperCollider Mode from the gedit menu. The SuperCollider output panel will appear with a message that SuperCollider has started. Now type the following code just inside the currently open document:
"Hello, World!".postln;
Make sure that the cursor is on the same line and press CTRL+E. You should see "Hello, World" printed two times in the output window. The string is duplicated because "postln" returned the same string as a value, and the output also prints the results of the evaluated expressions.

If you'd like to get some sound, make sure that JACK is started. If not, start it with qjackctl or the following command:
jackd -d alsa
After JACK has started, select SuperCollider->Start Server from the gedit menu and execute the following code string, just like we did with the "Hello, World" example above:
{SinOsc.ar}.play;
You should hear an annoying beep from your left speaker. Not much, huh? Well, press ESC (Stop Sound) inside gedit for now. And append something like the following code to your document (yes, you can do all the work in the same document):
// This example is a modified patch
// from the SuperCollider book by David Cottle
// You can enable syntax highlighting
// by selecting View->Highlight Mode->Others->SuperCollider
( // press CTRL+E here
{
  RLPF.ar(
    Saw.ar(55),
    LFNoise1.kr([5, 5], mul: 440, add: 880),
    0.1,
    mul: 0.25
  )
}.play;
)
Note the brackets around the actual code. They're used to group code together into "blocks" and execute SuperCollider instructions simultaneously. In this example you will need to press CTRL+E where indicated to select and run our block. Remember, that you can shutdown the sound anytime with ESC! :)

As you can see, we have a Saw oscillator, connected to a resonant low-pass filter (RLPF) here and the cutoff frequency is controlled by an interpolated random value (LFNoise1). You can open reference pages for the respective modules (UGens) by positioning the cursor over them and pressing CTRL+U, but make sure that you install supercollider-doc package to get those.

Well, I hope this tutorial will help you get started with SuperCollider. Make sure you also stop by the SuperCollider website and the wiki for more tutorials and examples.