Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Ruby DSL for MIDI

branch: master
Octocat-spinner-32 examples w/o block example September 18, 2011
Octocat-spinner-32 lib version November 07, 2011
Octocat-spinner-32 test play chord with flexible args November 07, 2011
Octocat-spinner-32 .gitignore first July 07, 2011
Octocat-spinner-32 LICENSE first July 07, 2011
Octocat-spinner-32 README.rdoc Update README.rdoc March 14, 2012
Octocat-spinner-32 Rakefile rakefile August 15, 2011
Octocat-spinner-32 TODO update todo September 18, 2011
README.rdoc

micromidi

A Ruby DSL for MIDI

Features

  • Cross-platform compatible using MRI or JRuby.

  • Simplified MIDI and Sysex message output

  • MIDI Thru, processing and custom input events

  • Optional shorthand for live coding

Installation

gem install micromidi

Requirements

Ruby 1.9.2+ or JRuby in 1.9 mode

Requires midi-eye, midi-message and unimidi. These should install automatically with the gem.

Usage

The following are basic examples that use unimidi inputs and outputs.

require "midi"

# prompt the user to select an input and output in the console...

@i = UniMIDI::Input.gets
@o = UniMIDI::Output.gets

This example plays some arpeggios

MIDI.using($o) do

  5.times do |oct|
    octave oct
    %w{C E G B}.each { |n| play n 0.5 }
  end

end

While running, this next example sends all input directly to the output except for notes; notes that are received are only sent to the output if their octave is between 1 and 3. Output is also printed to the console by passing $stdout along with the MIDI devices.

MIDI.using(@i, @o, $stdout) do

  thru_except :note { |msg| only(msg, :octave, (1..3)) }

  join

end

This is the same example redone using shorthand aliases

M(@i, @o) do

  te :n { |m| only(m, :oct, (1..3)) }

  j

end

Finally, here is an example that maps some MIDI Control Change messages to SysEx

MIDI.using(@i, @o) do

  *@the_map =
    [0x40, 0x7F, 0x00],
    [0x41, 0x7F, 0x00],
    [0x42, 0x7F, 0x00]

  node :roland, :model_id => 0x42, :device_id => 0x10

  receive :cc do |message|

    command @the_map[message.index - 1], message.value

  end

end

I've written up a few posts explaining each of the concepts used here in greater detail:

Documentation

Author

License

Apache 2.0, See the file LICENSE

Copyright © 2011 Ari Russo

Something went wrong with that request. Please try again.