Melody Consensus
melody_consensusExtracts consensus melody notes from repeated phrase bars, removes sustained backing, resolves octave, rest, and legato choices, and optionally writes notes to a track.
Instructions
The lead line of a phrase that repeats, when its stem also carries a backing part (a pad, a chord, a second voice): analyze_melody warns of a second part within 6 dB, notes_from_audio_loop doubles the lead at the octave. reps = the bar where each repetition of the phrase starts ([17, 25, 49, 57]); phrase_bars = its length. Every candidate pitch in [low, high] scores its first five harmonics on a constant-Q spectrum (an octave below the lead scores less than the lead), the scores are averaged over the repetitions, and each step takes the best pitch. Before scoring, what sounds through nearly all of the phrase comes off: each bin loses its held_pct percentile over the phrase's steps, so a held pad or chord stops winning (a lead holding one pitch through more than 100 - held_pct percent of the phrase would go with it: pass held_pct=None). A new note starts where the pitch changes or where the start of a step is onset_db louder than the step before. Steps rest_db or more under the loudest are rests; one-step notes quieter than short_db drop (None keeps them); gaps of up to legato_steps close up (0 keeps them). Returns notes_write rows with beats from the phrase's first bar, then a summary: notes per bar, confidence (how many repetitions picked the same pitch on their own, and the margin over the runner-up) and the notes where the octave choice was close. track= writes the phrase into that track at every bar of write_at (default: reps) with notes_write(mode=mode). Repetitions that differ (variants, fills) pull the average apart: pass only the bars where the phrase really repeats.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| low | No | C3 | |
| high | No | C7 | |
| mode | No | replace | |
| reps | Yes | ||
| track | No | ||
| source | Yes | ||
| project | Yes | ||
| rest_db | No | ||
| held_pct | No | ||
| onset_db | No | ||
| short_db | No | ||
| write_at | No | ||
| phrase_bars | Yes | ||
| legato_steps | No | ||
| steps_per_beat | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |