{
  "openapi": "3.1.1",
  "info": {
    "title": "Euclidean Rhythm Generator (MIDI) API",
    "version": "1.0.0",
    "summary": "Spread k beats evenly over n steps for several drums at once and download the groove as a MIDI file.",
    "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://tickworkeuclideanrhythm.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Spread k beats evenly over n steps for several drums at once and download the groove as a MIDI file.",
        "description": "Builds Euclidean rhythms with Bjorklund’s algorithm — E(3,8), E(5,16), E(7,12) and any other pulses/steps pair — with rotation, for up to eight drum voices. Voices of different lengths run against each other as a polymeter. You get the patterns as text, their beat intervals, a Standard MIDI File on the General MIDI drum channel and a Tickwork project to keep editing.\n\nMethodology:\n- Bjorklund’s algorithm distributes k onsets over n steps as evenly as possible by repeatedly pairing the groups of onsets with the remainder groups, like Euclid’s algorithm for the greatest common divisor (Toussaint 2005). The first step is always a hit; rotation r shifts the pattern r steps later.\n- Each voice is one step lane of its own length on a sixteenth-note grid, so voices of 8, 12 and 16 steps drift against each other and line up again after their least common multiple.\n- The MIDI file (format 1, 480 ticks per quarter note) puts every voice on channel 10 with its General MIDI percussion key; swing delays every off-beat sixteenth to the given share of an eighth note (50 % = straight). Notes last half a sixteenth.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "tickwork_euclidean_rhythm",
        "x-owner-app": "tickwork",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TickworkEuclideanRhythmInput"
              },
              "examples": {
                "example1": {
                  "summary": "Kick, snare and hats in three lengths",
                  "value": {
                    "voices": "4, 16, 0, kick\n3, 8, 2, snare\n7, 12, 0, closed-hat",
                    "tempo": 110,
                    "swing": 50,
                    "bars": 4
                  }
                },
                "example2": {
                  "summary": "Tresillo E(3,8) on a clap",
                  "value": {
                    "voices": "3, 8, 0, clap",
                    "tempo": 96,
                    "swing": 50,
                    "bars": 2
                  }
                },
                "example3": {
                  "summary": "Five against seven with swing",
                  "value": {
                    "voices": "5, 16, 0, rim\n7, 16, 3, closed-hat\n2, 8, 4, kick",
                    "tempo": 124,
                    "swing": 58,
                    "bars": 8
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TickworkEuclideanRhythmResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "TickworkEuclideanRhythmInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "voices": {
            "title": "Rhythm voices",
            "description": "One voice per line: pulses, steps, rotation (optional), sound (optional: kick, snare, clap, closed-hat, open-hat, low-tom, high-tom, rim or a MIDI key 0–127), velocity (optional). Example: 3, 8, 0, kick",
            "type": "string",
            "maxLength": 600,
            "default": "4, 16, 0, kick\n3, 8, 2, snare\n7, 12, 0, closed-hat"
          },
          "tempo": {
            "title": "Tempo",
            "type": "number",
            "minimum": 20,
            "maximum": 300,
            "default": 110,
            "x-unit": "BPM"
          },
          "swing": {
            "title": "Swing",
            "description": "50 = straight; 54–62 = light to strong shuffle on the off-beat sixteenths.",
            "type": "number",
            "minimum": 50,
            "maximum": 75,
            "default": 50,
            "x-unit": "%"
          },
          "bars": {
            "title": "Bars in the MIDI file",
            "type": "integer",
            "minimum": 1,
            "maximum": 16,
            "default": 4
          }
        },
        "required": []
      },
      "TickworkEuclideanRhythmResult": {
        "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": [
              "voices",
              "tempo",
              "swing",
              "bars",
              "cycleSteps",
              "notes",
              "seconds",
              "midiFile",
              "projectFile"
            ],
            "properties": {
              "voices": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "pulses",
                    "steps",
                    "rotation",
                    "key",
                    "velocity",
                    "pattern",
                    "intervals",
                    "density"
                  ],
                  "properties": {
                    "pulses": {
                      "type": "integer"
                    },
                    "steps": {
                      "type": "integer"
                    },
                    "rotation": {
                      "type": "integer"
                    },
                    "key": {
                      "type": "integer"
                    },
                    "velocity": {
                      "type": "integer"
                    },
                    "pattern": {
                      "type": "string",
                      "description": "x = hit, . = rest (one character per sixteenth)."
                    },
                    "intervals": {
                      "type": "array",
                      "items": {
                        "type": "integer"
                      }
                    },
                    "density": {
                      "type": "number"
                    }
                  }
                }
              },
              "tempo": {
                "type": "number"
              },
              "swing": {
                "type": "number"
              },
              "bars": {
                "type": "integer"
              },
              "cycleSteps": {
                "type": "integer",
                "description": "Sixteenths until every voice starts together again (least common multiple of the lengths)."
              },
              "notes": {
                "type": "integer"
              },
              "seconds": {
                "type": "number"
              },
              "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)."
                  }
                }
              },
              "projectFile": {
                "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"
              }
            }
          }
        }
      }
    }
  }
}