Skip to content

Latest commit

 

History

History
224 lines (165 loc) · 18.6 KB

project-format.md

File metadata and controls

224 lines (165 loc) · 18.6 KB

JSON project files

Principles

These rules hold for every change of the format. A change that breaks one of them is discussed first.

  • A project file can be written by hand or damaged: reading it never crashes. What cannot be read is skipped, with a warning that names it.
  • What this version does not understand is kept and written back as it was read: the keys a later version added, the sources of types it cannot open, the effects and links it cannot use. Opening and saving a project never loses what another version wrote.
  • A name never changes once released, and is never reused. A renamed key keeps its former name: read when the new name is absent, never written; when a project gives both, the new name wins. Former names are read for good, without a conversion script.
  • A type names what an element is, never the class or the folder of the code that builds it (see Types below).
  • Values have their native JSON type: a number is a number, a switch is a boolean, not text.
  • What only some projects have, such as effects and links, is written only when there is some, so that the other projects keep the same bytes.
  • version gives the format of the file. Opening a project of a later format warns that it was saved by a later version, and saving over it asks first.
  • This document changes with the format, in the same commit.

Naming styles

Each kind of name has one style, chosen for where else the name is written:

What Style Examples Why
Keys, and the ids of settings lower case, _ between words (snake_case) source_id, n_columns, output_resolution A setting id is also its name in OSC addresses and in MCP, and the name of the input of a shader: it must be an identifier in GLSL, Python and JavaScript, where - is not allowed.
Types of the core mapmap:, then lower case, - between words (kebab-case) mapmap:color-generator, mapmap:texture-layer A type is a value, never an identifier in code. It reads like the names of the shipped shader files, which are also the names of their types (mapmap.shaders:color-wheel.fs), and like the providers, which are domain names.
Providers reversed domain name, lower case mapmap.shaders, io.github.exemple.atelier The domain of the author keeps two extensions from taking the same name.
Keys of the ISF header of a shader upper case INPUTS, NAME, DEFAULT They belong to the ISF format, not to MapMap: MapMap does not choose them.

The keys of earlier versions in camelCase or PascalCase (className, sourceId, nColumns, outputResolution) and their type names (Video, TextureLayer) are former names: read, never written.

Existing files

A MapMap project is a JSON object. The writer emits sources and layers arrays, including when they are empty. A layer refers to its source by a numeric ID. Array order matters: the first layer is at the top of the stack. Mesh vertices are in row-major order. An older project may omit output_resolution, which earlier versions wrote outputResolution: read it when output_resolution is absent, and write only output_resolution.

The current development reader accepts earlier setting names such as sourceId and nColumns. When both spellings occur, the current spelling takes precedence. IDs and coordinates are already JSON numbers. Beta.1 stores many settings as strings. Beta.2 reads those projects directly. Saving a project writes the beta.2 format, with native numbers and booleans. Use Save As to keep a copy that beta.1 can read.

Beta.2 file format

Media paths

Interpret a relative image or video path from the directory containing the project. Resolve it before opening the media. Prefer that file even if the working directory contains another file with the same name. If a legacy path exists only in the working directory, use it as a fallback and write an unambiguous path on the next save.

Use a relative path for a newly added file inside the project directory. Keep an external absolute path usable. Preserve the target of an existing relative reference, including one containing .., when using Save As in another directory. If the user cancels locating a missing file, keep the reference so that putting the media back restores the project. Camera device IDs are opaque strings.

Test opening a project from another working directory, moving the project and its media together, and saving a copy to another directory. Check the resulting media target as well as the path written in JSON.

Structural validation

Require an object containing sources and layers arrays. Treat an empty array as valid. Check this envelope before replacing the open project. A failure should name the field and expected type and should be reported to callers, including remote callers.

Within valid arrays, keep readable entries and report skipped entries with their array index or ID. Keep accepting projects without an output resolution and projects using earlier setting names.

Keep a source whose type this version cannot open, such as a Syphon source opened on GNU/Linux or Windows: it is not an error of the file. Its layers stay, it shows a "missing" image, and it is written back as it was read, with its type. Only the settings that every source has (name, opacity, locked) can be changed. Its layers are not counted among the skipped entries.

Open a project of a later format, with a warning, and ask before saving over it: the later version may not open the project as it was. Saving to another file does not ask.

Keep the keys a later version added, at the top of the file as inside a source or a layer: write them back as they are, so that opening and saving a newer project with this version does not lose them. A project saved by MapMap 1.0.0-beta.2 or earlier still loses the keys it does not know at the top of the file, such as links.

Types

Each source, layer, shape and effect gives its type under the key type. A type is written <provider>:<name>:

  • The provider says who gives the type: mapmap for the core of MapMap, mapmap.shaders for the shaders shipped with MapMap, a reversed domain name for an extension (io.github.exemple.atelier). It is never a folder nor a namespace of the code, which can change without the format having to follow.
  • The name is unique within its provider. The types of the core are in lower case with hyphens between words; the name of a shader is its file name, and may hold / when it gives a path (io.github.exemple.atelier:shaders/vagues.fs).
  • Only lower-case letters, digits, ., _ and - are allowed, and / in the name. A type that does not follow this form is refused when it is registered, and a type never changes once released, nor is reused.
  • The provider mapmap and every provider that starts with mapmap. belong to MapMap.

A type names what an element is, not how the code builds it: the Checker generator is the class IsfGenerator with the file checker.fs, and its type is mapmap.shaders:checker.fs.

Type Name in earlier versions (className)
mapmap:color-generator ColorGenerator, and Color for the colour sources
mapmap:image Image
mapmap:video Video
mapmap:camera Camera, and Video with the identifier of a camera as uri
mapmap:syphon Syphon
mapmap.shaders:checker.fs CheckerGenerator
mapmap.shaders:grid.fs GridGenerator
mapmap.shaders:color-wheel.fs ColorWheelGenerator
mapmap:texture-layer TextureLayer, TextureMapping, and ColorLayer or ColorMapping for the colour layers
mapmap:quad Quad
mapmap:mesh Mesh
mapmap:triangle Triangle
mapmap:ellipse Ellipse

Read type; when it is absent, read className, the key of earlier versions, and follow the names of the table. Write only type. A project saved with this version opens empty in MapMap 1.0.0-beta.1, which only reads className: its sources and layers are skipped with a warning. A type that MapMap does not know, such as acme:ondes, is kept and written back as it was read (see above). An input of a shader cannot be named type or className.

Native scalar types

Write a numeric setting such as opacity as a number and a boolean setting such as visible as a boolean. Use the setting declaration to choose the type. A text setting whose value is "001" or "false" is still text. Read both representations of legacy numeric and boolean settings. The XML converter writes the same scalar types when importing a MapMap 0.4 to 0.6 project.

Changing these types causes a one-time diff. For example, 36 lines in the existing alpha-mixed.mmp fixture contain numeric or boolean settings stored as strings. Keep the legacy fixture as input and check the types and values of the saved project separately. Beta.1 expects strings for these settings and can misread a beta.2 project.

Effects

A source or a layer may have an effects array: the effects put on it, in order. It is written only when there is at least one effect, so a project without effects keeps the same bytes. In this version only the first effect acts, when it is enabled; the others are kept and written back, with a warning.

"effects": [
    {
        "brightness": 0,
        "contrast": 1,
        "enabled": true,
        "hue": 0,
        "id": 1,
        "mix": 1,
        "saturation": 0.25,
        "shader_hash": "5f0c…",
        "type": "mapmap.shaders:color-adjustment.fs"
    }
]
  • type is the type of the effect: the identifier of its shader file, as for a generator.
  • id is unique among the effects of the project. The settings of the effect are at the path effect/<id>/<setting> of its source or layer, for OSC, MCP and links. An effect without an id, or with the id of another one, is given a new id, with a warning.
  • enabled says whether the effect acts; off, the image passes unchanged.
  • mix doses the effect, from 0 (the image as it is) to 1 (the effect alone). Without it, 1.
  • shader_hash is a hash of the shader file; opening a project saved with another version of the file writes a warning.
  • The other keys are the settings of the effect, named after the inputs of its shader.

An effect of a type this version does not know is kept as it was read, written back, and not drawn: the image passes unchanged. An entry that is not an object or has no type is skipped, with a warning; effects that is not an array is skipped as a whole.

Groups

A project may have a groups array at the top of the file: the groups of layers, from the top of the stack. It is written only when there is at least one group, and a layer has a group_id only when it is in a group, so a project without groups keeps the same bytes. The layers array does not change: the layers of a group follow one another in it.

"groups": [
    {
        "collapsed": false,
        "depth": 0,
        "id": 2,
        "locked": false,
        "name": "Camion",
        "opacity": 1,
        "solo": false,
        "type": "mapmap:group",
        "visible": false
    }
],
"layers": [
    { "id": 1, "group_id": 2, "name": "Camion cabine", … },
    { "id": 4, "group_id": 2, "name": "Camion roue", … },
    { "id": 6, "name": "Maison", … }
]
  • id is unique among the groups; groups have ids of their own, as sources and layers. Their settings are reached at /mapmap/group/<id>/<setting> by OSC, with the kind group by MCP, and with the element group by links.
  • visible, solo, locked and opacity add to those of each of its layers: a layer is shown when its eye and that of its group are open; it is in solo when it or its group is; it is locked when it or its group is, and so are its shapes, whose own locked is written so; its opacity is multiplied by that of its group.
  • depth is the number of layers above the group. A group takes the place of its topmost layer: depth only places a group without layers.
  • collapsed says whether the group is folded in the list of layers, its layers out of sight. Without it, the group is unfolded.
  • A group without layers is kept and written.
  • Groups do not contain groups.

A layer whose group_id names no group of the project stays in no group, with a warning. A group without an id, or with the id of another one, is skipped, with a warning. A version of MapMap without groups opens the layers in the same order, in no group, and keeps groups and the group_id of each layer when it saves the project (1.0.0-beta.2 and earlier lose groups).

Links

A project may have a links array: what its triggers, such as the keys of the computer keyboard, do to its settings. It is written only when the project has at least one link, so a project without links keeps the same bytes.

The links may still change before MapMap 1.0: commands as targets, game controllers and other actions are planned. A project with links is not yet a stable contract; the reader keeps what it does not understand (see below), so that such changes lose nothing.

Each link has a trigger, a target and an action:

"links": [
    {
        "action": "toggle",
        "target": { "element": "layer", "id": 7, "setting": "visible" },
        "trigger": { "key": "M", "kind": "key" }
    }
]
  • trigger.kind is key for a key of the computer keyboard. trigger.key is the key and its modifiers in the portable text of QKeySequence, such as M or Shift+M: the same in every language of the system.
  • trigger.kind is midi for a MIDI device: trigger.message is control (a control change: a knob, a fader, some buttons) or note (a key, a pad), trigger.channel the channel, from 1 to 16, and trigger.number the number of the control or of the note, from 0 to 127. The port is not written: a device plugged into another port, or replaced by another one, keeps its links.
  • target.element is source or layer, target.id the id of the element, target.setting the path of the setting, as in OSC. target.component, x or y, makes the link drive one coordinate of a point, such as a vertex (output/vertices/2); without it, the link drives the whole value.
  • action is toggle, on, off, follow, increase, decrease or relative. A link without an action toggles. follow, which sets the setting at the position of the control, and relative, which moves it as much as the control turned since its previous message, are only for a MIDI control. increase and decrease move a number by a hundredth of its range, or a coordinate by a pixel. A coordinate only takes increase, decrease and relative.
{
    "action": "follow",
    "target": { "element": "layer", "id": 7, "setting": "opacity" },
    "trigger": { "channel": 1, "kind": "midi", "message": "control", "number": 21 }
}

A link this version cannot use does nothing, but it is kept as it was read and written back after the links in use, with a warning naming it: a trigger, an action or a target it does not know (a later version may add other devices, new actions or commands as targets), an action its trigger or its setting cannot have (follow for a key, toggle for a coordinate), an element or a setting the project does not have, or a setting that cannot be linked (one without a position between 0 and 1, such as a point or a text). Opening and saving a project with an older version then keeps its links. The writer leaves out a link whose element was deleted during the session.

A button, such as the go of a cue (see below), is pressed by toggle or on: each press does its action once. off and follow cannot target it, and a MIDI control learned on it gets toggle.

Media

A project may have a media array: what belongs to a media file rather than to a source. For now, the cues of a video file: up to eight moments, numbered from 1 to 8, that a key or a pad jumps to. It is written only when a file has at least one cue, so a project without cues keeps the same bytes.

"media": [
    {
        "cues": [
            { "color": "#e03030", "name": "Entrée du loup", "number": 1, "time": 12.48 },
            { "number": 3, "time": 60 }
        ],
        "uri": "videos/loup.mp4"
    }
]
  • uri is the path of the file, written as the uri of a source (see "Media paths"): relative to the project when the file is in its directory. Two sources reading the same file share its cues, and a source that reads another file shows the cues of that one.
  • number is from 1 to 8, time the moment in seconds from the start of the file. name and color are written only when the user gave them; a cue without a colour is gray.
  • The reader skips an entry without uri, a cue whose number is out of range or given twice, and a cue without a time or with a negative one, with a warning naming it. It keeps the keys it does not know, in an entry and in a cue, and writes them back. A cue beyond the end of its video is kept: a jump to it stops at the end.

The settings of a cue are in its video source, at cues/<number>/<setting>, as in OSC and MCP: time (empty while the cue is not placed; writing it places the cue), name, color, and the buttons go (jumps to the cue and plays this video; places the cue where the video plays when it is empty), set (places or moves it there) and clear. They are not written with the source.

Convert a beta.1 project with Python

Run python3 scripts/convert-beta1-project.py show.mmp to create show-beta.2.mmp in the same directory. The script accepts several project files in one invocation. It preserves the original, the order of sources, layers and vertices, and unknown properties. It leaves media references in place and needs no access to the media, cameras or Qt. Commit the converted file separately from creative edits so the type changes are easy to review.

Stability in Git

  • Keep serialized names stable across internal renames. Retain read aliases for keys already in released projects.
  • Give the file format a version independent of the application build. Change it when the file contract changes. An application-only release should produce identical bytes for the same project.
  • Keep the current four-space indentation, object key order and layout of vertices. Write UTF-8 with LF line endings and a final newline on every platform. Preserve IDs and the order of sources, layers and vertices.
  • Give new optional fields a default that reproduces the older behavior. Avoid writing a new field into every existing object merely because a release introduces it.
  • Test the actual file bytes after opening and saving a current-format project. Changing one layer name should replace one line. Moving one vertex should change only its coordinates. Run the same reference-file test on every supported platform.

Saving a beta.1 project migrates it to beta.2. Use separate tests for that migration and for edits to a project already in the current format.