rcoremidi 0.1.0
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 +7 -0
- data/README.md +129 -0
- data/ext/rcoremidi/client.c +579 -0
- data/ext/rcoremidi/client.h +15 -0
- data/ext/rcoremidi/extconf.rb +9 -0
- data/ext/rcoremidi/midi_client.c +64 -0
- data/ext/rcoremidi/midi_client.h +7 -0
- data/ext/rcoremidi/midi_object.c +207 -0
- data/ext/rcoremidi/midi_object.h +9 -0
- data/ext/rcoremidi/rcoremidi.c +105 -0
- data/ext/rcoremidi/rcoremidi.h +37 -0
- data/ext/rcoremidi/universal_packet.c +190 -0
- data/ext/rcoremidi/universal_packet.h +11 -0
- data/lib/rcoremidi/client.rb +58 -0
- data/lib/rcoremidi/destination.rb +26 -0
- data/lib/rcoremidi/device.rb +13 -0
- data/lib/rcoremidi/entity.rb +21 -0
- data/lib/rcoremidi/source.rb +4 -0
- data/lib/rcoremidi/version.rb +3 -0
- data/lib/rcoremidi.rb +7 -0
- metadata +132 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module RCoreMidi
|
|
2
|
+
# A CoreMIDI client that follows an external MIDI clock and sends notes.
|
|
3
|
+
#
|
|
4
|
+
# The C extension defines the driver methods:
|
|
5
|
+
#
|
|
6
|
+
# * <tt>new(name)</tt>, <tt>name</tt>
|
|
7
|
+
# * <tt>connect_to(source)</tt>: listen to a Source's MIDI clock
|
|
8
|
+
# * <tt>start</tt>: block the calling thread and dispatch clock events to
|
|
9
|
+
# the hooks below until +stop+ or +dispose+ is called
|
|
10
|
+
# * <tt>stop</tt>, <tt>running?</tt>, <tt>dispose</tt>
|
|
11
|
+
# * <tt>send_packets(destination, notes, base_host_time = now)</tt>: schedule
|
|
12
|
+
# each note (see TimedNote) relative to +base_host_time+
|
|
13
|
+
# * <tt>silence</tt>: unschedule pending packets and send All Sound Off and
|
|
14
|
+
# All Notes Off on all 16 channels of every destination sent to (up to 16)
|
|
15
|
+
# * <tt>dropped_clock_events</tt>: clock events lost because Ruby fell behind
|
|
16
|
+
#
|
|
17
|
+
# This class adds the Ruby side: endpoints to work with and no-op hooks that
|
|
18
|
+
# subclasses override. The hooks run on the thread that called +start+.
|
|
19
|
+
class Client
|
|
20
|
+
# MIDI clock resolution: the clock sends 24 ticks per quarter note.
|
|
21
|
+
TICKS_PER_QUARTER = 24
|
|
22
|
+
|
|
23
|
+
# What send_packets reads for each note it sends.
|
|
24
|
+
#
|
|
25
|
+
# * +on+, +off+: MIDI 1.0 message bytes, e.g. <tt>[0x90, 60, 100]</tt> and
|
|
26
|
+
# <tt>[0x80, 60, 0]</tt>
|
|
27
|
+
# * +on_timestamp+, +off_timestamp+: nanoseconds after the base host time
|
|
28
|
+
# given to send_packets (non-negative Integers)
|
|
29
|
+
#
|
|
30
|
+
# Any object responding to these four methods works; this Struct is the
|
|
31
|
+
# canonical shape.
|
|
32
|
+
TimedNote = Struct.new(:on, :on_timestamp, :off, :off_timestamp)
|
|
33
|
+
|
|
34
|
+
# The Source whose clock this client follows, and the Destination it
|
|
35
|
+
# sends notes to.
|
|
36
|
+
attr_accessor :midi_in, :midi_out
|
|
37
|
+
|
|
38
|
+
# Called on MIDI Start (0xFA). +host_time+ is the CoreMIDI host time of
|
|
39
|
+
# the message; the next clock is tick 0.
|
|
40
|
+
def on_start(host_time); end
|
|
41
|
+
|
|
42
|
+
# Called on each MIDI Clock (0xF8) while running. +tick+ counts clocks
|
|
43
|
+
# since Start (or the Song Position Pointer), +host_time+ is when the
|
|
44
|
+
# clock message arrived.
|
|
45
|
+
def on_tick(tick, host_time); end
|
|
46
|
+
|
|
47
|
+
# Called on MIDI Stop (0xFC).
|
|
48
|
+
def on_stop; end
|
|
49
|
+
|
|
50
|
+
# Called on MIDI Continue (0xFB).
|
|
51
|
+
def on_continue; end
|
|
52
|
+
|
|
53
|
+
# Listens to the clock of +midi_in+.
|
|
54
|
+
def connect!
|
|
55
|
+
connect_to midi_in
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module RCoreMidi
|
|
2
|
+
class Destination
|
|
3
|
+
attr_reader :name
|
|
4
|
+
|
|
5
|
+
# Finds the destination called +name+ across all devices, for example a
|
|
6
|
+
# port of a multi-port MIDI interface ('Port 1'). Raises ArgumentError when
|
|
7
|
+
# no destination or more than one device has that name.
|
|
8
|
+
def self.named(name)
|
|
9
|
+
matches = Device.all.flat_map do |device|
|
|
10
|
+
destinations_of(device).select { |d| d.name == name }.map { |d| [device, d] }
|
|
11
|
+
end
|
|
12
|
+
raise ArgumentError, "No MIDI destination named \"#{name}\"" if matches.empty?
|
|
13
|
+
if matches.size > 1
|
|
14
|
+
raise ArgumentError, "Several MIDI devices have a destination named \"#{name}\": " \
|
|
15
|
+
"#{matches.map { |device, _| device.name }.join(', ')}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
matches.first.last
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.destinations_of(device)
|
|
22
|
+
device.entities.flat_map(&:destinations)
|
|
23
|
+
end
|
|
24
|
+
private_class_method :destinations_of
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module RCoreMidi
|
|
2
|
+
class Entity
|
|
3
|
+
attr_reader :device
|
|
4
|
+
|
|
5
|
+
def sources
|
|
6
|
+
endpoints.select { |e| e.is_a? Source }
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def destinations
|
|
10
|
+
endpoints.select { |e| e.is_a? Destination }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def midi_in?
|
|
14
|
+
sources.any?
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def midi_out?
|
|
18
|
+
destinations.any?
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/rcoremidi.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rcoremidi
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Yann Marquet
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rake-compiler
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.2'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.2'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rdoc
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '6'
|
|
33
|
+
- - "<"
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '9'
|
|
36
|
+
type: :development
|
|
37
|
+
prerelease: false
|
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '6'
|
|
43
|
+
- - "<"
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '9'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: rspec
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - "~>"
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '3.13'
|
|
53
|
+
type: :development
|
|
54
|
+
prerelease: false
|
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - "~>"
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '3.13'
|
|
60
|
+
- !ruby/object:Gem::Dependency
|
|
61
|
+
name: rspec-its
|
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - "~>"
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '2.0'
|
|
67
|
+
type: :development
|
|
68
|
+
prerelease: false
|
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - "~>"
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '2.0'
|
|
74
|
+
description: |
|
|
75
|
+
A C extension wrapping macOS CoreMIDI: list MIDI devices, entities, sources
|
|
76
|
+
and destinations, follow an external MIDI clock (Start, Clock, Stop,
|
|
77
|
+
Continue, Song Position) through hooks on a Client subclass, and schedule
|
|
78
|
+
timestamped notes with CoreMIDI's host-time scheduler. macOS only.
|
|
79
|
+
email:
|
|
80
|
+
- ymarquet@gmail.com
|
|
81
|
+
executables: []
|
|
82
|
+
extensions:
|
|
83
|
+
- ext/rcoremidi/extconf.rb
|
|
84
|
+
extra_rdoc_files:
|
|
85
|
+
- README.md
|
|
86
|
+
files:
|
|
87
|
+
- README.md
|
|
88
|
+
- ext/rcoremidi/client.c
|
|
89
|
+
- ext/rcoremidi/client.h
|
|
90
|
+
- ext/rcoremidi/extconf.rb
|
|
91
|
+
- ext/rcoremidi/midi_client.c
|
|
92
|
+
- ext/rcoremidi/midi_client.h
|
|
93
|
+
- ext/rcoremidi/midi_object.c
|
|
94
|
+
- ext/rcoremidi/midi_object.h
|
|
95
|
+
- ext/rcoremidi/rcoremidi.c
|
|
96
|
+
- ext/rcoremidi/rcoremidi.h
|
|
97
|
+
- ext/rcoremidi/universal_packet.c
|
|
98
|
+
- ext/rcoremidi/universal_packet.h
|
|
99
|
+
- lib/rcoremidi.rb
|
|
100
|
+
- lib/rcoremidi/client.rb
|
|
101
|
+
- lib/rcoremidi/destination.rb
|
|
102
|
+
- lib/rcoremidi/device.rb
|
|
103
|
+
- lib/rcoremidi/entity.rb
|
|
104
|
+
- lib/rcoremidi/source.rb
|
|
105
|
+
- lib/rcoremidi/version.rb
|
|
106
|
+
homepage: https://github.com/StupidCodeFactory/rcoremidi
|
|
107
|
+
licenses:
|
|
108
|
+
- MIT
|
|
109
|
+
metadata:
|
|
110
|
+
homepage_uri: https://github.com/StupidCodeFactory/rcoremidi
|
|
111
|
+
changelog_uri: https://github.com/StupidCodeFactory/rcoremidi/blob/master/History.txt
|
|
112
|
+
rdoc_options:
|
|
113
|
+
- "--main"
|
|
114
|
+
- README.md
|
|
115
|
+
require_paths:
|
|
116
|
+
- lib
|
|
117
|
+
- ext/rcoremidi
|
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
|
+
requirements:
|
|
120
|
+
- - ">="
|
|
121
|
+
- !ruby/object:Gem::Version
|
|
122
|
+
version: '3.2'
|
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
|
+
requirements:
|
|
125
|
+
- - ">="
|
|
126
|
+
- !ruby/object:Gem::Version
|
|
127
|
+
version: '0'
|
|
128
|
+
requirements: []
|
|
129
|
+
rubygems_version: 4.0.20
|
|
130
|
+
specification_version: 4
|
|
131
|
+
summary: Ruby bindings for the macOS CoreMIDI framework
|
|
132
|
+
test_files: []
|