Posts Tagged ‘Code’
Public beta release of Isobar, a Python library for algorithmic composition
Underlying Variable 4 is a suite of Python code, with components to deal with various different tasks – interfacing with the weather station, navigating the global score, broadcasting data, and so on. There’s one part in particular that we’ve found useful in general usage: the pattern generation code, which can be used to describe, manipulate and generate sequences of musical events.
We’ve finally cleaned this up for public release, and have christened it Isobar, from the notation used in meteorological pressure systems. In this context, it’s a way of notating music, in a concise and flexible manner.
Overview
Isobar is a pure Python library which makes it easy to express musical patterns, and output them through MIDI or (soon) OSC devices. It’s inspired by SuperCollider’s excellent pattern library, which allows patterns to be combined like building blocks to create easily extensible compositions.
To get it: download Isobar from GitHub.
Please note that this is a beta release, meaning that all features and syntax are subject to change.
Examples
To give a taste of Isobar’s approach and capabilities, let’s look at some example code
from isobar import *
seq = PSeq([ 0, 1, 2, 3 ])
seq = PStutter(seq, 2)
seq = seq + PSeq([ 0, 12 ])for n in xrange(8):
print seq.next()> 0
> 12
> 1
> 13
> 2
…
The above creates a simple looping sequence (PSeq) based on increasing integers (or, if used as MIDI outputs, chromatic notes). Each value is repeated once (PStutter), and alternating notes are transposed an octave up. This is then used to output a sequence of numbers.
Note that patterns can simply be added together to transpose values. Many other operators can be applied in similar ways: for example, doing seq * 2
will double every value of a pattern, using lazy evaluation for no additional processor usage.
from isobar import *
from isobar.io.midiout import *scale = Scale([ 0, 2, 3, 7, 9, 11 ])
degree = PBrown(0, 2, -8, 8, repeats = False)notes = PDegree(degree, scale) + 60
midi = MidiOut()
timeline = Timeline(160)
timeline.output(midi)timeline.sched({ ‘note’: notes, ‘dur’: 0.25, ‘gate’: 0.9 })
timeline.run()
This example binds a pattern to a MIDI device, and uses a random walk (PBrown) to play values from a particular Scale. A Timeline object is used to schedule MIDI events at a given BPM, and plays them through the default MidiOut device.
By assigning this pattern to the ‘notes’ value, its output is used to generate a series of pitches. We could assign a separate pattern to the ‘amp’ value, to control the velocity of each note.
Many more examples are available in the isobar distribution on GitHub, with an up-to-date index of pattern objects in the README. We’ll be continuing to work on Isobar extensively over the next few months; see the TODO file for forthcoming developments.
Talk at dorkbotlondon, 11 May
The international dorkbot events are the discerning dork’s destination of choice to hear of the latest tech hobbyism, electronic arts and DIY. We’ll be talking briefly about Variable 4 at this Tuesday’s dorkbotlondon #69, with as much of the weather station as we can carry (which may, admittedly, not be much).
Expect some discussion of algorithms, weather systems, collaborative practices, and unforeseen hardware hiccups.