Ruby MIDI DJing/live-coding thing
Pull request Compare This branch is 6 commits ahead, 33 commits behind gilesbowkett:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Matt's fork of Arkx with a "Context Free" generator added on, see below.

Archaeopteryx readme:
Alpha! Not release-ready! Here be dragonnes! etc.

Archaeopteryx is a MIDI system for Ruby based on code from Topher Cyll's book "Practical Ruby

Archaeopteryx successfully generates original drum and bass rhythms, synchs original rhythms to
MP3 playback, and crossfades between existing MP3 tracks.

Archaeopteryx is a Ruby front-end to prosumer music software such as Propellerhead Reason and
Ableton Live. You need a MIDI consumer to get anything useful out of it. 

CFM Readme:
== Context Free Music Generator ==
by Matt Constantine (designmc at gmail, matt20120 on aim)

== What is this thing?
The idea behind CFM is to do for music what Context Free Art (see does for graphics. It might not be considered "context free" in the end, but that's the inspiration nevertheless.

It's a rule based generator, not necessarily just for melodies. For example, drum_example.rb uses a probability matrix to fire off rules. Those rules can call other rules and so on. If a rule is defined more than once, the generator picks randomly from each of them.

So a matrix could call a rule named :snare which is defined several times each time doing something different, varying a velocity, note number, or whatever. Say I want a bit more variation in what the snare is doing, I can make a rule that plays a triplet and hear the results realtime. And when it plays a triplet, maybe I want the last note accented, another rule or two and it's done.

The point is, is that it allows me to develop a rhythm or aleatoric melody and evolve it over time. It's pretty easy to get started with it playing quarter notes, or a scale or whatever, and turn that into something insanely complex as more and more rules are added. Each of the transformations become little toys to experiment with. A programmer/musician can develop what-ifs and hear those live. What if I send all the hi-hat hits back in time a beat or two, what if I shift this part up an octave? What if I play a static melody and shift it from dorian to lydian? What if I create a treble glissando triggered off of the tone of the occasional note of the sub-bass?

I don't know what kind of music this will be good for, but I know from the ContextFree Art community that the concept is a ton of fun (their community gallery at has lots of examples). It's interesting to see what we get with that applied to music.

== Getting Started
To see this in action, first make sure you have a Midi synth hooked up and running, GarageBand will work just fine. See Evan Light's tutorial to get started with GarageBand: 
Make sure you have a melodic patch of some sort loaded electric piano works nice. 

Then run 'ruby eval_cfm.rb cfm/styles/example.rb' to get started. 

Each file in /styles/ defines a set of rules to generate a piece of music. Each rule passes a transformation to other rules. 

If a rule is specified more than once, the CFM renderer randomly chooses between the two. For example, if a rule name :foo transforms notes up and another rule named :foo transforms them down, CFM will pick between the two producing a random walk. If a rule contains a 'm.note!' command, that rule will produce a note.

Basic transformations include: 
  :scale - sets the musical scale for child motifs to follow.
  :pitch - sets the absolute pitch for the context
  :beat - sets the absolute beat for the context
  :up or :down - changes pitch relative to the context
  :forward or :backward changes the beat relative to the context
  :harder or :softer changes the midi velocity, generally how loudly a note is played.
  :duration - sets a absolute duration for a note (no relative controls yet)
  :generations - sets the maximum number of descendent motifs a rule can produce. This provides a limit to recursion. You can overwrite this in descendent motifs, but there's no safety net for the time being.

The m.note! command plays a note. It takes transformations just like the rules.

The m.matrix triggers rules using a probability matrix just like the Arkx beat generator. Because it triggers rules and rules can do anything this opens up some new creative options for beats.

The notes produced by CFM are placed onto a matrix called the Canvas. Each point on the canvas is a hash. When a note is placed over an existing note its properties are merged with Hash#merge. So for example, one m.matrix function could specify the pitches to play, while another specifies the velocity to play each pitch. Once support is added in for tweaking midi controllers many more possibilities will emerge.

True to Arkx nature, rules can be tweaked in a realtime performance.

Thanks to Giles for the wonder that is Arkx. Thanks to Jeremy Voorhis for the abs_pitch class.