Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

This is some code which generates melodies from text files.

  • Loading branch information...
commit ffe84eaf074e84fcc9b2dfe7f7a7ac4854a0bb9a 1 parent 2a051f3
Giles authored
2  lib/midi/practical_ruby_projects/live_midi.rb
View
@@ -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'
5 muppets
View
@@ -0,0 +1,5 @@
+gonzo
+miss piggy
+kermit
+fozzie bear
+big bird
27 text2tone.rb
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
Please sign in to comment.
Something went wrong with that request. Please try again.