Skip to main content

Strudel Editor: Reading a Tab Screenshot Without a Model

How the import tab turns a picture of a bass or guitar tab into a pattern, using only image processing. The question that started it was whether a screenshot could become a song with no AI in the loop. For a clean digital rendering it can, because everything on the page is drawn from a handful of straight lines and one typeface.

What makes a tab easy to read​

A tab is a diagram, not a photograph. Four or six long horizontal lines are the strings, short vertical strokes are the bar lines, and numbers sit on the lines to name the fret. Under the staff a row of stems and beams carries the rhythm. Every one of those has a fixed geometry, so each can be found by projecting ink onto a row or a column and looking for runs. Nothing needs learning, and nothing is guessed from context.

flowchart LR
file[Screenshot] --> decode[Decode on the<br/>main thread]
decode --> dev[Distance from<br/>the page colour]
dev --> staff[Staff lines<br/>by row coverage]
staff --> bars[Bar lines<br/>by column coverage]
staff --> frets[Fret glyphs on<br/>each string line]
staff --> stems[Stems, beams and<br/>triplet brackets]
frets --> digits[Digit templates]
digits --> bar[Notes per bar]
stems --> bar
bars --> bar
bar --> code[Strudel code]

Measure everything in staff gaps​

A screenshot arrives at any zoom, on a dark or a light page. Two decisions remove both problems. Pixels are turned into their distance from the page colour, taken as the median luminance, so light ink on dark and dark ink on light look the same. Then every length the detectors use is a multiple of the gap between two staff lines, measured from the staff itself. A digit is about four fifths of a gap tall, a stem starts a gap under the bottom line, a bar is at least four gaps wide. The same thresholds work on a thumbnail and on a retina capture.

Two ink levels matter. Staff lines and bar lines are faint, close to a third of full contrast, and digits, beams and stems are bright. Digits are found in the bright layer only, so a line running behind a digit never glues itself to it.

The rhythm row is the clock​

The horizontal position of a note says nothing reliable about its length, because tab renderers space notes for legibility rather than for time. The row of stems under the staff is what carries the duration. Each stem sits in the same column as the note it belongs to, and the number of beams or flags on it says how short it is: none for a quarter note, then an eighth, a sixteenth. A bracket with a number in the middle marks a triplet, which takes two thirds of the usual length.

A stem with no fret number above it is the end of a tie, so the previous note rings on rather than a new one starting. That rule replaced a plan to detect the tie arc itself, which was harder and said less.

The strongest check available is arithmetic. Every bar of the sample adds up to exactly four beats once ties and triplets are counted. A misread beam or a missed stem breaks that sum, so the test for it catches rhythm errors that no hand transcription of the expected notes would.

Digits are the weak point​

Reading digits at eleven pixels tall is where the first versions failed, in three separate ways.

SymptomCauseFix
A 1 read as 9 or 4The flag on a 1 pulls its box off centre, and the box was stretched to fillSize cells by the glyph's height, and try small side shifts
An 8 read as 6Cells that overlapped blurred thin strokes into solid blocksWeight each pixel by how much of it a cell really covers
A 6 read as 0 in a different typefaceHand drawn templates for digits the sample never printedSample templates from real fonts, one set per typeface

The lesson is that a template is only as good as the font it came from. The sample uses one tab site's typeface and never prints a 2, a 4 or a 6, so those were first drawn by hand and were wrong. Sampling the browser's own sans serif face in two weights fixed them, and a screenshot in a different face now only needs another set added as data.

Anything that is not a digit is dropped rather than guessed. A slide or vibrato mark after a fret is removed, and an unreadable fret is reported as a warning and skipped, so the pattern is never silently wrong.

The tempo is a number after an equals sign​

The tempo marker is small, dim text in a layout that differs between sites, so no site specific position can be assumed. What stays the same is its shape: a note symbol, an equals sign, then digits. The reader scans the band of labels above the first staff, finds a short wide mark made of exactly two separate bars, and reads the digits right after it with the same templates as the fret numbers. Digits are normalised by their own strongest pixel, so dim text reads as well as bright, but the ink level used to find them has to be lower than for fret numbers. A result outside 30 to 300 beats per minute is treated as a misread and ignored.

Strokes that look like bar lines​

Two things in the sample drew a vertical stroke the full height of the staff without being a bar line: the large time signature at the start, and a playback cursor outlining one note. Both were caught by one rule, since neither encloses a plausible bar. A stroke closer than four gaps to the previous edge is ignored. A double bar line counts once.

Several tabs make one song​

A bass tab and a guitar tab of the same song are two screenshots, and the first version let the second replace the first. Keeping both raised two questions the single tab never had.

The first was what shape of code the flow view would accept, since the graph is rebuilt from the code on every edit. A spike settled it before any generator was written: a program of labelled $: blocks, one per instrument, already reads as one Notes node and its Voice per block, and compiles back to code that reads the same way again. Nothing in the flow package had to change for the graph, so the song is written in that form.

The second was what Add means. Strudel has a rule that is easy to miss: once any labelled block exists, an unlabelled last expression is no longer played. Appending a labelled guitar under a single tab loaded the old way would therefore have silenced the bass with no error. The append labels that expression first, which is the only edit it makes to code that is already there.

flowchart LR
bass[Bass tab] --> song[Song: first tempo,<br/>one block each]
guitar[Guitar tab] --> song
song --> load[Load: replace<br/>the code]
song --> add[Add: label the bare<br/>expression, append blocks]
load --> play[Strudel plays<br/>every block]
add --> play

Each block loops on its own, so instruments with different bar counts drift and realign only at the least common multiple of their lengths. Padding or cutting to one length would change what was transcribed, so the import warns instead and leaves the choice in the code. A tempo that differs between screenshots is handled the same way: the first file's tempo plays, and the others are reported.

A piano score joins a song the same way, as two instruments, one per hand. It brings one thing a tab never does, a metre other than four beats. Strudel's cycle is one bar for every block at once, so a score in three in a song of four has each bar stretched to the longer cycle and plays slower than marked. That is reported too rather than corrected, for the same reason as the loop lengths.

Each imported block can end with a pianoroll under its line, on by default. The visual is a call appended to the block, so it is one more node on that instrument's branch in the flow view rather than anything the import has to model, and leaving it off gives back exactly the code from before.

What it does not do​

MissingWhy
A tempo given in wordsOnly the form with an equals sign is read. Otherwise the code starts at 120 BPM.
Time signatureAssumed to be 4/4. Reading it needs the large digits at the staff start.
Dotted notes, other tuplets, half notesNone occur in the sample, so none were verified against real data.
Slides, bends, vibrato, ghost notesRead as a note without the effect, or skipped with a warning.
Photos, scans, handwritingThe geometry is no longer straight and clean, which every detector here relies on.
Standard notationRead separately, see reading a piano score.
Instruments of different lengthsEach loops on its own and the import warns. Nothing is padded or cut to match.

The shape of the result is the reason this stayed small. It writes its own note pattern with lengths and ties, so the audio and MIDI import, which keeps one bass note per sixteenth, did not have to grow a duration field it would use nowhere else.