Showing posts with label Live Coding. Show all posts
Showing posts with label Live Coding. Show all posts

Tuesday, 3 January 2017

Programming Euclidean Rhythms

I heard about Euclidean rhythms a few months ago when I saw Charlie Roberts perform at the International Conference on Live Coding (where I was also playing) in Hamilton, Canada. He was live coding using Gibberwocky; an extension to the Javascript-based live coding language, Gibber, that allows you to live code a digital audio workstation. It's an amazing piece of software and I suggest you Google it after reading this. Anyway, he created a drum beat by playing a kick drum and using a function "Euclid(3, 8)" and it sounded funky so I asked him what it was. He told me it was a Euclidean rhythm and that a couple of other live coding languages, such as TidalCycles, use them as well. He told me to read a paper by Godfried Toussaint called "The Euclidean Algorithm Generates Traditional Musical Rhythms", which explained the method to create these rhythms. I really wanted to include this simple and terse means of describing rhythms in my own Live Coding environment, FoxDot, but I did not get any useful information on how to actually program the algorithm described in the paper. I put off implementing the algorithm until I had some down-time recently and felt that I should put the code on the internet for anyone else interested.

What is a Euclidean Rhythm?


The idea of a Euclidean rhythm is to divide a number of steps, k, such that a smaller number of pulses, n, in a way that separates each pulse as equally as possible. For example, if you want three pulses over eight steps (n=3, k=8) then the algorithm returns [1,0,0,1,0,0,1,0] where a 1 represents a pulse and a 0 is the absence of a pulse. These rhythms are used in a whole host of musical genres and can create some even more interesting rhythmic patterns when used together. The algorithm is described best in the original paper mentioned above but the general idea is as follows:

1. Start with a list of n ones (pulses) and k-n zeros (non-pulses). So if n=5, k=13 and your starting list is as follows:

1111100000000

2. Take the last n number of trailing zeros from the end of the list and group each one with the first n values (all ones at this point) in turn e.g.

1111100000000   ->  11111000
                    00000

3. This is repeated until non-pulses are grouped with pulses, like so:

11111000      11111
00000     ->  00000
              000

4. In this example there are now two groups smaller than the others. Let's call these "spare" columns/groups. We do as we did previously, adding the trailing columns to the leading columns until we only have 1 or 0 "spare" columns

111    1 1 1
000    0 0 0
000 -> 0 0 0 -> 1001010010100
11     1 1
00     0 0

Programming a Euclidean Rhythm


The function below is written Python and returns the Euclidean Rhythm for any value of n and k (it returns k number of ones when n > k). I hope this is of use to some people. If you think the algorithm isn't quite right (I had to do a lot of figuring it out myself) or you think it can be made more efficient - please do let me know in the comments!

def Euclid(n, k):

    data = [[1 if i < n else 0] for i in range(k)]
    
    while True:
        
        k = k - n

        if k <= 1:
            break

        elif k < n:
            n, k = k, n

        for i in range(n):
            data[i] += data[-1]
            del data[-1]
    
    return [x for y in data for x in y]

Monday, 2 May 2016

My first Algorave performance

So on Friday I performed at my first ever Algorave; an event where digital artists get together to perform music and create visual spectacles using computer code. The music is created using a form of composition called Live Coding where music is algorithmically programmed. I'd been interested in Live Coding ever since my Masters in Computer Music but found the area-specific language, such as SuperCollider and Tidal, a bit difficult to grasp and musical ideas slow to develop. This prompted me to start development on my own system, FoxDot.

FoxDot is a Python based language that takes an object-oriented approach to Live Coding and makes music by creating Player Objects that are given instructions such as the notes to play and their respective durations. The sounds themselves are synthesised in SuperCollider - for which FoxDot was originally designed as an abstraction.

The music at Algoraves comes in a variety of forms but mainly with the intention to make people dance. I was playing alongside some artists of whom I've watched countless videos and even written essays about, so I was very honoured to do so. I was very nervous as it was the first time I'd used my FoxDot language in a public setting and I think it showed in my performance. I noticed that many performers would stand (I chose to sit) and move rhythmically with the music and even spend some time away from the keyboard. By doing this I think  they not only could take a moment to enjoy the occasion, but also have a think about their next 'move' in terms of their sound. I was typing almost constantly and I think that  had a detrimental effect on the overall performance; the set was varied and had  too many lulls - but I did see some people dancing so I can't be completely disappointed.

Here's the whole event on YouTube (I start around 10 min)!


I'm next performing at the International Conference on Live Interfaces at the end of June at the University of Sussex and have given myself the challenge of including a computer vision aspect to the performance and I can't wait!

Monday, 7 March 2016

TOPLAP Leeds: First public outing of "FoxDot"

Outside of my PhD research into nonverbal communication in musicians I also have a passion for Live Coding music and programming my own music-making system, FoxDot. I'm quite new on the Live Coding "scene" and have been wanting to get more involved for the last year or so but never really plucked up the courage to do something about it. Luckily for me I was asked by the Live Coding pioneer, Dr. Alex McLean, to help set up TOPLAP Leeds, a node extension of the established Live Coding group TOPLAP, along with a few other students.

What this means, I don't really know, but Alex encouraged me to put on a small demonstration of the code I've been working on to get some feedback from my peers. It was the first time I had used FoxDot in a public setting that wasn't YouTube and I was actually really nervous. I started working on the system last year for a module in composition as part of my Computer Music MA and from there it grew - but I had never really thought I would use it to perform. The feedback was really positive and the group gave me some great ideas to put into practice but my PhD comes first and I'm trying to limit the amount of time I spend on FoxDot to only weekday evenings and Sunday - but it's just so fun! 

FoxDot is a pre-processed Python based language that talks to a powerful sound synthesis engine called SuperCollider and let's you create music-playing objects that can work together or independently to make music and I'm really hoping to promote it over the next few years amongst the Live Coding community. It's generally in a working state but I have so many ideas for it that it seems like it's still very much in its infancy. The reason for writing this blog post about it is to try and make it all a bit more real. For so long I've been working on it in a private way; only letting the public see it in brief clips on YouTube - it's time I actually started to put it out there and letting it loose on the world. If you're interested in Live Coding, I urge you to check out http://toplap.org and also my FoxDot website https://sites.google.com/site/foxdotcode/ and see what you can do. I'm performing at the ODI Leeds on Friday 29th April and you can get tickets here.

I hope this is the first step of a long and rewarding journey.