ffi-coremidi 0.3.1 → 0.3.2

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: 4191e1b978dd6f7b928a1c1822850ded9034c0ae
4
- data.tar.gz: 780525a088dde5901dd1c9326d483ebe356e9c59
3
+ metadata.gz: 783d35848d8b43aad819797077531c839855b609
4
+ data.tar.gz: 3d5ddc1fdd6c4ba3334a3239230c70a30437b093
5
5
  SHA512:
6
- metadata.gz: 87ca289e7f5edb44619c6503c611828ad60c937e48952c0c99eb65665c75f869079cb1313cf25794fe47db0c944cd8849b764dada1e5c3df1ee82ff448ac9299
7
- data.tar.gz: 9c48b781b0b7ab4df324ec15c8f3d18c2131d4776849fcd98c75233d5f59297074a7485b2ef47c3d3d551d3886aa706a18586c87822f5b0556f38864e72270cf
6
+ metadata.gz: 930ba168f35d3a27c4f29a9ebea265d431c9183ea207232aea9665da7a98a90b09c4961707dae42a81a80384d85199d41224648a1c0c60f19da4f00419b3e50c
7
+ data.tar.gz: 37317428e46af018b23da9af3df7a5767d61ddcd87cf060c7261b3df526ce8389baaf7c14faff6e9f772c3ed088e63e8a1797e0f66eaca9cb63b089a5394c917
data/lib/coremidi.rb CHANGED
@@ -19,5 +19,5 @@ require "coremidi/source"
19
19
  require "coremidi/destination"
20
20
 
21
21
  module CoreMIDI
22
- VERSION = "0.3.1"
22
+ VERSION = "0.3.2"
23
23
  end
@@ -4,7 +4,7 @@ module CoreMIDI
4
4
  class Source
5
5
 
6
6
  include Endpoint
7
-
7
+
8
8
  attr_reader :buffer
9
9
 
10
10
  #
@@ -102,9 +102,9 @@ module CoreMIDI
102
102
  def self.all
103
103
  Endpoint.all_by_type[:source]
104
104
  end
105
-
105
+
106
106
  protected
107
-
107
+
108
108
  # Base initialization for this endpoint -- done whether or not the endpoint is enabled to check whether
109
109
  # it is truly available for use
110
110
  def connect
@@ -122,6 +122,17 @@ module CoreMIDI
122
122
 
123
123
  private
124
124
 
125
+ def enqueue_message(bytes, time)
126
+ if bytes.first.eql?(0xF0) || !@sysex_buffer.empty?
127
+ @sysex_buffer += bytes
128
+ if bytes.last.eql?(0xF7)
129
+ bytes = @sysex_buffer.dup
130
+ @sysex_buffer.clear
131
+ end
132
+ end
133
+ @buffer << get_message_formatted(bytes, time) if @sysex_buffer.empty?
134
+ end
135
+
125
136
  # New MIDI messages from the queue
126
137
  def queued_messages
127
138
  @buffer.slice(@pointer, @buffer.length - @pointer)
@@ -134,26 +145,35 @@ module CoreMIDI
134
145
 
135
146
  # The callback fired by coremidi when new MIDI messages are in the buffer
136
147
  def get_event_callback
137
- Proc.new do | new_packets, refCon_ptr, connRefCon_ptr |
138
- time = Time.now.to_f
139
- packet = new_packets[:packet][0]
140
- len = packet[:length]
141
- #p "packets received: #{new_packets[:numPackets]}"
142
- #p "first packet length: #{len} data: #{packet[:data].to_a.to_s}"
143
- if len > 0
144
- bytes = packet[:data].to_a[0, len]
145
- if bytes.first.eql?(0xF0) || !@sysex_buffer.empty?
146
- @sysex_buffer += bytes
147
- if bytes.last.eql?(0xF7)
148
- bytes = @sysex_buffer.dup
149
- @sysex_buffer.clear
150
- end
151
- end
152
- @buffer << get_message_formatted(bytes, time) if @sysex_buffer.empty?
148
+ Proc.new do |new_packets, refCon_ptr, connRefCon_ptr|
149
+ begin
150
+ # p "packets received: #{new_packets[:numPackets]}"
151
+ timestamp = Time.now.to_f
152
+ messages = get_messages(new_packets)
153
+ messages.each { |message| enqueue_message(message, timestamp) }
154
+ rescue Exception => exception
155
+ Thread.main.raise(exception)
153
156
  end
154
157
  end
155
158
  end
156
159
 
160
+ def get_messages(new_packets)
161
+ count = new_packets[:numPackets]
162
+ first = new_packets[:packet][0]
163
+ data = first[:data].to_a
164
+ messages = []
165
+ messages << data.slice!(0, first[:length])
166
+ (count - 1).times do |i|
167
+ length_index = 8
168
+ message_length = data[length_index]
169
+ message_start_index = length_index + 2
170
+ packet_end_index = message_start_index + message_length
171
+ packet = data.slice!(0..packet_end_index)
172
+ messages << packet.slice(message_start_index, message_length)
173
+ end
174
+ messages
175
+ end
176
+
157
177
  # Timestamp for a received MIDI message
158
178
  def timestamp(now)
159
179
  (now - @start_time) * 1000
@@ -175,7 +195,7 @@ module CoreMIDI
175
195
  raise "MIDIInputPortCreate returned error code #{port[:error]}" unless port[:error].zero?
176
196
  true
177
197
  end
178
-
198
+
179
199
  # Initialize the MIDI message buffer
180
200
  def initialize_buffer
181
201
  @pointer = 0
@@ -186,7 +206,7 @@ module CoreMIDI
186
206
  end
187
207
  true
188
208
  end
189
-
209
+
190
210
  end
191
211
 
192
212
  end
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.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Russo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-04 00:00:00.000000000 Z
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi