{
  "openapi": "3.1.1",
  "info": {
    "title": "MIDI File Inspector API",
    "version": "1.0.0",
    "summary": "See what is inside a MIDI file: tracks, instruments, tempo map, notes, length and an estimated key.",
    "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://tickworkmidiinspector.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "See what is inside a MIDI file: tracks, instruments, tempo map, notes, length and an estimated key.",
        "description": "Reads a Standard MIDI File (.mid, format 0, 1 or 2) and lists its tracks with channels, General MIDI instruments, note counts and ranges, the tempo map, time and key signatures, note lengths, the most notes sounding at once, drum hits and an estimated key from the pitch content. Includes a piano-roll overview. The same reader Tickwork uses to import MIDI files.\n\nMethodology:\n- The file is parsed byte by byte following the Standard MIDI File 1.0 specification: header chunk, track chunks, variable-length delta times, running status, meta and SysEx events. Unknown chunks are skipped; RIFF-wrapped files (.rmi) are unwrapped.\n- Notes are paired from note-on to the next note-off of the same key and channel (a note-on with velocity 0 counts as a note-off). Times in seconds use the tempo map (120 BPM until the first tempo event); SMPTE files use frames per second instead.\n- The key estimate correlates the duration-weighted pitch-class histogram of all pitched notes (channel 10 excluded) with the Krumhansl–Kessler major and minor key profiles in all 24 keys and reports the best and second-best match.\n- Polyphony is the largest number of notes sounding at the same moment across all tracks; note lengths are given in beats (quarter notes).\n\nThe key is a statistical estimate from the notes, not an analysis of harmony; modal or atonal music often gets a nearby major or minor key.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "tickwork_midi_inspector",
        "x-owner-app": "tickwork",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TickworkMidiInspectorInput"
              },
              "examples": {
                "example1": {
                  "summary": "Inspect the lo-fi song sample",
                  "value": {
                    "sample": "lofi-song"
                  }
                },
                "example2": {
                  "summary": "Inspect the acid line sample",
                  "value": {
                    "sample": "acid-locks"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TickworkMidiInspectorResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "TickworkMidiInspectorInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "file": {
            "title": "MIDI file (.mid)",
            "description": "Up to 4 MB. Leave empty to inspect a built-in sample. Nothing is stored; the file is read once for this report. 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": "lofi-song"
          }
        },
        "required": []
      },
      "TickworkMidiInspectorResult": {
        "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",
              "format",
              "ppq",
              "smpte",
              "tracks",
              "notes",
              "durationSeconds",
              "durationBeats",
              "bars",
              "tempos",
              "timeSignatures",
              "keySignatures",
              "key",
              "noteLengths",
              "maxPolyphony",
              "pitchClasses",
              "drumHits",
              "trackReports"
            ],
            "properties": {
              "file": {
                "type": "string"
              },
              "sample": {
                "type": "boolean"
              },
              "format": {
                "type": "integer"
              },
              "ppq": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "smpte": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "tracks": {
                "type": "integer"
              },
              "notes": {
                "type": "integer"
              },
              "durationSeconds": {
                "type": "number"
              },
              "durationBeats": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "bars": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "tempos": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "tick",
                    "seconds",
                    "bpm"
                  ],
                  "properties": {
                    "tick": {
                      "type": "integer"
                    },
                    "seconds": {
                      "type": "number"
                    },
                    "bpm": {
                      "type": "number"
                    }
                  }
                }
              },
              "timeSignatures": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "tick",
                    "signature"
                  ],
                  "properties": {
                    "tick": {
                      "type": "integer"
                    },
                    "signature": {
                      "type": "string"
                    }
                  }
                }
              },
              "keySignatures": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "tick",
                    "key"
                  ],
                  "properties": {
                    "tick": {
                      "type": "integer"
                    },
                    "key": {
                      "type": "string"
                    }
                  }
                }
              },
              "key": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "tonic",
                  "mode",
                  "name",
                  "correlation",
                  "runnerUp",
                  "runnerUpCorrelation"
                ],
                "properties": {
                  "tonic": {
                    "type": "integer"
                  },
                  "mode": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "correlation": {
                    "type": "number"
                  },
                  "runnerUp": {
                    "type": "string"
                  },
                  "runnerUpCorrelation": {
                    "type": "number"
                  }
                }
              },
              "noteLengths": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "shortestBeats",
                  "medianBeats",
                  "longestBeats"
                ],
                "properties": {
                  "shortestBeats": {
                    "type": "number"
                  },
                  "medianBeats": {
                    "type": "number"
                  },
                  "longestBeats": {
                    "type": "number"
                  }
                }
              },
              "maxPolyphony": {
                "type": "integer"
              },
              "pitchClasses": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "pitch",
                    "share"
                  ],
                  "properties": {
                    "pitch": {
                      "type": "string"
                    },
                    "share": {
                      "type": "number"
                    }
                  }
                }
              },
              "drumHits": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "key",
                    "name",
                    "hits"
                  ],
                  "properties": {
                    "key": {
                      "type": "integer"
                    },
                    "name": {
                      "type": "string"
                    },
                    "hits": {
                      "type": "integer"
                    }
                  }
                }
              },
              "trackReports": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "track",
                    "name",
                    "instrument",
                    "channels",
                    "programs",
                    "notes",
                    "lowest",
                    "highest",
                    "meanVelocity",
                    "firstSeconds",
                    "lastSeconds",
                    "controllers",
                    "pitchBends",
                    "drums"
                  ],
                  "properties": {
                    "track": {
                      "type": "integer"
                    },
                    "name": {
                      "type": "string"
                    },
                    "instrument": {
                      "type": "string"
                    },
                    "channels": {
                      "type": "array",
                      "items": {
                        "type": "integer"
                      }
                    },
                    "programs": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "notes": {
                      "type": "integer"
                    },
                    "lowest": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "highest": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "meanVelocity": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "firstSeconds": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "lastSeconds": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "controllers": {
                      "type": "integer"
                    },
                    "pitchBends": {
                      "type": "integer"
                    },
                    "drums": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}