ffi-coremidi 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/coremidi.rb +1 -1
- data/lib/coremidi/source.rb +35 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24583f1bb64dea16e2988a4ed7f4c51411000413
|
4
|
+
data.tar.gz: 3d7804e408e78313e46095ca9fa879c1c427d9e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8d2c2fc9c502f21710213e46ecd03937a61f58f0f6bdbc74652ab3995c5615eb1ef23ebdf79a1fe0afaa8fecdd39898ae1ad29b257de5314b2a038f2ff6f688
|
7
|
+
data.tar.gz: adbb7aa16fe70b8306cd0dd8f9740a15b1b23fd3c4b04ec61616120b3fcc3ad0e1e132c4a526d0cc682d0eb94067940c86f023654e457e01cc7e414033df57aa
|
data/lib/coremidi.rb
CHANGED
data/lib/coremidi/source.rb
CHANGED
@@ -5,7 +5,12 @@ module CoreMIDI
|
|
5
5
|
|
6
6
|
include Endpoint
|
7
7
|
|
8
|
-
|
8
|
+
# The buffer of received messages since instantiation
|
9
|
+
# @return [Array<Hash>]
|
10
|
+
def buffer
|
11
|
+
fill_buffer
|
12
|
+
@buffer
|
13
|
+
end
|
9
14
|
|
10
15
|
#
|
11
16
|
# An array of MIDI event hashes as such:
|
@@ -20,13 +25,7 @@ module CoreMIDI
|
|
20
25
|
#
|
21
26
|
# @return [Array<Hash>]
|
22
27
|
def gets
|
23
|
-
|
24
|
-
# per https://github.com/arirusso/unimidi/issues/20#issuecomment-44761318
|
25
|
-
sleep(0.0001) # patch to prevent 100% CPU issue with some midi controllers
|
26
|
-
end
|
27
|
-
messages = queued_messages
|
28
|
-
@pointer = @buffer.length
|
29
|
-
messages
|
28
|
+
fill_buffer
|
30
29
|
end
|
31
30
|
alias_method :read, :gets
|
32
31
|
|
@@ -103,6 +102,18 @@ module CoreMIDI
|
|
103
102
|
|
104
103
|
protected
|
105
104
|
|
105
|
+
# Migrate new received messages from the callback queue to
|
106
|
+
# the buffer
|
107
|
+
def fill_buffer
|
108
|
+
messages = []
|
109
|
+
until @queue.empty?
|
110
|
+
messages << @queue.pop
|
111
|
+
end
|
112
|
+
@buffer += messages
|
113
|
+
@pointer = @buffer.length
|
114
|
+
messages
|
115
|
+
end
|
116
|
+
|
106
117
|
# Base initialization for this endpoint -- done whether or not the endpoint is enabled to check whether
|
107
118
|
# it is truly available for use
|
108
119
|
def connect
|
@@ -111,8 +122,8 @@ module CoreMIDI
|
|
111
122
|
@resource = API.MIDIEntityGetSource(@entity.resource, @resource_id)
|
112
123
|
error = API.MIDIPortConnectSource(@handle, @resource, nil )
|
113
124
|
initialize_buffer
|
125
|
+
@queue = Queue.new
|
114
126
|
@sysex_buffer = []
|
115
|
-
@start_time = Time.now.to_f
|
116
127
|
|
117
128
|
error.zero?
|
118
129
|
end
|
@@ -120,8 +131,8 @@ module CoreMIDI
|
|
120
131
|
|
121
132
|
private
|
122
133
|
|
123
|
-
# Add a single message to the
|
124
|
-
# @param [Array<
|
134
|
+
# Add a single message to the callback queue
|
135
|
+
# @param [Array<Fixnum>] bytes Message data
|
125
136
|
# @param [Float] timestamp The system float timestamp
|
126
137
|
# @return [Array<Hash>] The resulting buffer
|
127
138
|
def enqueue_message(bytes, timestamp)
|
@@ -132,28 +143,32 @@ module CoreMIDI
|
|
132
143
|
@sysex_buffer.clear
|
133
144
|
end
|
134
145
|
end
|
135
|
-
|
136
|
-
@
|
146
|
+
message = get_message_formatted(bytes, timestamp)
|
147
|
+
@queue << message
|
148
|
+
message
|
137
149
|
end
|
138
150
|
|
139
151
|
# New MIDI messages from the queue
|
140
152
|
def queued_messages
|
141
|
-
@
|
153
|
+
@queue.pop
|
142
154
|
end
|
143
155
|
|
144
156
|
# Are there new MIDI messages in the queue?
|
145
157
|
def queued_messages?
|
146
|
-
|
158
|
+
!@queue.empty?
|
147
159
|
end
|
148
160
|
|
149
|
-
# The callback fired by coremidi when new MIDI messages are
|
161
|
+
# The callback fired by coremidi when new MIDI messages are received
|
150
162
|
def get_event_callback
|
163
|
+
Thread.abort_on_exception = true
|
151
164
|
Proc.new do |new_packets, refCon_ptr, connRefCon_ptr|
|
152
165
|
begin
|
153
166
|
# p "packets received: #{new_packets[:numPackets]}"
|
154
167
|
timestamp = Time.now.to_f
|
155
168
|
messages = get_messages(new_packets)
|
156
|
-
messages.each
|
169
|
+
messages.each do |message|
|
170
|
+
enqueue_message(message, timestamp)
|
171
|
+
end
|
157
172
|
rescue Exception => exception
|
158
173
|
Thread.main.raise(exception)
|
159
174
|
end
|
@@ -162,7 +177,7 @@ module CoreMIDI
|
|
162
177
|
|
163
178
|
# Get MIDI messages from the given CoreMIDI packet list
|
164
179
|
# @param [API::MIDIPacketList] new_packets The packet list
|
165
|
-
# @return [Array<Array<
|
180
|
+
# @return [Array<Array<Fixnum>>] A collection of MIDI messages
|
166
181
|
def get_messages(packet_list)
|
167
182
|
count = packet_list[:numPackets]
|
168
183
|
first = packet_list[:packet][0]
|
@@ -186,8 +201,8 @@ module CoreMIDI
|
|
186
201
|
end
|
187
202
|
|
188
203
|
# Get the next index for "length" from the blob of MIDI data
|
189
|
-
# @param [Array<
|
190
|
-
# @return [
|
204
|
+
# @param [Array<Fixnum>] data
|
205
|
+
# @return [Fixnum]
|
191
206
|
def find_next_length_index(data)
|
192
207
|
last_is_zero = false
|
193
208
|
data.each_with_index do |num, i|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-coremidi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ari Russo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|