Demos

Harmonize like Bach

Play a melody and hear it as a Bach chorale.

Remix this demo ↓
Click the keys or type A S D F G H J K L · Backspace deletes

Harmonization

Beats matching Bach’s chord

Beats matching Bach’s chord

Remix this demo

Paste it into your coding agent in your project.

Read the full prompt
Adapt this for [what I want to build].

Build a symbolic four-part harmonizer. I enter a melody, hear its harmony and inspect the chord choice at each beat. Notes are MIDI integers, not an audio upload. Code synthesizes all four voices; the decision model chooses from code-supplied chord/bass options. Inspect my project first and build a working local interaction, not a static mock.

Start with C major and soprano [72,74,76,72], one beat each. Provide an editable melody, key and tempo. Code enumerates chord/inversion candidates that contain the soprano note, then enumerates valid bass/tenor/alto pitches. Reject out-of-range or crossing voices in code; do not ask the model to repair invalid notes. Preserve the entered soprano. Never present a voicing without valid notes as a completed harmony.
Use one choice question per beat with the complete melody in shared state. Each question sees the shared melody and its own chord candidates. Questions cannot read one another's answers. Code must choose a valid voice-leading path from the returned chord distributions. If using a sequential variant instead, put the selected earlier chords explicitly in the next request's shared state. Do not claim a parallel request conditions on its own predicted earlier chords.
A deterministic sample can use hand-authored chords and voicings, clearly marked "Sample mode. No model call." Keep any original Bach score, recorded model output, and newly computed result separately labelled.


Build this in my codebase; no starter repository is required. Keep the demo's saved comparisons separate from this new integration. The small request below illustrates the integration contract, not the benchmark configuration or a new measured result.

API and response:
Send POST https://api.spinda.ai/v1/systemone. Read SPINDA_API_KEY on the server and set Authorization: Bearer <key>, Content-Type: application/json, and a unique Idempotency-Key for each logical request. Never expose the key to browser code, logs or this chat. Use decision-model-large. Never substitute another model or spoof a response. See https://spinda.ai/docs for the current contract.
Require response.model to equal decision-model-large and reject preview responses. Require exactly the requested question IDs. Each answer must have type choice, a choice among the offered IDs, and a probabilities object with exactly those IDs. Reject booleans, nonfinite values, values outside [0,1], and totals more than 0.02 from 1. Do not use confidence as the chosen option's probability. Validate the entire response before playing or accepting any result.

Calls and edits:
Start with a clearly labelled, deterministic sample mode that needs no key and makes no network calls. Provide an explicit Live action; changing tempo, editing a note or switching a saved example must not silently send requests. Keep keys, request limits and caching on the server. Default to at most 16 live calls per local run, reserve a call before sending, and disable overlapping runs. Do not retry automatically. An explicit retry must reuse the exact body and idempotency key; honor Retry-After on 429. Retain the original attempt after a timeout, because cancelling the browser request does not cancel server work or a charge. A new input is a new request with a new key.
Tie each result to the exact input revision. After a melody, key or style edit, mark the old result as previous and never attach an in-flight old result to the new phrase. Playback follows the currently displayed phrase. Provide Stop, stop prior oscillators before a new playback, and start browser audio from a user action. Keep native, labelled controls for key, tempo, play and stop. Support touch and keyboard without trapping focus.

Delivery:
Reuse my framework and create a short README with install/run commands, sample mode, the live call cap and the server-side environment setup. Do not clone a nonexistent starter, require a private dataset, or add Google-model comparisons without the real model and its inputs. Never treat matching Bach's notes as evidence of listener preference. Do not add an interpretability graph unless it belongs to the exact model and request that made the decision.

Reference request, generated by the demo's canonical chord candidate builder. Four beat questions share one melody:
```json
{
  "model": "decision-model-large",
  "state": "{\"task\":\"Harmonize this soprano melody as a four-part chorale in the style of J. S. Bach. For each melody note, choose the chord and bass note.\",\"key\":\"C major\",\"meter\":\"4/4, one chord per quarter note\",\"style_notes\":\"Functional harmony (tonic, predominant, dominant). Strong cadences at phrase ends, usually V or V7 to I. Prefer a smooth, mostly stepwise bass with some leaps of a fourth or fifth. Use inversions to keep the bass melodic. Second-inversion chords mainly as a cadential I64 before V.\",\"melody\":[{\"beat\":1,\"bar\":1,\"beat_in_bar\":1,\"pitch\":72,\"name\":\"C5\"},{\"beat\":2,\"bar\":1,\"beat_in_bar\":2,\"pitch\":74,\"name\":\"D5\"},{\"beat\":3,\"bar\":1,\"beat_in_bar\":3,\"pitch\":76,\"name\":\"E5\"},{\"beat\":4,\"bar\":1,\"beat_in_bar\":4,\"pitch\":72,\"name\":\"C5\"}],\"phrase_end_beats\":[4]}",
  "questions": {
    "beat_1": {
      "type": "choice",
      "criteria": {
        "I": "I (tonic): C, root position, C in the bass; notes C E G.",
        "I6": "I6 (tonic): C, first inversion, E in the bass; notes C E G.",
        "I64": "I64 (cadential six-four, resolves to V): C, second inversion, G in the bass; notes C E G.",
        "IV": "IV (predominant): F, root position, F in the bass; notes F A C.",
        "IV6": "IV6 (predominant): F, first inversion, A in the bass; notes F A C.",
        "vi": "vi (submediant, a tonic substitute): Am, root position, A in the bass; notes A C E.",
        "ii7": "ii7 (predominant): Dm7, root position, D in the bass; notes D F A C.",
        "ii65": "ii65 (predominant): Dm7, first inversion, F in the bass; notes D F A C.",
        "V7/V": "V7/V (secondary dominant leading to V): D7, root position, D in the bass; notes D F♯ A C.",
        "V65/V": "V65/V (secondary dominant leading to V): D7, first inversion, F♯ in the bass; notes D F♯ A C.",
        "V7/IV": "V7/IV (secondary dominant leading to IV): C7, root position, C in the bass; notes C E G A♯."
      },
      "instructions": "Bar 1, beat 1: the melody is C5 (scale degree 1); first note, next note D5 (scale degree 2). Which chord and bass note would Bach use here?"
    },
    "beat_2": {
      "type": "choice",
      "criteria": {
        "ii": "ii (predominant): Dm, root position, D in the bass; notes D F A.",
        "ii6": "ii6 (predominant): Dm, first inversion, F in the bass; notes D F A.",
        "V": "V (dominant): G, root position, G in the bass; notes G B D.",
        "V6": "V6 (dominant): G, first inversion, B in the bass; notes G B D.",
        "viio6": "viio6 (dominant): B°, first inversion, D in the bass; notes B D F.",
        "ii7": "ii7 (predominant): Dm7, root position, D in the bass; notes D F A C.",
        "ii65": "ii65 (predominant): Dm7, first inversion, F in the bass; notes D F A C.",
        "V7": "V7 (dominant): G7, root position, G in the bass; notes G B D F.",
        "V65": "V65 (dominant): G7, first inversion, B in the bass; notes G B D F.",
        "V43": "V43 (dominant): G7, second inversion, D in the bass; notes G B D F.",
        "V42": "V42 (dominant): G7, third inversion, F in the bass; notes G B D F.",
        "V/V": "V/V (secondary dominant leading to V): D, root position, D in the bass; notes D F♯ A.",
        "V6/V": "V6/V (secondary dominant leading to V): D, first inversion, F♯ in the bass; notes D F♯ A.",
        "V7/V": "V7/V (secondary dominant leading to V): D7, root position, D in the bass; notes D F♯ A C.",
        "V65/V": "V65/V (secondary dominant leading to V): D7, first inversion, F♯ in the bass; notes D F♯ A C."
      },
      "instructions": "Bar 1, beat 2: the melody is D5 (scale degree 2); previous note C5 (scale degree 1), next note E5 (scale degree 3). Which chord and bass note would Bach use here?"
    },
    "beat_3": {
      "type": "choice",
      "criteria": {
        "I": "I (tonic): C, root position, C in the bass; notes C E G.",
        "I6": "I6 (tonic): C, first inversion, E in the bass; notes C E G.",
        "I64": "I64 (cadential six-four, resolves to V): C, second inversion, G in the bass; notes C E G.",
        "iii": "iii (mediant): Em, root position, E in the bass; notes E G B.",
        "vi": "vi (submediant, a tonic substitute): Am, root position, A in the bass; notes A C E.",
        "V/vi": "V/vi (secondary dominant leading to vi): E, root position, E in the bass; notes E G♯ B.",
        "V7/IV": "V7/IV (secondary dominant leading to IV): C7, root position, C in the bass; notes C E G A♯."
      },
      "instructions": "Bar 1, beat 3: the melody is E5 (scale degree 3); previous note D5 (scale degree 2), next note C5 (scale degree 1). Which chord and bass note would Bach use here?"
    },
    "beat_4": {
      "type": "choice",
      "criteria": {
        "I": "I (tonic): C, root position, C in the bass; notes C E G.",
        "I6": "I6 (tonic): C, first inversion, E in the bass; notes C E G.",
        "I64": "I64 (cadential six-four, resolves to V): C, second inversion, G in the bass; notes C E G.",
        "IV": "IV (predominant): F, root position, F in the bass; notes F A C.",
        "IV6": "IV6 (predominant): F, first inversion, A in the bass; notes F A C.",
        "vi": "vi (submediant, a tonic substitute): Am, root position, A in the bass; notes A C E.",
        "ii7": "ii7 (predominant): Dm7, root position, D in the bass; notes D F A C.",
        "ii65": "ii65 (predominant): Dm7, first inversion, F in the bass; notes D F A C.",
        "V7/V": "V7/V (secondary dominant leading to V): D7, root position, D in the bass; notes D F♯ A C.",
        "V65/V": "V65/V (secondary dominant leading to V): D7, first inversion, F♯ in the bass; notes D F♯ A C.",
        "V7/IV": "V7/IV (secondary dominant leading to IV): C7, root position, C in the bass; notes C E G A♯."
      },
      "instructions": "Bar 1, beat 4: the melody is C5 (scale degree 1); previous note E5 (scale degree 3), last note of the phrase. Which chord and bass note would Bach use here?"
    }
  }
}
```

Keep an internal candidate map from every option ID to its chord tones, inversion and bass. A response ID chooses from this map; it never supplies MIDI notes. Show the original chord probabilities and explain code constraints separately. If no complete voicing path exists, show a useful failure and retain the melody; do not silently switch to a sample or another model.

Verify locally with no live calls: key/range checks; candidates containing each soprano pitch; bass/inversion mapping; all four voices in range and ordered bass <= tenor <= alto <= soprano; response completeness across every beat; exact request/key recovery; no model-call-on-edit; stale response rejection; Stop and replay; and labelled sample mode. Exercise at least one complete harmony, a melody change during a pending fixture, and a no-valid-voicing case on phone and desktop. Report what ran and what failed. Do not make a live call merely to finish this prompt.