This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
abstracted some stuff for dealing with the midi interface and generat…
…ing notes
- Loading branch information
Matt Lyon
committed
Oct 31, 2008
1 parent
634cabf
commit 2c3e93d
Showing
9 changed files
with
121 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'midiator' | ||
|
||
class Midiator | ||
|
||
attr_accessor :interface | ||
|
||
def initialize | ||
@interface = MIDIator::Interface.new | ||
end | ||
|
||
def note(channel, pitch, velocity) | ||
@interface.driver.note_on(pitch, channel, velocity) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Ouroubourus | ||
module Midi | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Ouroubourus | ||
module MIDI | ||
module Generator | ||
|
||
def play(notes) | ||
[notes].flatten.each do |note| | ||
if note.start.zero? | ||
note_on(note.channel, note.pitch, note.velocity) | ||
@schedule.in(note.duration, L{ note_off(note.channel, note.pitch)}) | ||
else | ||
@schedule.in(note.start, L{ note_on(note.channel, note.pitch, note.velocity) }) | ||
@schedule.in(note.start + note.duration, L{ note_off(note.channel, note.pitch) }) | ||
end | ||
end | ||
end | ||
|
||
def note_on(channel, pitch, velocity) | ||
@interface.note(channel, pitch, velocity) | ||
end | ||
|
||
def note_off(channel, pitch) | ||
note_on(channel, pitch, 0) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Ouroubourus | ||
module MIDI | ||
class Note | ||
|
||
attr_reader :pitch, :velocity, :duration, :start, :channel | ||
|
||
def initialize(p, vel, dur, chan=1, s=0) | ||
self.pitch = p | ||
self.velocity = vel | ||
self.channel = chan | ||
self.duration = dur | ||
self.start = s | ||
end | ||
|
||
def pitch=(val) | ||
@pitch = seven_bit(val) | ||
end | ||
|
||
def velocity=(val) | ||
@velocity = seven_bit(val) | ||
end | ||
|
||
def channel=(val) | ||
val = 1 if val < 1 | ||
val = 16 if val > 16 | ||
@channel = val | ||
end | ||
|
||
def duration=(val) | ||
@duration = [1,val].max | ||
end | ||
|
||
def start=(val) | ||
@start = [0,val].max | ||
end | ||
|
||
protected | ||
def seven_bit(val) | ||
val = 0 if val < 0 | ||
val = 127 if val > 127 | ||
val | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters