midi-communications-windows 0.0.3

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.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.version +6 -0
  4. data/.yardoc/checksums +8 -0
  5. data/.yardoc/complete +0 -0
  6. data/.yardoc/object_types +0 -0
  7. data/.yardoc/objects/root.dat +0 -0
  8. data/.yardoc/proxy_types +0 -0
  9. data/.yardopts +8 -0
  10. data/Gemfile +3 -0
  11. data/LICENSE +165 -0
  12. data/README.md +176 -0
  13. data/Rakefile +13 -0
  14. data/doc/MIDICommunicationsWindows/API/MIDIHdr.html +144 -0
  15. data/doc/MIDICommunicationsWindows/API/MIDIInCaps.html +142 -0
  16. data/doc/MIDICommunicationsWindows/API/MIDIOutCaps.html +140 -0
  17. data/doc/MIDICommunicationsWindows/API/MSG.html +143 -0
  18. data/doc/MIDICommunicationsWindows/API.html +981 -0
  19. data/doc/MIDICommunicationsWindows/Device/ClassMethods.html +365 -0
  20. data/doc/MIDICommunicationsWindows/Device/InstanceMethods.html +1096 -0
  21. data/doc/MIDICommunicationsWindows/Device.html +988 -0
  22. data/doc/MIDICommunicationsWindows/Error.html +438 -0
  23. data/doc/MIDICommunicationsWindows/Input.html +1554 -0
  24. data/doc/MIDICommunicationsWindows/Message.html +700 -0
  25. data/doc/MIDICommunicationsWindows/Output.html +1697 -0
  26. data/doc/MIDICommunicationsWindows/TypeConversion.html +369 -0
  27. data/doc/MIDICommunicationsWindows.html +210 -0
  28. data/doc/_index.html +262 -0
  29. data/doc/class_list.html +54 -0
  30. data/doc/css/common.css +1 -0
  31. data/doc/css/full_list.css +206 -0
  32. data/doc/css/style.css +1089 -0
  33. data/doc/file.README.html +240 -0
  34. data/doc/file.testing-on-windows.html +253 -0
  35. data/doc/file_list.html +64 -0
  36. data/doc/frames.html +22 -0
  37. data/doc/index.html +240 -0
  38. data/doc/js/app.js +801 -0
  39. data/doc/js/full_list.js +334 -0
  40. data/doc/js/jquery.js +4 -0
  41. data/doc/method_list.html +382 -0
  42. data/doc/top-level-namespace.html +112 -0
  43. data/docs/testing-on-windows.md +222 -0
  44. data/examples/input.rb +27 -0
  45. data/examples/list_ports.rb +17 -0
  46. data/examples/output.rb +22 -0
  47. data/examples/sysex_output.rb +15 -0
  48. data/lib/midi-communications-windows/api.rb +340 -0
  49. data/lib/midi-communications-windows/device.rb +310 -0
  50. data/lib/midi-communications-windows/input.rb +486 -0
  51. data/lib/midi-communications-windows/message.rb +133 -0
  52. data/lib/midi-communications-windows/output.rb +206 -0
  53. data/lib/midi-communications-windows/type_conversion.rb +20 -0
  54. data/lib/midi-communications-windows/version.rb +4 -0
  55. data/lib/midi-communications-windows.rb +76 -0
  56. data/midi-communications-windows.gemspec +32 -0
  57. metadata +220 -0
data/doc/index.html ADDED
@@ -0,0 +1,240 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ File: README
8
+
9
+ &mdash; MIDI Communications Windows API
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css">
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css">
16
+
17
+ <script type="text/javascript">
18
+ pathId = "README";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div id="main_progress" aria-hidden="true"></div>
31
+
32
+ <div class="nav_wrap">
33
+ <iframe id="nav" src="class_list.html?1"></iframe>
34
+ <div id="resizer"></div>
35
+ </div>
36
+
37
+ <div id="main" tabindex="-1">
38
+ <div id="header">
39
+ <div id="menu">
40
+
41
+ <a href="_index.html">Index</a> &raquo;
42
+ <span class="title">File: README</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><div id='filecontents'><h1 id="MIDI_Communications_Windows_Layer">MIDI Communications Windows Layer</h1>
63
+ <p><a href="https://www.ruby-lang.org/"><img src="https://img.shields.io/badge/ruby-2.7+-red.svg" alt="Ruby Version" /></a>
64
+ <a href="https://www.gnu.org/licenses/lgpl-3.0.html"><img src="https://img.shields.io/badge/license-LGPL--3.0--or--later-blue.svg" alt="License" /></a></p>
65
+ <p><strong>Realtime MIDI IO with Ruby for Windows.</strong></p>
66
+ <p>Access the <a href="https://learn.microsoft.com/en-us/windows/win32/multimedia/midi-reference">Windows Multimedia (WinMM) MIDI API</a> with Ruby.</p>
67
+ <p>This library is part of a suite of Ruby libraries for MIDI:</p>
68
+ <table>
69
+ <thead>
70
+ <tr>
71
+ <th>Function</th>
72
+ <th>Library</th>
73
+ </tr>
74
+ </thead>
75
+ <tbody>
76
+ <tr>
77
+ <td>MIDI Events representation</td>
78
+ <td><a href="https://github.com/javier-sy/midi-events">MIDI Events</a></td>
79
+ </tr>
80
+ <tr>
81
+ <td>MIDI Data parsing</td>
82
+ <td><a href="https://github.com/javier-sy/midi-parser">MIDI Parser</a></td>
83
+ </tr>
84
+ <tr>
85
+ <td>MIDI communication with Instruments and Control Surfaces</td>
86
+ <td><a href="https://github.com/javier-sy/midi-communications">MIDI Communications</a></td>
87
+ </tr>
88
+ <tr>
89
+ <td>Low level MIDI interface to MacOS</td>
90
+ <td><a href="https://github.com/javier-sy/midi-communications-macos">MIDI Communications MacOS Layer</a></td>
91
+ </tr>
92
+ <tr>
93
+ <td>Low level MIDI interface to Windows</td>
94
+ <td><a href="https://github.com/javier-sy/midi-communications-windows">MIDI Communications Windows Layer</a> (this library)</td>
95
+ </tr>
96
+ <tr>
97
+ <td>Low level MIDI interface to Linux</td>
98
+ <td><strong>TO DO</strong> (by now <a href="https://github.com/javier-sy/midi-communications">MIDI Communications</a> uses <a href="http://github.com/arirusso/alsa-rawmidi">alsa-rawmidi</a>)</td>
99
+ </tr>
100
+ <tr>
101
+ <td>Low level MIDI interface to JRuby</td>
102
+ <td><strong>TO DO</strong> (by now <a href="https://github.com/javier-sy/midi-communications">MIDI Communications</a> uses <a href="http://github.com/arirusso/midi-jruby">midi-jruby</a>)</td>
103
+ </tr>
104
+ </tbody>
105
+ </table>
106
+ <h2 id="Status">Status</h2>
107
+ <p><strong>Early.</strong> Everything is written and has been exercised end to end on Windows 11
108
+ 25H2 against system loopback endpoints: enumeration, short messages in both
109
+ directions, System Exclusive in both directions including a message larger than
110
+ the whole buffer queue, twenty open/close cycles, and the error path. What has
111
+ not been exercised is anything needing real hardware — a physical interface slow
112
+ enough to make <code>Output</code>'s System Exclusive wait mean something, and a port
113
+ appearing or disappearing while the program runs.</p>
114
+ <p>The version stays in the 0.0.x series because that was a virtual machine with no
115
+ MIDI hardware in it, not because anything is known to be missing. It will not be
116
+ published to RubyGems until a physical MIDI interface has closed the items
117
+ <a href="docs/testing-on-windows.md"><code>docs/testing-on-windows.md</code></a> lists as untestable
118
+ without one.</p>
119
+ <p>That document is also how to rebuild the test environment: it is the procedure
120
+ these measurements were taken with, including how to make two ports collide in
121
+ WinMM's 31 characters of name.</p>
122
+ <h3 id="One_thing_worth_knowing_before_you_use_it">One thing worth knowing before you use it</h3>
123
+ <p><code>Input#gets</code> <strong>waits</strong>. It does not return an empty array when nothing has
124
+ arrived; it blocks until something does, and then returns everything that
125
+ accumulated. Calling it on a quiet port looks exactly like a hung program. That
126
+ is deliberate — <code>Musa::Clock::InputMidiClock</code> reads in a loop with no delay of
127
+ its own and relies on it — but it will surprise anyone arriving from an API that
128
+ polls.</p>
129
+ <h2 id="Requirements">Requirements</h2>
130
+ <ul>
131
+ <li><a href="http://github.com/ffi/ffi">ffi</a></li>
132
+ </ul>
133
+ <p>Nothing else. <code>winmm.dll</code> is part of Windows, so this gem binds a library that
134
+ is already on the machine and ships no compiled artifact of its own.</p>
135
+ <h3 id="Which_versions_of_Windows">Which versions of Windows</h3>
136
+ <p><strong>By construction, old ones.</strong> Everything this gem calls is the oldest MIDI API
137
+ Windows has — <code>midiInOpen</code>, <code>midiOutShortMsg</code>, <code>midiOutLongMsg</code> and their
138
+ neighbours — plus three functions for a thread's message queue, <code>GetMessageW</code>,
139
+ <code>PeekMessageW</code> and <code>PostThreadMessageW</code>. All of it, the Unicode entry points
140
+ included, dates from the NT era. Nothing here calls Windows MIDI Services, which
141
+ means nothing here needs Windows 11.</p>
142
+ <p>What changes on an older system is not whether the gem works but what the
143
+ platform gives it. Before Windows MIDI Services a MIDI port is <strong>exclusive</strong> —
144
+ one program at a time — and there are no system loopback endpoints, so routing
145
+ MIDI between applications on one machine needs a third-party driver such as
146
+ loopMIDI. The same code, a poorer platform.</p>
147
+ <p>A 32-bit Ruby should also be fine: the two size checks that only hold on 64-bit
148
+ Windows are guarded, and the two that are checked everywhere describe structures
149
+ whose layout does not depend on the word size.</p>
150
+ <p><strong>None of which has been run.</strong> The only system this has ever executed on is
151
+ Windows 11 25H2, in a virtual machine, on an x64 Ruby under ARM emulation. The
152
+ paragraphs above say what the code asks of Windows, not what has been observed;
153
+ treat them as a reason to expect it to work rather than as a report that it does.</p>
154
+ <p>Where the floor actually sits is a question about Ruby, not about this gem:
155
+ RubyInstaller recommends Windows 10 or 11 and publishes no hard cutoff.</p>
156
+ <h2 id="Installation">Installation</h2>
157
+ <p>If you're using Bundler, add this line to your application's Gemfile:</p>
158
+ <p><code>gem &quot;midi-communications-windows&quot;</code></p>
159
+ <p>Otherwise</p>
160
+ <p><code>gem install midi-communications-windows</code></p>
161
+ <h2 id="Documentation">Documentation</h2>
162
+ <p><a href="http://rubydoc.info/github/javier-sy/midi-communications-windows">rdoc</a></p>
163
+ <h2 id="Why_WinMM_and_not_one_of_the_newer_Windows_MIDI_APIs">Why WinMM and not one of the newer Windows MIDI APIs</h2>
164
+ <p>Windows has three MIDI APIs a program could reach for, and as of February 2026
165
+ the oldest is the right one for Ruby.</p>
166
+ <p><strong>Windows MIDI Services</strong> became generally available in Windows 11 in February
167
+ 2026, replacing the MIDI stack underneath. Rather than retiring the older APIs,
168
+ Microsoft reconnected them to the new service, so a WinMM client needs nothing
169
+ installed to reach what the new stack provides — including the loopback
170
+ endpoints the system now creates itself, which is what previously required a
171
+ third-party driver.</p>
172
+ <p>Multi-client access arrives the same way, but <strong>per endpoint, not per API</strong>.
173
+ Measured on Windows 11 25H2 through this library: two clients opened the same
174
+ loopback input at once and both received every message, while a second open of
175
+ the classic <code>wdmaud</code> software synthesiser was refused with &quot;The specified device
176
+ is already in use&quot;. Endpoints carried by the new transports are shared;
177
+ endpoints still on the old drivers are exclusive, as they always were. On
178
+ Windows 10 there is no Windows MIDI Services at all.</p>
179
+ <p><strong>The Windows MIDI Services App SDK</strong> offers MIDI 2.0 and UMP, neither of which
180
+ this library needs: <code>midi-communications</code> and MusaDSL are MIDI 1.0 throughout.
181
+ It is published only as WinRT, and Microsoft's guidance is that other languages
182
+ obtain a WinRT projection from their toolchain. Ruby has none.</p>
183
+ <p><strong>WinRT <code>Windows.Devices.Midi</code></strong> is, under the new stack, another compatibility
184
+ layer onto the same service. It offers what WinMM offers, in exchange for
185
+ hand-written COM.</p>
186
+ <h2 id="Differences_from_the_macOS_layer">Differences from the macOS layer</h2>
187
+ <p>The two libraries implement the same contract over platforms that do not have
188
+ the same shape. Where they differ, they differ because the platforms do:</p>
189
+ <ul>
190
+ <li><strong><code>manufacturer</code> and <code>model</code> are <code>nil</code>.</strong> WinMM reports <code>wMid</code> and <code>wPid</code>,
191
+ numeric codes from a manufacturer registry that stopped being maintained in
192
+ the 1990s and that class-compliant USB devices almost all answer with
193
+ Microsoft's. Core MIDI reports real strings. Inventing text from the codes
194
+ would describe the code table, not the hardware.</li>
195
+ <li><strong><code>display_name</code> is the port name.</strong> On macOS it is composed as
196
+ &quot;manufacturer model (name)&quot;, which here would be a name wrapped in the
197
+ punctuation of two absent fields.</li>
198
+ <li><strong>Port ids are unique within a direction, not across both.</strong> A WinMM port is
199
+ identified by its index among inputs or among outputs, and that index is what
200
+ is passed to <code>midiInOpen</code>. Core MIDI numbers endpoints of both directions from
201
+ one counter. Input 0 and output 0 are both valid here, and unrelated.</li>
202
+ <li><strong>Port names are truncated to 31 characters, and do not identify a port.</strong>
203
+ That is all WinMM stores, and it drops the rest silently. Two loopback
204
+ endpoints whose names differed only past character 31 came back identical in
205
+ every field of <code>MIDIINCAPSW</code> — same name, same <code>wMid</code>, same <code>wPid</code>, same
206
+ <code>wTechnology</code> — distinguishable only by index. Core MIDI names are neither
207
+ truncated nor, in practice, ambiguous.</li>
208
+ <li><strong>Enumeration is not cached, but wrappers are reused.</strong> The macOS layer reads
209
+ the device list once and keeps it, so a device plugged in later is never seen.
210
+ Here WinMM is asked on every call, and a port still present comes back as the
211
+ same object it was before, so opening a port and then reading from it works
212
+ whether or not the caller kept the reference.</li>
213
+ <li><strong>There is no packet-list parsing.</strong> Core MIDI delivers a list of packets that
214
+ has to be walked; WinMM delivers one complete short message at a time, with
215
+ running status already resolved by the driver.</li>
216
+ </ul>
217
+ <h2 id="Relationship_to_midi_winmm">Relationship to midi-winmm</h2>
218
+ <p>This library is <strong>not</strong> derived from <a href="http://github.com/arirusso/midi-winmm">midi-winmm</a>,
219
+ which was written in 2011 for 32-bit Ruby. Windows is LLP64: on a 64-bit Ruby,
220
+ <code>unsigned long</code> is 32 bits while a <code>HANDLE</code> is 64, so that library's
221
+ <code>typedef :ulong, :HANDLE</code> truncates every handle it obtains. It also reads port
222
+ names through the ANSI entry points, which mangle any name that is not ASCII.
223
+ Both are addressed here by construction; see the notes in
224
+ <code>lib/midi-communications-windows/api.rb</code>.</p>
225
+ <h2 id="Author">Author</h2>
226
+ <ul>
227
+ <li><a href="https://github.com/javier-sy">Javier Sánchez Yeste</a></li>
228
+ </ul>
229
+ <h2 id="License">License</h2>
230
+ <p><a href="https://github.com/javier-sy/midi-communications-windows">MIDI Communications Windows Layer</a> Copyright (c) 2026 <a href="https://yeste.studio">Javier Sánchez Yeste</a>, licensed under LGPL 3.0 License</p></div></div>
231
+
232
+ <div id="footer">
233
+ Generated on Sun Sep 6 21:20:52 2026 by
234
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
235
+ 0.9.45 (ruby-3.4.7).
236
+ </div>
237
+
238
+ </div>
239
+ </body>
240
+ </html>