banjo 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/banjo.rb +7 -1
- data/lib/banjo/channel.rb +27 -10
- data/lib/banjo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3c8b4a3d76f825ce4ed6e3530a046f1f14c2842
|
4
|
+
data.tar.gz: b3934b768ff3391be3b4dae71d84e4868aaf8a6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2125321edbdf759281a505206e50838bcb95568e2c027c1855c7490df31296f5e3bd4a4bb221961e9b0c13adae62d23f82c819a1de48d8692df9cfda117f649f
|
7
|
+
data.tar.gz: dbf2a5bc685b1f46f44e8e139de50d72a6725c65762f0d9519594b6e59d65158583392caffbb938c9ca7a4f14f26accf9d60bdac69166b3c398438aade0be11d
|
data/lib/banjo.rb
CHANGED
@@ -9,7 +9,10 @@ $: << '.'
|
|
9
9
|
|
10
10
|
module Banjo
|
11
11
|
class << self
|
12
|
+
attr_accessor :beats_per_measure
|
13
|
+
attr_accessor :measures_per_loop
|
12
14
|
attr_accessor :tempo
|
15
|
+
attr_accessor :ticks_per_beat
|
13
16
|
attr_accessor :ticks_per_period
|
14
17
|
end
|
15
18
|
|
@@ -20,7 +23,10 @@ module Banjo
|
|
20
23
|
end
|
21
24
|
|
22
25
|
def self.play
|
23
|
-
|
26
|
+
Banjo.measures_per_loop ||= 1
|
27
|
+
Banjo.ticks_per_period = Banjo.ticks_per_beat * Banjo.beats_per_measure * Banjo.measures_per_loop
|
28
|
+
tempo_in_ms = 60.0 / Banjo.tempo / Banjo.ticks_per_beat
|
29
|
+
puts "Beat every: #{tempo_in_ms}"
|
24
30
|
|
25
31
|
EventMachine.run do
|
26
32
|
n = 0
|
data/lib/banjo/channel.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Banjo
|
2
2
|
class Channel
|
3
3
|
attr_accessor :output, :tick
|
4
|
+
DEFAULT_DURATION = 0.5
|
4
5
|
|
5
6
|
def channel
|
6
7
|
0
|
@@ -19,16 +20,30 @@ module Banjo
|
|
19
20
|
@tick = tick
|
20
21
|
end
|
21
22
|
|
22
|
-
def tick_note(tick, note, velocity = 50, duration =
|
23
|
+
def tick_note(tick, note, velocity = 50, duration = DEFAULT_DURATION)
|
23
24
|
play_note(note, velocity, duration) if tick == self.tick
|
24
25
|
end
|
25
26
|
|
27
|
+
def tick_notes(notes, velocity = 50, duration = DEFAULT_DURATION)
|
28
|
+
notes.each do |tick, note|
|
29
|
+
tick_note(tick, note, velocity, duration)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
26
33
|
def mod_note(mod, note, offset = 0, velocity = 50)
|
27
|
-
play_note(note, velocity,
|
34
|
+
play_note(note, velocity, DEFAULT_DURATION) if ((tick + offset) % mod == 0)
|
35
|
+
end
|
36
|
+
|
37
|
+
def play_note(note, velocity = 50, duration = DEFAULT_DURATION)
|
38
|
+
EM.defer { play_note!(note, velocity, duration) }
|
28
39
|
end
|
29
40
|
|
30
|
-
def
|
31
|
-
|
41
|
+
def modulation(value = 0)
|
42
|
+
output.puts 0xB0, 0x01, value
|
43
|
+
end
|
44
|
+
|
45
|
+
def pitch(value = 63)
|
46
|
+
output.puts 0xE0, 0, value
|
32
47
|
end
|
33
48
|
|
34
49
|
def arpeggio(notes, velocity = 50)
|
@@ -38,12 +53,14 @@ module Banjo
|
|
38
53
|
end
|
39
54
|
end
|
40
55
|
|
41
|
-
def
|
42
|
-
output.
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
56
|
+
def stfu
|
57
|
+
output.puts 0xB0, 0x7B, 0
|
58
|
+
end
|
59
|
+
|
60
|
+
def play_note!(note, velocity = 50, duration = DEFAULT_DURATION)
|
61
|
+
output.puts(0x80, note, velocity)
|
62
|
+
sleep(duration)
|
63
|
+
output.puts(0x90, note, velocity)
|
47
64
|
end
|
48
65
|
end
|
49
66
|
end
|
data/lib/banjo/version.rb
CHANGED