collavoce 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/collavoce.rb +1 -0
- data/lib/collavoce/tracker.rb +19 -0
- data/lib/collavoce/voice.rb +17 -6
- metadata +16 -3
data/lib/collavoce.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Collavoce
|
2
|
+
class Tracker
|
3
|
+
def initialize(*tracks)
|
4
|
+
@tracks = tracks
|
5
|
+
end
|
6
|
+
|
7
|
+
def run(bpm = 120)
|
8
|
+
@threads = []
|
9
|
+
@tracks.each do |track|
|
10
|
+
@threads << Thread.new do
|
11
|
+
track.each do |voice|
|
12
|
+
voice.new(:bpm => bpm).run
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
@threads.map(&:join)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/collavoce/voice.rb
CHANGED
@@ -5,14 +5,25 @@ module Collavoce
|
|
5
5
|
MidiSystem = javax.sound.midi.MidiSystem
|
6
6
|
ShortMessage = javax.sound.midi.ShortMessage
|
7
7
|
|
8
|
-
BPM = 160
|
9
|
-
BarDuration = (60.to_f / BPM) * 4
|
10
|
-
|
11
8
|
attr_accessor :notes
|
9
|
+
|
10
|
+
def self.notes(notes)
|
11
|
+
@notes = notes
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.channel(channel)
|
15
|
+
@channel = channel
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.new(options = {})
|
19
|
+
super({:notes => @notes, :channel => @channel}.merge(options))
|
20
|
+
end
|
12
21
|
|
13
22
|
def initialize(options = {})
|
14
|
-
@channel
|
15
|
-
@notes
|
23
|
+
@channel = (options.delete(:channel) || 1) - 1
|
24
|
+
@notes = options.delete(:notes).map { |n| Note.new(n) }
|
25
|
+
@bpm = options.delete(:bpm) || 120
|
26
|
+
@bar_duration = (60.to_f / @bpm) * 4
|
16
27
|
end
|
17
28
|
|
18
29
|
def device
|
@@ -35,7 +46,7 @@ module Collavoce
|
|
35
46
|
noteoff = ShortMessage.new
|
36
47
|
noteoff.set_message(ShortMessage::NOTE_OFF, channel, note.value, 127);
|
37
48
|
receiver.send(noteon, 0)
|
38
|
-
sleep
|
49
|
+
sleep @bar_duration * note.duration
|
39
50
|
receiver.send(noteoff, 0)
|
40
51
|
end
|
41
52
|
|
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
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mat Schaffer
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-12-01 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -29,6 +29,18 @@ dependencies:
|
|
29
29
|
version: "0"
|
30
30
|
type: :development
|
31
31
|
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: mocha
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
32
44
|
description:
|
33
45
|
email: mat@schaffer.me
|
34
46
|
executables: []
|
@@ -41,6 +53,7 @@ files:
|
|
41
53
|
- README.rdoc
|
42
54
|
- lib/collavoce.rb
|
43
55
|
- lib/collavoce/note.rb
|
56
|
+
- lib/collavoce/tracker.rb
|
44
57
|
- lib/collavoce/voice.rb
|
45
58
|
has_rdoc: true
|
46
59
|
homepage: https://github.com/matschaffer/collavoce
|