hex705

the first creature to discover water was likely not a fish

Processing – MIDI — GarageBand

leave a comment

Processing can be used as a MIDI controller with Garage Band — this brief tutorial will get you started. There are limitations to this system — but it is enough to do some simple sound experiments. This is a basic introduction only.

MIDI (musical instrument digital interface) is a serial protocol that permits communication between computers and electronic instruments.  It defines the rate of communication, message structure and a grammar that is shared by standard compliant devices.  MIDI was defined in 1982.

On a basic level MIDI separates controllers from sound modules or voice banks.  A controller is any device that can send note messages (triggers) to sound modules.  These may be electronic keyboards, MIDI drum kits, an Arduino with MIDI interface or for this example, PROCESSING.  A voice bank is a software application, or hardware device that receives messages from controllers and generates sounds based on those messages.  We will use GARAGE BAND as our voice bank.

What you will Need

Getting Started

In this example, we will use Processing to send MIDI messages to GarageBand.  The messages must pass through the IAC driver in your MAC and this must be configured to get you up and running.  Processing will require an external library to be installed.  Both of these steps are straight forward.

Configuring the IAC Driver

  1. Open Audio MIDI setup ( it is in Applications –> Utilities )AUdio_anotate.001
  2. Open the MIDI  window :midiWindow
  3. Once opened, double-click IAC driver icon to reveal the IAC driver Properties, find and select Device is online.IAC_selectOnline
  4. You can now QUIT Audio MIDI setup.

Set-up Garage Band (I am using GB ’09, version 5.0)

  1. Launch Garage Band.  NOTE: This is NOT a Garage Band tutorial.
  2. From Pop-up, select: New Project–> Piano (use defaults).
  3. You should have basic window with one or more tracks.
  4. Click on the Grand Piano track — so that it is highlighted green.GB_piano
  5. On the lower left of GB, Below the tracks, SHOW the track editor  by clicking on the scissor and sound icon — hit a key on the keyboard you just revealed — you should hear a note.  If not, check your speakers.edit
  6. Leave GB open — and set up processing.

Import and Install RWMidi Library for Processing

  1. All external libraries for Processing must reside in a folder called libraries in the default Processing sketch folder. If this folder does not exist, create it.
  2. OPEN the folder: User — > Documents –> Processing and find or create libraries (small ‘l’ and plural).  OPEN libraries.
  3. DOWNLOAD and unzip the RWMidi Library.
  4. Drop the unzipped RWMidi folder into libraries folder from above.
  5. (re)-Launch Processing.

Make Some Noise

  1. Run the sample code below.
  2. Mouse CLicks on sketch will generate a single note of fixed duration
  3. keys: ‘a’,’s’,’d’,’f’ will generate notes with length determines by keyPressed duration.
  4. You may need to adjust system preferences –> keyboard to handle key repeats.

SAMPLE CODE

DOWNLOAD EXAMPLES


//
// see http://www.hex705.com/processing-midi-garage-band/
// created by hex705,  steve daniels, January 2011.
// 

// use 'a','s','d','f' to send note signals to Garage Band
// change your keyboard setting in sys preferences if you want to control repeats and duration
// mouse sends fixed length notes

import rwmidi.*;

MidiOutput output;

// variables for note generation from keystrike
int aChannel,  sChannel,  dChannel,  fChannel;
int aNote,     sNote,     dNote,     fNote;
int aVelocity, sVelocity, dVelocity, fVelocity;
int aSuccess,  sSuccess,  dSuccess,  fSuccess;

void setup() {

  size(256,256);

  // just like serial ports, you can list the devices if you like
  /*
  println("output devices");
  println(RWMidi.getOutputDevices());
  println("\ninput devices");
  println(RWMidi.getInputDevices());
  */

  // creates a connection to IAC as an output
  output = RWMidi.getOutputDevices()[0].createOutput();  // talks to garageband  

}

void draw() {
  // nothing here
}

void mousePressed() {

  // send a note 400 mS long
  int duration = 400;

  int channel  = 1;    // GB seems to ignore this, but mehtod needs it
  int note     = 60;   // midi notes are numbered 0 -127 -- not all notes are played by all voices
  int velocity = 127;  // range 0-127, 127= max

  int success = output.sendNoteOn(channel, note, velocity);  // sendNoteOn returns 0 = fail, 1 = success
  delay(duration);  // note length  -see keys below for better solution
  success =    output.sendNoteOff(channel, note, velocity);  // sendNoteOff returns 0 = fail, 1 = success

}

void keyPressed(){

  if (key == 'a' || key == 'A' ) {
    aChannel = 1;
    aNote = 60;
    aVelocity = 127;
    aSuccess = output.sendNoteOn(aChannel, aNote, aVelocity); // note return a variabel of type INT
  }

  if (key == 's' || key == 'S' ) {
    sChannel = 1;
    sNote = 61;
    sVelocity = 127;
    sSuccess = output.sendNoteOn(sChannel, sNote, sVelocity); // note return a variabel of type INT
  }

  if (key == 'd' || key == 'D' ) {
    dChannel = 1;
    dNote = 62;
    dVelocity = 127;
    dSuccess = output.sendNoteOn(dChannel, dNote, dVelocity); // note return a variabel of type INT

  }

  if (key == 'f' || key == 'F' ) {
    fChannel = 1;
    fNote = 63;
    fVelocity = 127;
    fSuccess = output.sendNoteOn(fChannel, fNote, fVelocity); // note return a variabel of type INT

  }

}

void keyReleased(){

  if (key == 'a' || key == 'A' ) {

    aSuccess = output.sendNoteOff(aChannel, aNote, aVelocity); // note return a variabel of type INT

  }

  if (key == 's' || key == 'S' ) {

    sSuccess = output.sendNoteOff(sChannel, sNote, sVelocity); // note return a variabel of type INT

  }

  if (key == 'd' || key == 'D' ) {

    dSuccess = output.sendNoteOff(dChannel, dNote, dVelocity); // note return a variabel of type INT

  }

  if (key == 'f' || key == 'F' ) {

    fSuccess = output.sendNoteOff(fChannel, fNote, fVelocity); // note return a variabel of type INT

  }

}

Caveats

  • Garage Band can only be one voice at a time — ie the voice can be a keyboard OR a drum kit — but not both on the same track.
  • there does not appear to be a way to route multiple midi inputs to different voices / tracks in garage band (but I could be wrong about that).
  • even with a general MIDI instrument setup on a track, garage band does not playback different voices when it receives Program Change messages on the fly.  It does properly interpret Program Change messages during recording — but you will only hear a difference on playback (not while recording).  I don’t know what that is about (suggestions?).

Written by hex705

February 6th, 2011 at 12:28 pm

Posted in Sounds

Tagged with , , , ,