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 +4 -4
- data/lib/midiops.rb +0 -1
- data/lib/midiops/note.rb +23 -0
- data/lib/midiops/observer.rb +3 -3
- data/lib/midiops/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: 7fda112a3552a1c02142d825389c00a76b1881e4
|
4
|
+
data.tar.gz: 7a3d4acacd618629b0260afd27588fd77a8fe354
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5e63782941ab259e5362489b0963c75b712e6704d4489ee2222104d21b71523b013b79cc3966ff12f9f31647dd89f77966345d05d2deda3c419ff9172ab91cc
|
7
|
+
data.tar.gz: 31c1113ce6e4da3bc4d2eaf7ad3bd7639f7ea5177e01e82f853c8741e43b5fa11aa8221a101ef1f256dcc6eb907792a9916e87be2df308af0d7a34400ffa1bcc
|
data/lib/midiops.rb
CHANGED
data/lib/midiops/note.rb
CHANGED
@@ -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
|
data/lib/midiops/observer.rb
CHANGED
@@ -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,
|
22
|
-
@handler.add [144+ch, MIDIOps::Note.
|
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.
|
27
|
+
@handler.add [128+ch, MIDIOps::Note.note_to_code(note_string), :ARG], handler
|
28
28
|
end
|
29
29
|
|
30
30
|
def listen input
|
data/lib/midiops/version.rb
CHANGED