ffi-coremidi 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/lib/coremidi.rb +6 -3
- data/lib/coremidi/api.rb +1 -1
- data/lib/coremidi/destination.rb +3 -3
- data/lib/coremidi/device.rb +9 -9
- data/lib/coremidi/endpoint.rb +3 -3
- data/lib/coremidi/entity.rb +23 -23
- data/lib/coremidi/source.rb +5 -5
- data/lib/coremidi/type_conversion.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 548ce7a99e6cb8697066d0d52ce5884efd8437dd
|
4
|
+
data.tar.gz: 033b84506aafc25fbd008bda1e808ce22aea5a78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09b13413a37eecc61cfeb931780fe721410a37a9e523afda53550e98e38e73435849ade03965b8acebd46155d6ee98e689f3d860ecb1d0b337b5f54d146114f7'
|
7
|
+
data.tar.gz: 90ec924b77f5fb32ef936712292578f49b6e70d9c7ef28fcc93428333fea229ba88991e976a2c9c59c6e42450755911a458363b377974d7ff7b53349d0f84008
|
data/LICENSE
CHANGED
data/README.md
CHANGED
data/lib/coremidi.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
# ffi-coremidi
|
2
1
|
#
|
2
|
+
# ffi-coremidi
|
3
3
|
# Realtime MIDI IO with Ruby for OSX
|
4
|
-
#
|
4
|
+
#
|
5
|
+
# (c)2011-2017 Ari Russo
|
6
|
+
# https://github.com/arirusso/ffi-coremidi
|
7
|
+
#
|
5
8
|
|
6
9
|
# Libs
|
7
10
|
require "ffi"
|
@@ -19,5 +22,5 @@ require "coremidi/source"
|
|
19
22
|
require "coremidi/destination"
|
20
23
|
|
21
24
|
module CoreMIDI
|
22
|
-
VERSION = "0.3.
|
25
|
+
VERSION = "0.3.9"
|
23
26
|
end
|
data/lib/coremidi/api.rb
CHANGED
@@ -110,7 +110,7 @@ module CoreMIDI
|
|
110
110
|
|
111
111
|
# @param [FFI::Pointer] resource A pointer to an underlying struct
|
112
112
|
# @param [String, Symbol] name The property name to get
|
113
|
-
# @return [
|
113
|
+
# @return [Integer]
|
114
114
|
def self.get_int(resource, name)
|
115
115
|
property = API::CF.CFStringCreateWithCString(nil, name.to_s, 0)
|
116
116
|
value = FFI::MemoryPointer.new(:pointer, 32)
|
data/lib/coremidi/destination.rb
CHANGED
@@ -34,7 +34,7 @@ module CoreMIDI
|
|
34
34
|
alias_method :puts_hex, :puts_s
|
35
35
|
|
36
36
|
# Send a MIDI message comprised of numeric bytes
|
37
|
-
# @param [*
|
37
|
+
# @param [*Integer] data Numeric bytes eg 0x90, 0x40, 0x40
|
38
38
|
# @return [Boolean]
|
39
39
|
def puts_bytes(*data)
|
40
40
|
type = sysex?(data) ? :sysex : :small
|
@@ -44,12 +44,12 @@ module CoreMIDI
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# Send a MIDI message of indeterminate type
|
47
|
-
# @param [*Array<
|
47
|
+
# @param [*Array<Integer>, *Array<String>, *Integer, *String] args
|
48
48
|
# @return [Boolean]
|
49
49
|
def puts(*args)
|
50
50
|
case args.first
|
51
51
|
when Array then args.each { |arg| puts(*arg) }
|
52
|
-
when
|
52
|
+
when Integer then puts_bytes(*args)
|
53
53
|
when String then puts_bytestr(*args)
|
54
54
|
end
|
55
55
|
end
|
data/lib/coremidi/device.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module CoreMIDI
|
2
2
|
|
3
|
-
# A MIDI device may have multiple logically distinct sub-components. For example, one device may
|
4
|
-
# encompass a MIDI synthesizer and a pair of MIDI ports, both addressable via a USB port. Each
|
3
|
+
# A MIDI device may have multiple logically distinct sub-components. For example, one device may
|
4
|
+
# encompass a MIDI synthesizer and a pair of MIDI ports, both addressable via a USB port. Each
|
5
5
|
# such element of a device is called a MIDI entity.
|
6
6
|
#
|
7
7
|
# https://developer.apple.com/library/ios/documentation/CoreMidi/Reference/MIDIServices_Reference/Reference/reference.html
|
@@ -11,7 +11,7 @@ module CoreMIDI
|
|
11
11
|
:id, # Unique Numeric id
|
12
12
|
:name # Device name from coremidi
|
13
13
|
|
14
|
-
# @param [
|
14
|
+
# @param [Integer] id The ID for the device
|
15
15
|
# @param [Object] device_pointer The underlying device pointer
|
16
16
|
# @param [Hash] options
|
17
17
|
# @option options [Boolean] :include_offline Whether to include offline entities (default: false)
|
@@ -21,7 +21,7 @@ module CoreMIDI
|
|
21
21
|
@entities = []
|
22
22
|
populate(options)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# Endpoints for this device
|
26
26
|
# @return [Array<Endpoint>]
|
27
27
|
def endpoints
|
@@ -32,9 +32,9 @@ module CoreMIDI
|
|
32
32
|
end
|
33
33
|
endpoints
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
# Assign all of this Device's endpoints an consecutive local id
|
37
|
-
# @param [Integer] last_id The highest already used endpoint ID
|
37
|
+
# @param [Integer] last_id The highest already used endpoint ID
|
38
38
|
# @return [Integer] The highest used endpoint ID after populating this device's endpoints
|
39
39
|
def populate_endpoint_ids(last_id)
|
40
40
|
id = 0
|
@@ -72,7 +72,7 @@ module CoreMIDI
|
|
72
72
|
|
73
73
|
# Has the device list been populated?
|
74
74
|
def self.populated?
|
75
|
-
!@devices.nil? && !@devices.empty?
|
75
|
+
!@devices.nil? && !@devices.empty?
|
76
76
|
end
|
77
77
|
|
78
78
|
private
|
@@ -82,7 +82,7 @@ module CoreMIDI
|
|
82
82
|
@name = API.get_string(@resource, "name")
|
83
83
|
raise RuntimeError.new("Can't get device name") unless @name
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
# All of the endpoints for all devices a consecutive local id
|
87
87
|
def self.populate_endpoint_ids
|
88
88
|
counter = 0
|
@@ -93,7 +93,7 @@ module CoreMIDI
|
|
93
93
|
# Populates the entities for this device. These entities are in turn used to gather the endpoints.
|
94
94
|
# @param [Hash] options
|
95
95
|
# @option options [Boolean] :include_offline Whether to include offline entities (default: false)
|
96
|
-
# @return [
|
96
|
+
# @return [Integer] The number of entities populated
|
97
97
|
def populate_entities(options = {})
|
98
98
|
include_if_offline = options[:include_offline] || false
|
99
99
|
i = 0
|
data/lib/coremidi/endpoint.rb
CHANGED
@@ -17,7 +17,7 @@ module CoreMIDI
|
|
17
17
|
|
18
18
|
alias_method :enabled?, :enabled
|
19
19
|
|
20
|
-
# @param [
|
20
|
+
# @param [Integer] resource_id
|
21
21
|
# @param [Entity] entity
|
22
22
|
def initialize(resource_id, entity)
|
23
23
|
@entity = entity
|
@@ -33,8 +33,8 @@ module CoreMIDI
|
|
33
33
|
end
|
34
34
|
|
35
35
|
# Set the id for this endpoint (the id is immutable)
|
36
|
-
# @param [
|
37
|
-
# @return [
|
36
|
+
# @param [Integer] val
|
37
|
+
# @return [Integer]
|
38
38
|
def id=(id)
|
39
39
|
@id ||= id
|
40
40
|
end
|
data/lib/coremidi/entity.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
module CoreMIDI
|
2
2
|
|
3
|
-
# A MIDI entity can have any number of MIDI endpoints, each of which is a source or destination
|
4
|
-
# of a 16-channel MIDI stream. By grouping a device's endpoints into entities, the system has
|
5
|
-
# enough information for an application to make reasonable default assumptions about how to
|
6
|
-
# communicate in a bi-directional manner with each entity, as is necessary in MIDI librarian
|
3
|
+
# A MIDI entity can have any number of MIDI endpoints, each of which is a source or destination
|
4
|
+
# of a 16-channel MIDI stream. By grouping a device's endpoints into entities, the system has
|
5
|
+
# enough information for an application to make reasonable default assumptions about how to
|
6
|
+
# communicate in a bi-directional manner with each entity, as is necessary in MIDI librarian
|
7
7
|
# applications.
|
8
8
|
#
|
9
9
|
# https://developer.apple.com/library/ios/documentation/CoreMidi/Reference/MIDIServices_Reference/Reference/reference.html
|
10
10
|
class Entity
|
11
11
|
|
12
|
-
attr_reader :endpoints,
|
12
|
+
attr_reader :endpoints,
|
13
13
|
:manufacturer,
|
14
14
|
:model,
|
15
15
|
:name,
|
16
16
|
:resource
|
17
|
-
|
17
|
+
|
18
18
|
# @param [FFI::Pointer] resource A pointer to the underlying entity
|
19
19
|
# @param [Hash] options
|
20
20
|
# @option options [Boolean] :include_offline Include offline endpoints in the list
|
21
21
|
def initialize(resource, options = {})
|
22
|
-
@endpoints = {
|
23
|
-
:source => [],
|
24
|
-
:destination => []
|
22
|
+
@endpoints = {
|
23
|
+
:source => [],
|
24
|
+
:destination => []
|
25
25
|
}
|
26
26
|
@resource = resource
|
27
27
|
populate(options)
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# Assign all of this Entity's endpoints an consecutive local id
|
31
|
-
# @param [
|
32
|
-
# @return [
|
31
|
+
# @param [Integer] starting_id
|
32
|
+
# @return [Integer]
|
33
33
|
def populate_endpoint_ids(starting_id)
|
34
34
|
counter = 0
|
35
35
|
@endpoints.values.flatten.each do |endpoint|
|
@@ -38,7 +38,7 @@ module CoreMIDI
|
|
38
38
|
end
|
39
39
|
counter
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
# Is the entity online?
|
43
43
|
# @return [Boolean]
|
44
44
|
def online?
|
@@ -52,12 +52,12 @@ module CoreMIDI
|
|
52
52
|
def get_name
|
53
53
|
"#{@manufacturer} #{@model}"
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
# Populate endpoints of a specified type for this entity
|
57
57
|
# @param [Symbol] type The endpoint type eg :source, :destination
|
58
58
|
# @param [Hash] options
|
59
59
|
# @option options [Boolean] :include_offline Include offline endpoints in the list
|
60
|
-
# @return [
|
60
|
+
# @return [Integer]
|
61
61
|
def populate_endpoints_by_type(type, options = {})
|
62
62
|
endpoint_class = Endpoint.get_class(type)
|
63
63
|
num_endpoints = number_of_endpoints(type)
|
@@ -66,18 +66,18 @@ module CoreMIDI
|
|
66
66
|
if endpoint.online? || options[:include_offline]
|
67
67
|
@endpoints[type] << endpoint
|
68
68
|
end
|
69
|
-
end
|
70
|
-
@endpoints[type].size
|
69
|
+
end
|
70
|
+
@endpoints[type].size
|
71
71
|
end
|
72
72
|
|
73
73
|
# Populate the endpoints for this entity
|
74
74
|
# @param [Hash] options
|
75
75
|
# @option options [Boolean] :include_offline Include offline endpoints in the list
|
76
|
-
# @return [
|
76
|
+
# @return [Integer]
|
77
77
|
def populate_endpoints(options = {})
|
78
78
|
@endpoints.keys.map { |type| populate_endpoints_by_type(type, options) }.reduce(&:+)
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
# The number of endpoints for this entity
|
82
82
|
# @param [Symbol] type The endpoint type eg :source, :destination
|
83
83
|
def number_of_endpoints(type)
|
@@ -86,20 +86,20 @@ module CoreMIDI
|
|
86
86
|
when :destination then API.MIDIEntityGetNumberOfDestinations(@resource)
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
# A CFString property from the underlying entity
|
91
91
|
# @param [Symbol, String] name The property name
|
92
92
|
# @return [String, nil]
|
93
93
|
def get_string(name)
|
94
94
|
API.get_string(@resource, name)
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
# An Integer property from the underlying entity
|
98
98
|
# @param [Symbol, String] name The property name
|
99
|
-
# @return [
|
99
|
+
# @return [Integer, nil]
|
100
100
|
def get_int(name)
|
101
101
|
API.get_int(@resource, name)
|
102
|
-
end
|
102
|
+
end
|
103
103
|
|
104
104
|
# Populate the entity properties from the underlying resource
|
105
105
|
# @param [Hash] options
|
data/lib/coremidi/source.rb
CHANGED
@@ -121,7 +121,7 @@ module CoreMIDI
|
|
121
121
|
private
|
122
122
|
|
123
123
|
# Add a single message to the buffer
|
124
|
-
# @param [Array<
|
124
|
+
# @param [Array<Integer>] bytes Message data
|
125
125
|
# @param [Float] timestamp The system float timestamp
|
126
126
|
# @return [Array<Hash>] The resulting buffer
|
127
127
|
def enqueue_message(bytes, timestamp)
|
@@ -162,7 +162,7 @@ module CoreMIDI
|
|
162
162
|
|
163
163
|
# Get MIDI messages from the given CoreMIDI packet list
|
164
164
|
# @param [API::MIDIPacketList] new_packets The packet list
|
165
|
-
# @return [Array<Array<
|
165
|
+
# @return [Array<Array<Integer>>] A collection of MIDI messages
|
166
166
|
def get_messages(packet_list)
|
167
167
|
count = packet_list[:numPackets]
|
168
168
|
first = packet_list[:packet][0]
|
@@ -186,8 +186,8 @@ module CoreMIDI
|
|
186
186
|
end
|
187
187
|
|
188
188
|
# Get the next index for "length" from the blob of MIDI data
|
189
|
-
# @param [Array<
|
190
|
-
# @return [
|
189
|
+
# @param [Array<Integer>] data
|
190
|
+
# @return [Integer]
|
191
191
|
def find_next_length_index(data)
|
192
192
|
last_is_zero = false
|
193
193
|
data.each_with_index do |num, i|
|
@@ -204,7 +204,7 @@ module CoreMIDI
|
|
204
204
|
end
|
205
205
|
|
206
206
|
# Timestamp for a received MIDI message
|
207
|
-
# @return [
|
207
|
+
# @return [Integer]
|
208
208
|
def timestamp(now)
|
209
209
|
(now - @start_time) * 1000
|
210
210
|
end
|
@@ -6,10 +6,10 @@ module CoreMIDI
|
|
6
6
|
extend self
|
7
7
|
|
8
8
|
# Convert an array of numeric byes to a hex string (e.g. [0x90, 0x40, 0x40] becomes "904040")
|
9
|
-
# @param [Array<
|
9
|
+
# @param [Array<Integer>] bytes
|
10
10
|
# @return [String]
|
11
11
|
def numeric_bytes_to_hex_string(bytes)
|
12
|
-
string_bytes = bytes.map do |byte|
|
12
|
+
string_bytes = bytes.map do |byte|
|
13
13
|
str = byte.to_s(16).upcase
|
14
14
|
str = "0" + str if byte < 16
|
15
15
|
str
|
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.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ari Russo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -132,7 +132,7 @@ files:
|
|
132
132
|
- test/io_test.rb
|
133
133
|
homepage: http://github.com/arirusso/ffi-coremidi
|
134
134
|
licenses:
|
135
|
-
- Apache
|
135
|
+
- Apache-2.0
|
136
136
|
metadata: {}
|
137
137
|
post_install_message:
|
138
138
|
rdoc_options: []
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: 1.3.6
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project: ffi-coremidi
|
153
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.6.8
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: Realtime MIDI IO with Ruby for OSX
|