mmplayer 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mmplayer.rb +1 -1
- data/lib/mmplayer/message_handler.rb +27 -14
- data/test/message_handler_test.rb +6 -2
- 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: a60391f734494cf22b9e343379660079567721e8
|
4
|
+
data.tar.gz: 4d75bfe1d744172b82fc9866ef9e4af6735d68e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64d867081ec9fb0b087076da7981aa978b7cc7ca704f01f7c6c8b4d0fa440c40383ecdc93171370e87ba91d0282d4bb6325aa7669c69118d60124c0bc1013054
|
7
|
+
data.tar.gz: 18ca9e448f75dc6d2d97cb071060ea5e49af680a991bb184cb55b9e752454f2a1a45d0073986b97e60182f9afc1d2688b20e87648a8d447a6589e26cbb563943
|
data/lib/mmplayer.rb
CHANGED
@@ -49,22 +49,16 @@ module MMPlayer
|
|
49
49
|
# @param [MIDIMessage] message
|
50
50
|
# @return [Boolean, nil]
|
51
51
|
def note_message(message)
|
52
|
-
|
53
|
-
|
54
|
-
callback.call(message.velocity)
|
55
|
-
true
|
56
|
-
end
|
52
|
+
call_callback(:note, message.note, message.velocity) |
|
53
|
+
call_catch_all_callback(:note, message)
|
57
54
|
end
|
58
55
|
|
59
56
|
# Find and call a cc received callback if it exists
|
60
57
|
# @param [MIDIMessage] message
|
61
58
|
# @return [Boolean, nil]
|
62
59
|
def cc_message(message)
|
63
|
-
|
64
|
-
|
65
|
-
callback.call(message.value)
|
66
|
-
true
|
67
|
-
end
|
60
|
+
call_callback(:cc, message.index, message.value) |
|
61
|
+
call_catch_all_callback(:cc, message)
|
68
62
|
end
|
69
63
|
|
70
64
|
# Find and call a system message callback if it exists
|
@@ -72,10 +66,7 @@ module MMPlayer
|
|
72
66
|
# @return [Boolean, nil]
|
73
67
|
def system_message(message)
|
74
68
|
name = message.name.downcase.to_sym
|
75
|
-
|
76
|
-
callback.call
|
77
|
-
true
|
78
|
-
end
|
69
|
+
call_callback(:system, name)
|
79
70
|
end
|
80
71
|
|
81
72
|
# Find and call a channel message callback if it exists for the given message and channel
|
@@ -91,6 +82,28 @@ module MMPlayer
|
|
91
82
|
end
|
92
83
|
end
|
93
84
|
|
85
|
+
private
|
86
|
+
|
87
|
+
# Execute the catch-all callback for the given type if it exists
|
88
|
+
# @param [Symbol] type
|
89
|
+
# @param [MIDIMessage] message
|
90
|
+
# @return [Boolean]
|
91
|
+
def call_catch_all_callback(type, message)
|
92
|
+
call_callback(type, nil, message)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Execute the callback for the given type and key and pass it the given args
|
96
|
+
# @param [Symbol] type
|
97
|
+
# @param [Object] key
|
98
|
+
# @param [*Object] arguments
|
99
|
+
# @return [Boolean]
|
100
|
+
def call_callback(type, key, *arguments)
|
101
|
+
unless (callback = @callback[type][key]).nil?
|
102
|
+
callback.call(*arguments)
|
103
|
+
true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
94
107
|
end
|
95
108
|
|
96
109
|
end
|
@@ -33,10 +33,14 @@ class MMPlayer::MessageHandlerTest < Minitest::Test
|
|
33
33
|
@var2 = nil
|
34
34
|
@catchall = proc { |vel| @var2 = vel }
|
35
35
|
@handler.add_callback(:note, nil, &@catchall)
|
36
|
-
@catchall.expects(:call).
|
36
|
+
@catchall.expects(:call).once
|
37
37
|
end
|
38
38
|
|
39
|
-
|
39
|
+
teardown do
|
40
|
+
@catchall.unstub(:call)
|
41
|
+
end
|
42
|
+
|
43
|
+
should "call both callbacks" do
|
40
44
|
assert @handler.send(:note_message, @message)
|
41
45
|
end
|
42
46
|
|