FileTools C++ Class

Here is the source for the FileTools C++ Class promised a few posts back, which uses inotify to monitor files for changes.

Again we start off with the class header:

Read more...

CodeTools C++ Class

As promised a couple of posts back, I will present a C++ class to compile some arbitrary code using GCC and load it into memory.

The code is pretty simple, we start off with the class header:

// CodeTools.hpp

#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>

typedef class CodeTools {
public:
    static bool compileString(char*, bool (*callback)(void*));
    static bool compileFile(char*, bool (*callback)(void*));

private:
} *pCodeTools;
Read more...

Fun with Renoise and Fluxus

Amidst my experimentations with livecoding I decided to purchase the amazing Renoise Tracker (and overall DAW) while it is on special (30% discount!). My intentions are to play around with Renoise to make music (online and off), and using the built in OSC and JACK support, coordinate the music using Fluxus, and of course be able to respond to it. I am also toying with the idea of using an Arduino or two as input devices. Fun stuff I reckon :P

For anyone wondering how to make Fluxus respond to the Renoise audio, it is simple using JACK:

; If I remember correctly you may need to connect the Renoise
; output to the Fluxus input using something like qjackctl first

(start-audio "renoise:output_01_left" 1024 44100) ; This will tell Fluxus to listen to the left channel..
(gain 1)

; .. and later in your render loop, using the "gh" function you can react to the sound
(every-frame
  (begin
    (scale (vmul (vector (gh 1) (gh 2) (gh 3)) 0.1))
    (draw-torus)))

Pretty neat. Using OSC it is also really simple to control Renoise. First you will want to enable the OSC server in the Renoise preferences, and then you can use the following:

(osc-destination "osc.udp://localhost:8000") ; With the port you specify in the preferences
(osc-send "/renoise/song/bpm" "i" (list 120)) ; Set the BPM to 120
(osc-send "/renoise/transport/start" "" (list)) ; Start playback
(osc-send "/renoise/transport/stop" "" (list)) ; Stop playback

Next up is to get Fluxus working nicely with Emacs.. and I promise some more updates will come shortly (including the code I've promised) :)

Comment on this post.

C++ Eval? Hell yes.

Recently I've been getting back into live coding, and as part of that I have been experimenting with a simple livecoding framework in C++.

One of my experiments involves using C++ as a scripting language, by compiling code on the fly (using g++, but any compiler should work) into a shared object, and then dlopen-ing the resultant file and hooking up the necessary functions.

By doing this I can have full access to the engine/framework and speed is never a concern. It also means I can modify it later to load any arbitrary shared object (ie. generated via C or any other language, perhaps Chicken?).

The workflow I desired to achieve was to have an OpenGL context open, blank at first. From there I could open the editor of my choice, hack on some high level C++/OpenGL, and when I saved the file, the engine would recompile the file and load it, causing its rendering function to be overridden with the new one.

I'm happy to say I've achieved what I was after!

Read more...

Change GTK display on the fly

While working on my netbook away from my desktop machine, I pondered how I could view my email clients display (claws-mail, a GTK app), without having to resort to something such as VNC.

I know this can be done using utilities such as xmove, which essentially act as a proxy X server that can detach a client from one display and move it to another. But this requires you to start xmove before the application, and to tell the application to launch with its display on xmove.

Nah. We need something cooler than this.

After using some Google fu it became apparent that the GTK library has a function named gtk_window_set_screen which is demonstrated in the gtk-demo application that comes with the GTK sources. This function allows the application to switch X11 display on the fly.. provided the application has a way to do so (which barely any do, apart from the GIMP, because most don't need to).

So I decided to look into ways of doing code injection in Linux, as a way of being able to call that function inside our target application. Turns out this is easy as pie using GDB.

Read more...

Mimicking Threading in PHP

People often criticize PHP for not having the ability to use threading), which is a fair point and quite often a drawback. Here I am presenting a method for mimicking threads through forking) of the PHP interpreter. This may not work as well on a Windows system since AFAIK forks are more expensive there than on unix (*I would love to be proven wrong however!*). You will also need to make sure that you have the extension=sockets.so somewhere in your php.ini.

The code is very simple and short, it works using socket IPC and PHP serialization:

Read more...

Chicken Scheme, and OpenGL

Today I'm posting an example of how you can quickly get started with OpenGL using Chicken Scheme.

I am posting the code in full, but I have commented it pretty well and so everything should be quite simple to understand.

Unless you take out the texture rendering, you will probably want to get SOIL for your distribution (Archers can get it with sudo pacman -S soil).

Read more...

Acer Aspire ONE D255E

A week ago I went searching for a small netbook. My requirements were pretty simple; it needed to be cheap, and be able to dual boot Linux and Windows 7. Because I'm in New Zealand, the first place I checked out was Dick Smith Electronics, which currently had a great special running on the Acer Aspire ONE D255E (**$399 NZD**, roughly $300 USD). Now the specs listed on the site were actually false, but the actual specs of the laptop are higher.

The machine uses the Intel Atom N455 processor, which is a dual core CPU running at 1.66GHz. It has 1GB of DDR3 memory, a 250GB Hard Drive (non-SSD of course), 10.1" LED LCD at 1024x600 (which is tiny, but well suited to a window manager such as ratpoison. The VGA port also handles my 1920x1080 display with no trouble), and comes with Windows 7 Starter edition. These specs seem reasonable to me, and I'm used to getting the most out of my hardware. For interest sake, the machine also has a built-in webcam, 2-in-1 card reader, 802 11b/g/n Wifi (Atheros), a Synaptics touchpad that has basic multi-touch support, and a 3-cell Li-ion battery that gives roughly 4 hours of battery life (can also upgrade to a 6-cell). This particular machine has no bluetooth, although it seems to be an optional extra (along with internal 3G), and of course no optical drive.

The first thing I did when I unboxed this machine (after installing the battery) was format the hard drive (*Windows 7 starter is plenty capable, but it's not for me*). After getting a hold of an external optical drive I proceeded to install Windows 7 Ultimate on it, giving Win7 about 60GB of space, using a single partition only (there's a trick to getting rid of the System Reserved partition, but it's a pretty simple one). Once installed, I booted the machine up, and surprise surprise, there's pretty much nil driver support for this thing using the built-in Win7 drivers. Even VGA was limited to 800x600. Luckily I have an extra machine on standby that I was able to use to download some drivers. Unfortunately this system is new enough that the drivers are only just hitting the net, and I wasn't able to find the correct ones on the Acer site itself (If you want the names and download locations, ask in the comments). But after spending a couple of hours finding the correct ones, it was up and running smoothly.

Read more...

A Newbie Guide to Call/cc

I haven't had much to write about in the last couple of weeks, but I've really wanted to do a small piece on the magic of call-with-current-continuation in Scheme, aka. call/cc.

For some reason I had a difficult time wrapping my head around this little statement, even though it isn't terribly complicated at all (from an end coder perspective that is; I don't want to imagine the headaches it causes for the compiler hackers ;)). For all intents and purposes, you can think of call/cc as a glorified return or a smart goto statement (and that is how it will sound when I try to explain it).

But first of all, what is this continuation thing?

You can think of a continuation as an object that represents the position of execution in a running program. If we call a continuation object as though it were a function, we will jump to that position in the program, and continue the flow from there.

Read more...

A Scheme Infix Transformer

As promised in the last post, I am going to share an infix function, that takes a list that looks like (1 + (2 * 3)) and turns it into (+ 1 (* 2 3)) (Prefix).

Creating this function was a perfect place to start playing with Unit Testing as well. Something that I have not used much of until now.

Unit testing is really useful in this situation. We can write a tiny test that checks if our infix/lr (lr because it parses left to right, not that it matters) function gives the appropriate result. That test will look like this:

; Load the lightweight unit testing unit
(use srfi-78)

; And write the test
(check (infix/lr '(1 + (2 * 3) + 4)) ; Check that this
       =>                            ; matches
       '(+ (+ 1 (* 2 3)) 4))         ; this
Read more...