Repository navigation
Generate keys-first chord arrangements #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5b84ec9
b2c0e53
724fa63
743ea63
a3764f8
22c7de5
eba53cd
3ae2101
e82a331
9d032a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, { | ||
|
|
@@ -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 | ||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: Merge collision — the Line 155 ends with Reply with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.