đŸ’Ÿ Archived View for lofi.haiku-os.org â€ș docs â€ș develop â€ș midi â€ș design.gmi captured on 2023-12-28 at 15:17:56. Gemini links have been rewritten to link to archived content

View Raw

More Information

âŹ…ïž Previous capture (2023-09-28)

-=-=-=-=-=-=-

Midi Kit design

The Midi Kit consists of the midi_server and two shared libraries, libmidi2.so and libmidi.so. The latter is the “old” pre-R5 Midi Kit and has been re-implemented using the facilities from libmidi2, which makes it fully compatible with the new kit. This document describes the design and implementation of the OpenBeOS midi_server and libmidi2.so.

The midi_server has two jobs: it keeps track of the endpoints that the client apps have created, and it publishes endpoints for the devices from /dev/midi. (This last task could have been done by any other app, but it was just as convenient to make the midi_server do that.) The libmidi2.so library also has two jobs: it assists the midi_server with the housekeeping stuff, and it allows endpoints to send and receive MIDI events. (That’s right, the midi_server has nothing to do with the actual MIDI data.)

======================================================================

Ooh, pictures

The following image shows the center of Midi Kit activity, the midi_server, and its data structures:

[image: image0]

And here is the picture for libmidi2.so:

[image: image1]

Note that these diagrams give only a conceptual overview of who is responsible for which bits of data. The actual implementation details of the kit may differ.

======================================================================

Housekeeping

what Be did

, although there are some differences. In Be’s implementation, the BMidiRosters only have BMidiEndpoints for remote endpoints if they are registered. In our implementation, the BMidiRosters have BMidiEndpoint objects for *all* endpoints, including remote endpoints that aren’t published at all. If there are many unpublished endpoints in the system, our approach is less optimal. However, it made the implementation of the Midi Kit much easier ;-)

Initialization

Error handling

Creating and deleting endpoints

Changing endpoint attributes

Connections

Watching

Thread safety

Misc remarks

The messages

Message: Mapp (MSG_REGISTER_APP)
    BMessenger midi:messenger
Reply:
    (no reply)

Message: mAPP (MSG_APP_REGISTERED)
    (no fields)

Message: Mnew (MSG_CREATE_ENDPOINT)
    bool     midi:consumer
    bool     midi:registered
    char[]   midi:name
    BMessage midi:properties
    int32    midi:port       (consumer only)
    int64    midi:latency    (consumer only)
Reply:
    int32    midi:result
    int32    midi:id

Message: mNEW (MSG_ENPOINT_CREATED)
    int32    midi:id
    bool     midi:consumer
    bool     midi:registered
    char[]   midi:name
    BMessage midi:properties
    int32    midi:port       (consumer only)
    int64    midi:latency    (consumer only)

Message: Mdel (MSG_DELETE_ENDPOINT)
    int32 midi:id
Reply:
    (no reply)

Message: Mdie (MSG_PURGE_ENDPOINT)
    int32 midi:id
Reply:
    (no reply)

Message: mDEL (MSG_ENDPOINT_DELETED)
    int32 midi:id

Message: Mchg (MSG_CHANGE_ENDPOINT)
    int32    midi:id
    int32    midi:registered (optional)
    char[]   midi:name       (optional)
    int64    midi:latency    (optional)
    BMessage midi:properties (optional)
Reply:
    int32 midi:result

Message: mCHG (MSG_ENDPOINT_CHANGED)
    int32 midi:id
    int32    midi:registered (optional)
    char[]   midi:name       (optional)
    int64    midi:latency    (optional)
    BMessage midi:properties (optional)

======================================================================

MIDI events

+-----------+--------------------------------+
| 4 bytes   | ID of the producer             |
+-----------+--------------------------------+
| 4 bytes   | ID of the consumer             |
+-----------+--------------------------------+
| 8 bytes   | performance time               |
+-----------+--------------------------------+
| 1 byte    | atomic (1 = true, 0 = false)   |
+-----------+--------------------------------+
| 3 bytes   | padding (0)                    |
+-----------+--------------------------------+
| x bytes   | MIDI event data                |
+-----------+--------------------------------+