Skip to content

Instantly share code, notes, and snippets.

@jedgarpark
Created June 24, 2025 22:04
Show Gist options
  • Save jedgarpark/a85049961c783cba9aa723df32f1ee2e to your computer and use it in GitHub Desktop.
Save jedgarpark/a85049961c783cba9aa723df32f1ee2e to your computer and use it in GitHub Desktop.
# SPDX-FileCopyrightText: 2025 Musical Scales Library
# SPDX-License-Identifier: MIT
"""
Musical Scales Library for MIDI Step Sequencer
Contains scales from Western, Middle Eastern, Asian and global traditions
All scales are provided as MIDI note numbers across 3 octaves (C3-C6)
"""
# Musical scales - Western, Middle Eastern, Asian and global traditions
SCALES = {
# Western scales
"pentatonic_major": [
48, 50, 52, 55, 57, # C3, D3, E3, G3, A3
60, 62, 64, 67, 69, # C4, D4, E4, G4, A4
72, 74, 76, 79, 81 # C5, D5, E5, G5, A5
],
"pentatonic_minor": [
48, 51, 53, 55, 58, # C3, Eb3, F3, G3, Bb3
60, 63, 65, 67, 70, # C4, Eb4, F4, G4, Bb4
72, 75, 77, 79, 82 # C5, Eb5, F5, G5, Bb5
],
"major": [ # Ionian
48, 50, 52, 53, 55, 57, 59, # C3-B3
60, 62, 64, 65, 67, 69, 71, # C4-B4
72, 74, 76, 77, 79, 81, 83 # C5-B5
],
"dorian": [
48, 50, 51, 53, 55, 57, 58, # C3, D3, Eb3, F3, G3, A3, Bb3
60, 62, 63, 65, 67, 69, 70, # C4, D4, Eb4, F4, G4, A4, Bb4
72, 74, 75, 77, 79, 81, 82 # C5, D5, Eb5, F5, G5, A5, Bb5
],
"phrygian": [
48, 49, 51, 53, 55, 56, 58, # C3, Db3, Eb3, F3, G3, Ab3, Bb3
60, 61, 63, 65, 67, 68, 70, # C4, Db4, Eb4, F4, G4, Ab4, Bb4
72, 73, 75, 77, 79, 80, 82 # C5, Db5, Eb5, F5, G5, Ab5, Bb5
],
"lydian": [
48, 50, 52, 54, 55, 57, 59, # C3, D3, E3, F#3, G3, A3, B3
60, 62, 64, 66, 67, 69, 71, # C4, D4, E4, F#4, G4, A4, B4
72, 74, 76, 78, 79, 81, 83 # C5, D5, E5, F#5, G5, A5, B5
],
"mixolydian": [
48, 50, 52, 53, 55, 57, 58, # C3, D3, E3, F3, G3, A3, Bb3
60, 62, 64, 65, 67, 69, 70, # C4, D4, E4, F4, G4, A4, Bb4
72, 74, 76, 77, 79, 81, 82 # C5, D5, E5, F5, G5, A5, Bb5
],
"minor": [ # Aeolian/Natural Minor
48, 50, 51, 53, 55, 56, 58, # C3, D3, Eb3, F3, G3, Ab3, Bb3
60, 62, 63, 65, 67, 68, 70, # C4, D4, Eb4, F4, G4, Ab4, Bb4
72, 74, 75, 77, 79, 80, 82 # C5, D5, Eb5, F5, G5, Ab5, Bb5
],
"locrian": [
48, 49, 51, 53, 54, 56, 58, # C3, Db3, Eb3, F3, Gb3, Ab3, Bb3
60, 61, 63, 65, 66, 68, 70, # C4, Db4, Eb4, F4, Gb4, Ab4, Bb4
72, 73, 75, 77, 78, 80, 82 # C5, Db5, Eb5, F5, Gb5, Ab5, Bb5
],
"harmonic_minor": [
48, 50, 51, 53, 55, 56, 59, # C3, D3, Eb3, F3, G3, Ab3, B3
60, 62, 63, 65, 67, 68, 71, # C4, D4, Eb4, F4, G4, Ab4, B4
72, 74, 75, 77, 79, 80, 83 # C5, D5, Eb5, F5, G5, Ab5, B5
],
"melodic_minor": [
48, 50, 51, 53, 55, 57, 59, # C3, D3, Eb3, F3, G3, A3, B3
60, 62, 63, 65, 67, 69, 71, # C4, D4, Eb4, F4, G4, A4, B4
72, 74, 75, 77, 79, 81, 83 # C5, D5, Eb5, F5, G5, A5, B5
],
"blues": [
48, 51, 53, 54, 55, 58, # C3, Eb3, F3, Gb3, G3, Bb3
60, 63, 65, 66, 67, 70, # C4, Eb4, F4, Gb4, G4, Bb4
72, 75, 77, 78, 79, 82 # C5, Eb5, F5, Gb5, G5, Bb5
],
"chromatic": [
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, # C3-B3
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, # C4-B4
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83 # C5-B5
],
# Middle Eastern Maqams (approximated in 12-TET)
"maqam_rast": [ # Similar to major but with microtonal inflections
48, 50, 52, 53, 55, 57, 58, 59, # C3, D3, E3, F3, G3, A3, Bb3, B3
60, 62, 64, 65, 67, 69, 70, 71, # C4, D4, E4, F4, G4, A4, Bb4, B4
72, 74, 76, 77, 79, 81, 82, 83 # C5, D5, E5, F5, G5, A5, Bb5, B5
],
"maqam_hijaz": [ # Phrygian dominant - quintessential Middle Eastern sound
48, 49, 52, 53, 55, 56, 58, # C3, Db3, E3, F3, G3, Ab3, Bb3
60, 61, 64, 65, 67, 68, 70, # C4, Db4, E4, F4, G4, Ab4, Bb4
72, 73, 76, 77, 79, 80, 82 # C5, Db5, E5, F5, G5, Ab5, Bb5
],
"maqam_bayati": [ # Like dorian with neutral 2nd and 6th
48, 49, 51, 53, 55, 56, 58, # C3, Db3, Eb3, F3, G3, Ab3, Bb3
60, 61, 63, 65, 67, 68, 70, # C4, Db4, Eb4, F4, G4, Ab4, Bb4
72, 73, 75, 77, 79, 80, 82 # C5, Db5, Eb5, F5, G5, Ab5, Bb5
],
"maqam_saba": [ # Very distinctive with flat 2nd, 3rd, and 6th
48, 49, 50, 53, 55, 56, 58, # C3, Db3, D3, F3, G3, Ab3, Bb3
60, 61, 62, 65, 67, 68, 70, # C4, Db4, D4, F4, G4, Ab4, Bb4
72, 73, 74, 77, 79, 80, 82 # C5, Db5, D5, F5, G5, Ab5, Bb5
],
"maqam_kurd": [ # Kurdish maqam, like phrygian
48, 49, 51, 53, 55, 56, 58, # C3, Db3, Eb3, F3, G3, Ab3, Bb3
60, 61, 63, 65, 67, 68, 70, # C4, Db4, Eb4, F4, G4, Ab4, Bb4
72, 73, 75, 77, 79, 80, 82 # C5, Db5, Eb5, F5, G5, Ab5, Bb5
],
# Indonesian Gamelan (approximated in 12-TET)
"slendro": [ # Javanese 5-note scale, roughly equal intervals
48, 50, 53, 55, 58, # C3, D3, F3, G3, Bb3
60, 62, 65, 67, 70, # C4, D4, F4, G4, Bb4
72, 74, 77, 79, 82 # C5, D5, F5, G5, Bb5
],
"pelog_lima": [ # Pelog 5-note subset (Balinese selisir mode)
48, 49, 52, 55, 58, # C3, Db3, E3, G3, Bb3
60, 61, 64, 67, 70, # C4, Db4, E4, G4, Bb4
72, 73, 76, 79, 82 # C5, Db5, E5, G5, Bb5
],
"pelog_tujuh": [ # Full 7-note pelog scale
48, 49, 51, 54, 55, 58, 59, # C3, Db3, Eb3, F#3, G3, Bb3, B3
60, 61, 63, 66, 67, 70, 71, # C4, Db4, Eb4, F#4, G4, Bb4, B4
72, 73, 75, 78, 79, 82, 83 # C5, Db5, Eb5, F#5, G5, Bb5, B5
],
# Japanese Scales
"hirajoshi": [ # Traditional Japanese scale
48, 50, 51, 55, 56, # C3, D3, Eb3, G3, Ab3
60, 62, 63, 67, 68, # C4, D4, Eb4, G4, Ab4
72, 74, 75, 79, 80 # C5, D5, Eb5, G5, Ab5
],
"in_scale": [ # Japanese In scale (sad/contemplative)
48, 49, 53, 55, 56, # C3, Db3, F3, G3, Ab3
60, 61, 65, 67, 68, # C4, Db4, F4, G4, Ab4
72, 73, 77, 79, 80 # C5, Db5, F5, G5, Ab5
],
"yo_scale": [ # Japanese Yo scale (bright/happy)
48, 50, 53, 55, 57, # C3, D3, F3, G3, A3
60, 62, 65, 67, 69, # C4, D4, F4, G4, A4
72, 74, 77, 79, 81 # C5, D5, F5, G5, A5
],
# Indian Ragas (simplified 12-TET approximations)
"raga_bhairav": [ # Morning raga, very devotional
48, 49, 52, 53, 55, 56, 59, # C3, Db3, E3, F3, G3, Ab3, B3
60, 61, 64, 65, 67, 68, 71, # C4, Db4, E4, F4, G4, Ab4, B4
72, 73, 76, 77, 79, 80, 83 # C5, Db5, E5, F5, G5, Ab5, B5
],
"raga_yaman": [ # Evening raga, romantic
48, 50, 52, 54, 55, 57, 59, # C3, D3, E3, F#3, G3, A3, B3
60, 62, 64, 66, 67, 69, 71, # C4, D4, E4, F#4, G4, A4, B4
72, 74, 76, 78, 79, 81, 83 # C5, D5, E5, F#5, G5, A5, B5
],
"raga_kafi": [ # Folk-influenced raga
48, 50, 51, 53, 55, 57, 58, # C3, D3, Eb3, F3, G3, A3, Bb3
60, 62, 63, 65, 67, 69, 70, # C4, D4, Eb4, F4, G4, A4, Bb4
72, 74, 75, 77, 79, 81, 82 # C5, D5, Eb5, F5, G5, A5, Bb5
],
# Chinese Scales
"chinese_pentatonic": [ # Traditional Chinese 5-note scale
48, 50, 52, 55, 57, # C3, D3, E3, G3, A3
60, 62, 64, 67, 69, # C4, D4, E4, G4, A4
72, 74, 76, 79, 81 # C5, D5, E5, G5, A5
],
# African-influenced scales
"african_pentatonic": [ # Common African pentatonic pattern
48, 51, 53, 55, 58, # C3, Eb3, F3, G3, Bb3
60, 63, 65, 67, 70, # C4, Eb4, F4, G4, Bb4
72, 75, 77, 79, 82 # C5, Eb5, F5, G5, Bb5
],
# Eastern European
"ee_scale": [ # Hungarian/Romani scale
48, 50, 51, 54, 55, 56, 59, # C3, D3, Eb3, F#3, G3, Ab3, B3
60, 62, 63, 66, 67, 68, 71, # C4, D4, Eb4, F#4, G4, Ab4, B4
72, 74, 75, 78, 79, 80, 83 # C5, D5, Eb5, F#5, G5, A5, B5
],
# Celtic
"irish_scale": [ # Traditional Irish mode
48, 50, 52, 53, 55, 57, 58, # C3, D3, E3, F3, G3, A3, Bb3
60, 62, 64, 65, 67, 69, 70, # C4, D4, E4, F4, G4, A4, Bb4
72, 74, 76, 77, 79, 81, 82 # C5, D5, E5, F5, G5, A5, Bb5
]
}
def get_scale(scale_name):
"""
Get a scale by name
Args:
scale_name (str): Name of the scale to retrieve
Returns:
list: List of MIDI note numbers, or None if scale not found
"""
return SCALES.get(scale_name)
def list_scales():
"""
Get a list of all available scale names
Returns:
list: List of scale names
"""
return sorted(SCALES.keys())
def get_scale_info():
"""
Get information about all scales organized by category
Returns:
dict: Dictionary with scale categories and descriptions
"""
return {
"Western": [
"pentatonic_major", "pentatonic_minor", "major", "dorian", "phrygian",
"lydian", "mixolydian", "minor", "locrian", "harmonic_minor",
"melodic_minor", "blues", "chromatic"
],
"Middle Eastern": [
"maqam_rast", "maqam_hijaz", "maqam_bayati", "maqam_saba", "maqam_kurd"
],
"Indonesian": [
"slendro", "pelog_lima", "pelog_tujuh"
],
"Japanese": [
"hirajoshi", "in_scale", "yo_scale"
],
"Indian": [
"raga_bhairav", "raga_yaman", "raga_kafi"
],
"Chinese": [
"chinese_pentatonic"
],
"African": [
"african_pentatonic"
],
"Eastern European": [
"ee_scale"
],
"Celtic": [
"irish_scale"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment