{
  "openapi": "3.1.1",
  "info": {
    "title": "MIDI Quantizer with Swing API",
    "version": "1.0.0",
    "summary": "Tighten the timing of a MIDI file to a grid, with strength, swing and a window that keeps the feel.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://tickworkmidiquantizer.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Tighten the timing of a MIDI file to a grid, with strength, swing and a window that keeps the feel.",
        "description": "Moves the notes of a Standard MIDI File toward a 1/4 to 1/32 or triplet grid. Strength below 100 % keeps part of the human feel, swing shifts every off-beat grid line, the window leaves notes far from the grid alone, and note ends can be quantized too. Controllers, pitch bends, programs and every other event are kept. You get the new MIDI file and a before/after timing report.\n\nMethodology:\n- Every note-on is paired with its note-off (same key and channel). Its grid target is the nearest grid line; with swing, every odd grid line sits at the swing share of a grid pair (MPC-style: 50 % = straight, 66 % ≈ triplet).\n- A note is moved only when its distance to the target is within the window (a share of half a grid step); it then moves by strength × distance, rounded to whole ticks. Without “ends”, the length is kept; with it, the end moves toward its own grid line the same way (at least one tick long).\n- All other events — controllers, pitch bends, program changes, SysEx, tempo and text — keep their exact times. The file keeps its resolution and is written with explicit status bytes.\n\nQuantizing changes the feel of a performance; keep the original file.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "tickwork_midi_quantizer",
        "x-owner-app": "tickwork",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TickworkMidiQuantizerInput"
              },
              "examples": {
                "example1": {
                  "summary": "Tighten a loose groove to sixteenths",
                  "value": {
                    "sample": "humanized-groove",
                    "grid": "1/16",
                    "strength": 100,
                    "swing": 50,
                    "window": 100,
                    "ends": false
                  }
                },
                "example2": {
                  "summary": "Half-strength with swing 58 %",
                  "value": {
                    "sample": "humanized-groove",
                    "grid": "1/16",
                    "strength": 50,
                    "swing": 58,
                    "window": 100,
                    "ends": false
                  }
                },
                "example3": {
                  "summary": "Eighth-note triplets, ends included",
                  "value": {
                    "sample": "lofi-song",
                    "grid": "1/8T",
                    "strength": 100,
                    "swing": 50,
                    "window": 100,
                    "ends": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TickworkMidiQuantizerResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "TickworkMidiQuantizerInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "file": {
            "title": "MIDI file (.mid)",
            "description": "Up to 4 MB. Leave empty to quantize a built-in, loosely played sample. Upload as {filename, contentType?, contentBase64}. Max 4096 KiB. Accepts .mid,.midi,.rmi,.smf,audio/midi,audio/x-midi,application/octet-stream.",
            "type": "object",
            "additionalProperties": false,
            "required": [
              "filename",
              "contentBase64"
            ],
            "properties": {
              "filename": {
                "type": "string"
              },
              "contentType": {
                "type": "string"
              },
              "contentBase64": {
                "type": "string"
              }
            }
          },
          "sample": {
            "title": "Sample when no file is uploaded",
            "type": "string",
            "enum": [
              "lofi-song",
              "acid-locks",
              "humanized-groove"
            ],
            "default": "humanized-groove"
          },
          "grid": {
            "title": "Grid",
            "type": "string",
            "enum": [
              "1/4",
              "1/8",
              "1/8T",
              "1/16",
              "1/16T",
              "1/32"
            ],
            "default": "1/16"
          },
          "strength": {
            "title": "Strength",
            "description": "100 % puts notes exactly on the grid; 50 % moves them half way.",
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "default": 100,
            "x-unit": "%"
          },
          "swing": {
            "title": "Swing",
            "description": "Position of every second grid line inside a pair (50 = straight, 66 ≈ triplet feel). Ignored for triplet grids.",
            "type": "number",
            "minimum": 50,
            "maximum": 75,
            "default": 50,
            "x-unit": "%"
          },
          "window": {
            "title": "Window",
            "description": "Only notes within this share of half a grid step are moved; 100 % moves all notes.",
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "default": 100,
            "x-unit": "%"
          },
          "ends": {
            "title": "Quantize note ends too",
            "type": "boolean",
            "default": false
          }
        },
        "required": []
      },
      "TickworkMidiQuantizerResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "file",
              "sample",
              "grid",
              "strength",
              "swing",
              "window",
              "ends",
              "ppq",
              "gridTicks",
              "notes",
              "moved",
              "meanShiftTicks",
              "maxShiftTicks",
              "deviationBefore",
              "deviationAfter",
              "perTrack",
              "midiFile"
            ],
            "properties": {
              "file": {
                "type": "string"
              },
              "sample": {
                "type": "boolean"
              },
              "grid": {
                "type": "string"
              },
              "strength": {
                "type": "number"
              },
              "swing": {
                "type": "number"
              },
              "window": {
                "type": "number"
              },
              "ends": {
                "type": "boolean"
              },
              "ppq": {
                "type": "integer"
              },
              "gridTicks": {
                "type": "number"
              },
              "notes": {
                "type": "integer"
              },
              "moved": {
                "type": "integer"
              },
              "meanShiftTicks": {
                "type": "number"
              },
              "maxShiftTicks": {
                "type": "number"
              },
              "deviationBefore": {
                "type": "number",
                "description": "Mean distance of note starts from the grid before, in ticks."
              },
              "deviationAfter": {
                "type": "number"
              },
              "perTrack": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "track",
                    "name",
                    "notes",
                    "moved"
                  ],
                  "properties": {
                    "track": {
                      "type": "integer"
                    },
                    "name": {
                      "type": "string"
                    },
                    "notes": {
                      "type": "integer"
                    },
                    "moved": {
                      "type": "integer"
                    }
                  }
                }
              },
              "midiFile": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "artifactId",
                  "filename",
                  "mime",
                  "bytes",
                  "sha256",
                  "path"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  },
                  "mime": {
                    "type": "string"
                  },
                  "bytes": {
                    "type": "integer"
                  },
                  "sha256": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string",
                    "description": "Download path on the same site (valid for about 2 hours)."
                  }
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}