forked from ology/Music
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modal-chords
48 lines (37 loc) · 1.27 KB
/
modal-chords
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env perl
use strict;
use warnings;
# Play the chords of the given scale mode.
use Data::Dumper::Compact 'ddc';
use lib map { "$ENV{HOME}/sandbox/$_/lib" } qw(MIDI-Util Music-ToRoman);
use MIDI::Util qw(setup_score midi_format);
use Music::Chord::Note;
use Music::Scales qw(get_scale_notes);
use Music::ToRoman;
my $note = shift || 'C';
my $mode = shift || 'ionian'; # ionian, dorian, phrygian, lydian, mixolydian, aeolian, locrian
my $octave = shift || 4;
# Get a chord map of major/minor/diminished designations
my $mtr = Music::ToRoman->new(
scale_note => $note,
scale_name => $mode,
);
my @chords = $mtr->get_scale_chords;
my @scale = get_scale_notes($note, $mode);
my @chord_scale = map { $scale[$_] . $chords[$_] } 0 .. $#chords;
#warn(__PACKAGE__,' ',__LINE__," MARK: ",ddc(\@chord_scale));exit;
my $score = setup_score();
my $mcn = Music::Chord::Note->new;
# Add each chord to the score
for my $c (@chord_scale) {
my @chord = $mcn->chord_with_octave($c, $octave);
@chord = midi_format(@chord);
print ddc(\@chord);
$score->n('wn', @chord);
}
# Add a resolving chord to the score
my @chord = $mcn->chord_with_octave($chord_scale[0], $octave);
@chord = midi_format(@chord);
print ddc(\@chord);
$score->n('wn', @chord);
$score->write_score("$0.mid");