MIDI arpeggiator in Ruby


  • Classic arpeggiator functions which can be controlled via OSC or MIDI

  • Cross-platform compatibile using Ruby 1.9 (MRI) or JRuby

  • Run in a background thread for live coding

  • Generate or sync to MIDI clock

  • Sync between multiple Diamond instances

  • Preset and user-definable pattern algorithms


gem install diamond


Ruby 1.9.2+ or JRuby in 1.9 mode

Requires the diamond-engine and osc-access gems (as well as all of their dependencies). These should install automatically when you install Diamond using the gem.


require "diamond"

First, select a MIDI output using unimidi. (more…)

@output = UniMIDI::Output.gets

The Arpeggiator has a number of optional parameters. For this example, here's a straightforward setup

opts = { 
  :gate => 90, 
  :interval => 7,
  :midi => @output,
  :pattern => Diamond::Pattern["UpDown"],
  :range => 4,     
  :rate => 8

Create an Arpeggiator object, passing in a tempo value and the options above. In this case the tempo will be 138 BPM

arp = Diamond::Arpeggiator.new(138, opts)

Of course, an arpeggiator needs notes to work with. As you might expect, it's easy to use a MIDI input for that. (see example). However, again for the sake of simplicity here's a chord in Ruby

chord = ["C3", "G3", "Bb3", "A4"]

Use Arpeggiator#add and Arpeggiator#remove to change the notes that the arpeggiator sees. (Arpeggiator#<< is the same as add)

arp << "C5"

Now start the arpeggiator. By default, the arpeggiator will run in a background thread so if you are working in IRB this will allow you to live code, sync it other arpeggiators, or just run another foreground process. (To start in the foreground, just pass :focus => true to Arpeggiator#start)


All of the arpeggiator options can be controlled on the on the fly

arp.rate = 16
arp.gate = 20  
arp.remove("C5", "A4")

This screencast video shows Diamond being live coded in this way… and this blog post explains

Check out these posts and examples for more




Other Documentation



Apache 2.0, See the file LICENSE

Copyright © 2011 Ari Russo