midiops 0.2.0 → 0.2.1

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: c863cc841a88dc2ba892df7a86cd3c8d7eef9f6f
4
- data.tar.gz: bec221cd5ffb9874547dabb2418f81565141df4b
3
+ metadata.gz: 7fda112a3552a1c02142d825389c00a76b1881e4
4
+ data.tar.gz: 7a3d4acacd618629b0260afd27588fd77a8fe354
5
5
  SHA512:
6
- metadata.gz: da6ff6e7f9533fc5c1540b47c4a8d507e02e114975836cb8b640329556a48a6fb0116d3d9285651cb55dd6a03537026a9f67957a327f850392b78c78ff228325
7
- data.tar.gz: d8062bdbbd76083eb7a4ee9e7a12f8c067a16e4893b36c13b166dbd75407f17e0750cfc2adcf00df373e9019e97a519991b8ac318f64e82c442e28822bf623b7
6
+ metadata.gz: d5e63782941ab259e5362489b0963c75b712e6704d4489ee2222104d21b71523b013b79cc3966ff12f9f31647dd89f77966345d05d2deda3c419ff9172ab91cc
7
+ data.tar.gz: 31c1113ce6e4da3bc4d2eaf7ad3bd7639f7ea5177e01e82f853c8741e43b5fa11aa8221a101ef1f256dcc6eb907792a9916e87be2df308af0d7a34400ffa1bcc
@@ -2,5 +2,4 @@ require "midiops/version"
2
2
  require "midiops/observer"
3
3
 
4
4
  module MIDIOps
5
- # Your code goes here...
6
5
  end
@@ -35,6 +35,29 @@ module MIDIOps
35
35
  def key_to_code key, octave
36
36
  KEY_OFFSETS[key] + 12 + (12 * octave)
37
37
  end
38
+
39
+ def parse_note note
40
+ # formats to accept: "C3" / "B-1" / "C#4" (sharp) / "Db5" (flat)
41
+
42
+ case note
43
+ when /^([A-Ga-g])(-?[0-9]{1,2})$/
44
+ m = $~.captures
45
+ {key: m[0].upcase.to_sym, octave: m[1].to_i}
46
+ when /^([CDFGAcdfga])\#(-?[0-9]{1,2})$/
47
+ m = $~.captures
48
+ {key: "#{m[0].upcase}sharp".to_sym, octave: m[1].to_i}
49
+ when /^([DEGABdegab])b(-?[0-9]{1,2})$/
50
+ m = $~.captures
51
+ {key: "#{m[0].upcase}flat".to_sym, octave: m[1].to_i}
52
+ else
53
+ raise RuntimeError, "Invalid note format: #{note}"
54
+ end
55
+ end
56
+
57
+ def note_to_code note
58
+ res = parse_note note
59
+ key_to_code res[:key], res[:octave]
60
+ end
38
61
  end
39
62
  end
40
63
  end
@@ -18,13 +18,13 @@ module MIDIOps
18
18
  @handler.add [176+ch, number, :ARG], handler
19
19
  end
20
20
 
21
- def on_key_press ch, key, octave, &handler
22
- @handler.add [144+ch, MIDIOps::Note.key_to_code(key, octave), :ARG], handler
21
+ def on_key_press ch, note_string, &handler
22
+ @handler.add [144+ch, MIDIOps::Note.note_to_code(note_string), :ARG], handler
23
23
  end
24
24
  alias_method :on_key, :on_key_press
25
25
 
26
26
  def on_key_release ch, key, octave, &handler
27
- @handler.add [128+ch, MIDIOps::Note.key_to_code(key, octave), :ARG], handler
27
+ @handler.add [128+ch, MIDIOps::Note.note_to_code(note_string), :ARG], handler
28
28
  end
29
29
 
30
30
  def listen input
@@ -1,3 +1,3 @@
1
1
  module MIDIOps
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midiops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - polamjag