Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Control protocol

Version 0.1. HTTP with the web console, MIDI System Exclusive and OSC are implemented in the standalone program on Windows, macOS and Linux. Phones, tablets and the plugins have no control API.

One model of what can be read and changed in a running Masterpiece, and the ways to reach it: HTTP with JSON, MIDI System Exclusive, and OSC. The model is the reference. A transport section only says how the model’s operations are written as bytes or paths; it adds no operation of its own, so a console, a script and a web page see the same organ.

The definition is protocol/control.yaml. Its types, properties, program properties, commands, operations, errors and encodings are the ground truth; tools/gen-protocol.py generates src/mp_api/ControlProtocol.h, the tables the program uses, and resources/web/openapi.json, the HTTP description the program serves at /api/v1/openapi.json. gen-protocol.py --check fails when either is out of date. A change to the protocol is a change to the YAML file, then the generator, and the three committed together.

In the program, src/mp_api/ControlModel is the model, src/mp_api/ApiServer the HTTP transport (cpp-httplib, one MIT-licensed header), SysexTransport the MIDI transport and OscTransport the OSC one. Every request is carried out on the message thread, as a click in the window is; while an organ loads every call answers busy. Changes are found by comparing every value 20 times a second, so a change made anywhere (the window, MIDI, a piston, the sequencer, another client) reaches every subscriber.

The window, the MIDI mapping and these transports all act through the same commands inside the program. A stop drawn over SysEx is drawn exactly as a click or a learned MIDI message draws it, and it is reported to every client as a change.

Principles

  • The organ as loaded, by type and index. Every object has a type and an index from 0, dense, valid for one load of one organ. An index is the position in a list, so the state of every switch is a plain bit field. The organ file’s own id is one of the object’s properties, for clients that keep a mapping across loads.
  • A session number names the load. It moves on each time an organ loads or unloads. A request may carry the session it was built for, and is refused with stale-session when the organ has changed under it.
  • Requests and replies, and events. Each request has one reply. A client that subscribes also receives an event for every change it subscribed to, whatever caused it.
  • Small messages. Every operation fits a 64-byte SysEx message, except names and descriptions, which come one object at a time. A board with 2 KB of RAM can take part.
  • Integers. Every value is a whole number in a range the property states; a level in dB is in tenths of a dB, for example.
  • Reading is always allowed once a transport is on; changing needs permission. Each transport has its own switch in Settings > Remote control, off by default. Allow changes from the network governs every change, and HTTP can add a token.

Object types

CodeTypeIndex rangeValueChangeableNotes
0programproperties belowper propertysomeOne per running program
1switch0 to switches - 10 off, 1 onyesEvery switch of the organ file: drawstops, couplers, tremulants, pistons and the rest. Its role is a property
2control0 to controls - 10 to 127yesShoes, crescendo and other continuous controls
3division0 to divisions - 1its live level, 0 to 203: 127 as voiced, 0 silent, 203 at +24 dB, in steps of about 0.32 dByesFor names and grouping; the level is a fader over every rank in it, heard at once, back at 127 at each load
4keyboard0 to keyboards - 1nonenoManuals and pedal; notes stay on MIDI
5general0 to generals - 11 while it is the last recalledpressThe player’s general pistons
6divisional0 to divisionals - 11 while it is the last recalled in its divisionpressThe player’s divisional pistons
7eqpreset0 to presets - 11 while the EQ is this presetpressThe program’s ten, then the player’s own
8temperament0 to temperaments - 11 while chosenpress
9commandthe list belownonepressButtons that are no object of the organ
10rank0 to ranks - 1voicing level in tenths of a dB, -240 to +120yesEvery rank of pipes; heard from the next note, as on the Voicing tab
11notekeyboard index × 128 + MIDI note1 while the key is downyes1 plays the key, 0 releases it, on the keyboard’s channel
12pipe0 to pipes - 1, in rank order then by keyits own voicing level in tenths of a dB, on top of its rank’syesHeard from the next note
13enclosure0 to enclosures - 1how open its shades are, 0 to 127noMoved by its control
14tremulant0 to tremulants - 11 while it runsyesMoves the switch the player would
15windchest0 to compartments - 1pressure now, in tenths of a percent of nominalnoReservoirs and chests of the wind model
16route0 to ranks - 1, one per rankan output as the mixer lists them, from 1; after the last output, a speaker group in the order of the groupsyesWhere the rank plays, as Rank routing… on the Outputs tab of Organ settings; heard from the next note. A rank with no route of its own reads where the default destination sends it. Property to: the output’s or group’s name
17pair0 to outputs - 1its live level, 0 to 203, as divisionyesThe mixer’s outputs, in the order of the Outputs tab, each by its name; heard at once, back at 127 at each load
18ranklevel0 to ranks - 1the rank’s live level, 0 to 203, as divisionyesA fader on top of the rank’s voicing, heard at once, back at 127 at each load
19brightness0 to ranks + divisions - 1tenths of a dB, -120 to +120yesThe treble shelf of the voicing EQ, above 3 kHz: one per rank, then one per division; a rank hears its division’s added to its own. Heard at once
20bass0 to ranks + divisions - 1tenths of a dB, -120 to +120yesThe bass shelf of the voicing EQ, below 200 Hz: one per rank, then one per division, as the brightnesses. Heard at once
21pan0 to ranks + divisions - 1-100 full left, 0 the middle, +100 full rightyesWhere a rank or a division stands: one per rank, then one per division, as the brightnesses; a rank’s and its division’s add. Heard at once
22width0 to ranks + divisions - 1percent, 0 mono, 100 as recorded, 200 twice as wideyesThe stereo width of a rank or a division: one per rank, then one per division, as the brightnesses; a rank’s and its division’s multiply. Heard at once
23muteranks, then divisions, then perspectives or windchest groups, then outputs1 mutedyesThe mixer’s mute buttons; the strip’s fader stays where it is. Heard at once, back to 0 at each load
24soloin the order of mute1 soloedyesThe mixer’s solo buttons. While any rank, division or group is soloed, only the ranks under a soloed strip sound; the outputs solo among themselves. A mute wins over a solo
25organfavourite slot - 1, 64 slots; a list gives the slots that hold an organ1 while it is the organ loadedpressThe favourite organs of the Open window, by name only, no file paths. A press loads it; busy while an organ loads. Listed with no organ loaded

A press acts like a thumb piston: it does what the object does, once.

Program properties (type 0)

IndexPropertyValueChangeable
0Session number0 to 2 097 151, roundno
1Organ loaded0 none, 1 loading, 2 readyno
2Load progress0 to 1000 (tenths of a percent)no
3Master gaintenths of a dB, -400 to +240yes
4Transposesemitones, -12 to +12yes
5Temperamentindex into temperamentyes
6Sequencer framethe frame as the sequencer shows it, from 0 (shown 000) to 998yes
7Setter0 off, 1 onyes
8Organ EQ on0, 1yes
9Organ EQ presetindex into eqpreset, or -1 when none matchesyes
10Polyphony limitvoices, 64 to 65 536; the program holds it to 16 384yes
11Sounding voicesvoicesno
12Late blocks since the program startedcountno
13Real-time render threads0, 1yes
14MIDI recorder0 stopped, 1 recording; set 1 to record, 0 to stop (a take not yet saved is first saved to a dated file in the recordings folder)yes
15Audio recorder0 stopped, 1 recording; set 1 to record to a dated file in the recordings folder, 0 to stopyes
16Metronome0 off, 1 onyes
17Metronome tempobeats a minute, 20 to 300yes
18Room0, 1yes
19Room wet sharepercent, 0 to 100yes
20Pipe detunetenths of a cent, 0 (off) to 100yes
21Wind swaytenths of a cent, 0 (off) to 100yes
22Sparse loading1 every note, 2 every second, 3 every third, 4 half by the sides of the organyes
23Pedal combinations coupled: the first manual’s divisionals also recall the Pedal’s of the same number0, 1yes
24Attack emphasistenths of a dB, -120 to +120, 0 offyes
25Attack lengthmilliseconds, 5 to 300yes

New properties are added at the end; an index is never reused.

Commands (type 9)

IndexCommand
0Panic: every note off
1General cancel
2Sequencer next
3Sequencer previous
4Sequencer first
5Sequencer last
6Voicing EQ next preset
7Voicing EQ previous preset
8Quit: saves and quits Masterpiece. Needs the setting Allow quitting Masterpiece and shutting the computer down, and is refused (busy) in the first two minutes after the program starts
9Power off: the same, then the computer shuts down
10Score page forward: the page-turn message on the MIDI output, for a score app
11Score page back

Properties of an object

Asked for with Describe, one object at a time.

PropertyTypesValue
nameallThe name the organ file gives, or the program’s
odfIdswitch, control, division, keyboardThe organ file’s own id
roleswitchstop, coupler, tremulant, piston, other
latchingswitch1 for a drawstop, 0 for a piston
divisionswitch, control, divisionalIndex into division, or -1
availableswitch0 for a stop a demo does not ship
channelkeyboardThe MIDI channel it plays on, 1 to 16
owneqpreset1 for the player’s own
setgeneral, divisional1 when the piston holds a registration
holdsgeneral, divisionalThe switches it draws when recalled, as indices into switch
tuningrank, pipeIts voicing tuning, in tenths of a cent
rank, keypipeIts rank (an index into rank) and the MIDI note it sounds for
controlenclosureThe control that moves it, an index into control, or -1
rate, depthtremulantIts rate in hundredths of a hertz, its depth in tenths of a percent
busrankThe mixer bus its main perspective plays through; routing is changed on the Outputs tab of Organ settings
consoleswitch, control1 for what the organ’s console shows: its stops, couplers and tremulants, and what else is drawn and can be clicked. A list gives only these unless asked for all (?all=1); every object keeps its index either way

Operations

CodeOperationRequestReply
1Identifyprogram name, protocol version, program version, session, unit number
2Counttypehow many objects of that type
3Describetype, indexthe object’s properties
4Gettype, indexvalue
5Settype, index, valuethe value now
6Presstype, indexdone
7Dumptype, first index, countthe values; for a type whose values are 0 and 1, a bit field
8Subscribea set of typesdone; from then on, events
9Unsubscribea set of types, or alldone
10Event(sent by the program)type, index, value
11Error(a reply)the request’s operation and an error code

A Set on a switch takes 0, 1, or 2 for toggle. A Set on a momentary switch (a piston) presses it for 1 and does nothing for 0.

When an organ loads, every subscriber receives an event for program property 1 (organ loaded) and property 0 (the new session), and should Count and Dump again.

Errors

CodeError
1unknown-operation
2unknown-type
3out-of-range: no object at that index
4bad-value: outside the property’s range
5read-only
6not-allowed: changing is switched off for this transport, or the token is missing
7no-organ
8stale-session
9busy: an organ is loading
10bad-message: too short, too long or malformed
11unsupported-version

Versions

The protocol version is a major and a minor number. A minor version adds properties, commands, types or operations at the end; a client written for an earlier minor version works unchanged. A major version may change what exists, and a client is refused with unsupported-version.

HTTP and JSON

The program serves HTTP on the port chosen in Settings > Remote control (8080 by default), on the local network, or on 127.0.0.1 alone with This computer only. It also serves the web console at / and the API description at /api/v1/openapi.json.

OperationMethod and path
IdentifyGET /api/v1
Countincluded in GET /api/v1/{types}
DescribeGET /api/v1/{types}/{index}, or the whole list with GET /api/v1/{types}
GetGET /api/v1/{types}/{index}/value
SetPUT /api/v1/{types}/{index}/value with {"value": 1}, or {"value": "toggle"} for a switch
PressPOST /api/v1/{types}/{index}/press
DumpGET /api/v1/{types}/values
Subscribe, eventsGET /api/v1/events?types=switches,controls, a server-sent event stream; the program’s events always come with it. At most 16 streams are open at once; one more is refused with busy
Errorthe HTTP status, with {"error": "out-of-range"}

The type in a path is its plural: switches, controls, generals, eqpresets. The program is GET /api/v1/program and PUT /api/v1/program/{property}. A request that changes something is sent as Content-Type: application/json (a page of another site cannot send that without the browser asking first, and the server never agrees, so a stray web page cannot change the organ), carries Authorization: Bearer <token> when a token is set, and may carry X-Session: <n>.

A stream opens with event: hello and the session. An event:

event: change
data: {"type": "switch", "index": 12, "value": 1, "session": 41}

A Dump of switches:

{"session": 41, "type": "switch", "first": 0, "count": 60, "values": [0, 1, 1, 0, ...]}

Console pages

The web console draws the organ’s own console pages with these requests. Coordinates are in the page’s own pixels; layout picks one of the page’s layouts, 0 by default.

RequestAnswer
GET /api/v1/pages{session, pages: [{index, name, width, height, layouts: [{layout, portrait}]}]}
GET /api/v1/pages/{n}/picture?layout=&x=&y=&w=&h=The page, or the part given, as PNG, with the page’s change count in X-Serial
GET /api/v1/pages/{n}/changes?layout=&since={serial, areas: [{x, y, w, h}]}, the parts drawn again since that count, or {serial, full: true} when the page must be fetched whole
POST /api/v1/pages/{n}/pointer with {"phase": "down", "x": 0, "y": 0}A tap or a drag (down, move, up) carried out on the page as a click is. It needs permission to change, as a Set does. Drawn manuals are not played from a browser

MIDI System Exclusive

Turned on in Settings > Remote control with Answer the same requests over MIDI (System Exclusive). Requests are read on the MIDI inputs and answered on the console’s MIDI output; this protocol’s messages are kept from the organ. A message is at most 64 bytes, F0 and F7 included.

Message layout

F0 7D 4D 50 <unit> <major> <operation> <sequence> <payload ...> F7
ByteMeaning
7DThe ID for non-commercial and experimental use, while the protocol is tried. A registered manufacturer ID replaces it before version 1.0
4D 50M P
unit0 to 126, for several programs on one MIDI network: 0 unless the settings file sets apisysexunit; 127 addresses all
majorthe protocol’s major version
operationthe code from the operations table
sequence0 to 127, chosen by the client and repeated in the reply, to pair them; 0 in events

Every data byte is 7 bits, as MIDI requires.

FieldBytesEncoding
type1the type code
index214 bits, low 7 bits first
value321 bits, two’s complement, low 7 bits first
count2as index
textvariableUTF-8, in groups of 7 bytes each preceded by a byte with their high bits (the 8-to-7 packing of sample dumps)

Payloads

OperationRequest payloadReply payload
Identifynoneminor, program version (3 bytes), session (value), unit, then name (text)
Counttypetype, count
Describetype, indextype, index, then property code (1 byte) and its value, repeated, and the name last, cut to fit the message; the whole name over HTTP or OSC
Gettype, indextype, index, value
Settype, index, valuetype, index, value now
Presstype, indextype, index
Dumptype, first, count (up to 280 for bits, 16 for values)type, first, count, then bits 7 to a byte, low bit first, or values
Subscribe, Unsubscribea type mask (3 bytes, as a value: bit n for type n)the mask now
Eventtype, index, value
Erroroperation, error code

A Dump of 280 switches is 40 bytes of bits; a console asks for 0-279, 280-559 and so on until it has them all.

Examples

Draw switch 12 on unit 0, sequence 5:

F0 7D 4D 50 00 00 05 05 01 0C 00 01 00 00 F7
                     |  |  |  |     |
                     |  |  |  |     value 1
                     |  |  |  index 12
                     |  |  type switch
                     |  sequence 5
                     operation Set

The reply carries the same sequence and the value now:

F0 7D 4D 50 00 00 05 05 01 0C 00 01 00 00 F7

The event every subscriber receives:

F0 7D 4D 50 00 00 0A 00 01 0C 00 01 00 00 F7

OSC

Turned on in Settings > Remote control with Answer the same requests over OSC. UDP on the port chosen there (9000 by default). A client first says where replies and events go, with /mp/replyto; until then the program listens and answers nothing. {type} is the plural name, as in the HTTP paths.

OperationAddress and argumentsReply
Reply to/mp/replyto with the host as a string (the computer itself when left out) and the portthe same, as confirmation
Identify/mp/identifyprotocol, version, program version, session, organ
Count/mp/{type}/countthe count
Describe/mp/{type}/{index}/describeeach property’s name, then its value
Get/mp/{type}/{index} with no argumentthe value
Set/mp/{type}/{index} with an integer, or a float, roundedthe value now
Press/mp/{type}/{index}/pressthe address
Dump/mp/{type}/dump with the first index and a count, both optionalthe first index, then up to 1,000 values
Subscribe/mp/subscribe with the type names as strings; none for every typethe type mask now
Unsubscribe/mp/unsubscribe, the samethe type mask now
Event/mp/{type}/{index} with the value, sent by the program
Error/mp/error with the address, the error code and its name

A reply uses the address of its request, and an event the address of a Get, so a fader in TouchOSC or Open Stage Control bound to /mp/controls/0 moves the shoe and follows it.

The program’s properties go by name, /mp/program/masterGain, and commands may too, /mp/commands/panic/press. With changes from the network turned off, a Set or Press is refused with not-allowed, as over HTTP.

MIDI-CI Property Exchange

A later binding for MIDI 2.0 tools: each HTTP resource becomes a property resource with the same JSON, under names of the form X-MP-Switches.

Open questions

  • A registered SysEx manufacturer ID, applied for before version 1.0.
  • Whether notes may be played through these transports, for automation and tests. MIDI is the transport for playing.
  • 14-bit values for continuous controls, for consoles with fine shoe sensors.