Skip to content
markksantosPublic

About

A browser MIDI editor for plucked strings — thirteen instruments across nine musical cultures, every note synthesized as a physical string model, and an original Bach-style suite written in it

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🎸 PLECTRUM

A browser MIDI editor for plucked strings — thirteen instruments across nine musical cultures, and not one audio sample

Vanilla JS Web Audio Dependencies Build License: MIT

Features · Getting Started · The Instruments · The Music · How It Works · Tech Stack


Plectrum — the Fughetta in the roll view


Most browser sequencers are a grid of divs playing back a soundfont someone else recorded. Plectrum has no samples, no soundfont and no network requests: every note you hear is a string, simulated from scratch — a wave travelling down a delay line, losing its high partials a little faster than its low ones on every lap, coloured by a model of the box it is nailed to.

That single decision is what makes the instrument list possible. A koto is not a guitar with a different filename; it is thirteen open strings in hirajōshi, silk, over movable bridges. A sitar has a curved bridge that makes the wave fold back on itself, and thirteen more strings underneath that no one touches. Change the drop-down and the physics change with it.

The score survives the switch. Pitch is the truth in Plectrum, and string-and-fret is only how a given instrument happens to spell that pitch — so moving a Bach fughetta from a classical guitar to a guzheng transposes nothing. It just shows you, in red, the twenty-nine per cent of the piece a D-pentatonic instrument was never built to play.

It ships with an original two-movement Baroque suite, written in the editor.

✨ Features

  • Two views over one score — tablature (a row per string, fret numbers on the string) and a piano roll (a row per semitone, notes coloured by voice). Same notes, same edits, tab to switch
  • Thirteen instruments, nine cultures — each declaring its own string count, tuning, fret model and timbre, grouped by where they come from
  • Four fret models — fretted, fretless, open-string (nothing is stopped; each string is one pitch) and keyboard. The tablature grid renders all of them
  • Strings that behave like strings — a second note on a string damps the first, exactly as it does under your hand, so the tab you are looking at is the tab that is playing
  • Honest about reach — a note the current instrument cannot produce is drawn as a red ✕ on the string that comes nearest to it, and counted in the status bar. Nothing is silently dropped or transposed
  • A real transport — play, pause, stop, loop region, tempo, metronome and click-to-seek, all scheduled against the audio clock with a 250 ms lookahead so timing never drifts with the UI
  • Sound with no sound files — extended Karplus-Strong per note, rendered in JavaScript and cached, through a body-resonance chain built per instrument. Measured at ±5 cents across the whole roster
  • Jawari and sawari — the sitar and shamisen get a saturating bridge nonlinearity for their buzz, and the sitar rings its sympathetic strings whenever you play their pitch class
  • Standard MIDI export — format 1, PPQ 480, correct GM program per instrument. Plus JSON save and load
  • Undo everything — 120 levels, ⌘Z / ⇧⌘Z
  • No build step — twelve ES modules and one HTML file. Serve the folder and it runs

🚀 Getting Started

1. Clone

git clone https://github.com/markksantos/plectrum.git
cd plectrum

2. Serve it

python3 -m http.server 8791

3. Open it

http://localhost:8791

Any static server works. It needs one only because ES modules will not load over file:// — there is nothing to build and nothing to install, and once the page is open it never touches the network again.

4. Press play. It opens on the Prelude.

Keys

Input Action
space Play / pause
return Stop
tab Switch between tablature and roll
0–9 Set the fret at the tab cursor — two digits in quick succession read as one number
Arrows Move the tab cursor; transpose the roll selection (shift for octaves)
Drag a note Move it. Drag its right edge to lengthen it, drag it up or down to re-finger it
alt-click Delete a note
shift-click Add to the selection
Click the ruler Seek. shift-drag it to set a loop region
L / M Loop / metronome
⌘Z / ⇧⌘Z Undo / redo

🪕 The Instruments

Instrument Strings Tuning Neck Region
Classical guitar 6 E A D G B E 19 frets Spain / Europe
Steel-string guitar 6 E A D G B E 20 frets Americas
Oud 6 C F A D G C fretless Arab world / Turkey
Bağlama (saz) 3 G D A 17 frets Anatolia
Sitar 4 + 13 sympathetic Pa Sa Ma Pa 20 frets North India
Pipa 4 A D E A 24 frets China
Guzheng 21 D pentatonic open China
Koto 13 hirajōshi open Japan
Shamisen 3 B E B (honchōshi) fretless Japan
Kora 21 F heptatonic open West Africa
Charango 5 G C E A E, re-entrant 18 frets Andes
Banjo 5 open G, re-entrant 22 frets Appalachia
Harpsichord — keyboard roll view only Baroque Europe

Two of these deliberately do not behave: the charango and the banjo have re-entrant tunings, so their strings genuinely do not run low to high, and the tablature lays them out in the order they sit under your fingers rather than pretending otherwise. The banjo's short fifth string starts at the fifth fret and the fingering engine knows it.

Two more are approximations, and it is worth saying so: the oud and the bağlama live between the semitones. Their real frets and positions divide the octave far more finely than twelve, and Plectrum quantises them. What you get is the instrument's body, tuning and attack — not its maqam or its perde.

The Fughetta on a koto

The Fughetta loaded onto a koto. The dots are notes hirajōshi can reach; the red ✕ are the 119 of 416 it cannot, each parked on the string it came closest to.

🎼 The Music

Suite in E minor — original, written in this editor in the manner of Bach's lute works. Both movements are for classical guitar and stay inside a real hand: zero unreachable notes, nothing above the tenth fret.

I. Prelude · 48 bars · 760 notes · 2:24

One figuration, held from the first bar to the last, while the harmony carries the entire argument. A chromatic bass walks down through the opening eight bars — E, D♯, D, C♯, C, B — then a descending-fifths sequence turns the music toward the relative major, E7 pulls it home, and a dominant pedal is broken open by a diminished seventh before the final flourish and a Picardy third.

The harmony is composed bar by bar as a table of five-voice guitar shapes in pieces/prelude-e-minor.js; three figuration patterns break those shapes into sixteenths. Read the table and you can read the piece.

II. Fughetta · 32 bars · 416 notes · 1:27

Three voices, written out note by note. The subject climbs the tonic triad, leaps to the dominant, falls back through the leading tone and turns upward again. Its answer is tonal rather than real — the head stays diatonic to E minor, and only the tail transposes exactly, tipping the music into B minor the way the answer in a minor-key fugue is supposed to.

Then: a countersubject, an entry in the bass, an episode of the head motif in imitation over falling fifths, a middle entry read through G major, an entry in A minor, a second episode, a stretto with the two outer voices two beats apart, a dominant pedal, and the same Picardy third to close.

Both are in the Piece menu, and both export as MIDI.

The Prelude in tablature

The Prelude in tablature — the sustained bass and tenor under the arpeggios

🔧 How It Works

Write-up: Karplus-Strong with tanh saturation never decays: normalise by drive — the buzz bug in the string model, and the maths behind the fix.

instruments.js   tuning, fret model, timbre, region — the whole roster
       ↓
synth.js         Karplus-Strong renderer → AudioBuffer cache → body filters
       ↓
player.js        lookahead scheduler on the audio clock, loop, metronome
       ↑
model.js         the score, undo/redo, and pitch ⇄ string/fret assignment
       ↓
tabview.js       ┐
rollview.js      ├─ two canvases over one coordinate system (grid.js)
app.js           ┘  toolbar, keyboard, render loop
       ↓
midi.js          Standard MIDI File writer
pieces/          the compositions, as data

The string

Each note is a delay line the length of one period, filled with a burst of filtered noise, fed back into itself through three things:

  • A one-pole lowpass, so high partials die faster than low ones. This is the single most important line in the file. Without it you get a filtered noise burst; with it you get a string.
  • An allpass, which stretches the partials sharp. Short thick strings are stiff, and stiffness is exactly why a banjo and a pipa ring metallic where a nylon guitar does not.
  • A feedback gain solved from the instrument's decay time, so the string falls 60 dB in the time it is supposed to.

Before the loop runs, the excitation is combed by the plucking point — a real string cannot vibrate in a mode that has a node where you plucked it, so a delayed copy is subtracted out. Afterwards, the whole instrument runs through a short chain of peaking biquads standing in for the air and wood of its body.

Buffers are rendered once per pitch, cached, and thrown away when you change instruments.

Two things worth knowing before editing it

  • The buzz nonlinearity has to be unity-gain at small signal. The sitar's jawari and the shamisen's sawari are a tanh inside the feedback loop. Normalising it by tanh(drive) instead of drive gives the loop a small-signal gain of about 1.5 — and a feedback loop with gain above one is not a string, it is an oscillator. Four instruments rang forever before that was caught.
  • Fingering is a scheduling problem, not a lookup. assignStrings walks the score in time order, tracks which strings are still sounding, and picks positions by cost: distance from the running hand position, plus a penalty for climbing the neck, plus a large penalty for stealing a string that has not finished ringing. That is why the tablature reads like something a person would play, and why it changes when you edit the bar before it.

Verified, and not

Measured across all thirteen instruments: tuning within ±5 cents, decay from 0.25 s (charango) to 1.0 s (guzheng) to fall 20 dB, no clipping, no denormals, no runaway loops. Playback holds the audio clock to within a hundredth of a beat over a full movement. Exported MIDI parses to 760 note-ons matched by 760 note-offs across exactly 48 bars at 80 bpm.

What none of that tells you is whether the oud sounds like an oud. Put on headphones and decide.

⚙️ Performance

The expensive thing is synthesising a string, and it happens once per pitch. A movement uses about twenty-six distinct pitches, so the entire Prelude costs roughly 26 buffers — rendered in slices on idle before the first bar plays, then reused for the remaining 734 notes. Playback itself is BufferSource nodes and a gain envelope.

Drawing is two canvases redrawn only when something changes, with the playhead the one thing that dirties a frame while the transport runs. Total weight is about 2,500 lines across twelve modules, no dependencies, no images, no webfonts.

🛠️ Tech Stack

What How
Language Vanilla JavaScript, ES modules, no bundler
Synthesis Extended Karplus-Strong, rendered in JS into AudioBuffers
Audio graph Web Audio — buffer sources, peaking biquads, a limiter
Scheduling setInterval lookahead against AudioContext.currentTime
Rendering Two <canvas> elements over a shared beat/pitch coordinate system
Export Hand-written Standard MIDI File writer (format 1, PPQ 480)
Storage JSON in, JSON out — no database, no localStorage
Type System sans, with a serif for the wordmark. No webfonts
Build None

📄 License

MIT © Mark Santos

About

A browser MIDI editor for plucked strings — thirteen instruments across nine musical cultures, every note synthesized as a physical string model, and an original Bach-style suite written in it

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages