Algorithmic Music in a Box
wesen - Manuel Odendahl - http://ruinwesen.com/
wesen - Manuel Odendahl - http://ruinwesen.com/
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Algorithmic</strong> <strong>Music</strong> <strong>in</strong> a<br />
<strong>Box</strong><br />
wesen - Manuel Odendahl - http://ru<strong>in</strong>wesen.com/
<strong>Algorithmic</strong> <strong>Music</strong><br />
• Produc<strong>in</strong>g electronic music for the last 3<br />
years<br />
• Background <strong>in</strong> programm<strong>in</strong>g, hack<strong>in</strong>g<br />
• Learnt electronics on the fly<br />
• Interested <strong>in</strong> build<strong>in</strong>g MIDI controllers<br />
• Microcontroller programm<strong>in</strong>g
In a <strong>Box</strong><br />
• First MIDI controller<br />
• Big clunky wooden box<br />
• Dozens of pots that<br />
would break once a<br />
week<br />
• USB MIDI: 2 Atmels
Hardware Synthesizers<br />
• Later on moved from computer production<br />
to hardware<br />
• Focus on more m<strong>in</strong>imal ideas<br />
• Hardware has its limitations<br />
• 4 keypresses to access the delay on the<br />
Elektron Mach<strong>in</strong>eDrum
Elektron Controller<br />
• Special midi controller:<br />
• 4 pots, MIDI out, just to control the delay<br />
• Completely new possibilities by “hack<strong>in</strong>g”<br />
exist<strong>in</strong>g synthesizers<br />
• Read<strong>in</strong>g <strong>in</strong>ternals, MIDI implementations<br />
and work<strong>in</strong>g around the limitations
Ru<strong>in</strong>wesen<br />
• New design of the controller, allowed to<br />
hack around a lot of limitations of the<br />
Mach<strong>in</strong>eDrum and MonoMach<strong>in</strong>e<br />
• Decided to start a company build<strong>in</strong>g digital<br />
and analog hardware with Ru<strong>in</strong> from<br />
Canada
MidiCommand and<br />
MidiDu<strong>in</strong>o<br />
• Evolved from the idea of a simple<br />
controller to a custom programmable<br />
opensource controller <strong>in</strong>spired by the<br />
Ardu<strong>in</strong>o<br />
• Integrated the MidiCommand and the<br />
Ru<strong>in</strong>Wesen microcontroller code <strong>in</strong>to<br />
Ardu<strong>in</strong>o environment
Midi Hack<strong>in</strong>g<br />
• This is where the fun starts!<br />
• Thoroughly <strong>in</strong>terested <strong>in</strong> musical theory<br />
and “flow”<br />
• How can hardware, even with simple<br />
controls, be used to change the way we<br />
th<strong>in</strong>k about music
Midi Hack<strong>in</strong>g<br />
• A lot of musical “concepts” have their roots<br />
<strong>in</strong> mathematics and algorithms<br />
• Exactly the right spot to merge hack<strong>in</strong>g<br />
ideas and musical ideas, explor<strong>in</strong>g concept<br />
both “artistically” and on the code level<br />
• Amaz<strong>in</strong>g how for example techno mirrors<br />
traditional music
The MIDI Protocol<br />
• Published <strong>in</strong> 1983<br />
• Serial l<strong>in</strong>k with 31250 bps<br />
• 2 separate cables: IN and OUT<br />
• Current loop: <strong>in</strong>formation is exchanged by<br />
current (to avoid ground loops)
The MIDI Protocol<br />
• Information is encoded <strong>in</strong> bytes<br />
• Use of MSB as status flag:<br />
• 0 - 127: data byte<br />
• 128 - 255: command byte<br />
• Easy <strong>in</strong>-ligne signal<strong>in</strong>g of commands
MIDI Protocol<br />
• The lower nibble of MIDI commands<br />
<strong>in</strong>dicates the selected MIDI channel<br />
• 16 MIDI channels multiplexed on one<br />
cable<br />
• Devices can listen on a specific MIDI<br />
channel or on all channels (omni mode)<br />
• Sysex and realtime messages have no<br />
channel
The MIDI Protocol<br />
• <strong>Music</strong> oriented commands:<br />
• Note On, Note Off, Controller Change,<br />
Program Change, Aftertouch<br />
• Realtime Commands: Clock, Start, Stop<br />
• Sysex (general data)
MIDI Commands<br />
• Note 60 On Velocity 100 (channel 0): 0x90,<br />
0x3c, 0x64<br />
• Controller 30 Value 10 (channel 4): 0xB4,<br />
0x1E, 0x0A<br />
• Sysex with bytes 0x00 0x23 0x35: 0xF0<br />
0x00 0x23 0x35 0xF7<br />
• have to encode 8 bits data <strong>in</strong> 7 bits
The MIDI Protocol<br />
• Three k<strong>in</strong>ds of MIDI devices:<br />
• Mostly receiv<strong>in</strong>g data: synthesizers<br />
• Mostly send<strong>in</strong>g data: sequencers, midi<br />
controller<br />
• Most devices support system specific<br />
functions us<strong>in</strong>g Sysex messages with a<br />
proprietary format
The MIDI Protocol<br />
• MIDI can be connected to a computer<br />
us<strong>in</strong>g a MIDI <strong>in</strong>terface: soundcard, USB<br />
MIDI device<br />
• MIDI can be cha<strong>in</strong>ed<br />
• most devices have a MIDI Thru which<br />
mirrors the <strong>in</strong>put<br />
• us<strong>in</strong>g custom MIDI hubs and mergers
MidiDu<strong>in</strong>o<br />
• Integration of Ru<strong>in</strong>Wesen MIDI controllers<br />
with Ardu<strong>in</strong>o<br />
• Custom MIDI and USB MIDI bootloader<br />
• Lots of MIDI functionality <strong>in</strong>tegrated for<br />
easy use
MidiDu<strong>in</strong>o<br />
• Based on Atmel CPUs<br />
• Libraries written <strong>in</strong> ASM, C and C++<br />
• ASM for “voodoo” time-critical stuff:<br />
• pars<strong>in</strong>g UI<br />
• MIDI clock generation and<br />
synchronization
MidiDu<strong>in</strong>o<br />
• Just open up a sketch, write a few l<strong>in</strong>es, and<br />
upload it to your controller<br />
• Hav<strong>in</strong>g this functionality <strong>in</strong> hardware is a big<br />
plus compared to software<br />
• Once it’s written, just plug it <strong>in</strong>, no setup<br />
required<br />
• Doesn’t need a computer if you use<br />
hardware
Exploratory<br />
Programm<strong>in</strong>g<br />
• No need to setup, doesn’t feel like an<br />
application but more like a sketch<br />
• Try out lots of crazy ideas<br />
• Randomization of parameters<br />
• Sequencers<br />
• Cool tricks
Uses<br />
• Change the behaviour and layout of your<br />
custom MIDI controller<br />
• Implement custom features for your<br />
software or synthesizer. For example:<br />
• “Hack<strong>in</strong>g” new features out of the<br />
Mach<strong>in</strong>eDrum and Monomach<strong>in</strong>e<br />
• Interfac<strong>in</strong>g with Ableton Live
Interfac<strong>in</strong>g with the<br />
Mach<strong>in</strong>eDrum<br />
• Control the effect mach<strong>in</strong>es directly over<br />
MIDI<br />
• Use the pitch of percussion mach<strong>in</strong>es to<br />
play notes: turn the MD <strong>in</strong>to a polyphonic<br />
16-track synthesizer<br />
• Randomize sounds and explore new<br />
variations
Hack<strong>in</strong>g the<br />
MonoMach<strong>in</strong>e<br />
• Revert to kit and revert to track<br />
functionality<br />
• Multi-track joystick control<br />
• Randomize parameters
Hack<strong>in</strong>g Ableton Live<br />
• Use the Ableton Live API for remote<br />
control surfaces to hook <strong>in</strong>to the <strong>in</strong>ternals<br />
of Live<br />
• Control clips, read out clip names,<br />
randomize parameters, etc...
Use cases<br />
• Simple Hello World example: send out a<br />
MIDI note<br />
void setup() { }<br />
void loop() { }<br />
void handleGui() {<br />
if (BUTTON_PRESSED(BUTTON_1))<br />
MidiUart.sendNoteOn(random(100),<br />
random(100));<br />
}
Hello World<br />
• Scale Pitch to match a scale, for example<br />
m<strong>in</strong>or scale<br />
void setup() { }<br />
void loop() { }<br />
void handleGui() {<br />
if (BUTTON_PRESSED(BUTTON_1))<br />
MidiUart.sendNoteOn(scalePitch(random(60,<br />
80), 60, m<strong>in</strong>orScale),<br />
random(100));<br />
}
Random Notes<br />
• Same concept, but this time produce pitch<br />
<strong>in</strong>formation for the drum mach<strong>in</strong>e<br />
• Indicate which sound eng<strong>in</strong>e is loaded <strong>in</strong> a<br />
track, then use lookup tables to produce<br />
the correct pitch<br />
• In this example, use the FM snare drum
Random Notes<br />
• Lookup table for the snare drum pitch:<br />
static const u<strong>in</strong>t8_t efm_sd_tun<strong>in</strong>g[] = {<br />
1, 5, 9, 14, 18, 22, 27, 31, 35, 39, 44, 48,<br />
52, 56, 61, 65, 69, 73, 78, 82,<br />
86, 91, 95, 99, 103, 108, 112, 116, 120, 125,<br />
};
Random Notes<br />
• Tell MidiDu<strong>in</strong>o which sound eng<strong>in</strong>e is<br />
loaded on which track<br />
void setup() {<br />
LCD.l<strong>in</strong>e1("MD NOTE TEST");<br />
MD::trackModels[0] = EFM_SD_MODEL;<br />
MD::trackModels[1] = EFM_SD_MODEL;<br />
MD::trackModels[2] = EFM_SD_MODEL;<br />
MD::trackModels[3] = EFM_SD_MODEL;<br />
}
Random Notes<br />
• Send a random m<strong>in</strong>orscale note when a<br />
button is pressed:<br />
void handleGui() {<br />
u<strong>in</strong>t8_t i;<br />
for (i = 0; i < 4; i++) {<br />
if (BUTTON_PRESSED(i + 4))<br />
MD::sendNoteOn(i,<br />
scalePitch(random(47, 80), 47, m<strong>in</strong>orScale),<br />
100);<br />
}<br />
}
Euclidean Rhythms<br />
• Paper by Gotfried Toussa<strong>in</strong>t: the euclidean<br />
algorithm can be used to generate most<br />
african and western rhythms<br />
• Pattern of length n, us<strong>in</strong>g a rhythmic unit,<br />
for example 16th notes<br />
• Number of pulses k, which are distributed<br />
over the pattern length
Euclidean Rhythm<br />
• For example, 3 pulses <strong>in</strong> a pattern of 8<br />
steps gives X . . X . . X .<br />
• Pattern of 4 pulses <strong>in</strong> a pattern of 9 steps<br />
gives X . X . X . X . .<br />
• These rhythms sound “natural” even if they<br />
are <strong>in</strong> a weird form, very easy way to try<br />
out a lot of <strong>in</strong>terest<strong>in</strong>g rhythmic ideas
Euclidean Rhythm<br />
• Idea: build a sequencer where each track is<br />
generated us<strong>in</strong>g k, n and an offset from the<br />
beg<strong>in</strong>n<strong>in</strong>g<br />
• Implementation of the algorithm very easy<br />
• Same algorithm as draw<strong>in</strong>g l<strong>in</strong>es on a pixel<br />
display
Euclidean Rhythm<br />
• Algorithm generates a bit pattern with the<br />
hits<br />
u<strong>in</strong>t32_t pattern = 0;<br />
u<strong>in</strong>t8_t cnt = len;<br />
for (u<strong>in</strong>t8_t i = 0; i < len; i++) {<br />
pattern
Euclidean Rhythm<br />
• Hidden away <strong>in</strong> a classed called<br />
EuclideanDrumTrack<br />
• Use tempo synchronization on the<br />
MidiDu<strong>in</strong>o<br />
• Tempo can be generated <strong>in</strong>ternally<br />
• Or synchronized to an external clock<br />
source
Euclidean Rhythm<br />
• Use a callback on every 16th note and<br />
check for each track if a hit has to be sent<br />
void on16Callback() {<br />
for (u<strong>in</strong>t8_t i = 0; i < 4; i++) {<br />
if (euclids[i].track.isHit(<br />
MidiClock.div16th_counter)) {<br />
MD::triggerTrack(euclids[i].<br />
pitchEncoder.getValue(), 100);<br />
}<br />
}<br />
}
Euclidean Rhythm<br />
• Amaz<strong>in</strong>g way to try out new <strong>in</strong>terest<strong>in</strong>g<br />
polyrhythms<br />
• Hav<strong>in</strong>g it on hardware makes it really easy<br />
to get <strong>in</strong>to the flow<br />
• Put away the computer, use the small<br />
MIDI controller and try away
Euclidean Bassl<strong>in</strong>e<br />
• Use the euclidean algorithm to generate<br />
the rhythmic pattern of the bassl<strong>in</strong>e<br />
• Use an arpeggiator to produce the pitches<br />
• Length of the arpeggiator can be different<br />
than the number of pitches, generat<strong>in</strong>g a<br />
second layer of rhythmic shift<strong>in</strong>g
Euclidean Bassl<strong>in</strong>e<br />
• This sketch works on 3 levels<br />
• Rhythm is produced by<br />
EuclideanDrumTrack<br />
• Notes are produced randomly<br />
• Notes are transformed to Mach<strong>in</strong>eDrum<br />
pitches<br />
• Turns the mach<strong>in</strong>edrum <strong>in</strong>to an algorithmic<br />
bassl<strong>in</strong>e step sequencer
Euclidean Bassl<strong>in</strong>e<br />
• MidiClock callback produces the pitches:<br />
void on16Callback() {<br />
if (track.isHit(MidiClock.div16th_counter)) {<br />
MD::sendNoteOn(ROM_TRACK,<br />
pitches[pitches_idx], 100);<br />
pitches_idx = (pitches_idx + 1) %<br />
pitches_len;<br />
}<br />
}
Controll<strong>in</strong>g graphical<br />
ideas<br />
• Us<strong>in</strong>g a MIDI controller not for music, but<br />
to control design parameters for CNC<br />
mill<strong>in</strong>g applications<br />
• Us<strong>in</strong>g algorithmically generated CNC files<br />
to mill LED lamps out of wood<br />
• Control design parameters with the MIDI<br />
controller <strong>in</strong>stead of the mouse
Lamp sketch<br />
• Mill circles of different radii us<strong>in</strong>g attractors<br />
to create “attraction” zones
Lamp sketch<br />
• Process<strong>in</strong>g sketch generates a preview of<br />
the mill<strong>in</strong>g<br />
• Uses the Ru<strong>in</strong>Wesen MIDI library to<br />
control parameters<br />
• MidiDu<strong>in</strong>o just has a simple MIDI controller<br />
sketch send<strong>in</strong>g out MIDI CC messages
Lamp sketch<br />
• Work <strong>in</strong> progress: send the MidiDu<strong>in</strong>o<br />
<strong>in</strong>formation about the parameters it<br />
controls: no MIDI <strong>in</strong>formation visible<br />
anymore<br />
•<br />
<strong>in</strong>put For = now: RWMidi.getInputDevices()[1]<br />
.createInput(this);<br />
void controllerChangeReceived(Controller c) {<br />
...<br />
}
Lamp sketch<br />
• F<strong>in</strong>d out new <strong>in</strong>terest<strong>in</strong>g regions by<br />
controll<strong>in</strong>g more than one parameter at<br />
once (not easy to do with just a mouse)<br />
• Apply MIDI algorithms and methods to<br />
generate new comb<strong>in</strong>ations:<br />
• Tempo synchronization<br />
• Easy hookup of a MIDI controller to<br />
control visuals <strong>in</strong> a club sett<strong>in</strong>g
Lamp sketch<br />
• Lamp callback code for parameters<br />
void controllerChangeReceived(Controller c) {<br />
switch (c.getCC()) {<br />
case 2:<br />
num = c.getValue() + 1;<br />
break;<br />
case 3:<br />
distance = c.getValue();<br />
break;<br />
}<br />
}
Lamp sketch<br />
• Randomize when press<strong>in</strong>g a button on the<br />
MidiDu<strong>in</strong>o, send<strong>in</strong>g a Note On message<br />
void noteOnReceived(Note n) {<br />
if (n.getPitch() == 100) {<br />
for (<strong>in</strong>t i = 0; i < 5; i++) {<br />
attractors[i][0] = random(0, 400);<br />
attractors[i][1] = random(0, 400);<br />
}<br />
}<br />
}
Conclusion<br />
• MIDI hardware hack<strong>in</strong>g is an <strong>in</strong>credibly<br />
<strong>in</strong>terest<strong>in</strong>g th<strong>in</strong>g to do<br />
• Really changes the way you th<strong>in</strong>k about<br />
music<br />
• Hands-on approach now possible without<br />
much setup
Workshop tomorrow<br />
• 12 MidiDu<strong>in</strong>o boards<br />
• Let’s try it out with hardware synthesizers,<br />
software synthesizers, Process<strong>in</strong>g sketches,<br />
and other crazy ideas
Thank you!<br />
http://ru<strong>in</strong>wesen.com/<br />
http://twitter.com/wesen<br />
http://myspace.com/daswesen