(Arduino) Interactive Generative Sequencer

Following my ongoing work on a theory of rhythms and a corresponding physical instrument using lasers, here is a version of the same idea implemented into an Arduino: a generative sequencer. The idea is to generate rhythms, and perhaps melodies, from one rhythm seed, then use mutated copies of it to create something more interesting, all this in realtime using knobs and buttons.

This is not ‘yet another step sequencer’, but really a generative music device, that builds a real time MIDI loop based on an underlying theory described in a previous post.

This is work in progress, and is shown ‘as is’ for the sake of getting feedback.

Approach

The approach is to generate a “seed” of rhythm that is then copied a few times into “instances”, each instance being distorted in its own way. The controls for the human player (or programmer) are therefore all about adjusting the deformations (transforms actually) to apply to each instance, and of course defining the seed.

Eventually each instance is wired to a MIDI note, channel etc. to remote control a synthesizer or a drum machine or any MIDI setup, to generate actual sounds.

Principle: one seed, many transformed instances
Principle: one seed, many transformed instances

The maths

Given a seed of rhythm of lengh length composed of pulses, each of duration m, then:

for each instance k of the seed, each pulse i,
pulse(k, i) happen at time t = phase(k)  + i . m . stretch(k), t < length
where phase(k) and stretch(k) are the phase and stretch settings for the instance k.

Realtime control of the sequencer is therefore all about setting the phase and stretch values for each instance, once the pulse number and the pulse duration of the seed have been globally set.

Inversely, for a given instance k, at time t, we have a pulse if:

there exists an i, such as t = phase(k) + i * m * stretch(k)
i.e. i = (t - phase(k))/(m * stretch(k))

In other words, if

(t - phase(k))/(m * stretch(k)) is integer
(i.e. numerator % denominator == 0)

Thinking in MIDI ticks (24 per quarters), in 4/4, for 1 bar, length = 4 * 24, phase is in [-24 .. 24] and stretch is in [4:1 .. 1:4] and m in [12 .. 48] by steps of 12 ticks.

The implementation is the very simple: for each instance of the seed, and given its phase and stretch settings, whenever the modulo condition above is true, then we emit its MIDI note, with the set velocity on the set MIDI channel.

As usual, the pace of the loop is primarily based on the value from the Tempo potentiometer.

Overview of the circuit
Overview of the circuit, with the switches and the knobs

Adding some swing

8th note swing
8th note swing

The EMU SP-1200, early Linn machines, Roland 909, Akai MPC and many other machines are famous for their swing quantize, a feature that delays every other note by a certain amount in order to create a groovy feeling (see Swung Note).

Different machines express the swing factor in different ways, we will stick to the MPC format, expressed in percent from 50% (no swing, play straight) to 75% (hard shuffle).

For a swing for 8th notes, this swing factor represents the ratio of the period of the first 8th note over the period of the second 8th note, in percent.

In the Arduino code of our generative sequencer, we chose to do a fixed swing for 8th notes only.

A big constraint is that we are limited to a resolution of 24 ticks per quarter note, which is not a lot! By contrast, MPC have a 96 ppq resolution. Because a hard swing of 70% translates into hardly 2 MIDI ticks at 24 ppq, doing the swing on top of the ticks will not be accurate at all!

The only solution is to vary the internal tempo before and after each 8th note. The drawback (or advantage) is that the MIDI clock being sent will also move, reflecting the same swing. Since the Swing knob value is actually between 0 and 25 (to be read from50% to 75%), the tempo before (t-) and the tempo after (t+), are given by:

t+/- = (50 +/- swing) * t / 50
where t is the base loop period without swing

Video Demo

Here is a video demo. There are only 3 instances, selected by the switches 1, 2 and 3; the first switch selects the GLOBAL settings: step duration (quarter, 8th etc.), swing factor, tempo. Each instance can be set its Phase, Stretch, MIDI note, velocity and MIDI channel. Here I have preset the MIDI channels, instance 1 on channel 1 (the microKorg) and instances 2 and 3 on channel 2 (the MPC with a drum kit).

The goal is to build a simple beat by only adjusting the parameters.


(Arduino) Interactice Generative Sequencer from cyrille martraire on Vimeo.

The code

You can download the Arduino project here: generativesequencer1; below is the same source code for convenience. The code includes the knob pagination described in a previous post.

Please note that some parts of the code are not used any more, such as the big constant arrays, and some comments are not up to date (e-g no prime number anymore).

All analog inputs are wired to simple knobs. Digital inputs 8, 9, 10 , 11 are the four buttons used to switch pages. Digital output 12 is the activity LED (showing when the knob is active within the knob pagination). MIDI out is on the Tx pin.

/*
 * Generative rhythm sequencer, more details at: http://cyrille.martraire.com
 *
 * Knob mapping according to a grid 2^n . prime^m, against the MIDI 24 ticks/quarter.
 *
 * Knob pagination to multiplex the knobs several times with LED to show activity.
 *
 * Memory-less event handling thanks to maths relationships.
 *
 * MIDI note on output on every 16 channel and MIDI clock according to tempo.
 *
 *
 * Creative Commons License Cyrille Martraire cyrille.martraire.com
 */
// DEBUG
int debug = false;
//---------- USER INPUT AND PAGINATION -----------
#define PAGE_NB 4
#define KNOB_NB 6
#define FIRST_PAGE_BUTTON 8
#define PROTECTED -1
#define ACTIVE 1
#define SYNC_LED 12
// the permanent storage of every value for every page, used by the actual music code
int pageValues[PAGE_NB][KNOB_NB];
// last read knob values
int knobsValues[KNOB_NB];
// knobs state (protected, enable...)
int knobsStates[KNOB_NB];
// current (temp) value just read
int value = 0;
// the current page id of values being edited
int currentPage = 0;
// signals the page change
boolean pageChange = false;
//temp variable to detect when the knob's value matches the stored value
boolean inSync = false;
// ---------- KNOBS CALIBRATION AND MAPPING ---------
// rhythmic scale, to select globally
int scale2[] =  {1, 2, 3, 6, 6, 12, 12, 24, 24, 48, 48, 96, 192, 384, 768};
int scale3[] =  {1, 2, 3, 6, 9, 12, 18, 24, 36, 48, 72, 96, 144, 384, 768};
int scale5[] =  {1, 2, 3, 6, 12, 15, 24, 24, 30, 48, 60, 96, 120, 384, 768};
int scale7[] =  {1, 2, 3, 6, 12, 21, 24, 24, 42, 48, 84, 96, 168, 384, 768};
int scale9[] =  {1, 2, 3, 6, 12, 12, 24, 24, 27, 48, 54, 96, 108, 384, 768};
int scale11[] = {1, 2, 3, 6, 12, 12, 24, 24, 33, 48, 66, 96, 132, 384, 768};
//int scale13[] = {1, 2, 3, 6, 12, 24, 12, 24, 39, 48, 78, 96, 156, 384, 768};
int maxValue = 890;
int scaleLen = 15;
int *scale = scale3;
int step = 60;
int center = 30;
int coeff = 10;
//---------- GENERATIVE MUSIC CODE ---------
unsigned int cursor = 0;
int bars = 1;
int length = bars * 4 * 24;
// INPUTS
int PHASE = 0;
int STRETCH = 1;
//int DIRECTION = 2;
int NOTE = 2;
int DURATION = 3;
int VELOCITY = 4;
int CHANNEL = 5;
// GLOBAL KNOBS (seed and global settings)
int seedDuration = 24;
int seedTimes = 8;
int instanceNb = 4;
int swing = 0;//0..25% (on top of 50%)
//
int loopPeriod = 125/6;//120BPM
int actualPeriod = loopPeriod;
//instance i
int phase = 0;
int stretch = 1;
int note = 48;
int duration = 24;
int velocity = 100;
int channel = 1;
void setup(){
  if(debug){
   Serial.begin(19200); //debug
  } else {
    Serial.begin(31250);
  }

  pinMode(13, OUTPUT);

  setupKnobMapping();

  setupPagination();
}
void setupKnobMapping(){
  step = maxValue / scaleLen;
  if (step * scaleLen < maxValue) {
     step++;
  }
  center = step / 2; // for phase only
  coeff = step / 8; // +/-3 ticks, for phase only
}

void loop () {
    midiClock();

    //TODO partition inputs reading every other cycle if required by CPU load
    poolInputWithPagination();

    poolGlobalSettings();

    // parameters for each instance (pages 1 to 3)
    for(int index = 1; index < instanceNb; index++){
        processSeeInstance(pageValues[index]);
    }

    cursor++;
    cursor = cursor % length;
    delay(actualPeriod);
}
void poolGlobalSettings(){
    // global parameters
    seedDuration = mapC(pageValues[0][0], maxValue, 1, 4) * 12;
    seedTimes = mapC(pageValues[0][1], maxValue, 1, 16);
    instanceNb = 4;//mapC(pageValues[0][2], maxValue, 1, PAGE_NB);
    // = mapC(pageValues[0][3], maxValue, 1, PAGE_NB);
    swing = mapC(pageValues[0][4], maxValue, 0, 25);
    loopPeriod = mapC(pageValues[0][5], maxValue, 63, 2);// 12.5 ms - 62.5
    if (cursor % 24 <= 12){
      actualPeriod = (50 + swing) * loopPeriod / 50;
    } else {
      actualPeriod = (50 - swing) * loopPeriod / 50;
    }
    //TODO prime number selection and scale switch
}
// custom map function, with min value always 0, and out max cannot be exceeded
long mapC(long x, long in_max, long out_min, long out_max)
{
  if (x > in_max) {
    return out_max;
  }
  return x * (out_max - out_min) / in_max + out_min;
}
void processSeeInstance(int * params){
  phase = mapC(params[PHASE], maxValue, 0, 24);
  stretch = mapC(params[STRETCH], maxValue, 0, 4);
  stretch = pow(2, stretch);// 4:1 to 1:4, in fourth
  note = mapC(params[NOTE], maxValue, 36, 48);
  //duration = mapC(params[DURATION], maxValue, 6, 96);
  velocity = mapC(params[VELOCITY], maxValue, 0, 127);
  channel = mapC(params[CHANNEL], maxValue, 0, 4);

  if(isPulse(phase, stretch)) {
     noteOn(channel, note, velocity);
  }
}
// for each instance, and for the given cursor, is there a pulse?
boolean isPulse(byte phase, byte stretch){
  int num = cursor - phase;
  int denum = seedDuration * stretch / 4;
  return num % denum == 0;
}
// Sends a MIDI tick (expected to be 24 ticks per quarter)
void midiClock(){
  Serial.print(0xF8, BYTE);
}
//  plays a MIDI note for one MIDI channel.  Does not check that
// channel is less than 15, or that data values are less than 127:
void noteOn(char channel, char noteNb, char velo) {
   midiOut(0x90 | channel, noteNb, velo);
}
//  plays a MIDI message Status, Data1, Data2, no check
void midiOut(char cmd, char data1, char data2) {
   Serial.print(cmd, BYTE);
   Serial.print(data1, BYTE);
   Serial.print(data2, BYTE);
}
//********************************************
void setupPagination(){
  pinMode(SYNC_LED, OUTPUT);
  for(int i=0; i < KNOB_NB; i++){
    knobsValues[i] = analogRead(i);
    knobsStates[i] = ACTIVE;
  }
}
// read knobs and digital switches and handle pagination
void poolInputWithPagination(){
  // read page selection buttons
  for(int i = FIRST_PAGE_BUTTON;i < FIRST_PAGE_BUTTON + PAGE_NB; i++){
     value = digitalRead(i);
     if(value == LOW){
         pageChange = true;
         currentPage = i - FIRST_PAGE_BUTTON;
     }
  }
  // if page has changed then protect knobs (unfrequent)
  if(pageChange){
    pageChange = false;
    digitalWrite(SYNC_LED, LOW);
    for(int i=0; i < KNOB_NB; i++){
      knobsStates[i] = PROTECTED;
    }
  }
  // read knobs values, show sync with the LED, enable knob when it matches the stored value
  for(int i = 0;i < KNOB_NB; i++){
     value = analogRead(i);
     inSync = abs(value - pageValues[currentPage][i]) < 20;

     // enable knob when it matches the stored value
     if(inSync){
        knobsStates[i] = ACTIVE;
     }

     // if knob is moving, show if it's active or not
     if(abs(value - knobsValues[i]) > 5){
          // if knob is active, blink LED
          if(knobsStates[i] == ACTIVE){
            digitalWrite(SYNC_LED, HIGH);
          } else {
            digitalWrite(SYNC_LED, LOW);
          }
     }
     knobsValues[i] = value;

     // if enabled then miror the real time knob value
     if(knobsStates[i] == ACTIVE){
        pageValues[currentPage][i] = value;
     }
  }
}
void printAll(){
     Serial.println("");
     Serial.print("page ");
     Serial.print(currentPage);

     //Serial.println("");
     //printArray(knobsValues, 6);
     //Serial.println("");
     //printArray(knobsStates, 6);

     for(int i = 0; i < 4; i++){
       Serial.println("");
       printArray(pageValues[i], 6);
     }
}
void printArray(int *array, int len){
  for(int i = 0;i< len;i++){
       Serial.print(" ");
       Serial.print(array[i]);
  }
}

Read More

Music Production Patterns

Here is a collection of tips and tricks to produce current popular genres (Hip-Hop, House and Electro in particular) found freely on the Internet, and presented into the pattern form.

The pattern form

This means each trick or set of related tricks is given an expressive name along with a short description of its intent. Full description of each pattern is left out, as it would represent a rewriting of many sources (I have no time for that), but links to the full source material are given at the bottom in the references section.

Of course this is only useful if you already know what it is about, and should be considered more as a reminder.

Arranging a tune

At the top level of a tune structure, we deal with the arrangement.

  1. Anticipation and Surprise: create anticipation and surprise: Build-ups (Snare Rolls, Reverse Crash, Filter Opening, Synth Fx, Accelerating LFO, Pitch Glide), Breakdowns (drop parts, close filter)
  2. Playing The Studio: allow for spontaneous action in the studio, e-g. Dub-Style (mixer, reverb send, effect send, use of feedback)
  3. Round Trip Creation (e-g. beat first, lyrics, then back to beat to optimize with the vocals)
  4. Question-Answer: Q/A relationship to sustain a tension: Q (lyrics) – A (riff); see also Da Capo, Ternary Form
  5. Useful and insightful definitions:
    1. Vibe: inspiration for a tune, the focus throughout the song (vocal, sound, chord progression…); can be found before or after a beat is created
    2. Character: anything that is highly distinctive (sounds, voice, filter effects, fills, sweeps…)
    3. Energy: drums, bass, and riffs (arp, synth, guitar…) driving the tune


A typical project studio
A typical project studio

Make It Believable

Sometime we want to achieve realism, sometime we do not want to, but there is always a need to be realistic in some way, even in a virtual musical world.

  1. Layer, Layer, Layer: no simple sound, layer similar sounds to make them richer and more complex
  2. Ambiance: Preserve or re-create ambiance (Overhead miking, Parallel Compression…)
  3. Altered Background: sounds in the back should have some reverb and high frequencies attenuated
  4. Possible for a Performer: the performer could possibly do that (or not if we want artificial feeling)
  5. Tone Matching (compatible sounds, physically or for the genre)


Groove and Feel

Getting a strong groove is key to a good tune.

  1. First Beat Straight and Loudest
  2. Primary Beats Louder (than secondary beats)
  3. Swing: play offbeats late, from straight to triplet feel
  4. Silence Matters: make sure there is silence between hits (use Gating, Side Chain Compressor, Manual Edit in the DAW, Adjust Decay)
  5. Dragging or Rushing: make other beats late or early
  6. Evolving Dynamics (through velocity, modulation, filter or sample start modulation)
  7. Layer Beats: Backbeat, Polyrhythm, Ghost Notes
  8. Sync to Tempo: Sync everything (arpeggiator, effects, lfos) to tempo or to some multiple of the tempo (via MIDI or manually)
  9. Notes Duration Matter: the funky bass, it’s in the notes duration


Sound Design

For more character, a tune needs unique and special sounds

  1. Happy Accident: make sure happy accident can still happen, and Record Everything
  2. Unlimited Combinations: Combine Everything to Everything (Compressor, Filter, Effects, Automation, Instruments…)
  3. Extreme Processing: Pitch Shift, Reverse, Audible Looping, Glitch, Overdrive
  4. Uncommon Devices: Circuit Bending, Domestic things that make sounds, exotic spaces to record in
  5. Hybridate Audio Features: (Extract-Promote): extract sample part then loop it as the oscillator in a synth, extract convolution profile then apply it to another sound, extract FFT spectrum or RMS envelope to apply it to another sound etc.
Using a musical toy for special sounds
Using a musical toy for special sounds

Keep it Simple (The Enough Repetition Rule)

  1. Four Hooks Maximum: do not confuse the listener with too many distinct things
  2. Reuse With Variation: it is OK to use again and again the same hook provided it is slightly changed to make it less obvious and boring
  3. Attractive or Complementary: some tracks must attract attention, other tracks must not compete for attention
  4. KISS: Keep it simple (but no simpler): stick to simple melodies, riffs and chords progressions

Keep It Interesting (The Enough Variation Rule)

  1. Alternate Sounds (Alternate Claps, Samples switched by velocity etc.)
  2. Modulations (Sample Start Modulation, Automation of whatever)
  3. Effects, Triggered Effects (via automation)
  4. Widen Stereo: Hard Pan, Haas Effect (Hard Pan With 15-60ms Delay), Stereo Modulation Effect (Chorus etc.)

A ProTools Session during mixing
A ProTools Session during mixing

Mixing

We’ll fix that in the mix.

  1. The Drum and Bass Backbone: Get them right and solid first
    1. Exclusive Frequencies: boost one, cut the other by the same amount on the same frequency
    2. Exclusive Timing: if possible, if one plays, the other should be silent; variations involve using Side Chain Compressor or Gating
  2. Tune Drums: tune low-end drums and percussion sounds to the root tonic note to avoid very low frequency beats
  3. Sound Substitution: if it cannot sound good, change the sounds
  4. Frequency Separation: reduce clutter with sounds frequencies not overlapping too much
  5. The usual traps: Phase & Mono (phase issues result in Comb filter effects or phase cancellation; clubs are more or less mono)
  6. Create Space (aka Multidimensional Mix): Left, Right, Foreground and Background: Stereo Placement, Damp Highs, Delay + Pan
  7. Less is More, know when to cut something
  8. Mixing Order Priorities: e-g. for Hip-Hop: D&B first, Vocals, then other tracks
  9. Mixing Panning Priorities: most important tracks centered, the rest panned around
  10. Sub Mixes: drums, leads & vocals, the rest, or drums, bass, the rest
  11. Mix down several mixes: Main Mix, Raised Vocals Mix (lead and back vocals +1dB), Lowered Vocals Mix, TV Live Mix (no lead vocals), Instrumental Mix (for promotion)
  12. Mixing for the genre and the goal: More extreme for clubs, more “tone-down” for radio…

Other Techniques

  1. Side Chain Compressor: consider using a separate track to trigger the side chain for more control
  2. Automate level on basses that play too many notes with a different level
  3. Widening stereo for drums: add background kick with reverb and less highs, add stereo claps
  4. Tips to enhance background vocal:
    1. Add Silk: hipass filter >900Hz
    2. Add Sheen: boost 11-12KHz 1-4dB
    3. Heavier effects than lead vocals: subtle ping pong stereo delays, hall reverb, plate reverb, and choruses
    4. Multiple Takes: double, triple, stacking harmonies: For example, pan low vocal/harmony tracks hard left & right. Next, pan medium vocal/harmony tracks 75% left & 75% right. Lastly, pan high vocal/harmony tracks 40% left & 40% right.
  5. Compressor: (too many resources on that one…, typical gain reduction: 10-15dB)
  6. EQ: (too many resources as well), Cut or Boost?

References

Read More

Geometric Rhythm Machine

In the post Playing with laser beams to create very simple rhythms” I explained a theoretical approach that I want to materialize into an instrument. The idea is to create complex rhythms by combining several times the same rhythmic patterns, but each time with some variation compared to the original pattern.

Several possible variations (or transforms, since a variation is generated by applying a transform to the original pattern) were proposed, starting from an hypothetical rhythmic pattern “x.x.xx..”. Three linear transforms: Reverse (”..xx.x.x”), Roll (”x.x.xx..”) and Scale 2:1 (”x…x…x.x…..”) or 1:2 (”xxx.”), and some non-linear transforms: Truncate (”xx..”) etc.

Geometry + Light = Tangible transforms

The very idea behind the various experiments made using laser light beams and LDR sensors is to build an instrument that proposes all the previous transforms in a tangible fashion: when you move physical object, you also change the rhythm accordingly.

Let’s consider a very narrow light beam turning just like the hands of a clock. Let’s suppose that our clock has no number written around, but we can position marks (mirrors) wherever on the clock surface. Still in the context of creating rhythms, now assume that every time a hand crosses a mark (mirror) we trigger a sound. So far we have a rhythmic clock, which is a funny instrument already. But we can do better…

Going back to our rhythmic pattern “x.x.xx..”, we can represent it with 4 mirrors that we position on a same circle. On the illustration below this original pattern is displayed in orange, each mirror shown by an X letter.. If we now link these 4 mirrors together with some adhesive tape, we have built a physical object that represents a rhythmic pattern. The rotating red line represents the laser beam turning like the clock hands.

Illustration of how the geometry of the rhythmic clock physically represents the transforms
Illustration of how the geometry of the rhythmic clock physically represents the transforms

Now we have a physical pattern (the original one), we can of course create copies of it (need more mirrors and more adhesive tape). We can then position the copies elsewhere on the clock. The point is that where you put a copy defines the transform that applies to it compared with the original pattern:

  • If we just shift a pattern left or right while remaining on the same circle, then we are actually doing the Roll transform (change the phase of the pattern) (example in blue on the picture)
  • If we reverse the adhesive tape with its mirrors glued on, then of course we also apply the Reverse transform to the pattern (example in grey on the picture)
  • If we move the pattern to another (concentric) circle, then we are actually applying the Scale transform, where the scaling coefficient is the fraction of the radius of the circle over the radius of the circle of the original pattern (example in green on the picture)

Therefore, simple polar geometry is enough to provide a complete set of physical operations that fully mimic the desired operations on rhythmic pattern. And since this geometry is in deep relationship with how the rhythm is being made, the musician can understand what’s happening and how to place the mirrors to get any the desired result. The system is controllable.

To apply the Truncate transform (that is not a linear transform) we can just stick a piece of black paper to hide the mirror(s) we want to mute.

If we layer the clock we just described, with one layer for each timbre to play, then again changing the timbre (yet another non-linear transform) can then be done by physically moving the pattern (mirrors on adhesive tape) across the layers.

From theory to practice

Second prototype, with big accuracy issues
Second prototype, with big accuracy issues

Though appealing in principle, this geometric approach is hard to implement into a physical installation, mostly because accuracy issues:

  1. The rotating mirror must rotate perfectly, with no axis deviation; any angular deviation is multiplied by two and then leads to important position deviation in the light spot in the distance: delta = distance . tan(2 deviation angle)
  2. Each laser module is already not very accurate: the light beam is not always perfectly aligned with the body. To fix that would require careful tilt and pan adjustment on the laser module support
  3. Positioning the retroreflectors in a way that is accurate and easy to add, move or remove at the same time is not that easy; furthermore, even if in theory the retroreflectors reflect all the incoming light back to where it comes from, in practice maximum reflectance happens when the light hits the reflector orthogonally, which is useful to prevent missed hits

Don’t hesitate to check these pages for progress, and any feedback much appreciated.

Read More

Rhythmic clock machine

The rotating mirror and the 4 laser beams
The rotating mirror and the 4 laser beams

I finally received ten retroreflectors, the experiments started in Playing with laser beams to create very simple rhythms”, we can now move on.

Once again, the rotating mirror is reflecting the four parallel laser beams so that they sweep a 180 degrees area, where some retroreflectors are positioned to hit the beams trajectories.

Every time a beam hits a reflector then it should trigger a sound on a MIDI synth (here it is my little microkorg playing the sounds).

Generative music (a.k.a mangled rhythm)

However in the first try I forgot to set a short loop perid (the period was set to 100ms). Given the velocity of the laser beam when it hits the reflectors there is very little time to catch the signal on the sensors, and with a measure every 100ms the Arduino is missing most hits.

This means we got a simple and regular theoretical rhythm that is mangled by the input sampling process, and this fuzzyness actually creates “interesting” generative music, as in the video:


Generative music installation with laser beams and low-frequency sensors sampling from cyrille martraire on Vimeo.

Note that it is not totally random… (actually it is not random at all, just the result of different frequencies that sometime are in sync and most times are not).

Laser beams on the wall
Laser beams on the wall

Regular rhythm at last

With a shorter Arduino loop period (10ms) it becomes reliable: every (almost) hit triggers a note, as illustrated in the next video where we can hear a steady rhythmic pattern.

The Arduino code is quite simple: for each of the 4 sensors, read analog value, compare to threshold, debounce (not to send multiple notes for the actual same hit), then send MIDI note.

Arduino code for the rhythmic clock project

Laser beams generate regular rhythm at least from cyrille martraire on Vimeo.

Any feedback welcome…

Read More

Playing with laser beams to create very simple rhythms

Just like many arts, music arousal is considered to follow the well-known Wundt curve that defines the balance between attractiveness and boredom. Too much repetition is boring, not enough repetition is confusing and considered just noise.

What for?

Let us assert that idea to music, to generate rhythms. A very simple application of the Wundt curve principle is to consider one given rhythmic pattern (e-g. , “x.x.xx..”) then to build up a more elaborate polyrhythm by combining various repetitions of it, although each copy must be distorted a bit to make the combination more complex hence more attractive. In other word, given a rhythmic seed, make it grow a rhythmic tree.

The transforms to apply to the rhythmic patterns can be linear:

  • Reverse (“..xx.x.x”)
  • Roll (“x.x.xx..”)
  • Scale 2:1 (“x…x…x.x…..”) or 1:2 (“xxx.”)

or non-linear:

  • Truncate (“xx..”)
  • Switch timbre (not really a transform, just to put somewhere)

In practice

To put that into practice I have been trying simple Java programs long ago, but it was too slow a process, and since I did not build a genetic algorithm around it was driven at random.

To make it more fun to investigate, we have started a small project of building an instrument to program rhythms on using laser beams and small reflectors. Each reflector triggers a sound (on a MIDI controlled MPC500) when hit by a laser beam (you need the sound on to listen to the Clap sound being triggered):

Playing with the beams to create very simple rythms from cyrille martraire on Vimeo.

The Arduino board
The Arduino board

Then by having several reflectors linked to each other to make patterns, we expect to be able to program rhythms by moving reflectors sets in the playground, using its geometry to derive the transformations to apply to the patterns.

EDIT: here is another video after some progress:

Playing with dual beams for kick and clap beat from cyrille martraire on Vimeo.

Read More

Akai MPC program editor in Java

I juste wanted to automate the creation of programs for my Akai MPC500 sampler/groove machine, for my personal needs, and I ended up releasing a piece of software to sourceforge. It is called MPC Maid, read “assistant of the MPC”, here is a screenshot of the program editor:

MPC Maid program editor view
MPC Maid program editor view

The MPC file format was freely available on the website of Stephen Norum, very well documented. However my day job is to design and code big financial server-side systems, hence coding at the byte-level was refreshing…

Chop loop into slices

I had been playing around with audio/Music Information Retrieval (MIR) recently for fun, so I took the opportunity to integrate some of that, in the form of a really simple loop slicer.

Audio Slice Editor view
Audio Slice Editor view

You just drag and drop a WAV file from the file explorer into its waveform editor, then it analyzes the audio samples to detects the beats. There is a slider to adjust the sensitivity of the detection, which means this is not a totally automatic algorithm.

The idea for the detection comes from the article “Beat Detection Algorithms” from Frédéric Patin, with some personal modifications. In particular I have added a toggle to prevent a detection immediately after another, and a zero-cross detection to cut the slices on a zero-crossing, in order to reduce the glitches (but of course this is not enough to be perfect, fortunately the MPC has a convenient small decay at the very end of every sample, which solves the problem).

The idea is to compute the energy in sliding time-domain windows,then compare the energy of each window against the average in the surrounding; when it exceeds it enough, there is a beat.

Since many loops available are commercial quality, their length gives the tempo with an extreme accuracy. I used that to generate a MIDI file of the groove of the loop. Coupled with the program edition this allows for exporting the slices, the MPC program that uses them, and the MIDI sequence of their placements, in other words this is roughly equivalent to the REX file idea.

Native-looking but fully portable

Making sure that the software is fully portable and looks native in Mac OS X and in Windows requires careful attention, especially on the Mac side, where the menu is on top of the screen, not the window, the shortcuts are different, and even worst, the menu do not follow the same conventions! For instance the “About” menu is in the Application special menu, not in the Help menu as on Windows. To achieve that in Java requires the Apple OSXAdapter to call by reflection an API that will not be available on non Mac platforms!

Again I hardly do any user interface usually at work, so this little project was overal a good experience to me, and now the users have begun to play with it it is soon to become even more interesting!

Update: here is a video of how to chop a loop almost automatically into slices, then how to play it back at a different tempo on the MPC:

Read More