NAME

Scales - supply necessary notes / offsets for musical scales

SYNOPSIS

use Music::Scales;

my @maj = get_scale_notes('Eb');           # defaults to major
print join(" ",@maj);                      # "Eb F G Ab Bb C D Eb"
my @blues = get_scale_nums('bl');		   # 'bl','blu','blue','blues'
print join(" ",@blues);                    # "Eb F G Ab Bb C D Eb"
my %min = get_scale_offsets ('G','m',1);   # ascending harmonic minor
print map {"$_=$min{$_}" } sort keys %min; # "A=0 B=-1 C=0 D=0 F=1 G=0"

DESCRIPTION

Given a keynote A-G and a scale-name, will return the scale, either as an array of notenames or as a hash of semitone-offsets for each note.

METHODS

get_scale_notes($notename[,$scale,$ascending,$keypref])

returns an array of notenames, starting from the given keynote and ascending up the given scale for one octave.

Scaletypes and valid values for $scale are listed below.

If $ascending is set and the mode is "minor" ('min' or 'm'), the leading note will be sharpened, providing an ascending melodic minor.

Enharmonic equivalencies are calculated using a set of defaults for each key, but can be overidden with $keypref, setting this to be either '#' or 'b' for sharps and flats respectively. These defaults are:

C='' Db='b' D='#' Eb='b' E='#' F='b' Gb='b' G='#' Ab='b' A='#' Bb='b' B='#'

'Minor' mode (where the keynote is shifted up a minor 3rd, resulting in G minor using 'Bb' rather than 'A#') are used for modes 2 and 6. All other modes use the default mapping.

get_scale_offsets($notename[,$scale,$ascending,$keypref])

as get_scale(), except it returns a hash of notenames with the values being a semitone offset (-1, 0 or 1) as shown in the synopsis.

get_scale_nums($scale[,$ascending])

returns an array of semitone offsets for the requested scale.

SCALES

Scales can be passed either by name or number. The default scale is 'major' if none / invalid is given. Text::Abbrev is used on scalenames, so they can be as abbreviated as unambiguously possible ('dor','io' etc.). Other abbreviations are shown in brackets.

 1 ionian
 1 major 
 2 dorian
 3 phrygian 
 4 lydian 
 5 mixolydian 
 6 aeolian 
 6 minor (m)
 7 locrian 
 8 blues 
 9 pentatonic (pmajor)
10 chromatic 
11 diminished 
12 wholetone 
13 augmented 
14 hungarian minor 
15 3 semitone 
16 4 semitone 
17 neapolitan minor (nmin)
18 neapolitan major (nmaj)
19 todi 
20 marva 
21 persian 
22 oriental 
23 romanian 
24 pelog 
25 iwato 
26 hirajoshi 
27 egyptian 
28 pentatonic minor (pminor)

EXAMPLE

This will print every scale in every key, adjusting the enharmonic equivalents accordingly.

	foreach my $note qw (C C# D D# E F F# G G# A A# B) {
        foreach my $mode (1..28) {
            my @notes = get_scale_notes($note,$mode);
            print join(" ",@notes),"\n";
        }
    }

TODO

Add further range of scales from http://www.cs.ruu.nl/pub/MIDI/DOC/scales.zip
Improve enharmonic eqivalents.
Microtones
Frequency generation (although this is already done by PDL::Audio::Scale)
Generate ragas,gamelan etc.  - maybe needs an 'ethnic' subset of modules

AUTHOR

Ben Daglish (bdaglish@surfnet-ds.co.uk)

BUGS

Minor 'flat' scales not using sharps properly for leading notes etc. - to be fixed in a later version, hopefully.

All feedback most welcome.

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).