Skip to content

Melody Evaluation System

This document explains the candidate selection and evaluation mechanism used in melody generation.

New to music theory?

This page assumes the melodic vocabulary — chord tones, passing tones, motifs, hooks. If those are unfamiliar, the course chapter Melody, Motifs & Hooks teaches them with playable examples first.

Overview

MIDI Sketch generates multiple melody candidates and selects one through an evaluation system.

The five stages of melody candidate selection A left-to-right band of five stages. The generator produces twenty to a hundred candidates for the section, evaluates each one with both a penalty-based culling score and a style score, combines them into a single number, sorts the candidates and drops the bottom half, then draws the winner from the surviving half with a probability proportional to its score. melody candidate pipeline Generate 20–100 per section, chorus gets the most Evaluate each culling score and style score together Combine scores 40% style + 40% culling + 20% interval bias Rank and cull sort, then drop the bottom half Pick the winner weighted random from the surviving half Many candidates go in and one melody comes out, but the winner is drawn from the top half rather than simply taken from the top.

Candidate Generation

Section-Specific Candidate Counts

Different sections use different candidate counts:

SectionCandidatesNotes
Chorus100Hook section
B (Pre-chorus)50Transition section
Bridge / Chant30Contrast section
A (Verse) / Intro / Outro20Stable sections; also Interlude, MixBreak and Drop

Generation Process

For each candidate:

  1. Rhythm Pattern - Generate note positions and durations
  2. Pitch Selection - Apply melody template (PlateauTalk, RunUpTarget, etc.)
  3. Constraint Application - Apply singability and range limits
  4. Embellishment - Add passing tones, neighbor tones

Articulation gate

Articulation gating applies only to interior notes shorter than a quarter note. Phrase starts and ends, and notes at least a quarter note long, keep their full duration; stepwise motion stays legato while skips and leaps receive only a small gap. The minimum duration is one sixteenth note, so the floor can lengthen an input shorter than a sixteenth.

Rhythm-locked sections

When a section reuses a locked rhythm pattern, a separate path takes over: it always generates 20 candidates regardless of section, totals the seven quality dimensions with equal weight instead of style weights, and blends 35 % style + 40 % penalty + 25 % global motif rather than the 40/40/20 mix described below. The rank cut and the weighted-random pick are the same.

Evaluation and Selection

Every candidate is scored once, on three axes computed together rather than in sequence:

  • Style score (40 %) — the seven weighted quality dimensions below.
  • Penalty score (40 %) — starts at 1.0 and subtracts singing-difficulty and musical-fault penalties.
  • Interval-bias score (20 %) — how well the candidate's mix of steps, skips, leaps and repeated pitches matches the vocal style's preferences.

A global-motif bonus is added on top when a motif is in play, weighted by section (Chorus 0.35 down to Bridge 0.05) so important sections preserve motif identity.

The candidates are then sorted and the bottom half is discarded — a fixed rank cut, not an absolute threshold. The winner is drawn from the surviving half by score-weighted random selection, so a strong candidate is likely but not guaranteed to win. This keeps repeated sections from converging on the same melody.

Penalty Score

The penalty score starts at 1.0, subtracts nine penalties, adds two bonuses, and is clamped to 0.0-1.0. Nothing is discarded at this point — the result is one of the three numbers a candidate carries into the ranking:

How a candidate's culling score is built Left to right arithmetic. Every candidate starts from a base score of 1.0. Nine penalties are subtracted — high register, leap after a high note, rapid direction change, isolated notes, breathless runs, non-chord tones, monotony, low phrase cohesion and an excessive gap ratio. Two bonuses are then added back, for a clear melodic peak and for motif repetition, and the result is clamped to the range 0.0 to 1.0. start Base score 1.0 penalties, subtracted High register Leap after high Direction change Isolated note Breathless Non-chord tone Monotony Low cohesion Gap ratio bonuses, added Clear peak Motif repeat Culling score clamped to 0.0–1.0 The breathless penalty is skipped for Vocaloid styles, and the cohesion and gap gates move with the vocal style. Nothing is discarded here — this score is one of the numbers a candidate carries into the ranking.

Penalties

PenaltyMaxDetection Target
High Register0.5Consecutive or sustained notes at D5 (74) or above
Leap After High0.4Leap of a 5th or more landing at D5 or above
Rapid Direction Change0.3More than three direction reversals at eighth-note spacing or faster
Isolated Note0.3Notes with a 5th or wider on both sides
Breathless0.25More than five consecutive short notes with no breathing gap
Strong-Beat Non-Chord Tone0.2Fewer than half the strong-beat notes are chord tones
Monotony0.2Fewer than half the notes are distinct pitches
Low Cohesion~0.18Cohesion below the style threshold — scattered notes with no stepwise runs, rhythmic consistency or repeated cells
Gap Ratio~0.375Silence relative to the phrase, above the style threshold

The Breathless penalty is skipped for the Vocaloid styles, and the cohesion and gap thresholds move with the vocal style.

Phrase Cohesion Criteria
  • Stepwise motion runs (connected notes)
  • Consistent rhythm patterns
  • 3-gram cell repetition (interval + duration motifs)

Bonuses

BonusRangeDetection Target
Clear Peak0.0-0.15A single highest note, landing between 25% and 85% of the way through the phrase
Motif Repeat0.0-0.2AAAB repetition pattern

Style Score

Every candidate is scored on 7 dimensions, each weighted by the vocal style:

The seven dimensions of the melody score Seven boxes in a row — singability, chord tone ratio, contour shape, surprise element, AAAB pattern, rhythm-interval correlation and catchiness — each producing a value between 0.0 and 1.0. All seven feed a single bus that multiplies each score by its weight from the vocal style profile and sums them into one total melody score. melody score — seven dimensions, each 0.0 to 1.0 Singability Chord tone ratio Contour shape Surprise element AAAB pattern Rhythm–interval correlation Catchiness each score multiplied by its weight from the vocal style Total melody score The seven weights sum to 1.0 and shift with the style preset — Idol leans on AAAB and catchiness, Rock on surprise. No single dimension can carry a melody: the weighted total is what ranks a candidate.

Singability Score

Measures interval distribution:

Interval TypeTarget Range
Step (1-2 semitones)40-50%
Same pitch20-30%
Small leap (3-4 semitones)15-25%
Large leap (5+ semitones)5-10%

Chord Tone Ratio

Measures chord tone frequency on strong beats:

  • Strong beat: Beats 1 and 3 in 4/4 time (every 2 beats, tick % 960 == 0)
  • Higher ratio indicates more harmonically grounded melodies

Contour Shape

Detects melodic shapes:

  • Arch: Rise then fall
  • Wave: Oscillating pattern
  • Descending: Gradual descent

Surprise Element

Measures large leaps (5+ semitones) per phrase. Target: 1-2 leaps.

AAAB Pattern

Detects repetition with variation - same phrase repeats 3 times then varies.

Rhythm-Interval Correlation

Measures how well note durations match interval sizes:

CombinationScoreReason
Long note + large leapHighSingers need time for large jumps
Short note + stepHighQuick passages work best stepwise
Short note + large leapLowDifficult to sing

Based on pop vocal theory: singers need preparation time for large pitch changes. This scoring rewards melodies that are naturally singable.

Catchiness

Measures hook memorability from four factors: repetition of 2- and 3-note interval patterns (30 %), consistency of note durations (25 %), the proportion of intervals no larger than a major 3rd (25 %), and recognisable hook contours (20 %). Two to four consecutive same-pitch notes earn a bonus; five or more are penalised as monotonous. This is the heaviest single weight for the Idol and K-Pop profiles.

Style-Specific Weights

Different vocal styles use different evaluation weights:

StyleSingabilitySurprisePlateau BiasHigh Register
Standard0.150.151.00.8
Idol0.180.051.250.85
Rock0.150.200.81.2
Ballad0.300.051.00.5
Anime0.100.151.31.3
Vocaloid0.100.200.91.2
CityPop0.150.150.90.9
KPop0.120.181.41.1

Singability and Surprise are scoring weights that sum to 1.0 across all seven dimensions. Plateau Bias and High Register are generation biases applied while candidates are built, so they are multipliers around 1.0 rather than weights.

Parameter Definitions
  • Singability: Weight for interval-based scoring
  • Surprise: Weight for large leap detection
  • Plateau Bias: Preference for same-pitch continuation
  • High Register: Preference for higher pitches

Style-Specific Cohesion Thresholds

Different styles require different levels of melodic cohesion:

StyleCohesion threshold
Ballad, CityPop0.50
Standard and others0.45
Vocaloid, UltraVocaloid, Rock, PowerfulShout0.35

Melodies below the cohesion threshold are penalised.

Style-Specific Gap Thresholds

StyleGap threshold
Ballad0.50
CityPop0.45
Standard and others0.40
Anime0.35
Idol, BrightKira, CuteAffected, Rock, PowerfulShout0.30
Vocaloid, UltraVocaloid0.25

Post-Generation Analysis

The Dissonance Analyzer checks harmonic issues after generation.

Issue Types

TypeDescriptionExample
Simultaneous ClashTwo notes with dissonant intervalBass E + Melody F = minor 2nd
Non-Chord ToneNote not in current chordD over C major chord
Sustained Over Chord ChangeNote became non-chord after changeC sustained over F chord
Non-Diatonic NoteNote not in the key's scaleF# in C major

Severity Levels

SeverityIntervalsNotes
HighMinor 2nd (1), Major 2nd (2) in close range, minor 9th (13), Major 7th (11) over any chord other than I or IVStrong dissonance
MediumTritone (6) in close range, Major 7th over I or IV (may be an intended maj7), strong-beat non-chord toneContext-dependent
LowWeak-beat non-chord tone (passing tone), compound minor 2nd or Major 7th, compound tritoneOften acceptable

Any issue landing on beat 1 of a section start is raised one level, because a clash at that position is the most exposed.

CLI Usage

bash
# Generate and analyze
./build/bin/midisketch_cli --seed 42 --analyze

# Analyze existing MIDI
./build/bin/midisketch_cli --input song.mid --analyze

See the CLI dissonance analysis reference for the current report fields and output example.

Pipeline Summary

The whole melody evaluation pipeline, from candidates to the finished report Five stages laid out in two rows. Generation makes twenty to a hundred candidates per section. The culling score starts each candidate at 1.0, subtracts nine style-aware penalties and adds two bonuses. Scoring rates seven dimensions and weights them by the vocal style. Selection blends the two scores with an interval bias, sorts, drops the bottom half and draws a winner at random from the rest. Post-analysis is an opt-in dissonance report that never rewrites the music. 1 · generation 20–100 candidates chorus 100 · pre-chorus 50 bridge and chant 30 · rest 20 rhythm · pitch · limits · ornaments 2 · culling score start at 1.0 − nine penalties, style-aware + clear peak, motif repeat = culling score 0.0–1.0 3 · scoring seven dimensions singability, chord tone, contour, surprise, AAAB, rhythm, catchiness weighted by the vocal style 4 · selection combined = 40% style + 40% culling + 20% interval bias plus a global-motif bonus, weighted by section sorted by score, the bottom half is culled weighted random pick from the top half 5 · post-analysis Dissonance Analyzer reads the finished song clashes, non-chord tones, sustains over a change, non-diatonic notes — each rated high, medium or low --analyze prints the report; nothing is rewritten Selection is where candidates actually disappear; the analyzer only reports on the melody that was already chosen.

Summary

  • Multiple candidates are generated per section (20-100)
  • Each candidate carries one combined score: 40 % style, 40 % penalty, 20 % interval bias
  • The bottom half is cut by rank, and the winner is a score-weighted random draw from the rest
  • Style-specific weights and thresholds adjust evaluation criteria
  • Post-generation dissonance analysis available