midiator 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/examples/chromatic_scale.rb +33 -0
- data/examples/metronome.rb +75 -0
- data/lib/midiator.rb +32 -0
- data/lib/midiator/driver.rb +100 -0
- data/lib/midiator/driver_registry.rb +53 -0
- data/lib/midiator/drivers/alsa.rb +52 -0
- data/lib/midiator/drivers/core_midi.rb +82 -0
- data/lib/midiator/drivers/winmm.rb +49 -0
- data/lib/midiator/drums.rb +39 -0
- data/lib/midiator/exceptions.rb +18 -0
- data/lib/midiator/interface.rb +90 -0
- data/lib/midiator/notes.rb +93 -0
- data/lib/midiator/timer.rb +62 -0
- data/lib/string_extensions.rb +59 -0
- data/misc/rake/packaging.rb +50 -0
- data/misc/rake/rdoc.rb +45 -0
- data/misc/rake/testing.rb +32 -0
- data/spec/driver_registry_spec.rb +115 -0
- data/spec/driver_spec.rb +29 -0
- data/spec/interface_spec.rb +128 -0
- data/spec/string_extensions_spec.rb +35 -0
- metadata +76 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Rake tasks related to testing.
|
4
|
+
#
|
5
|
+
# == Authors
|
6
|
+
#
|
7
|
+
# * Ben Bleything <ben@bleything.net>
|
8
|
+
#
|
9
|
+
# == Copyright
|
10
|
+
#
|
11
|
+
# Copyright (c) 2008 Ben Bleything
|
12
|
+
#
|
13
|
+
# This code released under the terms of the MIT license.
|
14
|
+
#
|
15
|
+
|
16
|
+
require 'spec/rake/spectask'
|
17
|
+
|
18
|
+
desc "Run the RSpec suite"
|
19
|
+
Spec::Rake::SpecTask.new( :spec ) do |r|
|
20
|
+
r.libs = SPEC_FILES
|
21
|
+
r.spec_opts = %w(--format specdoc --color)
|
22
|
+
end
|
23
|
+
|
24
|
+
namespace :spec do
|
25
|
+
### Run the specifications and generate coverage information
|
26
|
+
Spec::Rake::SpecTask.new( :coverage ) do |r|
|
27
|
+
r.rcov = true
|
28
|
+
r.rcov_dir = 'coverage'
|
29
|
+
r.rcov_opts = %w( -x Library\/Ruby,^spec )
|
30
|
+
r.libs = SPEC_FILES
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Contains the specifications for the MIDIator::DriverRegistry class.
|
4
|
+
#
|
5
|
+
# == Authors
|
6
|
+
#
|
7
|
+
# * Ben Bleything <ben@bleything.net>
|
8
|
+
#
|
9
|
+
# == Copyright
|
10
|
+
#
|
11
|
+
# Copyright (c) 2008 Ben Bleything
|
12
|
+
#
|
13
|
+
# This code released under the terms of the MIT license.
|
14
|
+
#
|
15
|
+
|
16
|
+
require File.join( File.dirname(__FILE__), 'lib', 'spec_helper.rb' )
|
17
|
+
|
18
|
+
describe MIDIator::DriverRegistry do
|
19
|
+
before( :all ) do
|
20
|
+
# alias MIDIator::Driver's inherited method out of the way and
|
21
|
+
# redefine it as a no-op. This prevents MIDIator::Driver from trying
|
22
|
+
# to auto-register subclasses.
|
23
|
+
MIDIator::Driver.instance_eval {
|
24
|
+
class << self
|
25
|
+
alias_method :old_inherited, :inherited
|
26
|
+
end
|
27
|
+
|
28
|
+
def self::inherited( klass )
|
29
|
+
# no-op
|
30
|
+
end
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
after( :all ) do
|
35
|
+
# move MIDIator::Driver's inherited method back into place
|
36
|
+
MIDIator::Driver.instance_eval {
|
37
|
+
class << self
|
38
|
+
alias_method :inherited, :old_inherited
|
39
|
+
end
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
before( :each ) do
|
44
|
+
@registry = MIDIator::DriverRegistry.instance
|
45
|
+
|
46
|
+
@driver_fixture = {
|
47
|
+
:a => "is for apple",
|
48
|
+
:b => "is for bunches of apples"
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
after( :each ) do
|
53
|
+
@registry.instance_variable_set( :@drivers, nil )
|
54
|
+
end
|
55
|
+
|
56
|
+
it "is a Singleton" do
|
57
|
+
lambda { MIDIator::DriverRegistry.new }.should raise_error
|
58
|
+
MIDIator::DriverRegistry.should respond_to( :instance )
|
59
|
+
end
|
60
|
+
|
61
|
+
it "knows how many drivers are registered" do
|
62
|
+
@registry.instance_variable_set( :@drivers, @driver_fixture )
|
63
|
+
@registry.size.should == @driver_fixture.size
|
64
|
+
end
|
65
|
+
|
66
|
+
it "can be dereferenced as though it was a hash" do
|
67
|
+
@registry.instance_variable_set( :@drivers, @driver_fixture )
|
68
|
+
@driver_fixture.keys.each do |key|
|
69
|
+
@registry[ key ].should == @driver_fixture[ key ]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "aliases #register_driver to #register and #<<" do
|
74
|
+
register_driver = @registry.method( :register_driver )
|
75
|
+
|
76
|
+
@registry.method( :<< ).should == register_driver
|
77
|
+
@registry.method( :register ).should == register_driver
|
78
|
+
end
|
79
|
+
|
80
|
+
it "keeps track of registered drivers by name" do
|
81
|
+
Bees = Class.new( MIDIator::Driver )
|
82
|
+
Sandwiches = Class.new( MIDIator::Driver )
|
83
|
+
Guns = Class.new( MIDIator::Driver )
|
84
|
+
|
85
|
+
@registry.register( :bees, Bees )
|
86
|
+
@registry.register( :sandwiches, Sandwiches )
|
87
|
+
@registry.register( :guns, Guns )
|
88
|
+
|
89
|
+
@registry[ :bees ].should be( Bees )
|
90
|
+
@registry[ :sandwiches ].should be( Sandwiches )
|
91
|
+
@registry[ :guns ].should be( Guns )
|
92
|
+
end
|
93
|
+
|
94
|
+
it "prevents anything other than a MIDIator::Driver subclass from being registered" do
|
95
|
+
lambda {
|
96
|
+
@registry.register( :failboat, String )
|
97
|
+
}.should raise_error( ArgumentError, "Attempted to register something that is not a MIDIator::Driver" )
|
98
|
+
|
99
|
+
lambda {
|
100
|
+
@registry.register( :great_success, Class.new( MIDIator::Driver ) )
|
101
|
+
}.should_not raise_error
|
102
|
+
end
|
103
|
+
|
104
|
+
it "prevents a single driver from being registered multiple times" do
|
105
|
+
klass = Class.new( MIDIator::Driver )
|
106
|
+
|
107
|
+
lambda {
|
108
|
+
@registry.register( :first_try, klass )
|
109
|
+
}.should_not raise_error
|
110
|
+
|
111
|
+
lambda {
|
112
|
+
@registry.register( :second_try, klass )
|
113
|
+
}.should raise_error( ArgumentError, "Already registered #{klass.to_s} as 'first_try'." )
|
114
|
+
end
|
115
|
+
end
|
data/spec/driver_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Contains the specifications for the MIDIator::Driver class.
|
4
|
+
#
|
5
|
+
# == Authors
|
6
|
+
#
|
7
|
+
# * Ben Bleything <ben@bleything.net>
|
8
|
+
#
|
9
|
+
# == Copyright
|
10
|
+
#
|
11
|
+
# Copyright (c) 2008 Ben Bleything
|
12
|
+
#
|
13
|
+
# This code released under the terms of the MIT license.
|
14
|
+
#
|
15
|
+
|
16
|
+
require File.join( File.dirname(__FILE__), 'lib', 'spec_helper.rb' )
|
17
|
+
|
18
|
+
describe MIDIator::Driver do
|
19
|
+
it "automatically registers subclasses" do
|
20
|
+
SomeCoolDriver = Class.new
|
21
|
+
SomeCoolDriver.should_receive( :< ).with( MIDIator::Driver ).and_return( true )
|
22
|
+
|
23
|
+
# call inherited directly since we can't set up expectations ahead of
|
24
|
+
# time with Class.new( MIDIator::Driver )
|
25
|
+
MIDIator::Driver.inherited( SomeCoolDriver )
|
26
|
+
|
27
|
+
MIDIator::DriverRegistry.instance[ "some_cool_driver" ].should be( SomeCoolDriver )
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Contains the specifications for the MIDIator::Interface class.
|
4
|
+
#
|
5
|
+
# == Authors
|
6
|
+
#
|
7
|
+
# * Ben Bleything <ben@bleything.net>
|
8
|
+
#
|
9
|
+
# == Copyright
|
10
|
+
#
|
11
|
+
# Copyright (c) 2008 Ben Bleything
|
12
|
+
#
|
13
|
+
# This code released under the terms of the MIT license.
|
14
|
+
#
|
15
|
+
|
16
|
+
require File.join( File.dirname(__FILE__), 'lib', 'spec_helper.rb' )
|
17
|
+
|
18
|
+
describe MIDIator::Interface do
|
19
|
+
before( :each ) do
|
20
|
+
@driver_name = 'i_like_bees'
|
21
|
+
|
22
|
+
@interface = MIDIator::Interface.new
|
23
|
+
@driver_class = mock( "driver class" )
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "auto-detects the correct driver for your platform" do
|
27
|
+
before( :all ) do
|
28
|
+
# remember RUBY_PLATFORM so we can reset it later
|
29
|
+
@ruby_platform = RUBY_PLATFORM
|
30
|
+
|
31
|
+
$stderr.puts "*" * 72
|
32
|
+
$stderr.puts "NOTE: constant redefinition warnings are normal for these specs"
|
33
|
+
$stderr.puts "*" * 72
|
34
|
+
end
|
35
|
+
|
36
|
+
after( :all ) do
|
37
|
+
# reset RUBY_PLATFORM to whatever is correct for our platform
|
38
|
+
RUBY_PLATFORM = @ruby_platform
|
39
|
+
|
40
|
+
$stderr.puts "*" * 72
|
41
|
+
$stderr.puts "NOTE: you shouldn't see any more warnings"
|
42
|
+
$stderr.puts "*" * 72
|
43
|
+
end
|
44
|
+
|
45
|
+
it "selects WinMM for Windows" do
|
46
|
+
RUBY_PLATFORM = "i386-win32"
|
47
|
+
@interface.should_receive( :use ).with( :winmm )
|
48
|
+
|
49
|
+
@interface.autodetect_driver
|
50
|
+
end
|
51
|
+
|
52
|
+
it "selects CoreMIDI for OSX" do
|
53
|
+
RUBY_PLATFORM = "universal-darwin9.0"
|
54
|
+
@interface.should_receive( :use ).with( :core_midi )
|
55
|
+
|
56
|
+
@interface.autodetect_driver
|
57
|
+
end
|
58
|
+
|
59
|
+
it "selects ALSA for Linux" do
|
60
|
+
RUBY_PLATFORM = "i486-linux"
|
61
|
+
@interface.should_receive( :use ).with( :alsa )
|
62
|
+
|
63
|
+
@interface.autodetect_driver
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "provides the #use method to load/specify a MIDI driver" do
|
68
|
+
it "requires the driver's file from midiator/drivers" do
|
69
|
+
path = "midiator/drivers/#{@driver_name}"
|
70
|
+
@interface.should_receive( :require ).with( path )
|
71
|
+
|
72
|
+
# stub out the rest of #use
|
73
|
+
Object.should_receive( :module_eval ).and_return(
|
74
|
+
mock( 'foo', :null_object => true )
|
75
|
+
)
|
76
|
+
|
77
|
+
@interface.use( @driver_name )
|
78
|
+
end
|
79
|
+
|
80
|
+
it "captures a LoadError and gives the user a slightly better message" do
|
81
|
+
@interface.should_receive( :require ).and_raise( LoadError )
|
82
|
+
|
83
|
+
lambda {
|
84
|
+
@interface.use( @driver_name )
|
85
|
+
}.should raise_error( LoadError, "Could not load driver '#{@driver_name.to_s}'.")
|
86
|
+
end
|
87
|
+
|
88
|
+
it "instantiates the driver's class" do
|
89
|
+
@interface.stub!( :require )
|
90
|
+
|
91
|
+
Object.should_receive( :module_eval ).with(
|
92
|
+
"::MIDIator::Driver::ILikeBees"
|
93
|
+
).and_return( Class.new )
|
94
|
+
|
95
|
+
@interface.use( @driver_name )
|
96
|
+
end
|
97
|
+
|
98
|
+
it "correctly spells MIDI if the driver name includes it" do
|
99
|
+
@interface.stub!( :require )
|
100
|
+
|
101
|
+
Object.should_receive( :module_eval ).with(
|
102
|
+
"::MIDIator::Driver::SomeClassThatHasMIDIInItsName"
|
103
|
+
).and_return( Class.new )
|
104
|
+
|
105
|
+
@interface.use( "some_class_that_has_midi_in_its_name" )
|
106
|
+
end
|
107
|
+
|
108
|
+
it "correctly spells ALSA when the ALSA driver is requested" do
|
109
|
+
@interface.stub!( :require )
|
110
|
+
|
111
|
+
Object.should_receive( :module_eval ).with(
|
112
|
+
"::MIDIator::Driver::ALSA"
|
113
|
+
).and_return( Class.new )
|
114
|
+
|
115
|
+
@interface.use( :alsa )
|
116
|
+
end
|
117
|
+
|
118
|
+
it "correctly spells WinMM when the WinMM driver is requested" do
|
119
|
+
@interface.stub!( :require )
|
120
|
+
|
121
|
+
Object.should_receive( :module_eval ).with(
|
122
|
+
"::MIDIator::Driver::WinMM"
|
123
|
+
).and_return( Class.new )
|
124
|
+
|
125
|
+
@interface.use( :winmm )
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Contains the specifications for the extensions to Ruby's built-in String
|
4
|
+
# class.
|
5
|
+
#
|
6
|
+
# == Authors
|
7
|
+
#
|
8
|
+
# * Ben Bleything <ben@bleything.net>
|
9
|
+
#
|
10
|
+
# == Copyright
|
11
|
+
#
|
12
|
+
# Copyright (c) 2008 Ben Bleything
|
13
|
+
#
|
14
|
+
# This code released under the terms of the MIT license.
|
15
|
+
#
|
16
|
+
|
17
|
+
require File.join( File.dirname(__FILE__), 'lib', 'spec_helper.rb' )
|
18
|
+
|
19
|
+
describe "MIDIator's extensions to Ruby's String class" do
|
20
|
+
it "converts under_scored strings to CamelCase" do
|
21
|
+
"this_is_some_strings".camelize.should == "ThisIsSomeStrings"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "converts file path strings to module paths" do
|
25
|
+
"some/file/lives/here".camelize.should == "Some::File::Lives::Here"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "converts CamelCase strings to under_scored" do
|
29
|
+
"TheseStringsBeCamelly".underscore.should == "these_strings_be_camelly"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "converts module path strings to file paths" do
|
33
|
+
"This::Is::A::Module".underscore.should == "this/is/a/module"
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: midiator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Bleything
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-19 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: MIDIator provides an OS-agnostic way to send live MIDI messages to your machine's MIDI playback system.
|
17
|
+
email: ben@bleything.net
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- spec/driver_registry_spec.rb
|
26
|
+
- spec/driver_spec.rb
|
27
|
+
- spec/interface_spec.rb
|
28
|
+
- spec/string_extensions_spec.rb
|
29
|
+
- lib/midiator/driver.rb
|
30
|
+
- lib/midiator/driver_registry.rb
|
31
|
+
- lib/midiator/drivers/alsa.rb
|
32
|
+
- lib/midiator/drivers/core_midi.rb
|
33
|
+
- lib/midiator/drivers/winmm.rb
|
34
|
+
- lib/midiator/drums.rb
|
35
|
+
- lib/midiator/exceptions.rb
|
36
|
+
- lib/midiator/interface.rb
|
37
|
+
- lib/midiator/notes.rb
|
38
|
+
- lib/midiator/timer.rb
|
39
|
+
- lib/midiator.rb
|
40
|
+
- lib/string_extensions.rb
|
41
|
+
- examples/chromatic_scale.rb
|
42
|
+
- examples/metronome.rb
|
43
|
+
- misc/rake/packaging.rb
|
44
|
+
- misc/rake/rdoc.rb
|
45
|
+
- misc/rake/testing.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://projects.bleything.net/projects/show/midiator
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: midiator
|
68
|
+
rubygems_version: 1.2.0
|
69
|
+
signing_key:
|
70
|
+
specification_version: 2
|
71
|
+
summary: MIDIator - A a nice Ruby interface to your system's MIDI services.
|
72
|
+
test_files:
|
73
|
+
- spec/driver_registry_spec.rb
|
74
|
+
- spec/driver_spec.rb
|
75
|
+
- spec/interface_spec.rb
|
76
|
+
- spec/string_extensions_spec.rb
|