Using Indigo to Control MIDI Devices

Posted on
Thu Sep 02, 2010 10:46 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Using Indigo to Control MIDI Devices

As a follow-up to my post on Using MIDI to Control Indigo, here's how you can use Indigo to control a MIDI device (in this case, one that's connected to a machine on your local network) by using Indigo triggers and the same "MidiPipe" freeware application (http://homepage.mac.com/nicowald/SubtleSoft/) described in my other post.

STEPS:

  1. Enable Remote Apple Events on the Mac to which your MIDI gear that you want to control is attached. Do this by opening System Preferences, selecting "Sharing" then putting a check in "Remote Apple Events". For added security, set it to only allow remote commands from Administrators (or just your account).
  2. Download and install MidiPipe to the same machine to which you just enabled Remote Apple Events (link provided above).
  3. On the right side of the MidiPipe window, there'll be a "Pipes" pane. You can optionally name the "unnamed pipe" something appropriate like "Indigo to Keyboard" by erasing the "unnamed pipe" and typing your new pipe name then hitting the Return key (hitting the Return key is important).
    1. Add the first module to the pipe by dragging "Midi In" from the left pane to the top of the right pane. Configure it to accept input from the "MidiPipe Input 1" virtual input (which is created by default when you install and run MidiPipe) by selecting that option at the bottom of the MidiPipe window.
    2. Add the "Midi Out" module to the pipe (below "Midi In") and set its output to the MIDI interface or MIDI instrument attached to the Mac.
  4. On the Mac running Indigo, open the Indigo 4 client application. We're going to create a new trigger that sends a remote Apple Event to MidiPipe on your other Mac.
  5. Click on TRIGGERS (or any folder within that category) in the left column. Click the New button at the top of the window.
  6. As an example, we'll set up the trigger to play a short broken C chord whenever the lights in the room turn on or off. Use the following settings for the Trigger tab.
    • Name: (Whatever you like. I used "Music Room Light Send MIDI").
    • Type: Device State Changed
    • Device: (Your device. I chose my Music Room Light). Set the condition to "On/Off State" and sub-condition to "Has Any Change".
    In the Condition tab, set it to "Always". Use the following settings in the Actions tab.
    • Type: Execute AppleScript
    • Select the "Embedded" radio button and enter the following code into the text entry field.
      Code: Select all
      tell application "MidiPipe" of machine "eppc://<admin username>:<admin password>@<your MIDI computer name>.local"
          MIDISend toPort "MidiPipe Input 1" withData {144, 48, 75}
          delay 0.2
          MIDISend toPort "MidiPipe Input 1" withData {144, 52, 80}
          delay 0.2
          MIDISend toPort "MidiPipe Input 1" withData {144, 55, 67}
          delay 0.2
          MIDISend toPort "MidiPipe Input 1" withData {144, 60, 70}
          delay 4
          
          MIDISend toPort "MidiPipe Input 1" withData {128, 48, 40}
          delay 0.2
          MIDISend toPort "MidiPipe Input 1" withData {128, 52, 45}
          delay 0.2
          MIDISend toPort "MidiPipe Input 1" withData {128, 55, 46}
          delay 0.2
          MIDISend toPort "MidiPipe Input 1" withData {128, 60, 36}
      end tell
         

  7. Change the <admin username>, <admin password>, and <your MIDI computer name> to the correct information. For instance, if your short login name on the Mac with your MIDI gear attached is "jdoe", that's what you'll put for <admin username>, and you'll put your login password for the <admin password>. Note that if you use special characters like dollar signs, percent signs, spaces, etc, those characters will have to be URL encoded which, while not hard, is a bit beyond the topic of this post. Replace <your MIDI computer name> with the Bonjour computer name listed in the Sharing control pane of System Preferences on the computer with the MIDI gear attached (it ends in ".local" and is shown in small text under "Computer Name" in the Sharing control pane).
  8. Click the OK button to finish creating the trigger.
  9. Try out the trigger by turning on or off the device you selected in the Trigger tab of the trigger you just created. Your remotely attached MIDI keyboard or synth should produce a short broken C chord.

WAHT THE APPLESCRIPT DOES:

The above AppleScript connects to your Mac with the MIDI gear attached and tells the MidiPipe application to send MIDI messages via the MidiPipe virtual MIDI input. In earlier steps, you set MidiPipe to accept input on this virtual interface and resend it to your attached MIDI gear (keyboard or other synth).

Here's what the data in each of those MIDISend instructions does. The first item defines the type of MIDI command. Integer 144 represents a MIDI "Note On" message on MIDI channel 1 (a value of 145 would be the same message on MIDI channel 2, 146 on channel 3, etc. up to channel 16). Value 128 is a MIDI "Note Off" message on MIDI channel 1. The second item in the data defines the sub-type of MIDI message. For Note On and Note Off messages, integers 0 through 127 represent notes on the keyboard (yes, MIDI allows for 128 different notes, not just the 88 found on a piano). In this case, 48, 52, 55, and 60 represent C3, E3, G3, and C4 on the keyboard, respectively. The third item in the data sent with each MIDISend instruction is the specific value associated with the MIDI sub-type. For Note On and Note Off messages, this third item is the On- or Off- "velocity" (how fast you pressed or released the key) and has a range of 0 to 127. With almost all MIDI instruments, the On-velocity controls how loud the note sounds, but it can also change sound characteristics of the note. Off-velocity is often only supported on pro-sumer or professional MIDI gear so, while I put it in the above data, any value from 0 to 127 would likely work, as long as some value is included. The "delay" instructions simply tell the AppleScript interpreter to pause before going on to the next instruction. Here, it simulates a rolled (or broken) chord held for 4 seconds.

Any feedback, questions, or comments are welcome.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests