Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Keys-first chord arrangement generation: `window.chordr.generateChordArrangement()`
turns named harmony events into a playable two-hand keys part (`generateKeysArrangement`),
with slash-bass support, note durations (`lengthSeconds` for the arrangement's
total length, `defaultDuration` for the trailing chord), register clamps and
voice leading between changes. `{instrument: "guitar"}` instead generates
tuning-aware guitar shapes (`generateGuitarArrangement`), honouring `tuning`,
`stringCount`, `maxFret` and `isBass`.
- Accept both audio detector `{t, name}` events and chart chord/template pairs
(`chordTemplates`, indexed by the event's `id`), so the generators work with
authored charts and the audio detector's events alike.
- Add `generateAccompanimentFromLyrics(filename, options)`: a third
arrangement-generation path that harmonizes a song's sung melody (read
from lyrics_karaoke's canonical `/playback` payload) into a backing chord
sequence — key estimation via a Krumhansl-Schmuckler-style pitch-class
correlation, then a windowed best-fit diatonic triad per chord change —
and feeds it into the existing keys/guitar generator. Covers a song whose
only harmonic information is its vocal line: no chord chart, no full-mix
audio worth chord-detecting.

- `window.chordr.getChartTransformStatus()` reports whether the
`chart-transform` provider is registered and currently selected on this
host (`"pending"` / `"active"` / `"registered"` / `"unavailable"`).
Expand Down
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ capability's presence at call time (`getattr(app.state,
handle its absence: `difficulty_ladder` returns HTTP 503 (see above),
`feedpakr` degrades to a warning and no-ops rather than failing the
build. This plugin's `plugin.json` is
currently at `0.5.4`; the chart-transform block has been declared in its
currently at `0.6.0`; the chart-transform block has been declared in its
current canonical shape since `0.2.0` (commit `084e1b2`). If you change
what `chart-transform`/`analyze_chart_chords_v1` returns or how it's
registered, both of those repos' consuming code needs to be checked, not
Expand Down Expand Up @@ -128,7 +128,7 @@ before assuming a given host can run it.
## Testing

```bash
node --test tests/*.test.js # 81 pass
node --test tests/*.test.js # 99 pass
python3 -m pip install -r tests/requirements.txt
python3 -m unittest discover -s tests -p 'test_*.py' # 18 pass
```
Expand Down
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ window.chordr.identifyChord(chordNotes, {
isBass,
});
window.chordr.identifyPianoChord(midiNotes);
window.chordr.parseChordName("Cmin7/E"); // { root, bass, quality, intervals, pitchClasses } | null
window.chordr.generateChordArrangement(chords, {
instrument: "keys", // default; or "guitar" / "acoustic" / "electric"
lengthSeconds: 180, // total arrangement length; the trailing chord fills the remainder
defaultDuration: 2, // seconds the trailing chord lasts without a lengthSeconds
chordTemplates, // names for chart events that carry only an id
tuning, capo, stringCount, maxFret, isBass, // guitar shapes
});
window.chordr.generateKeysArrangement(chords, options); // keys-only entry point
window.chordr.generateGuitarArrangement(chords, options); // guitar-only entry point
await window.chordr.generateArrangementFromAudio(audioUrl, {
instrument: "keys",
lengthSeconds: 180,
});
await window.chordr.generateAccompanimentFromLyrics(filename, {
instrument: "keys", // default; or "guitar"
arrangementIndex, // optional — forwarded to lyrics_karaoke's /playback
windowSeconds: 2, // chord-change grid; smaller = more frequent changes
});
window.chordr.identifyFromHighway(chordNotes, highway);
window.chordr.groupChordEvents(chords);
window.chordr.generateChordTemplates(chords, existingTemplates, {
Expand All @@ -61,6 +80,80 @@ tolerates `{ string, fret }` objects. It returns `null` when the pitch-class
set does not match a supported chord quality. See `CHORD_QUALITIES` in
`chordr/screen.js`.

`generateChordArrangement(chords, options)` turns named harmony events such as
`[{t: 0, name: "C"}, {t: 2, name: "G/B"}]` into a playable arrangement. Keys
is the default and primary output: each note is `{t, midi, sus, hand}` with a
Comment thread
pullfrog[bot] marked this conversation as resolved.
Resolved
compact right-hand voicing, a left-hand root/slash bass, and voice leading
between changes. `{instrument: "guitar"}` instead returns `{t, s, f, sus}`
notes plus the selected fret shapes in `shapes`, searched against the open
strings that `tuning`/`stringCount`/`isBass` describe — `isBass: true` searches
a 4/5-string bass's fifths rather than the low six guitar strings, so its frets
decode back to the chord that was asked for. Chart chords without an inline
`name` can use `options.chordTemplates` (their `id` indexes that array), so the
API works with authored charts and the audio detector's named events alike. The
function does not mutate its inputs.

Every note lasts until the next onset, so nothing has to be tuned for the
voicing to be musical; the only length options concern the trailing chord.
`lengthSeconds` is the arrangement's *total* length, so a final chord that
starts early is held until then — that is what fills out a track whose last
detected chord is short. `defaultDuration` (2s by default) is that trailing
chord's own length and its floor, so a `lengthSeconds` below the last onset
extends nothing rather than collapsing the final note.

The result is deliberately an arrangement payload rather than an automatic
`chart-transform`: the host transform contract can replace notes but cannot
change instrument type or create a new arrangement. An editor/importer should
materialize this payload as a separate Keys or Guitar arrangement, leaving the
song's original part intact — and note that the two payloads are not the same
thing on the wire. The guitar notes are *already* wire notes (`{t, s, f, sus}`,
feedpak-spec §6.2); the keys notes are not. `{t, midi, sus, hand}` has to be
converted first, because a keys/keys arrangement reuses `s`/`f` for a 24-semitone
MIDI bucket (`midi = s * 24 + f`) rather than a string index and fret:

```js
const wireNotes = notes.map((n) => ({
t: n.t,
s: Math.floor(n.midi / 24),
f: n.midi % 24,
sus: n.sus,
}));
```

Write the payload verbatim and every note decodes as `null`, leaving a
silently unidentifiable part — the chordr#19 failure mode, in reverse.
`hand` has no wire field at all: it is a rendering hint (which hand plays the
note), so keep it in your own copy or drop it. The generator's register clamps
keep `f` under 24. Chordr reads that encoded form back through
`identifyChord(notes, { isPiano: true })` and `identifyPianoChord`, and
feedBack-plugin-piano claims keys arrangements by the same pattern.

`generateArrangementFromAudio(audioUrl, options)` is the end-to-end fallback
for a song with no authored piano part: it runs Chordr's existing audio chord
detection and feeds those harmony events into the same keys-first generator.
It returns `null` if audio detection fails.

`generateAccompanimentFromLyrics(filename, options)` is a third generation
path for a song whose only harmonic signal is its sung melody — a Vocals
arrangement with synced lyrics and pitch, but no chord chart and no full-mix
audio worth running chord detection on. It fetches
[lyrics_karaoke's canonical `/playback` payload](https://github.com/get-flashbacks/feedback-plugin-lyrics-karaoke/blob/main/docs/architecture/vocals-playback-contract.md)
for `filename` (`options.arrangementIndex` is forwarded as that endpoint's
`arrangement` query param), takes the primary voice's pitched tokens, and
*harmonizes* them: it estimates a key center from the melody's duration-weighted
pitch-class distribution (a Krumhansl-Schmuckler-style correlation against
major/minor key profiles), then buckets the melody into `options.windowSeconds`
windows (default 2) and picks whichever diatonic triad of that key best
covers each window's notes. The resulting chord sequence is fed straight into
`generateChordArrangement`, so the same `instrument`/voicing options apply,
and the returned arrangement carries an extra `key: {root, mode}` field
describing what was detected. This is melody harmonization, not chord
detection — it invents a plausible backing, it does not recover a chord
progression that was actually played. Returns `null` when there is nothing
to harmonize from: the lyrics_karaoke route is unavailable or 404s, the
track is lyrics-only (no `midi` on any token), or the response's
`schema_version` isn't the one this function understands.

`groupChordEvents` returns a `{ parentIndex, continuation }` entry for every

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Merge collision — the generateAccompanimentFromLyrics paragraph above runs straight into this groupChordEvents paragraph

Line 155 ends with ...isn't the one this function understands. and this line follows with no blank line between them, so rendered Markdown fuses two unrelated API descriptions into one paragraph — a merge-resolution collision from 724fa63 that 743ea63 did not fix. Insert a blank line between the two paragraphs.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e82a331.

chord event. A nonempty event whose played `{s,f}` notes are a subset of the
active preceding full chord retains that full chord's parent index, including
Expand Down
4 changes: 2 additions & 2 deletions chordr/plugin.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "chordr",
"name": "Chordr",
"version": "0.5.4",
"description": "Derives chord names and shapes from chart data for guitar and piano arrangements — a shared capability other plugins consume rather than duplicating chord logic themselves.",
"version": "0.6.0",
"description": "Derives chords and generates playable keys/guitar arrangements from chart data, audio analysis, or a sung melody — a shared capability other plugins consume rather than duplicating chord logic themselves.",
"category": "tools",
"type": "utility",
"icon": "🎼",
Expand Down
Loading
Loading