Permalink
Browse files

This is some code which generates melodies from text files.

  • Loading branch information...
1 parent 2a051f3 commit ffe84eaf074e84fcc9b2dfe7f7a7ac4854a0bb9a @gilesbowkett committed Oct 18, 2008
Showing with 32 additions and 2 deletions.
  1. +1 −1 lib/midi/practical_ruby_projects/live_midi.rb
  2. +5 −0 muppets
  3. +26 −1 text2tone.rb
@@ -25,7 +25,7 @@ def to_code
def initialize(options)
@clock = options[:clock]
@logging = options[:logging]
- @midi_destination = options[:midi_destination]
+ @midi_destination = options[:midi_destination] || 0
if @logging
puts <<LOG_PLAYBACK
require 'lib/archaeopteryx'
View
@@ -0,0 +1,5 @@
+gonzo
+miss piggy
+kermit
+fozzie bear
+big bird
View
@@ -1,3 +1,28 @@
+# usage: ruby text2tone.rb muppets
+
require 'lib/archaeopteryx'
-LiveMIDI.new(:clock => Clock.new(101))
+clock = Clock.new(101)
+midi = LiveMIDI.new(:clock => clock, :logging => false)
+
+def note(midi_note_number)
+ Note.create(:channel => 0,
+ :number => midi_note_number,
+ :duration => 0.25,
+ :velocity => 100 + rand(27))
+end
+
+
+file = ARGV[0]
+base_note = 60 # middle C
+
+File.new(file).each_line do |line|
+ line.split.each do |word|
+ midi.play(note(base_note + word.length))
+ clock.tick
+ end
+end
+
+while true
+ gets
+end

0 comments on commit ffe84ea

Please sign in to comment.