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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1602d6a96258f60f5abd2b1266f9f7ab042a06a2
4
- data.tar.gz: 02de585c8ea9fad0d8dc02e060d8aeb0b7daa247
3
+ metadata.gz: c3c8b4a3d76f825ce4ed6e3530a046f1f14c2842
4
+ data.tar.gz: b3934b768ff3391be3b4dae71d84e4868aaf8a6a
5
5
  SHA512:
6
- metadata.gz: 865bca105bcdcc6061cdcc7af867cbd60173814f8668cc32f53776cd01103a1d47003c695423210f829dd811c771cd236a178f485a3c7f1352fa7d9b3b9e595a
7
- data.tar.gz: 18c29122e833874acd3227d876825357a370e211e582577183ffba57202c6871a5f920504d2c5f6b3a9dfe9862a912a0782079b4cb0a30e329ed55b873370a27
6
+ metadata.gz: 2125321edbdf759281a505206e50838bcb95568e2c027c1855c7490df31296f5e3bd4a4bb221961e9b0c13adae62d23f82c819a1de48d8692df9cfda117f649f
7
+ data.tar.gz: dbf2a5bc685b1f46f44e8e139de50d72a6725c65762f0d9519594b6e59d65158583392caffbb938c9ca7a4f14f26accf9d60bdac69166b3c398438aade0be11d
@@ -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
- tempo_in_ms = 60.0 / Banjo.tempo / ticks_per_period
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
@@ -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 = 0.5)
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, 0.5) if ((tick + offset) % mod == 0)
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 play_note(note, velocity = 50, duration = 0.5)
31
- Thread.new { play_note!(note, velocity, duration) }
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 play_note!(note, velocity = 50, duration = 0.5)
42
- output.open do |o|
43
- o.puts(0x80, note, velocity)
44
- sleep(duration)
45
- o.puts(0x90, note, velocity)
46
- end
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
@@ -1,3 +1,3 @@
1
1
  module Banjo
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: banjo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Padilla