ffi-coremidi 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/coremidi.rb +1 -1
- data/lib/coremidi/source.rb +25 -11
- 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: 139d11b8026aa7260adbd6388fb4872b7773409e
|
4
|
+
data.tar.gz: 1254869a8df40213da841a526d06fb30a8e55c3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93cd4cc3d7c7415c6e5d90aa1b6794598639701cb528adf07c6ee5cd7051a65c250858b62c86ae36062a8cbf281e230452f8876868dd420286d5cfb24122c3a6
|
7
|
+
data.tar.gz: a71bcd64f2c44eb5e80e2bdd1912a3459ab82f0e9e94f0532e98c5ac7b214c0337636db2e76fbf2fc5a12248721cedef96878c9258421773692641110cb88e6c
|
data/lib/coremidi.rb
CHANGED
data/lib/coremidi/source.rb
CHANGED
@@ -122,7 +122,11 @@ module CoreMIDI
|
|
122
122
|
|
123
123
|
private
|
124
124
|
|
125
|
-
|
125
|
+
# Add a single message to the buffer
|
126
|
+
# @param [Array<Fixnum>] bytes Message data
|
127
|
+
# @param [Float] timestamp The system float timestamp
|
128
|
+
# @return [Array<Hash>] The resulting buffer
|
129
|
+
def enqueue_message(bytes, timestamp)
|
126
130
|
if bytes.first.eql?(0xF0) || !@sysex_buffer.empty?
|
127
131
|
@sysex_buffer += bytes
|
128
132
|
if bytes.last.eql?(0xF7)
|
@@ -130,7 +134,8 @@ module CoreMIDI
|
|
130
134
|
@sysex_buffer.clear
|
131
135
|
end
|
132
136
|
end
|
133
|
-
@buffer << get_message_formatted(bytes,
|
137
|
+
@buffer << get_message_formatted(bytes, timestamp) if @sysex_buffer.empty?
|
138
|
+
@buffer
|
134
139
|
end
|
135
140
|
|
136
141
|
# New MIDI messages from the queue
|
@@ -157,29 +162,36 @@ module CoreMIDI
|
|
157
162
|
end
|
158
163
|
end
|
159
164
|
|
160
|
-
|
161
|
-
|
162
|
-
|
165
|
+
# Get MIDI messages from the given CoreMIDI packet list
|
166
|
+
# @param [API::MIDIPacketList] new_packets The packet list
|
167
|
+
# @return [Array<Array<Fixnum>>] A collection of MIDI messages
|
168
|
+
def get_messages(packet_list)
|
169
|
+
count = packet_list[:numPackets]
|
170
|
+
first = packet_list[:packet][0]
|
163
171
|
data = first[:data].to_a
|
164
172
|
messages = []
|
165
173
|
messages << data.slice!(0, first[:length])
|
166
174
|
(count - 1).times do |i|
|
167
|
-
|
168
|
-
message_length
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
175
|
+
message_length = data[8]
|
176
|
+
unless message_length.nil?
|
177
|
+
packet_end_index = 10 + message_length
|
178
|
+
if data.length >= packet_end_index + 1
|
179
|
+
packet = data.slice!(0..packet_end_index)
|
180
|
+
messages << packet.slice(10, message_length)
|
181
|
+
end
|
182
|
+
end
|
173
183
|
end
|
174
184
|
messages
|
175
185
|
end
|
176
186
|
|
177
187
|
# Timestamp for a received MIDI message
|
188
|
+
# @return [Fixnum]
|
178
189
|
def timestamp(now)
|
179
190
|
(now - @start_time) * 1000
|
180
191
|
end
|
181
192
|
|
182
193
|
# Give a message its timestamp and package it in a Hash
|
194
|
+
# @return [Hash]
|
183
195
|
def get_message_formatted(raw, time)
|
184
196
|
{
|
185
197
|
:data => raw,
|
@@ -188,6 +200,7 @@ module CoreMIDI
|
|
188
200
|
end
|
189
201
|
|
190
202
|
# Initialize a coremidi port for this endpoint
|
203
|
+
# @return [Boolean]
|
191
204
|
def initialize_port
|
192
205
|
@callback = get_event_callback
|
193
206
|
port = API.create_midi_input_port(@client, @resource_id, @name, @callback)
|
@@ -197,6 +210,7 @@ module CoreMIDI
|
|
197
210
|
end
|
198
211
|
|
199
212
|
# Initialize the MIDI message buffer
|
213
|
+
# @return [Boolean]
|
200
214
|
def initialize_buffer
|
201
215
|
@pointer = 0
|
202
216
|
@buffer = []
|