Skip to content

Melody Evaluation System

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

Overview

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

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

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

Two-Stage Evaluation

Evaluation occurs in two stages: Culling (filter candidates) and Scoring (rank candidates).

Stage 1: Culling

Candidates are filtered using penalty-based evaluation:

Penalties

PenaltyRangeDetection Target
High Register0.0-1.0Consecutive high notes (above D5)
Leap After High0.0-1.0Large jump followed by high note
Rapid Direction Change0.0-1.0Zigzag patterns
Monotony0.0-1.0Repeated notes without variation
Breathless0.0-0.3Consecutive short notes without breaks
Gap Ratio0.0-1.0Scattered notes with silence between

Gap Ratio

The Gap Ratio penalty targets scattered, disconnected note patterns. Higher gap ratio indicates more silence between notes.

Bonuses

BonusRangeDetection Target
Clear Peak0.0-0.2Single high point in the phrase
Motif Repeat0.0-0.2AAAB repetition pattern
Phrase Cohesion0.0-1.0Notes forming coherent groups
Phrase Cohesion Criteria
  • Stepwise motion runs (connected notes)
  • Consistent rhythm patterns
  • 3-gram cell repetition (interval + duration motifs)

Stage 2: Scoring

Candidates that pass culling are scored on 6 dimensions:

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.

Style-Specific Weights

Different vocal styles use different evaluation weights:

StyleSingabilitySurprisePlateau BiasHigh Register
Standard0.250.151.01.0
Idol0.300.121.21.0
Rock0.200.200.81.2
Ballad0.400.101.10.9
Anime0.250.250.91.3
Vocaloid0.100.250.61.1
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 ThresholdNotes
BalladHigherNeeds smooth, connected lines
CityPopHigherLegato phrases preferred
VocaloidLowerTolerates angular melodies
RockLowerAccepts disconnected patterns

Melodies below the cohesion threshold receive penalties during culling.

Style-Specific Gap Thresholds

StyleGap ThresholdNotes
BalladHigherMore silence tolerated
Idol/RockLowerHigher note density expected

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 7th (11)Strong dissonance
MediumTritone (6), Strong beat non-chordContext-dependent
LowWeak beat non-chord (passing tone)Often acceptable

CLI Usage

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

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

Output example:

=== Dissonance Analysis ===
Total issues: 3
  Simultaneous clashes: 1 (high: 1, medium: 0)
  Non-chord tones: 2 (medium: 1, low: 1)

Pipeline Summary

Summary

  • Multiple candidates are generated per section (20-100)
  • Two-stage evaluation: culling then scoring
  • Style-specific weights adjust evaluation criteria
  • Post-generation dissonance analysis available

Released under the MIT License.