Skip to content
Browse files

Fixed tyop in midi#play. Added drum_chords.rb to show MIDIator::Drums…

… usage

Signed-off-by: Ben Bleything <ben@bleything.net>
  • Loading branch information...
1 parent 6d240d4 commit 057fc2597ccb8ac713e4b094cc79a70edaafdca9 @dbrady dbrady committed with bleything Jan 15, 2009
Showing with 42 additions and 5 deletions.
  1. +1 −1 examples/chords.rb
  2. +37 −0 examples/drum_chords.rb
  3. +4 −4 lib/midiator/interface.rb
View
2 examples/chords.rb
@@ -12,7 +12,7 @@
song = [ C3, C4MAJ, C3, C4MAJ, F3, F4MAJII, F3, F4MAJII, G3, G4MAJ, G3, G4MAJ, C5, C4MAJ, C2, C4MAJ]
-2.times do
+4.times do
song.each do |note|
midi.play note, 0.25
end
View
37 examples/drum_chords.rb
@@ -0,0 +1,37 @@
+#!/usr/bin/env ruby
+# Plays a simple polyphonic drumbeat.
+require 'rubygems'
+require 'midiator'
+
+midi = MIDIator::Interface.new
+midi.autodetect_driver
+
+midi.control_change 32, 10, 1 # TR-808 is Program 26 in LSB bank 1
+midi.program_change 10, 26
+
+include MIDIator::Drums
+
+song = [ BassDrum1,
+ [BassDrum2, SnareDrum1],
+ BassDrum1,
+ [BassDrum1, SnareDrum1, SnareDrum2, CrashCymbal1]
+]
+riff = [ HighTom1, HighTom2, LowTom1, LowTom2 ]
+
+# This starts to push the usability limit of play.
+4.times do
+ song.each do |note|
+ midi.play note, 0.25, 10
+ end
+end
+riff.each do |note|
+ midi.play note, 0.067, 10
+end
+midi.play CrashCymbal2, 0.25, 10
+
+4.times do
+ song.each do |note|
+ midi.play note, 0.25, 10
+ end
+end
+
View
8 lib/midiator/interface.rb
@@ -85,12 +85,12 @@ def use( driver_name )
### specified +duration+. If +note+ is an array, all notes in it are
### played as a chord.
def play( note, duration = 0.1, channel = 0, velocity = 100 )
- [notes].flatten.each do |note|
- @driver.note_on( note, channel, velocity )
+ [note].flatten.each do |n|
+ @driver.note_on( n, channel, velocity )
end
sleep duration
- [notes].flatten.each do |note|
- @driver.note_off( note, channel, velocity )
+ [note].flatten.each do |n|
+ @driver.note_off( n, channel, velocity )
end
end

0 comments on commit 057fc25

Please sign in to comment.
Something went wrong with that request. Please try again.