Skip to content
This repository has been archived by the owner on Oct 9, 2018. It is now read-only.

Commit

Permalink
retab, looking at the files outside an editor was a nightmare
Browse files Browse the repository at this point in the history
  • Loading branch information
bleything committed Apr 3, 2009
1 parent 0c344fa commit 16c9e77
Show file tree
Hide file tree
Showing 23 changed files with 833 additions and 833 deletions.
4 changes: 2 additions & 2 deletions examples/chromatic_scale.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
C5, Cs5, D5, Eb5, E5, F5, Fs5, G5, Gs5, A5, Bb5, B5 ] C5, Cs5, D5, Eb5, E5, F5, Fs5, G5, Gs5, A5, Bb5, B5 ]


scale.each do |note| scale.each do |note|
midi.play note midi.play note
end end


scale.reverse.each do |note| scale.reverse.each do |note|
midi.play note midi.play note
end end
24 changes: 12 additions & 12 deletions examples/metronome.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
@tempo = 120.0 @tempo = 120.0


if input = ARGV[0] if input = ARGV[0]
begin begin
@tempo = Float( input ) @tempo = Float( input )
rescue ArgumentError => e rescue ArgumentError => e
$stderr.puts "'#{input}' is not a valid tempo.\n" $stderr.puts "'#{input}' is not a valid tempo.\n"
$stderr.puts "Please specify the tempo in beats per minute " + $stderr.puts "Please specify the tempo in beats per minute " +
"(bpm). Fractional values are allowed!" "(bpm). Fractional values are allowed!"


exit 1 exit 1
end end
end end


require 'rubygems' require 'rubygems'
Expand Down Expand Up @@ -66,10 +66,10 @@
@timer = MIDIator::Timer.new( @interval / 10 ) @timer = MIDIator::Timer.new( @interval / 10 )


def register_next_bang( time ) def register_next_bang( time )
@timer.at( time ) do |yielded_time| @timer.at( time ) do |yielded_time|
register_next_bang yielded_time + @interval register_next_bang yielded_time + @interval
@midi.play MiddleC @midi.play MiddleC
end end
end end


puts "Starting metronome running at #{@tempo} bpm." puts "Starting metronome running at #{@tempo} bpm."
Expand Down
4 changes: 2 additions & 2 deletions examples/synth.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
C5, Cs5, D5, Eb5, E5, F5, Fs5, G5, Gs5, A5, Bb5, B5 ] C5, Cs5, D5, Eb5, E5, F5, Fs5, G5, Gs5, A5, Bb5, B5 ]


scale.each do |note| scale.each do |note|
midi.play note midi.play note
end end


scale.reverse.each do |note| scale.reverse.each do |note|
midi.play note midi.play note
end end
8 changes: 4 additions & 4 deletions lib/midiator.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
# #


module MIDIator module MIDIator
VERSION = "0.3.0" VERSION = "0.3.0"
end end


##################################################################### #####################################################################
### E X T E R N A L D E P E N D E N C I E S ### E X T E R N A L D E P E N D E N C I E S
##################################################################### #####################################################################
require 'rubygems' require 'rubygems'
require 'platform' require 'platform'


##################################################################### #####################################################################
### C O R E L I B R A R Y E X T E N S I O N S ### C O R E L I B R A R Y E X T E N S I O N S
##################################################################### #####################################################################
require 'string_extensions' require 'string_extensions'


##################################################################### #####################################################################
### M I D I A T O R C O R E ### M I D I A T O R C O R E
##################################################################### #####################################################################
require 'midiator/driver' require 'midiator/driver'
require 'midiator/driver_registry' require 'midiator/driver_registry'
Expand Down
174 changes: 87 additions & 87 deletions lib/midiator/driver.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,127 +22,127 @@


class MIDIator::Driver class MIDIator::Driver


########################################################################## ##########################################################################
### M I D I C O M M A N D C O N S T A N T S ### M I D I C O M M A N D C O N S T A N T S
########################################################################## ##########################################################################


# Note on # Note on
ON = 0x90 ON = 0x90


# Note off # Note off
OFF = 0x80 OFF = 0x80


# Polyphonic aftertouch # Polyphonic aftertouch
PA = 0xa0 PA = 0xa0


# Control change # Control change
CC = 0xb0 CC = 0xb0


# Program change # Program change
PC = 0xc0 PC = 0xc0


# Channel aftertouch # Channel aftertouch
CA = 0xd0 CA = 0xd0


# Pitch bend # Pitch bend
PB = 0xe0 PB = 0xe0


########################################################################## ##########################################################################
### M A G I C H O O K S ### M A G I C H O O K S
########################################################################## ##########################################################################


### Auto-registers subclasses of MIDIator::Driver with the driver registry. ### Auto-registers subclasses of MIDIator::Driver with the driver registry.
def self::inherited( driver_class ) def self::inherited( driver_class )
driver_name = driver_class.to_s.underscore driver_name = driver_class.to_s.underscore
MIDIator::DriverRegistry.instance.register( driver_name, driver_class ) MIDIator::DriverRegistry.instance.register( driver_name, driver_class )
end end




########################################################################## ##########################################################################
### I N T E R F A C E A P I ### I N T E R F A C E A P I
########################################################################## ##########################################################################
# These methods are the same across all drivers and are the interface that # These methods are the same across all drivers and are the interface that
# MIDIator::Interface interacts with. # MIDIator::Interface interacts with.
########################################################################## ##########################################################################


### Do any pre-open setup necessary. Often will not be overridden. ### Do any pre-open setup necessary. Often will not be overridden.
def initialize def initialize
open open
end end




### Shortcut to send a note_on message. ### Shortcut to send a note_on message.
def note_on( note, channel, velocity ) def note_on( note, channel, velocity )
message( ON | channel, note, velocity ) message( ON | channel, note, velocity )
end end




### Shortcut to send a note_off message. ### Shortcut to send a note_off message.
def note_off( note, channel, velocity = 0 ) def note_off( note, channel, velocity = 0 )
message( OFF | channel, note, velocity ) message( OFF | channel, note, velocity )
end end




### Shortcut to send a polyphonic aftertouch message for an individual note. ### Shortcut to send a polyphonic aftertouch message for an individual note.
def aftertouch( note, channel, pressure ) def aftertouch( note, channel, pressure )
message( PA | channel, note, pressure ) message( PA | channel, note, pressure )
end end




### Shortcut to send a control change. ### Shortcut to send a control change.
def control_change( number, channel, value ) def control_change( number, channel, value )
message( CC | channel, number, value ) message( CC | channel, number, value )
end end




### Shortcut to send a program_change message. ### Shortcut to send a program_change message.
def program_change( channel, program ) def program_change( channel, program )
message( PC | channel, program ) message( PC | channel, program )
end end




### Shortcut to send a channel aftertouch message. ### Shortcut to send a channel aftertouch message.
def channel_aftertouch( channel, pressure ) def channel_aftertouch( channel, pressure )
message( CA | channel, pressure ) message( CA | channel, pressure )
end end




### Shortcut to send a pitch bend message. ### Shortcut to send a pitch bend message.
def pitch_bend( channel, value ) def pitch_bend( channel, value )
message( PB | channel, value ) message( PB | channel, value )
end end
alias bend pitch_bend alias bend pitch_bend




########################################################################## ##########################################################################
### D R I V E R A P I ### D R I V E R A P I
########################################################################## ##########################################################################
# subclasses must implement these methods. # subclasses must implement these methods.
########################################################################## ##########################################################################
protected protected
########################################################################## ##########################################################################


### Open the channel to the MIDI service. ### Open the channel to the MIDI service.
def open def open
raise NotImplementedError, "You must implement #open in your driver." raise NotImplementedError, "You must implement #open in your driver."
end end




### Close the channel to the MIDI service. ### Close the channel to the MIDI service.
def close def close
raise NotImplementedError, "You must implement #close in your driver." raise NotImplementedError, "You must implement #close in your driver."
end end




### Send MIDI message to the MIDI service. ### Send MIDI message to the MIDI service.
def message( *args ) def message( *args )
raise NotImplementedError, "You must implement #message in your driver." raise NotImplementedError, "You must implement #message in your driver."
end end




### The only non-required method. Override this to give the user instructions ### The only non-required method. Override this to give the user instructions
### if necessary. ### if necessary.
def instruct_user! def instruct_user!
end end


end end
48 changes: 24 additions & 24 deletions lib/midiator/driver_registry.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,37 +17,37 @@
require 'midiator' require 'midiator'


class MIDIator::DriverRegistry class MIDIator::DriverRegistry
include Singleton include Singleton


### Stores the given +klass+ in the <tt>@drivers</tt> hash, keyed by +name+. ### Stores the given +klass+ in the <tt>@drivers</tt> hash, keyed by +name+.
### Typically called via MIDIator::Driver's +inherited+ hook. ### Typically called via MIDIator::Driver's +inherited+ hook.
def register_driver( name, klass ) def register_driver( name, klass )
@drivers ||= {} @drivers ||= {}


raise ArgumentError, "Attempted to register something that is not a MIDIator::Driver" unless raise ArgumentError, "Attempted to register something that is not a MIDIator::Driver" unless
klass < MIDIator::Driver klass < MIDIator::Driver


@drivers.each do |existing_name, existing_klass| @drivers.each do |existing_name, existing_klass|
raise ArgumentError, "Already registered #{existing_klass.to_s} as '#{existing_name}'." if raise ArgumentError, "Already registered #{existing_klass.to_s} as '#{existing_name}'." if
existing_klass == klass existing_klass == klass
end end


@drivers[ name ] = klass @drivers[ name ] = klass
end end
alias register register_driver alias register register_driver
alias << register_driver alias << register_driver




### Returns the number of drivers currently registered. ### Returns the number of drivers currently registered.
def size def size
return @drivers.size return @drivers.size
end end




### Included to make the registry quack like a hash. Delegates to the ### Included to make the registry quack like a hash. Delegates to the
### <tt>@drivers</tt> hash. ### <tt>@drivers</tt> hash.
def []( name ) def []( name )
return @drivers[ name ] return @drivers[ name ]
end end


end end
Loading

0 comments on commit 16c9e77

Please sign in to comment.