Music::Scales(3pm)
π Music::Scales(3pm) π
okay bestie, sit DOWN, because we're about to talk about Music::Scales β yes that's the whole manual name, Music::Scales(3pm), and yes it's giving exactly what you think it's giving. π
β¨ NAME β¨
Scales β supplies all the notes and semitone offsets you need for musical scales. it's the plug for your scale needs, fr fr. πΉ
πΈ SYNOPSIS πΈ
here's the vibe, look:
use Music::Scales;
my @maj = get_scale_notes('Eb'); # defaults to major
print join(" ",@maj); # "Eb F G Ab Bb C D"
my @blues = get_scale_nums('bl'); # 'bl','blu','blue','blues'
print join(" ",@blues); # "0 3 5 6 7 10"
my %min = get_scale_offsets ('G','mm',1); # descending melodic minor
print map {"$_=$min{$_} "} sort keys %min; # "A=0 B=-1 C=0 D=0 E=-1 F=0 G=0"
like. look at that. iconic behaviour. π
π¦ DESCRIPTION π¦
so the whole deal is: you hand it a keynote from A to G (with optional # or b on it, cute) and a scale-name, and it hands you back the scale. you can get it as an array of notenames, OR as a hash of semitone-offsets for each note. your choice, queen. β¨
π METHODS π
get_scale_nums($scale[,$descending])
returns an array of semitone offsets for the scale you asked for, going up or down that scale for one octave. the $descending flag does two things at once, ngl β it sets the direction of the scale, AND it changes the notes for scales where the notes genuinely differ depending on which way you're going (melodic minor, we're looking at you π). scaletypes and the valid values for $scale are listed down in SCALES, keep scrolling bestie.
get_scale_notes($notename[,$scale,$descending,$keypref])
returns an array of notenames, starting from the keynote you gave it. enharmonic equivalencies β like, do we write F# or Gb β get calculated from the keynote plus the scale. basically it tries to do the Right Thing when the scale is an 8-note one (the 7th in G harmonic minor is F# and not Gb, even though G minor is a 'flat' key π₯²), but for any other scales (Chromatic, blues, etc.) it picks equivalencies based on the keynote. you can override all of that with $keypref β set it to '#' for sharps or 'b' for flats. and yes: "Cruftiness abounds here :)" β those are the module author's words and honestly? respect. π
get_scale_offsets($notename[,$scale,$descending,$keypref])
same energy as get_scale_notes(), except it returns a hash of notenames where the values are a semitone offset (-1, 0 or 1), just like the synopsis shows. π«Ά
get_scale_MIDI($notename,$octave[,$scale,$descending])
as get_scale_notes(), but it returns an array of MIDI note-numbers, given an octave number (-1..9). numbers go brrr. π₯
get_scale_PDL($notename,$octave[,$scale,$descending])
as get_scale_MIDI(), but it returns an array of PDL-format notes. serving crossover. β
is_scale($scalename)
returns true if $scalename is a valid scale name used in this module. a little vibe check for your scale name. π
π SCALES π
you can pass scales by name OR by number. the default scale is 'major' if you give none or give something invalid (it's not mad, it's just gonna do major). Text::Abbrev is used on scalenames, so you can abbreviate them as much as is unambiguously possible ('dor', 'io', etc.) β the other abbreviations are in brackets, bestie:
1 ionian / major / hypolydian
2 dorian / hypmixolydian
3 phrygian / hypoaeolian
4 lydian / hypolocrian
5 mixolydian / hypoionian
6 aeolian / hypodorian / minor / m
7 locrian / hypophrygian
8 harmonic minor / hm
9 melodic minor / mm
10 blues
11 pentatonic (pmajor)
12 chromatic
13 diminished
14 wholetone
15 augmented
16 hungarian minor
17 3 semitone
18 4 semitone
19 neapolitan minor (nmin)
20 neapolitan major (nmaj)
21 todi
22 marva
23 persian
24 oriental
25 romanian
26 pelog
27 iwato
28 hirajoshi
29 egyptian
30 pentatonic minor (pminor)
thirty scales. thirty. we ate and left no crumbs. π
π§ EXAMPLE π§
this one prints every scale in every key and adjusts the enharmonic equivalents accordingly. chef's kiss:
foreach my $note qw (C C# D D# E F F# G G# A A# B) {
foreach my $mode (1..30) {
my @notes = get_scale_notes($note,$mode);
push @notes, get_scale_notes($note,$mode,1); # descending
print join(" ",@notes),"\n";
}
}
π TODO π
the wishlist, in the author's own words:
- Add further range of scales from http://www.cs.ruu.nl/pub/MIDI/DOC/scales.zip
- Improve enharmonic eqivalents.
- Microtones
- Generate ragas,gamelan etc. - maybe needs an 'ethnic' subset of modules
(yes, "eqivalents" is spelled like that in the original, we keep it exactly π)
π AUTHOR π
Ben Daglish (bdaglish@surfnet-ds.co.uk)
Thanks to Steve Hay for pointing out my 'minor' mix-up and many suggestions. Thanks also to Gene Boggs for the 'is_scale' suggestion / code.
shoutout to the whole squad honestly. π«Ά
π BUGS π
A few enharmonic problems still...
All feedback most welcome.
so like, if you find something, pls tell them, they literally asked. π
π COPYRIGHT π
Copyright (c) 2003, Ben Daglish. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
π SEE ALSO π
PDL::Audio::Scale, perl(1).
go read those too, bestie, iykyk. β¨
and that's the whole manual, no cap. this was perl v5.36.0, dated 2023-02-20, from the Music::Scales(3pm) page β thanks for reading, ily, now go make some music. ππΆ
π¦ where this page comes from
- debian trixie: libmusic-scales-perl 0.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmusic-scales-perl 0.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmusic-scales-perl 0.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmusic-scales-perl 0.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms