MIDI arpeggiator in Ruby



  • Classic arpeggiator functionality and patterns
  • OSC and MIDI remote control
  • MIDI clock IO
  • Multiplex clocks and arpeggiators
  • Suited to live coding
  • Generative arpeggio patterns


gem install diamond

or with Bundler, add this to your Gemfile

gem "diamond"


require "diamond"

First, select a MIDI output using unimidi. (more about that here)

@output = UniMIDI::Output.gets

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

options = {
  :gate => 90,
  :interval => 7,
  :midi => @output,
  :pattern => "UpDown",
  :range => 4,
  :rate => 8

arpeggiator = Diamond::Arpeggiator.new(options)

Create a clock object, passing in a tempo value. In this case the tempo will be 138 BPM

clock = Diamond::Clock.new(138)

Point the clock to the arpeggiator

clock << arpeggiator

The arpeggiator will play based on inputted notes or chords; a MIDI input can be used for that. (see example). It's also possible to enter notes 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)

arpeggiator << "C5"

Starting the clock will also start the arpeggiator:


Note that by default, the clock will run in a background thread. If you're working in a PRY/IRB/etc this will allow you to continue to code while the arpeggiator runs. To start in the foreground, pass :focus => true to Clock#start.

All of the arpeggiator options can be controlled while the arpeggiator is running.

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

This screencast video shows Diamond being live coded in this way. (Note that the API has changed a bit since 2011 when the video was made).

This blog post explains what is happening in the video.




Other Documentation



Apache 2.0, See the file LICENSE

Copyright (c) 2011-2015 Ari Russo