collavoce 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +26 -0
- data/spec/note_spec.rb +79 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/tracker_spec.rb +26 -0
- data/spec/voice_spec.rb +85 -0
- metadata +7 -2
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rake/gempackagetask'
|
2
|
+
|
3
|
+
begin
|
4
|
+
spec = Gem::Specification.load(Dir['*.gemspec'].first)
|
5
|
+
gem = Rake::GemPackageTask.new(spec)
|
6
|
+
gem.define
|
7
|
+
rescue TypeError
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Push gem to rubygems.org"
|
11
|
+
task :push => :gem do
|
12
|
+
sh "gem push #{gem.package_dir}/#{gem.gem_file}"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Play a tune"
|
16
|
+
task :demo do
|
17
|
+
sh "ruby -Ilib examples/zelda.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Run all specs"
|
21
|
+
task :specs do
|
22
|
+
sh "rspec spec"
|
23
|
+
end
|
24
|
+
|
25
|
+
task :test => :specs
|
26
|
+
task :default => :specs
|
data/spec/note_spec.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Collavoce::Note do
|
4
|
+
Note = Collavoce::Note
|
5
|
+
|
6
|
+
it "converts basic notes" do
|
7
|
+
Note.new("C").value.should == 60
|
8
|
+
Note.new("D").value.should == 62
|
9
|
+
end
|
10
|
+
|
11
|
+
it "converts sharps and flats" do
|
12
|
+
Note.new("C#").value.should == 61
|
13
|
+
Note.new("C##").value.should == 62
|
14
|
+
Note.new("Eb").value.should == 63
|
15
|
+
Note.new("Ebb").value.should == 62
|
16
|
+
end
|
17
|
+
|
18
|
+
it "converts octaves" do
|
19
|
+
Note.new("C5").value.should == 72
|
20
|
+
Note.new("C3").value.should == 48
|
21
|
+
end
|
22
|
+
|
23
|
+
it "converts duration" do
|
24
|
+
Note.new("C5w").duration.should == 1
|
25
|
+
Note.new("C#5h").duration.should == 1.to_f / 2
|
26
|
+
Note.new("Db3q").duration.should == 1.to_f / 4
|
27
|
+
Note.new("Ee").duration.should == 1.to_f / 8
|
28
|
+
Note.new("Fbs").duration.should == 1.to_f / 16
|
29
|
+
Note.new("G#t").duration.should == 1.to_f / 32
|
30
|
+
|
31
|
+
Note.new("C").duration.should == 1.to_f / 4
|
32
|
+
end
|
33
|
+
|
34
|
+
it "converts complex durations" do
|
35
|
+
Note.new("C#5hs").duration.should == 1.to_f / 2 + 1.to_f / 16
|
36
|
+
end
|
37
|
+
|
38
|
+
it "converts rests" do
|
39
|
+
Note.new("Rs").value.should be_nil
|
40
|
+
Note.new("Rs").duration.should == 1.to_f / 16
|
41
|
+
end
|
42
|
+
|
43
|
+
it "augments and diminshes" do
|
44
|
+
c = Note.new("C")
|
45
|
+
c.value.should == 60
|
46
|
+
c.aug.value.should == 61
|
47
|
+
c.dim.value.should == 59
|
48
|
+
c.dim!
|
49
|
+
c.value.should == 59
|
50
|
+
c.aug!
|
51
|
+
c.value.should == 60
|
52
|
+
end
|
53
|
+
|
54
|
+
it "raises a useful exception if the note isn't parsable" do
|
55
|
+
lambda { Note.new("OMFG") }.should raise_error(Collavoce::Note::UnparsableError)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "knows about equality" do
|
59
|
+
Note.new("C").should == Note.new("C")
|
60
|
+
Note.new("C").should_not == Note.new("D")
|
61
|
+
Note.new("Cs").should_not == Note.new("Ce")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should play itself on a receiver" do
|
65
|
+
@receiver = mock('receiver')
|
66
|
+
@note = Note.new("C")
|
67
|
+
|
68
|
+
@receiver.expects(:send).with(is_a(Note::ShortMessage), 0).twice
|
69
|
+
@note.expects(:sleep).with(1)
|
70
|
+
|
71
|
+
@note.play(@receiver, 0, 4)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should just pause on rests" do
|
75
|
+
@note = Note.new("R")
|
76
|
+
@note.expects(:sleep).with(1)
|
77
|
+
@note.play(nil, nil, 4)
|
78
|
+
end
|
79
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class MelodyA < Collavoce::Voice
|
4
|
+
notes %w(C D E)
|
5
|
+
end
|
6
|
+
|
7
|
+
class MelodyB < Collavoce::Voice
|
8
|
+
notes %w(F G)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Collavoce::Tracker do
|
12
|
+
it "should play a list of voices" do
|
13
|
+
MelodyA.any_instance.expects(:run)
|
14
|
+
MelodyB.any_instance.expects(:run)
|
15
|
+
@tracker = Collavoce::Tracker.new([MelodyA, MelodyB])
|
16
|
+
@tracker.run
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should play multiple tracks (in parallel)" do
|
20
|
+
MelodyA.any_instance.expects(:run)
|
21
|
+
MelodyB.any_instance.expects(:run)
|
22
|
+
@tracker = Collavoce::Tracker.new([MelodyA],
|
23
|
+
[MelodyB])
|
24
|
+
@tracker.run
|
25
|
+
end
|
26
|
+
end
|
data/spec/voice_spec.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestVoice < Collavoce::Voice
|
4
|
+
channel 3
|
5
|
+
notes %w(C D E F)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Collavoce::Voice do
|
9
|
+
before(:each) do
|
10
|
+
@receiver = mock('receiver')
|
11
|
+
@voice = TestVoice.new(:bpm => 60)
|
12
|
+
@voice.stubs(:receiver).returns(@receiver)
|
13
|
+
@receiver.stubs(:send)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "plays notes to the system receiver" do
|
17
|
+
Collavoce::Note.any_instance.expects(:play).times(4)
|
18
|
+
@voice.play
|
19
|
+
end
|
20
|
+
|
21
|
+
it "plays notes on the specified 1-indexed channel (internal is 0-indexed)" do
|
22
|
+
Collavoce::Note.any_instance.expects(:play).with(@receiver, 2, 4).times(4)
|
23
|
+
@voice.play
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has helpers for modifying groups of notes" do
|
27
|
+
@voice.mod_notes(&:dim!)
|
28
|
+
@voice.notes[0].should == Collavoce::Note.new("Cb")
|
29
|
+
@voice.notes[1].should == Collavoce::Note.new("Db")
|
30
|
+
@voice.mod_notes(2, 3, &:aug!)
|
31
|
+
@voice.notes[2].should == Collavoce::Note.new("E")
|
32
|
+
@voice.notes[3].should == Collavoce::Note.new("F")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "has helpers for diminishing and augmenting notes" do
|
36
|
+
@voice.dim_notes
|
37
|
+
@voice.notes[0].should == Collavoce::Note.new("Cb")
|
38
|
+
@voice.notes[1].should == Collavoce::Note.new("Db")
|
39
|
+
@voice.aug_notes(2, 3)
|
40
|
+
@voice.notes[2].should == Collavoce::Note.new("E")
|
41
|
+
@voice.notes[3].should == Collavoce::Note.new("F")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "stops playing when Collavoce.stop is called" do
|
45
|
+
Collavoce.stop
|
46
|
+
Collavoce::Note.any_instance.expects(:play).never
|
47
|
+
@voice.play
|
48
|
+
end
|
49
|
+
|
50
|
+
it "tells the user if there are no output devices" do
|
51
|
+
@voice.stubs(:output_devices).returns([])
|
52
|
+
expect { @voice.device }.to raise_error(RuntimeError, /No output devices/)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "tells the user if the requested device wasn't found" do
|
56
|
+
Collavoce.device_name = "bob"
|
57
|
+
@voice.stubs(:output_devices).returns([])
|
58
|
+
expect { @voice.device }.to raise_error(RuntimeError, /bob/)
|
59
|
+
end
|
60
|
+
|
61
|
+
def make_mock_device(name)
|
62
|
+
info = stub_everything('info')
|
63
|
+
info.stubs(:get_name).returns(name)
|
64
|
+
device = stub_everything('device')
|
65
|
+
device.stubs(:get_device_info).returns(info)
|
66
|
+
device
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
it "picks the first device if no device was specified" do
|
71
|
+
Collavoce.device_name = nil
|
72
|
+
mock_device = make_mock_device('not bob')
|
73
|
+
@voice.stubs(:output_devices).returns([mock_device])
|
74
|
+
$stderr.stubs(:puts)
|
75
|
+
@voice.device.should == mock_device
|
76
|
+
end
|
77
|
+
|
78
|
+
it "uses the output device specifed by Collavoce.device" do
|
79
|
+
Collavoce.device_name = "bob"
|
80
|
+
mock_device = make_mock_device('bob')
|
81
|
+
@voice.stubs(:output_devices).returns([make_mock_device('not bob'), mock_device])
|
82
|
+
@voice.device.should == mock_device
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mat Schaffer
|
@@ -51,12 +51,17 @@ extra_rdoc_files:
|
|
51
51
|
- README.rdoc
|
52
52
|
files:
|
53
53
|
- .gemtest
|
54
|
+
- Rakefile
|
54
55
|
- README.rdoc
|
55
56
|
- lib/collavoce.rb
|
56
57
|
- lib/collavoce/note.rb
|
57
58
|
- lib/collavoce/sigint.rb
|
58
59
|
- lib/collavoce/tracker.rb
|
59
60
|
- lib/collavoce/voice.rb
|
61
|
+
- spec/note_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
- spec/tracker_spec.rb
|
64
|
+
- spec/voice_spec.rb
|
60
65
|
has_rdoc: true
|
61
66
|
homepage: https://github.com/matschaffer/collavoce
|
62
67
|
licenses: []
|