NOW LOADING

Bluetooth Low Energy MIDI Transport Architecture


How the Windows MIDI Services Bluetooth LE MIDI transport discovers, connects to, and exchanges MIDI with BLE MIDI 1.0 and BLE MIDI 2.0 devices.

Preview

The Bluetooth LE MIDI transport is preview code. BLE MIDI 2.0 support follows a draft specification (MIDI Association TSB item #274) which has not been published, so its details may change.

This page describes the design of the in-box Bluetooth Low Energy MIDI transport (Midi2.BluetoothMidiTransport.dll, registered as Midi2BluetoothMidiTransport). It is aimed at people working on the transport itself rather than at app developers.

One transport, two protocols

Both BLE MIDI 1.0 and BLE MIDI 2.0 live in the same GATT service:

Item UUID
MIDI Service 03B80E5A-EDE8-4B33-A751-6CE34EC4C700
MIDI 1.0 Characteristic 7772E5DB-3868-4112-A1A9-F2669D106BF3
UMP Characteristic C3B10ECF-88F5-4F7D-BFFA-8AD2C91FBAFE

A Peripheral rejects a subscription to a second MIDI Characteristic while one is already active, and the specification requires a Central which discovers both to subscribe to the UMP Characteristic. Preferring one over the other is therefore not a policy decision the service can make independently, and it cannot be split across two transport plugins: midisrv does not coordinate between plugins, so two of them would race to claim the same device. One transport owns the whole MIDI Service.

SelectPreferredMidiCharacteristic reads the UMP Characteristic first and falls back to the MIDI 1.0 Characteristic.

Discovery

Two watchers feed a single table of discovered devices, keyed by the device’s Bluetooth address rendered as 12 hexadecimal digits. That address is the only identifier both watchers can supply, and it is what the configuration commands and the endpoint device instance ids use.

  • BluetoothLEAdvertisementWatcher, filtered on the MIDI Service UUID, in Active scanning mode so scan response data is collected too. This is the primary source, because it finds devices which have never been paired. Requiring pairing before a device is even visible is one of the main complaints about the older Windows BLE MIDI 1.0 support.
  • A GATT DeviceWatcher over GattDeviceService.GetDeviceSelectorFromUuid. This only sees devices Windows has already enumerated, but it sees them whether or not they are advertising right now.

Entries which are neither paired nor connected are dropped from the available list once they have not advertised for a while.

Device names

The name in an advertisement is frequently absent. Many peripherals put the MIDI Service UUID in the advertisement and their name in the scan response, and since the watcher filters on the service UUID, only the packet without the name matches. Both an M-Vave SMK25Mini and an Artiphon Chorda behave this way, while a KORG nanoKEY Studio puts both in one packet.

A device discovered without a name therefore has one resolved from BluetoothLEDevice, which reports what the Bluetooth stack already knows and works for unpaired devices without connecting to them. That call is queued to the background worker: it is asynchronous, and an advertisement callback fires several times a second per device. The stack may not have parsed the scan response by the time the first advertisement arrives, so a few spaced retries are allowed.

A device is not listed, and cannot be connected, until it can be named. A Bluetooth address means nothing to a user, so offering one to pick from is a last resort reserved for a device whose name cannot be resolved at all. This gate applies to connecting as well as listing, because an endpoint takes its name from its device: connecting during the resolution window would publish a MIDI endpoint named after a hexadecimal address, and that name would then persist in the user’s configuration. A connection asked for during the window is not refused, only deferred, and name resolution starts it as soon as it finishes.

Connecting

Discovery never connects. Connecting is driven by the connectDevice configuration command, or by a devices array in the transport’s section of the configuration file, which is how a previously approved device is reconnected with no app running.

The midi console tool exposes all of this:

midi bluetooth list
midi bluetooth connect <device id>
midi bluetooth disconnect <device id>

Opening a GATT session and creating a device node both take service locks and raise PnP notifications, so a connect request is queued and drained by a background worker rather than run on the caller’s thread or on a watcher callback. Doing this work on a callback thread is what deadlocked the Network MIDI 2.0 transport.

Because of that, connectDevice returns before the connection has been attempted. The outcome is recorded against the discovered device and reported by listAvailableDevices as lastConnectError, which midi bluetooth list prints under the table. Without it, a failed connect is completely silent.

The worker resolves the address to a BluetoothLEDevice, opens the MIDI Service, selects a Characteristic, takes a GattSession with MaintainConnection(true), subscribes to notifications, then activates the endpoint.

Some devices answer when Windows asks for the MIDI Service by its UUID, and the request still fails. When that happens, the transport tries two other ways in: the MIDI Service’s own device node, which Windows only creates for a paired device, and then, if the link is still up, a list of every service on the device. It does the same for the Characteristics. It only does this when the first request failed outright or found nothing. A timeout, an error status or an ATT error already says what went wrong, and a device that’s switched off would only make each extra step wait out the same timeout.

Each of those steps is a blocking Bluetooth call with its own timeout, and establishing a link is much slower than talking over one which already exists: the radio may wait several advertising intervals, and a device which demands pairing adds a whole security exchange. The connect path therefore allows considerably longer than the data path. Because service shutdown joins the worker, and a connect attempt makes several of these calls back to back, the waits are abandoned early once shutdown begins rather than each running to its full timeout.

Because a connect attempt takes seconds and a wanted device is retried until it appears, “not connected” alone cannot distinguish an attempt under way from a device which is switched off. connectionState reports notConnected, waitingForDevice, connecting or connected so a caller can say which, and can stop a user queueing attempt after attempt while one is in flight. A device marked as requiring pairing reports notConnected rather than waitingForDevice, because the sweep has deliberately stopped retrying it.

By far the most common failure is a GATT status of Unreachable, which simply means the peripheral is asleep. BLE MIDI devices sleep aggressively, and a device that Windows lists as paired is very often not currently connectable.

Remembered devices

Because of that, a single connection attempt is nearly useless: at service start, or at the moment a user clicks connect, the device usually cannot answer. So connecting records an intent rather than performing a one-shot action.

A device stays in the wanted set until it is explicitly disconnected, and a connection is attempted again every time that device advertises or Windows enumerates its GATT service, rate limited per device. A device only advertises when it is awake and unconnected, which makes an advertisement the exact moment it becomes connectable. In practice this means a user can ask for a device that is switched off, turn it on later, and have it connect on its own.

A device that isn’t advertising is also retried on a timer, in case it’s awake but not being heard. Each of those tries costs a full Bluetooth timeout, and one worker makes every connection, so the timer backs off: 10 seconds after the first failure, doubling up to once a minute. Hearing the device, or being asked to connect it, starts the wait over. The worker also makes one connection at a time and serves devices it has just heard, or has just been asked for, before timer retries. Without that, two remembered devices that were switched off were measured keeping the worker busy all the time, and a device sitting on the desk waited about 30 seconds to connect.

A remembered device stays in the device list while it’s being retried, even when it’s switched off, so the customer can see it and disconnect it.

An unconfigured paired device is treated as wanted when the transport discovers it. If discovery also knows that the device is currently out of range, it waits for a later advertisement; if presence is unknown, it keeps the request because the paired-device watcher can still be the only evidence Windows has after a restart. A saved enabled: false entry is an explicit exception and prevents this automatic connection. This lets paired devices from the older Windows BLE MIDI support appear through the new transport without requiring a second manual connection step.

The intent itself is held in memory, so it does not survive a service restart. The durable form is a devices array in the transport’s section of the configuration file, which the service reads but never writes. midi bluetooth connect writes that entry, and disconnect removes it, so a connection made once is re-established on every subsequent service start. Saving a setting for a device, such as how long its endpoint stays after it goes offline, does not make it a device to reconnect.

Because a request is remembered rather than performed, connectDevice reports whether the device is actually present. A request for a device which is switched off succeeds and is honored later, and saying “connecting” in that case would be untrue.

Presence

Bluetooth LE offers no notion of a device being online, so presence is inferred:

  • A device which is connected is present, taken from the live link rather than from the fact that a connection object exists.
  • Otherwise a device is present if it has advertised recently. A device only advertises while it is awake and unconnected.

These are reported as isPresent and lastSeenAgoMilliseconds, alongside hasEndpoint.

hasEndpoint and presence are deliberately separate. An endpoint outlives a device going away, so the combination of an endpoint that exists and a device that is absent is exactly the silent disconnect that leaves an application holding an endpoint which will never carry data. Reporting one flag for both would hide it. A signal strength is also cleared once a device is no longer present, because a reading from several minutes ago reads as current.

Endpoint properties

Both kinds of device are presented to the service as UMP endpoints, because the transport does the translation. The native data format is what tells apps, and the service’s own transform selection, what the device really is.

  BLE MIDI 1.0 BLE MIDI 2.0
NativeDataFormat ByteStream UMP
SupportedDataFormats UMP UMP
MIDI 2.0 protocol capability no yes
Endpoint discovery and negotiation skipped, discovery marked complete performed

Marking discovery complete on a BLE MIDI 1.0 endpoint is what lets the service create its MIDI 1.0 ports immediately instead of waiting for a negotiation that will never be answered. Declaring ByteStream as the native format is also what makes the service insert its protocol downscaler, so an app sending MIDI 2.0 protocol messages to a MIDI 1.0 device still works.

BLE MIDI 1.0 packet format

midi_ble_midi1_codec.h is a self-contained implementation of the packet format with no dependency on Bluetooth, the service or COM, which is what makes it unit testable (Midi2.Transport.BluetoothMidi.unittests).

A packet is a Header Byte (bit 7 set, bit 6 reserved, bits 5-0 timestampHigh) followed by Timestamp Byte and message pairs (bit 7 set, bits 6-0 timestampLow). Timestamps are 13 bit millisecond values.

Decoding restores omitted Running Status bytes, so everything downstream sees whole messages. Running Status is canceled at the end of every packet. System Real-Time messages cancel neither Running Status nor an in-progress SysEx. A SysEx continuation packet is a header byte followed immediately by data with no timestamp byte, which is the only signal that distinguishes it from the start of a message.

Timestamps arrive in the sender’s clock domain, and correlating the two clocks is explicitly out of scope for the specification. The sender’s 13 bit value is unwrapped into a continuous millisecond count and mapped onto the local clock through a single offset, which preserves spacing both within a packet and across packet boundaries. Anchoring each packet to its own arrival time instead does not work: consecutive packets are anchored independently, so an early message in one packet can be given a timestamp before a late message in the packet before it, and the stream arrives out of order.

The offset is the smallest arrival delay observed, because arrival delay is never negative and the minimum is therefore the sample carrying the least transport latency. That minimum is taken over a sliding five second window rather than over all history. An all-time minimum never forgets an outlier, and following clock drift by creeping a fixed step per packet would make the correction rate depend on how fast the device happens to be sending rather than on how much time has passed. These are the timestamps apps get when a device is set to “As soon as possible”. Smoothing uses a more careful estimate that also measures clock drift; see Incoming timing.

Deciding that too much time has passed to trust the correlation cannot be left to the sender’s clock. Thirteen bits wraps every 8.192 seconds, so a long gap is reported as gap % 8192, and roughly half of those land below any plausible-gap threshold and read as an ordinary short delta: a twenty second silence arrives as 3,616 ms. The local arrival clock decides instead, and a gap longer than one wrap discards the correlation and re-anchors on the next packet.

Devices which do not keep time. Several inexpensive controllers never advance their timestamp at all. Every packet carries the same value however much time has really passed, including across a press and hold lasting a second, which is provable because a Note On and a Note Off have different status bytes, break Running Status, and must therefore each carry their own timestamp byte. Correlating against a stopped clock collapses an entire gesture onto a single instant.

Real time passing between packets while the sender’s timestamp stands still is the only way to detect this, because messages inside one packet are allowed to share a timestamp and Running Status leaves them no room to carry one. After three such observations the sender’s clock is abandoned and arrival time is used instead. Any subsequent movement of the timestamp restores correlation, so nothing is stored and a firmware fix takes effect on its own. Which of the two is in use is reported per device as MidiBluetoothTimestampSource and shown by midi bluetooth list and the setup app.

Encoding never generates Running Status: transmitting it is optional and every receiver is required to accept full messages. A complete message other than SysEx is never split across two packets. Because a packet carries a single timestampHigh, a message past a 128 ms boundary starts a new packet rather than relying on the receiver’s single wrap allowance.

Incoming timing: smoothing out connection interval jitter

This section is for anyone building a BLE MIDI 1.0 device. It explains what Windows does with your timestamps and what timing your users will get.

Why BLE MIDI jitters

BLE only moves data at connection events, one every connection interval. When a player presses a key, the message waits for the next event. That wait is anywhere from no time at all to one whole interval. It can be longer if the link skips an event or has to resend a packet, and the Windows Bluetooth stack adds a little more of its own.

If each message is handed to apps the moment its packet arrives, notes played exactly 10 ms apart can come out 7.5 ms apart, then 15 ms apart. MIDI clock and fast passages are hit hardest. Most apps act on a message when it arrives, not on its timestamp, so they hear all of it.

What Windows does about it

Every message carries a timestamp from your device’s clock. If Windows knows how your clock lines up with its own, it can hold each message until the time you stamped on it, plus a small steady delay. Then every message comes out with the spacing you played. The cost is a few milliseconds of extra latency, the same for every message.

This is the Smooth setting, and it’s the default. As soon as possible turns it off for a device, so each message is handed on the moment it arrives. That’s the lowest latency with the full jitter. The setting is per device, it’s saved, and it’s in the Bluetooth MIDI setup app as “Smooth (add some latency to improve jitter)” and “As soon as possible”. In the console, it’s midi bluetooth customize <device> --incoming-timing smooth|asap|default for one device and midi bluetooth defaults --incoming-timing smooth|asap for the transport default. midi bluetooth list shows each device’s setting and the delay smoothing is adding right now. When smoothing is on, the timestamp an app sees is the time the message was released, so apps that use timestamps and apps that don’t hear the same steady timing.

BLE MIDI 2.0 devices are smoothed the same way when they send JR Timestamps. There the samples are the device’s JR Clocks rather than the message timestamps. JR time is in 32 microsecond steps, so the 1 ms floor is gone. A device that sends the startup burst of JR Clocks when JR is agreed gives enough samples to start smoothing within about 125 ms at a 15 ms interval, and about 70 ms at 7.5 ms. A BLE MIDI 2.0 device that doesn’t send JR is delivered as it arrives.

How the clock is recovered

The 13-bit timestamp is unwrapped into a continuous millisecond count first, as described under BLE MIDI 1.0 packet format. After that:

  1. For every packet, Windows compares your timestamp with the time the packet arrived. The difference is your clock’s offset from ours plus however long the packet waited. Waiting is never negative, so the packets that waited least show the true offset.
  2. It keeps the smallest difference from each second, for the last 30 seconds, and fits a straight line under them (the lower convex hull). The line’s height is the offset. Its slope is how fast your clock runs compared with ours. The slope is only measured once there are 5 seconds of data, and it’s limited to 2%.
  3. Each message’s place on that line is when you played it, in Windows time. The release time is that plus the delay.
  4. The delay is measured, not guessed. Over the last 10 seconds, Windows works out how long packets waited after their place on the line, and picks a delay that covers all but 3% of them, plus 0.5 ms for timer wake-up. On real links a few percent of packets miss a connection event and arrive a whole interval late. Covering those would add a whole interval of delay to every message, so they’re left out and delivered as they arrive. It starts at one connection interval plus 2 ms (or 17 ms if the interval isn’t known). It grows straight away if messages start arriving after their release time. It shrinks in small steps (an eighth of the difference, 0.1 to 0.5 ms at a time, every 100 ms), so nobody hears it settle. It’s never less than 1 ms and never more than 50 ms.
  5. The first 8 packets after connecting, or after your clock restarts, are delivered as they arrive while the line is built.
  6. Messages always come out in the order they arrived. A message that arrives after its release time goes out the moment it arrives. When the link drops, anything still waiting goes out right away.

Both BLE MIDI specifications say timestamps can’t be in the future, and Windows never sends one. Windows still treats incoming timestamps as untrusted. A message whose timestamp lands more than 2 ms after it arrived is treated as played when it arrived, the delay has a ceiling, and the slope has a limit.

What jitter to expect

These figures come from a simulated link (the BleIncomingSmoothingTests unit tests), with a sender that stamps each message when it happens and a stack delay of up to 0.3 ms. Real links add skipped events and resends, which the delay grows to cover. For example, about 3% of the messages from one keyboard measured on a 15 ms interval missed a connection event and arrived 15 ms late. Covering them would have needed about 28 ms of delay. Leaving them out, the delay settles at about 16 ms in a replay of that capture.

Connection interval As soon as possible: added delay As soon as possible: jitter Smooth: added delay, once settled Smooth: jitter
7.5 ms none up to about 7.5 ms about 8.3 ms about 1 ms
11.25 ms none up to about 11.25 ms about 11.9 ms about 1 ms
15 ms none up to about 15 ms about 15.7 ms about 1 ms

The 1 ms that’s left is the timestamp itself: BLE MIDI 1.0 timestamps are whole milliseconds, so no receiver can do better. Smooth delay settles at about one connection interval because that’s how long a packet can wait. Windows has only been seen to negotiate 15 ms as the Central, so most devices connected to a PC will see the 15 ms row. A Central that negotiates a shorter interval, such as a phone connected to this PC as a peripheral, gets a lower delay.

How your device’s clock affects the result

Your device What happens
Stamps each message when it happens, from a crystal-accurate millisecond clock The best case. About 1 ms of jitter, with a delay of about one connection interval.
Clock runs fast or slow by up to 2% (for example an RC oscillator) Once 5 seconds of data are in, the slope is measured and the result is the same as the best case. Before that, the delay grows to cover the drift, and with a large drift some messages miss their release time and go out as they arrive.
Clock is off by more than 2% The slope stops at 2%. Messages start missing their release time, and the delay climbs to its 50 ms ceiling. If even 50 ms can’t cover the packets for 10 seconds, Windows stops smoothing that device until it reconnects, delivers its messages as they arrive, and reports a timestamp source of ArrivalTime. Holding every message for 50 ms while many still arrive late is worse than not smoothing at all.
Stamps messages when it builds the packet, not when they happen Smoothing can only recreate the spacing in the timestamps. Messages in one packet come out together, and the spacing between packets still follows the connection events. You get the full connection interval jitter plus the smoothing delay.
Timestamp never moves Detected after three packets, as described above. Messages are delivered as they arrive, and the device is reported with a timestamp source of ArrivalTime.
Clock restarts or jumps The line is thrown away and rebuilt from the next packets. The delay the link needs is kept. A packet can’t arrive before it was sent, so a timestamp that suddenly reads more than 50 ms ahead of every recent packet is counted as a jump. A packet that’s late, for example because it was resent, isn’t.
Clock keeps jumping, for example because it wraps somewhere other than 8,192 ms After three jumps within a minute, Windows stops using the device’s timestamps until it reconnects. Its messages are delivered as they arrive, and it’s reported with a timestamp source of ArrivalTime.

Recommendations for device makers

  • Stamp each message with the time it happened: the key press, the knob move, the clock tick. Not the time the packet was built.
  • Run the timestamp from a crystal-accurate millisecond clock, and never freeze it.
  • Never put a timestamp in the future, and wrap the 13-bit value at 8,192 ms. A counter that wraps anywhere else, such as a 16-bit count of 0.1 ms divided by 10, which wraps at 6,553 ms, looks like a clock jumping 1.6 seconds every time it wraps.
  • Keep the clock running while your firmware is busy. A clock that stalls during a burst of messages, or that skips ahead after a pause, places those messages in the wrong spot.
  • Ask for the shortest connection interval your stack allows. 7.5 ms is recommended for live playing, and the smoothing delay follows the interval.
  • Send each message at the next connection event. Holding messages back to fill packets adds latency that smoothing can’t take away.

BLE MIDI 2.0 packet format

The ATT notification payload is UMP data with no header or other framing. Words are big-endian, several UMPs may be concatenated, and fragmentation is prohibited: a UMP which does not fit is deferred to the next notification. A malformed UMP invalidates the rest of the payload, because without a valid length there is no way to find the next message boundary.

Jitter Reduction (JR) Timestamps are handled inside this transport, not in the service, because only the transport knows where each BLE packet starts and ends. This part is provisional. It follows BLE MIDI 2.0 Working Group discussion that isn’t in a published draft yet, so it will change when the specification does.

  • The transport asks for JR in both directions during the normal protocol negotiation. A device that can’t do JR, or turns it down, simply doesn’t get it.
  • Incoming JR Clock and JR Timestamp messages never reach apps. The transport uses them to timestamp the messages they describe, lining the device’s JR clock up with this PC’s clock the same way BLE MIDI 1.0 timestamps are. A message with no usable JR Timestamp gets the time it arrived.
  • With “As soon as possible” timing, incoming messages are timestamped and delivered right away, even when their JR Timestamp is slightly in the future. With “Smooth”, the default, they are held until their release time, as described under Incoming timing.
  • Nothing goes out with JR until the device has said it will receive it. After that, each packet has a JR Timestamp in front of each group of messages that share a JR tick. A JR Timestamp is never later than the time the packet is handed to Bluetooth, and JR time is rounded down to the tick. JR Timestamps and JR Clocks come from the same clock, this PC’s MIDI timestamp clock, which never steps or slews.
  • Messages aren’t held back to fill packets. Once the receiver rebuilds timing from JR, waiting only adds latency.
  • JR Clocks go out on their own schedule, separate from data, including while nothing else is being sent. Each one goes in a packet of its own, never after messages. When JR is agreed, when the device reconnects, and whenever the connection interval changes, Windows sends a startup burst: 12 JR Clocks, each one connection interval plus a twelfth of an interval after the last (16.25 ms apart at a 15 ms interval). Each clock lands a twelfth of the interval later in the cycle than the one before, so together they cover the whole interval evenly, and one of them almost certainly catches a connection event closely. That lets the receiver line up the clocks within about 200 ms. If the interval isn’t known, the burst is 16 clocks 8 ms apart instead.
  • After the burst, Windows sends a JR Clock every 75 to 100 ms, at a period that is a whole number of connection intervals plus 0.618 of one (84.27 ms at a 15 ms interval, 79.635 ms at 7.5 ms), or every 97 ms if the interval isn’t known. The UMP limit of one clock every 250 ms is there so the 16-bit JR time can be unwrapped, and it’s not a target. A clock period that’s a whole number of intervals, or a simple fraction of one, makes every clock wait the same time for its connection event. The receiver then sees the same measurement over and over, and can stay up to a whole interval too high for minutes. With 0.618 of an interval left over, each clock lands at a new point in the interval, and the points never repeat. Every due time is worked out from the start of the schedule, never from when the last clock actually went out. Each JR Clock’s time is read just before it’s handed to Bluetooth.
  • JR Clock and JR Timestamp messages sent by apps are dropped. Only the transport can time them against the link.
  • A JR Timestamp can’t be later than a JR Clock sent after it, because both come from the sender’s clock and the clock is read when it’s handed over. A device that sends one more than about 1 ms later than the next clock is future-dating its timestamps, which would make messages look as if they arrived faster than they could. Windows stops using that device’s timestamps until it reconnects, delivers its messages as they arrive, and reports it as ArrivalTime.
  • A device that never sends JR, or whose JR Clock stops or goes quiet, is reported as ArrivalTime in MidiBluetoothTimestampSource, the same as a BLE MIDI 1.0 device whose clock doesn’t run.
  • The transport learns what the device agreed to from the device’s own Stream Configuration Notification as it passes through, not from the service. That way it works with any version of the service.
  • In the Peripheral role, Windows answers the remote Central’s negotiation itself and agrees to JR in both directions. See Peripheral role.

Recommendations for BLE MIDI 2.0 device makers

These follow BLE MIDI 2.0 Working Group guidance, and they’re what Windows does when it sends.

  • Read the time for a JR Clock as the last step before you hand it to your Bluetooth stack, not when you queue or build it.
  • Never put a JR Timestamp later than your JR time when the message is handed over, and round down to the tick. Windows stops trusting the timestamps of a device that sends one later than a JR Clock after it.
  • Take every JR Clock and JR Timestamp on a connection from one steady clock. Don’t step or slew it, for example to follow network time, because a jump makes the receiver start over. Keep it within about 120 ppm of the right rate.
  • Send JR Clocks on a timer, including while idle, not only after messages. Put a clock first in a packet, never after the messages in it.
  • Send a clock every 75 to 100 ms. Use a period of a whole number of connection intervals plus 0.618 of one, keep it on a fixed grid, and don’t line it up again with when each clock actually went out.
  • Right after JR is agreed, after a reconnection, and when the connection interval changes, send about 12 clocks, each one interval plus a twelfth of an interval after the last.
  • Send messages at the next connection event. Don’t hold them back to fill packets.
  • Send JR only on a connection that agreed to it.
  • If your stack tells you exactly when connection events happen, handing a clock over just before one gives the receiver its best measurement. Most stacks don’t, and everything above works without it.

Sending

Writes go through a per-connection queue drained by a writer thread. The Central always writes without response. The connection interval gates throughput, so blocking a client’s thread on a BLE write is not acceptable. The queue is bounded and drops its oldest packets rather than letting a device which has stopped draining exhaust service memory.

Disconnection and return

MaintainConnection(true) asks Windows to re-establish a dropped link. On the way down, the translation state is reset in both directions: a link drop can cut a SysEx transfer in half, and BLE MIDI 2.0 says UMP stream state is not preserved across disconnections.

On the way back up, notifications have to be turned on again. A new link to a device that isn’t bonded starts with notifications off, and a device that returns without them looks alive to apps while delivering nothing. The transport watches two events for the link coming back:

  • BluetoothLEDevice.ConnectionStatusChanged carries no status, so the handler reads the status when it runs. A device that’s back before Windows notices it left, such as one that was reset, is dropped and reconnected within a fraction of a second, and every event then reads as connected. So any event that reads as connected counts as a possible new link, even if no drop was seen.
  • GattSession.SessionStatusChanged carries its own status, so it still shows a reconnect that the connection status missed.

Either one asks the connection’s writer thread to write the descriptor that turns notifications on, because a GATT call must not block a Bluetooth callback. Several requests before it runs become one write. A failed write is tried again a few times while the link stays up, waiting longer each time. If it still fails, the transport removes the connection and connects again from scratch, the same as pressing Disconnect and then Connect. After a successful write, a BLE MIDI 2.0 endpoint is queued for full discovery and protocol negotiation again. That waits until notifications are back on, because the device answers in notifications.

Endpoint customization

The transport supports the shared endpoint customization shape, so a user-supplied name, description, and image survive across service restarts:

{
  "update": [
    {
      "match": { "endpointDeviceInstanceId": "MIDIU_BLEMIDI_..." },
      "customProperties": { "name": "Studio Keyboard", "description": "...", "image": "keys.png" }
    }
  ]
}

The match is on the device instance id, which this transport derives from the Bluetooth address and the device-supplied name, so it is deterministic. listAvailableDevices reports that id for every discovered device, which means a customization can be written for a device that has never been connected: the id is known as soon as the device is seen. transportSuppliedEndpointName also matches, for callers which prefer that.

Customizations are cached whether or not the endpoint exists yet, and the cache is consulted before the device node is created, so an endpoint is never published under the wrong name and then renamed a moment later. A customization for an endpoint which already exists is applied in place, so renaming a connected device does not require disconnecting it. The custom name becomes the device node name and not only a MIDI property, so applications which know nothing about MIDI properties show it too.

The console command is midi bluetooth customize <device id> [--name] [--description] [--image], with --clear to remove it. The image is a bare file name; a path is rejected, because the service loads images by name from a known folder.

Peripheral role

Windows can publish itself as a BLE MIDI Peripheral, so a phone or tablet acting as a Central can connect to the PC. MidiBlePeripheral owns a GattServiceProvider for the MIDI service UUID with two GattLocalCharacteristic objects, MIDI 1.0 and UMP, each with Notify | WriteWithoutResponse | Read.

The translation, queuing, timestamping, and callback plumbing are the same code as the Central role: MidiBleConnection takes a small link abstraction supplying only the three things which differ, which are how a packet is written, what the maximum payload is, and whether the link is up. Everything downstream of that is shared and already exercised by the codec tests.

Both characteristics are published, and the first subscription is served. A Central which follows the specification subscribes to only one, preferring UMP when it supports it, so a BLE MIDI 1.0 Central and a BLE MIDI 2.0 Central can both connect. The specification asks a Peripheral to refuse a second subscription with ATT error 0x80. WinRT can’t refuse a subscription, so a second one, on either characteristic, is simply ignored: it gets no endpoint and no data. If the Central later moves to the other characteristic, its endpoint is rebuilt for that protocol and its approval still stands.

One Central is served at a time, which matches the single active connection the specification permits. The first client to subscribe keeps the link until it goes away; a new client resets the translation state, because anything queued for the previous one is stale.

A read of either characteristic is answered with an empty payload, which is the specified connection handshake and the mirror of what the Central role performs.

On the UMP characteristic, Windows answers the Central’s UMP Endpoint questions itself. The endpoint apps see represents the remote Central, so nothing above the transport is in a position to answer, and these requests never reach apps. Endpoint Discovery gets an Endpoint Info Notification (UMP 1.1, no Function Blocks, both protocols, JR in both directions), a Device Identity (Microsoft, Windows 11 family, model 5), the PC’s Bluetooth name, and the current Stream Configuration. A Stream Configuration Request gets whatever it asked for that Windows can do, as a final Stream Configuration Notification. JR then works in both directions, with the same startup burst and clock schedule as the Central role, timed against the interval the Central chose.

What the endpoint represents

The endpoint is the remote device which connected, not this PC, which is the same model the Network MIDI 2.0 host uses: a host does not publish an endpoint for itself, it publishes one per connected remote client, named after that client. So the endpoint is created when a Central subscribes and removed when it goes away, and it carries the remote device’s name.

The remote name comes from BluetoothLEDevice::FromIdAsync on the subscribed client’s session device id, falling back to the formatted Bluetooth address. The instance id is MIDIU_BLEMIDI_PERIPHERAL_<name>_<address>, kept distinct from the MIDIU_BLEMIDI_<name>_<address> form used for a device this PC connected out to, so the same phone acting in both directions cannot collide on one device node.

Creating and removing an endpoint calls back into the service, which must never happen on a Bluetooth callback thread, so SubscribedClientsChanged only sets a flag and wakes the background endpoint creator, which is the one thread allowed to touch device nodes.

The name this PC advertises is separate, and is the PC’s Bluetooth name. The GATT service provider puts that in the advertisement and gives an application no way to override it, so the transport reports the name rather than accepting one. It is shown by getPeripheralStatus but is not the endpoint name.

Commands

Commands are startPeripheral (its protocol argument is still accepted but no longer used), stopPeripheral, and getPeripheralStatus. The console equivalents are midi bluetooth peripheral start|stop|status. The configuration file section is:

"peripheral": { "enabled": true, "protocol": "bleMidi1" }

It is off unless the configuration file asks for it, because publishing makes the machine visible and connectable to anything nearby.

Device identity, pairing, and the in-box MIDI 1.0 stack

A BLE device may advertise a public address, which is stable, or a resolvable private address, which rotates every few minutes for privacy. Dedicated instruments use stable addresses. General-purpose computers do not: an iPhone connecting to this PC was observed as 58C641C7B5AD and later 66646A807FC1. Anything keyed on the raw address therefore mints a new identity on every rotation and leaves the previous one behind.

Windows resolves a rotating address back to a single stable identity once the device is bonded, because bonding records an identity address. Measured on a paired iPhone: connected at 53D91162DC72, disconnected, left for seventeen minutes, then reconnected, still 53D91162DC72. Unbonded, the same phone had previously appeared under a different address altogether. Note that re-pairing creates a new bond and therefore a new identity address, so an unpair and re-pair does move the endpoint.

BluetoothAddressType reports random in both the bonded and unbonded cases, so it cannot be used to tell an identity address from a rotating one. Whether the device is paired is the signal that matters.

Pairing was performed on the remote device, which offered to pair with this PC. That is the direction which has been tested, and it is the natural one, since the phone is the side which scanned for this PC and connected to it. Initiating the pairing from Windows instead has not been tried, so the guidance to give a user is the direction known to work: pair with this PC from the phone’s own Bluetooth settings or from the MIDI app doing the connecting.

The endpoint is therefore keyed on the address only when the device is bonded. Everything unbonded shares a single reusable endpoint, MIDIU_BLEMIDI_PERIPHERAL_UNPAIRED, whose name follows whatever is currently connected. That keeps an unbonded phone from leaving a new endpoint behind every quarter of an hour, at the cost of not being able to tell two unbonded devices apart, which is not possible anyway.

Whether pairing is a good idea depends on which role Windows is playing, and the two cases pull in opposite directions.

  Windows is the Peripheral (a phone connects to this PC) Windows is the Central (this PC connects to an instrument)
Does the address rotate? Yes, phones and computers rotate No, instruments use stable addresses
Is pairing needed for a stable identity? Yes No
Does pairing invite a conflict? No, this PC serves the GATT service Yes, see below
Advice Pair, from the device, with this PC Do not pair unless the device requires it

The conflict in the Central column is the in-box Windows BLE MIDI 1.0 support. It only enumerates devices after they are paired, and it then opens their GATT service, which can come back to this transport as GattOpenStatus::SharingViolation. It also only knows the MIDI 1.0 data I/O characteristic, so against a BLE MIDI 2.0 device it can claim a service it is unable to drive, blocking the transport that could have used the UMP characteristic and forcing a MIDI 1.0 fallback at best. Pairing an instrument is what exposes it to that, and an instrument gains nothing from pairing because its address was already stable.

The same applies to third-party vendor BLE MIDI drivers, which can hold a device exclusively for the same reason.

When this transport ships in-box, the BLE portion of the WinRT MIDI 1.0 stack needs a flag to disable it, so that only one component claims a BLE MIDI device.

Detecting that a device wants pairing

A device can demand authentication in two ways, and only one of them reaches this transport as an error.

The visible route is a GATT operation failing with an insufficient-authentication protocol error, which the MIDI Service and Characteristic lookups, the CCCD write and the Characteristic read all check for.

A request that fails with no protocol error is not treated as a pairing request. It’s reported with its error number instead, because nothing about it says the device wants pairing.

The invisible route is an SMP Security Request. The device accepts the connection, asks the Central to start encryption out of band, and drops the link when that does not happen. Nothing in the GATT path fails, so no error is ever raised: all this transport sees is a link which keeps going away moments after it comes up. Windows may raise its own pairing notification in this case, and may not; both have been observed on devices from the same vendor.

Repeated brief drops while unpaired are therefore treated as evidence. Two links which each lasted under ten seconds mark the device as requiring pairing, which stops the sweep retrying it, because each retry can raise another pairing prompt and can disturb a pairing already in progress. This is inference rather than a report from the device, so a device with a marginal link can be flagged the same way, and an explicit connect request always clears the flag and tries again.

Bonding discards the notification subscription

CCCD state is per-bond. A subscription taken on an unencrypted link is discarded when the device subsequently bonds, and neither the link nor the endpoint shows anything wrong: the connection stays up, the endpoint remains, and no data arrives. The transport therefore watches for a device becoming paired while connected and renews the subscription. Without that, pairing a device part way through a session silently stops its MIDI.

Generic device names

Apple deliberately withholds the user-assigned device name. Since iOS 16, UIDevice.name returns a generic name such as iPhone unless the app holds the com.apple.developer.device-information.user-assigned-device-name entitlement, which Apple grants only on request. An unpaired iPhone therefore appears as iPhone; pairing releases the real name.

Because a generic name is both unhelpful and very likely to collide, a name from the small set of known generic names is worth flagging to the user, along with the suggestion to pair the device. Endpoint customization is the other way out, and is per-device.

Specification conformance

Audited against MMA/AMEI RP-052 (BLE MIDI 1.0) and the BLE MIDI 2.0 transport draft, including every part of the latter which restates or supersedes the former. The draft’s Table 10 and Table 11 are the checklists.

Everything mandatory for the MIDI 1.0 Characteristic is implemented: the service and characteristic UUIDs, write without response, the empty-payload read handshake in both directions, notify, MTU negotiation with the packet size following the negotiated value, the header and timestamp byte layout, full messages, Running Status on receive, System Real-Time de-interleaving, the SysEx continuation rules including a timestamp byte before an interrupting real-time message and before EOX, 13-bit millisecond timestamps, and receiver-side timestampHigh overflow tracking. Running Status on transmit is optional and is not generated, which the specification permits because every receiver must accept full messages.

For the UMP Characteristic: big-endian words, multiple UMPs per payload, no fragmentation, discarding a malformed UMP along with the rest of its payload, the advertisement carrying the MIDI Service UUID, and UMP stream state being reset on reconnection.

Known deviations

Requirement Status Reason
Connection interval ≤ 15 ms, Central role Requested RequestPreferredConnectionParameters with the throughput-optimized preset. The interval is ultimately negotiated, so this is advisory.
Connection interval ≤ 15 ms, Peripheral role Not done A Peripheral is meant to propose the interval with a Connection Parameter Update Request. GattServiceProvider exposes no way to do so.
Peripheral rejects a second Characteristic subscription with ATT 0x80 Not possible WinRT does not let an application fail a CCCD write. Both Characteristics are published and a second subscription is ignored instead. A Central which follows the specification subscribes to only one, so it sees no difference.
Peripheral limited to one active connection Partial The first subscriber is served and later ones are ignored, but their subscription cannot be refused, for the same reason.
Encryption Not enabled Optional in both specifications. Requiring it would force pairing, and an unpaired device connecting is a case which has to keep working.
Data Length Extension (DLE) required for the UMP Characteristic, Bluetooth 5.0 recommended Not checked Whether a link uses DLE depends on the radio and its driver, and Windows doesn’t report it to apps or services, so the transport can’t check it.
Minimum 64-byte ATT payload for UMP Met by Windows Windows supports large payloads in both roles, and the negotiated size is used as-is. A link that negotiates less than 64 bytes for UMP still works, with smaller packets, and is logged as a warning.
Jitter Reduction Timestamps Provisional Handled in the transport in both roles, following the BLE MIDI 2.0 Working Group’s draft guidance, which isn’t published yet.
Endpoint Discovery retried three times before disconnecting Service-side Retry policy belongs to the service’s protocol manager, not this transport.

Connection interval

Both specifications require 15 ms or less and prefer the lowest both ends support, with 7.5 ms recommended for live performance. Windows exposes three presets through RequestPreferredConnectionParameters and no way to name an interval, and the presets are not what their names suggest. Measured on one PC against a BLE MIDI instrument, with the negotiated value read back from BluetoothLEDevice.GetConnectionParameters:

Preference Requested Negotiated
systemDefault (no request) — 15 ms
throughputOptimized min 15 ms, max 15 ms 15 ms
balanced min 30 ms, max 60 ms 60 ms
powerOptimized min 90 ms, max 180 ms 15 ms

Nothing below 15 ms has been observed in the Central role. Making no request produces the same 15 ms as the throughput preset, so requesting it neither helps nor harms; it is kept because it states the intent and guarantees the mandatory ceiling rather than relying on the default staying there. The balanced preset makes matters worse, which shows requests do influence the link. The power preset landing on 15 ms despite asking for far more suggests the device’s own Connection Parameter Update Request wins in that case.

The Peripheral role does better, because the remote Central chooses. An iPhone connecting to this PC negotiated 7.5 ms, which is the rate both specifications recommend for live performance and which Windows has not been observed to reach as Central.

The preference is settable with midi bluetooth connection-parameters, and the negotiated value is shown per device by midi bluetooth list and, for the peripheral role, by midi bluetooth peripheral status.

A link slower than 15 ms adds delay and uneven timing to every message, and Windows tends to choose one when it’s saving power. So when a connected device’s interval is over 15 ms, the Bluetooth MIDI setup app shows a warning that suggests setting the Windows power mode to Best performance, with a button that opens the power settings. If a connection attempt fails while the link was slower than 15 ms, the connection error says so and makes the same suggestion, because some devices drop a link that slow. The peripheral case is worth watching separately: there the remote Central chooses the interval, so it shows what a phone asks for rather than what Windows requests.

Not yet implemented

  • Nothing known. The open question is choosing a connection interval below 15 ms, which Windows doesn’t offer an app.

Didn't find what you were looking for?

Windows MIDI Services is an open source project with all source available on GitHub. We have a great community on Discord as well. Between GitHub and Discord, you should find the information you are looking for.