RockBlocks

RockBlocks Beat API

Turn your app’s words or code into a real drum beat. Send text and get TextyBeat’s groove — one beat per sentence — or send Python, JavaScript or SQL and get RockCode’s — one beat per block. You get the beat as JSON, a picture to show, a widget that plays it, and an Open in RockBlocks link that drops it straight into the drum machine. Free, no key, no sign-up. The same input always makes the same beat.

Try it

Text, as a playable widget:

Code, as a picture linked to RockBlocks:

RockCode beat for a short Python program

The endpoints

GET or POST /api/v1/beat
The beats as JSON, with openUrl, imageUrl, embedUrl and a ready-to-paste embedHtml.
GET or POST /api/v1/beat/image
The same beats drawn as an SVG — use the URL as an image.
/embed/beat?…
A widget for an <iframe>: shows the beat, plays it, and opens it in RockBlocks in a new tab.

All three take the same parameters — as a query string, or for POST as JSON (or form fields, or a plain-text body that is the input). CORS is open, so you can call it straight from a browser. Each IP address can make up to 120 requests a minute across the API, picture and widget — past that you’ll get a 429 for the rest of the minute. The same input always makes the same beat, so cache what you get back.

modetext (TextyBeat — one beat per sentence) or code (RockCode — one beat per block of code). Defaults to text.
inputThe text or code. Up to 280 characters of text or 2000 of code are used (the response says "truncated": trueif yours was longer). At most 4 beats come back, for RockBlocks’ Slots A–D. text or code work as the name too.
languageCode mode only: python, javascript, sql. Defaults to python.
kitDrum kit: Acoustic, 808, 909, Fart, Cats, Techno, Latin, Metal, Reggaeton, Middle Eastern, Birds, 8-Bit. Defaults to Acoustic.
bpmTempo, 40–240. Leave it out for TextyBeat’s 100 bpm, or each RockCode block’s own tempo.

From JavaScript

const res = await fetch("https://rockblocks.app/api/v1/beat", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ mode: "code", language: "javascript", input: myCode }),
});
const beat = await res.json();

img.src = beat.imageUrl;          // a picture of the beat
link.href = beat.openUrl;         // "Open in RockBlocks" (use target="_blank")
container.innerHTML = beat.embedHtml; // or a playable widget

No code: a picture or a widget

<a href="OPEN_URL" target="_blank" rel="noopener">
  <img src="https://rockblocks.app/api/v1/beat/image?mode=text&input=Hello%20world." alt="My beat">
</a>
<iframe
  src="https://rockblocks.app/embed/beat?mode=code&language=sql&input=SELECT%20name%20FROM%20users%20WHERE%20age%20%3E%2021"
  width="100%" height="220" style="border:0;border-radius:12px" title="RockBlocks beat"></iframe>

The response

Each beat has its source sentence or code block, tempo and time signature, and one entry per drum. Each beat-block on a drum has its RockBlocks tile id and its hits spelled out — at and length in beats — so you can draw or play it yourself. Errors come back as { "error": "…" } with status 400 (bad parameters) or 422 (no beat in that input).

{
  "mode": "text",
  "kit": "Acoustic",
  "truncated": false,
  "beats": [
    {
      "slot": "A",
      "source": "Every app has a beat.",
      "bpm": 100,
      "beats": 6,
      "timeSignature": "6/4",
      "lines": [
        {
          "instrument": "ride",
          "name": "Ride Cymbal",
          "color": "#6366f1",
          "volume": 100,
          "blocks": [
            null,
            {
              "tile": "c:re-ne",
              "label": "8th rest + 8th",
              "hits": [
                {
                  "at": 0.5,
                  "length": 0.5
                }
              ]
            },
            {
              "tile": "n-quarter",
              "label": "Quarter",
              "hits": [
                {
                  "at": 0,
                  "length": 1
                }
              ]
            },
            {
              "tile": "n-e-e",
              "label": "8th + 8th",
              "hits": [
                {
                  "at": 0,
                  "length": 0.5
                },
                {
                  "at": 0.5,
                  "length": 0.5
                }
              ]
            },
            {
              "tile": "n-quarter",
              "label": "Quarter",
              "hits": [
                {
                  "at": 0,
                  "length": 1
                }
              ]
            },
            {
              "tile": "c:re-ne",
              "label": "8th rest + 8th",
              "hits": [
                {
                  "at": 0.5,
                  "length": 0.5
                }
              ]
            }
          ]
        }
      ]
    },
    "…"
  ],
  "openUrl": "https://rockblocks.app/import#W3siYnBtIjoxMDAsImxpbmVzIjpbey…",
  "imageUrl": "https://rockblocks.app/api/v1/beat/image?mode=text&input=Every+app+has…",
  "embedUrl": "https://rockblocks.app/embed/beat?mode=text&input=Every+app+has+a+beat…",
  "embedHtml": "<iframe src=\"…\" …></iframe>"
}

TextySong API

Send any text and get back the whole song TextySong makes from it: drums from each sentence, a bass line and melody built on the rhythm of the words, arranged into a song structure. You also get how hinged or unhinged the song is (1–100) and every rule that set that number. The rules read how the text is typed (caps, punctuation, stretched letters, odd meters, long words, symbols), never what it means. There’s no AI, and the same text always makes the same song.

GET or POST /api/v1/song
The song as JSON, with playUrl (the song, ready to play on RockBlocks) and imageUrl(an SVG of the words’ drum beats).
inputThe text, up to 280characters. Each of the first four sentences writes a part’s drums: verse, chorus, bridge, fill. text works as the name too, and a plain-text POST body is the input.
data1 or true to also get the song as RockBlocks data (data.slots and data.stack, every note of the drums, bass, chords and melody). It’s about 60 KB, so it’s left out unless you ask.

The level is always the one the words set. On rockblocks.app, signed-in accounts can turn the dial by hand, but the API doesn’t take a level. Same CORS, limits and errors as the Beat API: 400 for bad parameters, 422 for text with no words.

const res = await fetch("https://rockblocks.app/api/v1/song", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ input: message }),
});
const song = await res.json();

level.textContent = `${song.hinge.level}/100 unhinged`; // set by how it's typed
link.href = song.playUrl;     // the whole song, playing on RockBlocks
img.src = song.imageUrl;      // a picture of the words' drum beats

Each section lists its bars, key, which parts play, whether the drums are full, light (pulled back while the bass carries the rhythm) or out, and how the melody plays the hook. theme is the rhythm taken from the words: onsetsin beats, the bass riff’s scale degrees. notes explains, in plain English, how the song was made.

{
  "input": "My flight got cancelled again. Why is this happening?! I just want to go home.",
  "truncated": false,
  "title": "My flight got cancelled again.",
  "hinge": {
    "level": 40,
    "base": 15,
    "rules": [
      {
        "id": "caps",
        "label": "Shouting",
        "rule": "12 points for each word in ALL CAPS",
        "found": "0 words",
        "points": 0,
        "max": 36
      },
      "…"
    ],
    "about": "The level comes from fixed rules about how the text is typed, never what it means: RockBlocks uses no AI. The same text always gets the same level."
  },
  "form": "The long wait",
  "style": "spiced-up",
  "bpm": 87,
  "key": "A Major (Ionian)",
  "seconds": 163,
  "sentences": [
    {
      "sentence": "My flight got cancelled again.",
      "slot": "A"
    },
    {
      "sentence": "Why is this happening?!",
      "slot": "B"
    },
    {
      "sentence": "I just want to go home.",
      "slot": "C"
    }
  ],
  "hook": {
    "beats": 16,
    "split": 8,
    "notes": [
      {
        "start": 0,
        "duration": 0.5,
        "degree": 0
      },
      {
        "start": 0.5,
        "duration": 0.5,
        "degree": 4
      },
      {
        "start": 1,
        "duration": 0.5,
        "degree": 3
      },
      {
        "start": 1.5,
        "duration": 1.5,
        "degree": 5
      },
      {
        "start": 3,
        "duration": 4.5,
        "degree": 4
      },
      {
        "start": 8,
        "duration": 0.5,
        "degree": 0
      },
      {
        "start": 8.5,
        "duration": 0.5,
        "degree": 4
      },
      {
        "start": 9,
        "duration": 0.25,
        "degree": 2
      },
      {
        "start": 9.25,
        "duration": 0.25,
        "degree": 2
      },
      {
        "start": 9.5,
        "duration": 0.25,
        "degree": 1
      },
      {
        "start": 9.75,
        "duration": 1.25,
        "degree": 1
      },
      {
        "start": 11,
        "duration": 4.5,
        "degree": 0
      }
    ],
    "origin": {
      "rhythm": "drums",
      "response": "echo",
      "pickup": false
    }
  },
  "theme": {
    "beats": 8,
    "onsets": [
      0,
      0.5,
      1,
      1.5,
      1.75,
      2.25,
      2.75,
      3,
      3.75,
      4,
      4.5,
      4.75,
      5.333,
      5.5,
      6.5,
      7.5
    ],
    "riff": [
      0,
      7,
      7,
      0,
      2,
      7,
      4,
      4,
      4,
      4,
      4,
      4,
      4,
      -3,
      0,
      -3
    ]
  },
  "sections": [
    {
      "name": "Intro",
      "kind": "intro",
      "bars": 2,
      "slots": [
        "C",
        "C"
      ],
      "key": "A Major (Ionian)",
      "parts": {
        "drums": true,
        "bass": true,
        "melody": true
      },
      "drums": "full",
      "bassCarriesTheme": false,
      "melody": "tease"
    },
    {
      "name": "Verse 1",
      "kind": "verse",
      "bars": 4,
      "slots": [
        "A",
        "A",
        "A",
        "A"
      ],
      "key": "A Major (Ionian)",
      "parts": {
        "drums": true,
        "bass": true,
        "melody": true
      },
      "drums": "mixed",
      "bassCarriesTheme": true,
      "melody": "verse"
    },
    "…"
  ],
  "beats": [
    {
      "slot": "A",
      "role": "Verse groove",
      "source": "My flight got cancelled again.",
      "kit": "Acoustic",
      "beats": 8,
      "timeSignature": "4/4 ×2",
      "lines": [
        {
          "instrument": "ride",
          "name": "Ride Cymbal",
          "color": "#6366f1",
          "volume": 100,
          "blocks": [
            null,
            {
              "tile": "c:re-ne",
              "label": "8th rest + 8th",
              "hits": [
                {
                  "at": 0.5,
                  "length": 0.5
                }
              ]
            },
            null,
            null,
            {
              "tile": "c:rs-nd",
              "label": "16th rest + Dot 8th",
              "hits": [
                {
                  "at": 0.25,
                  "length": 0.75
                }
              ]
            },
            {
              "tile": "c:rte-nts-nte-rts",
              "label": "8th Trip rest + 16th Trip + 8th Trip + 16th Trip rest",
              "hits": [
                {
                  "at": 0.3333,
                  "length": 0.1667
                },
                {
                  "at": 0.5,
                  "length": 0.3333
                }
              ]
            },
            {
              "tile": "n-quarter",
              "label": "Quarter",
              "hits": [
                {
                  "at": 0,
                  "length": 1
                }
              ]
            },
            {
              "tile": "c:rs-nd",
              "label": "16th rest + Dot 8th",
              "hits": [
                {
                  "at": 0.25,
                  "length": 0.75
                }
              ]
            }
          ]
        }
      ]
    },
    "…"
  ],
  "notes": [
    "TextySong: your words set the dial to 40/100. Nine fixed rules read how the message is typed (caps, !?, stretched letters, odd meters, long words, symbols and emoji, repeats, texting talk, run-on sentences), never what it means. Same words, same song, every time.",
    "…"
  ],
  "playUrl": "https://rockblocks.app/textysong?text=My+flight+got+cancelled+again.+Why+is+this+happening%3F%21+I+just+want+to+go+home.",
  "imageUrl": "https://rockblocks.app/api/v1/beat/image?mode=text&input=My+flight+got…"
}

How Open in RockBlocks works

openUrl carries the beats in the link’s #fragment, which browsers never send to a server. Opening it puts them in the visitor’s own RockBlocks Slots A–D (in empty slots where it can) and opens the drum machine, where they can remix it, add a bass line, and save it. Open it in a new tab — target="_blank" — so your app stays where it was.