Improvizone

Composing music using code

Andrew Booker 2019-04-28 09:35:34

I don't buy new hardware. I just put what I have in different coloured wooden rack units every now and again and hope it starts sounding different.

It does if I try hard enough, and in recent months I have taken to sussing out the MIDI system exclusive structures of my trusty old Korg 05R/W and Roland D110 units in order to set up randomly configured patches in order to explore all their capabilities without spending months pushing buttons, and then modify those patches as I played sounds through them. I did achieve goal this on a technical level. I even used the D110 version at a gig last year in front of many real living human bodies. I have yet to get the sounds to actually change much, at least in a good way.

I have a whole nother story about randomly generating program settings for my 05R/W and D110, but one thing I did along the way was make a simple HTML page to send MIDI notes to the sound module so that I could audition the sounds as I worked on them without having to hit drum pads. This is especially good for the Korg, because it has two midi inputs. One is the regular 5-pin DIN plug from the 1980s. The other is a weirder socket that connects to a computer via an RS-232 serial port. Those are from the 1960s. I hacked together an old lead from Fostex R8 tape machine and a serial connector, plus a USB serial port adapter, and got the serial input thing working a while ago. It has the advantage that I can be sending system exclusive calls to completely reconfigure the unit through the serial port, happy that they will not clash with any MIDI notes that might be going in through the standard MIDI input.

For my HTML page that generates MIDI notes, I could simply have sent a boring stream of the same repeating note. But I had been listening to my wife and son practising their piano and flute baroque pieces, and found myself making up music in a similar style in my head. I knew there was no way I could ever be bothered to even try and write any of it down, yet I also knew the music in my head followed a set of rules. Could I try and codify those rules, and get some software to compose the music for me?

I decided to give it a go as soon as I realised that modern HTML5 browsers have MIDI capability. I still use C++ for my video and MIDI sound module remote controller software, but I've been trying not to use it for everything, and once I found how easily I could send a note from javascript running in a Chrome to the USB midi interface connecting my laptop to my 05R/W, I began putting together a note generation algorithm.

Soon I had a setup that takes the following inputs:

Using a process of random selection of the semiquaver pattern and the note transition, the algorithm generates a stream of crotchet-length phrases. After eight of these, the root is reset to something related to the the last note selected. The mode is then re-applied to produce a new scale based on the new root note. This is called a harmonic modulation, and I love it, although I did have to rein in the ensuing random walk up and down the entire MIDI note range so that it kept within a reasonably central region of the register.

This may have been a long way off the baroque style I was originally aiming for, but it was generating some great material to play the drums to. I spend far too much time practising only to a metronome, with no incentive to come up with good drum patterns that will actually go with music, never mind enhance it. Before I fiddled with the music generator too much, I wanted a decent record of where my first version had got to.

The result is my latest video, which pulls together a few other strands of technical work over the past months. Ironically the one thing it does not demonstrate is any of the random sound module patch generation stuff that got me into this in the first place.

The HTML note generator does a convincing job of playing at 130 bpm, but not a good enough one for me to be able to superimpose a click for playing the drums to it. It was slightly slow. I nearly managed to play along to some recorded audio without a click, but found myself drifting against the fairly washy sounds from the Korg, plus I was then stuck with those sounds in the recording. The whole advantage of working with MIDI notes is that you can still be fiddling with the sounds at the mixing stage.

In order to be able to record drumming, ideally I wanted the midi notes in a sequencer played at bang on 130 bpm. In fact I just recorded the drums to a metronome, knowing that every so often I had to hit the crash cymbals. But to get the MIDI synced with my playing, I needed to export it from my HTML page. I could have done this all in the browser with a download facility at the end, but that seemed like the wrong direction, plus I wasn't keen on trying to put together a binary MIDI file in javascript.

Instead I wrote a simple python webserver to dump out the notes to a MIDI file, and had my HTML page send its generated notes to that. This setup nicely separates the note generation piece from the mechanics of persisting them. It's not yet true to my ideal, as I still have a process of gathering MIDI notes to play later, but at least now I have a MIDI file I can load into Cubase.

For the drum recording, I used another recent tool I put together in python which, at a single keypress, starts recording video from a USB camera and four channels of audio via two USB audio interfaces. This is so much quicker than firing up a new Cubase project and activating all the audio inputs and then assigning them to tracks and giving the tracks names and then having to go home and make the dinner. It's not optimal yet, as it runs on a hefty old desktop box from the dawn of 64 bit processing that has trouble even running Ubuntu 16.04. Practically everything I have done in the last many months has been one big exercise in not spending any money on music, and this was what I had. Nevertheless I think I will treat myself and upgrade this machine to a Raspberry Pi, which will not only take a fraction of the space and consume a fraction of the power, I expect it will boot up in a few seconds, rather than a few minutes.

The top left of the video shows the scrolling display on my HTML page of the MIDI notes it has come up with. That itself came courtesy of a C++ screengrabbing app. Couldn't be bothered to look for more than two minutes for one that still ran on Windows 7, so I spent an hour or so writing my own. The centre section has four columns, one for each of the semiquavers in a beat. The hyphenated numbers are the MIDI note, the note length in semiquavers and the velocity. Most note lengths are in the 1-4 range, every 8 rows there's the next bass note of length 32 that signifies the harmonic modulation. The scrolling is not well synchronised with the playing, being slightly slow, as I found early on.

Also there is my hair-brained video composition. Not satisfied with watching stationary video from three cameras I used, I made two of them fly around all over the place. While not a huge feat of arithmetic, it was enough that I could not face throwing the work away having finished it, so I kept it.

If I take this any further, I will need an architecture that lets me:

So far my HTML page is a good demo of the first two bits. The python web server I made takes care of the last bit. For playing it all in time to a click, I'm thinking another piece of ancient musical technology I have knocking around, the Roland TD6, might be able to help. As for the actual music generation, I have many other possibilities to explore. Obviously I can vary the tempo, the key (root note) and the mode, but also I can construct the phrases differently, using different time signatures etc. I don't like to come up with a vast inventory of plans at points like this, but for drumming enjoyment and sheer physical exercise I want to try something at about 160 bpm.

Temporary resurrection amid Cloudy Peaks << | >>