Modus- und Akkord-Checker
Output-Ausschnitte
...
Hiphip-hooray! "B"-Aeolisch ist möglich!
Modal-Ton-String: A,B,D,D-,E,G,G-,
Ton-String: D-EG
Hiphip-hooray! "E"-Vermindert ist möglich!
Modal-Ton-String: A,B-,C,D-,E,E-,G,G-,
Ton-String: D-EG
Es gibt 17 Modus-Möglichkeiten für "Db"-Mollb5!
Davon sind ...
Aeolisch:
"B"-Aeolisch
Ionisch:
"D"-Ionisch
Dorisch:
"E"-Dorisch
Mixolydisch:
"A"-Mixolydisch
Vermindert:
"D"-Vermindert
"Ab"-Vermindert
"Bb"-Vermindert
"G"-Vermindert
"F"-Vermindert
"B"-Vermindert
"Db"-Vermindert
"E"-Vermindert
Alteriert:
"Db"-Alteriert
"Eb"-Alteriert
Bitte einen Modus aus der folgenden Liste auswählen ( Nummer + Return! )
Nummer: 1 Modus: "D"-Vermindert
Nummer: 2 Modus: "D-"-Alteriert
Nummer: 3 Modus: "A-"-Vermindert
Nummer: 4 Modus: "B-"-Vermindert
Nummer: 5 Modus: "G"-Vermindert
Nummer: 6 Modus: "D"-Ionisch
Nummer: 7 Modus: "F"-Vermindert
Nummer: 8 Modus: "G-"-Phrygisch
Nummer: 9 Modus: "G"-Lydisch
Nummer: 10 Modus: "B"-Vermindert
Nummer: 11 Modus: "D-"-Lokrisch
Nummer: 12 Modus: "E-"-Alteriert
Nummer: 13 Modus: "E"-Dorisch
Nummer: 14 Modus: "D-"-Vermindert
Nummer: 15 Modus: "A"-Mixolydisch
Nummer: 16 Modus: "B"-Aeolisch
Nummer: 17 Modus: "E"-Vermindert
11
...
Hiphip-hooray! "Gb"-Mollsus4 ist möglich!
Mein zu vergleichender Regex-Akkordton-String: .*A,.*B,.*D-,.*G-,.*
Vergleich mit Modal-Ton-String: A,B,D,D-,E,G,G-,
Modal-Ton-String: A,B,D-,G-
Ton-String: D-EG
++++ *** ~~~ Ausgangsakkord ist/war: "Db"-Mollb5 ~~~ *** ++++
Es gibt 59 Akkord-Möglichkeiten für:
Modus "Db"-Lokrisch!
Es sind die folgenden Akkorde:
"A"-7sus2
"A"-7sus4
"A"-Dur
"A"-Dur6
"A"-Dur65
"A"-Dur6sus2
"A"-Dur7
"A"-Dur7add9
"A"-Dursus2
"B"-7sus2
"B"-7sus4
"B"-Dur7add9
"B"-Moll
"B"-Moll#5
"B"-Moll#5sus2
"B"-Moll6
"B"-Moll6sus2
"B"-Moll7
"B"-Mollsus2
"B"-Mollsus4
"D"-Dur
"D"-Dur6
"D"-Dur65
"D"-Dur6sus2
"D"-DurMaj7
"D"-Dursus2
"D"-Maj7sus2
"D"-Maj7sus4
"Db"-Moll#5
"Db"-Moll7b5
"Db"-Mollb5
"E"-7sus2
"E"-7sus4
"E"-Dur7add9
"E"-Moll
"E"-Moll6
"E"-Moll65
"E"-Moll6sus2
"E"-Moll7
"E"-Mollsus2
"E"-Mollsus4
"G"-Dur
"G"-Dur6
"G"-Dur65
"G"-Dur6b5
"G"-Dur6sus2
"G"-DurMaj7
"G"-DurMaj7b5
"G"-Durb5
"G"-Durb5sus2
"G"-Dursus2
"G"-Maj7sus2
"G"-dim2
"Gb"-7sus4
"Gb"-Moll
"Gb"-Moll#5
"Gb"-Moll6
"Gb"-Moll7
"Gb"-Mollsus4
Very, very verbose!
Code
#!/usr/bin/perl
# modefinder-1.0.pl
use strict;
use warnings;
# Variablen
my %chordtypes = (
"Maj7sus2" => ["Maj7sus2", "0", "2", "7", "11"],
"Maj7sus4" => ["Maj7sus4", "0", "5", "7", "11"],
"7sus2" => ["7sus2", "0", "2", "7", "10"],
"7sus4" => ["7sus4", "0", "5", "7", "10"],
"Dur" => ["Dur", "0", "4", "7", "12"],
"Dursus2" => ["Dursus2", "0", "2", "4", "7"],
"Durb5" => ["Durb5", "0", "4", "6", "12"],
"Durb5sus2" => ["Durb5sus2", "0", "2", "4", "6"],
"Dur#5" => ["Dur#5", "0", "4", "8", "12"],
"Dur#5sus2" => ["Dur#5sus2", "0", "2", "4", "8"],
"DurMaj7" => ["DurMaj7", "0", "4", "7", "11"],
"DurMaj7b5" => ["DurMaj7b5", "0", "4", "6", "11"],
"DurMaj7#5" => ["DurMaj7#5", "0", "4", "8", "11"],
"Dur7" => ["Dur7", "0", "4", "7", "10"],
"Dur7b5" => ["Dur7b5", "0", "4", "6", "10"],
"Dur7add9" => ["Dur7add9", "0", "5", "10", "14"],
"Dur6" => ["Dur6", "0", "4", "9", "12"],
"Dur65" => ["Dur65", "0", "4", "7", "9"],
"Dur6sus2" => ["Dur6sus2", "0", "2", "4", "9"],
"Dur6b5" => ["Dur6b5", "0", "4", "6", "9"],
"Moll" => ["Moll", "0", "3", "7", "12"],
"Mollsus2" => ["Mollsus2", "0", "2", "3", "7"],
"Mollsus4" => ["Mollsus4", "0", "3", "5", "7"],
"Mollb5" => ["Mollb5", "0", "3", "6", "12"],
"Mollb5sus2" => ["Mollb5sus2", "0", "2", "3", "6"],
"Moll#5" => ["Moll#5", "0", "3", "8", "12"],
"Moll#5sus2" => ["Moll#5sus2", "0", "2", "3", "8"],
"MollMaj7" => ["MollMaj7", "0", "3", "7", "11"],
"MollMaj7b5" => ["MollMaj7b5", "0", "3", "6", "11"],
"MollMaj7#5" => ["MollMaj7#5", "0", "3", "8", "11"],
"Moll7" => ["Moll7", "0", "3", "7", "10"],
"Moll7b5" => ["Moll7b5", "0", "3", "6", "10"],
"Moll6" => ["Moll6", "0", "3", "7", "12"],
"Moll6sus2" => ["Moll6sus2", "0", "2", "3", "7"],
"Moll65" => ["Moll65", "0", "3", "7", "9"],
"dim1" => ["dim1", "0", "1", "2", "3"],
"dim2" => ["dim2", "0", "2", "4", "6"],
"Dim7" => ["Dim7", "0", "3", "6", "9"] );
my %chroma = (
"C-" => 0,
"C" => 1,
"D-" => 2,
"D" => 3,
"E-" => 4,
"E" => 5,
"F-" => 5,
"F" => 6,
"G-" => 7,
"G" => 8,
"A-" => 9,
"A" => 10,
"B-" => 11,
"B" => 12 );
my %chroma_inv = (
"0" => "C-",
"1" => "C",
"2" => "D-",
"3" => "D",
"4" => "E-",
"5" => "E",
"6" => "F",
"7" => "G-",
"8" => "G",
"9" => "A-",
"10" => "A",
"11" => "B-",
"12" => "B" );
my %modes = (
Ionisch => ['0', '2', '4', '5', '7', '9', '11'],
Dorisch => ['0', '2', '3', '5', '7', '9', '10'],
Phrygisch => ['0', '1', '3', '5', '7', '8', '10'],
Lydisch => ['0', '2', '4', '6', '7', '9', '11'],
Mixolydisch => ['0', '2', '4', '5', '7', '9', '10'],
Aeolisch => ['0', '2', '3', '5', '7', '8', '10'],
Lokrisch => ['0', '1', '3', '5', '6', '8', '10'],
Vermindert => ['0', '2', '3', '5', '6', '8', '9','11'],
Alteriert => ['0', '1', '3', '4', '6', '8', '10'] );
### Kontrollausdruck der Modes auf Grundton A
foreach ( sort { $a cmp $b } keys %modes ) {
my $mode_temp = $_;
print "\nMein aktueller Modus: $mode_temp\n\n";
my $control_ref = $modes{$_};
my @control = @$control_ref;
my $notevalue_ctrl = '10';
foreach ( @control ) {
my $notevalue_temp = $notevalue_ctrl + $_;
if ( $notevalue_temp > 12 ) { $notevalue_temp = $notevalue_temp - 12 }
my $note_temp = $chroma_inv{$notevalue_temp};
print "Mein aktueller Ton: $note_temp\n";
}
}
# Programm
## Zufallsauswahl eines Akkords
my $grundton_value = int rand (12) + 1;
### Grundon-Default = 1
### $grundton_value = 1;
### Grundon-Default = 1
my $grundton = $chroma_inv{$grundton_value};
print "\nDer ausgewählte Grundton-Wert ist: $grundton_value\n";
print "Der ausgewählte Grundton ist: $grundton\n\n";
my @chordtypes = map { $_ } keys %chordtypes;
my $akkord = int rand (scalar @chordtypes);
$akkord = $chordtypes[$akkord];
print "Der ausgewählte Akkord ist: $akkord\n\n";
## Ermittlung der Intervalle + Töne, die im Akkord vorkommen
my %chordnotes;
my $intervalle_ref = $chordtypes{$akkord};
my @intervalle = @$intervalle_ref;
foreach ( @intervalle ) {
if ( $_ eq $intervalle[0] ) { next }
my $notevalue_temp = $grundton_value + $_;
# Doppelt wegen "add9"
if ( $notevalue_temp > 12 ) { $notevalue_temp = $notevalue_temp - 12 }
if ( $notevalue_temp > 12 ) { $notevalue_temp = $notevalue_temp - 12 }
my $note_temp = $chroma_inv{$notevalue_temp};
if ( not exists $chordnotes{$note_temp} ) { $chordnotes{$note_temp} = 1 }
}
print "Array der Intervalle:\n\n";
print join (" :: ", map { $_ } @intervalle);
print "\n\n";
print "Array der Töne:\n\n";
print join (" :: ", map { $_ } keys %chordnotes);
print "\n\n";
## Ermitteln des Tonstrings aus dem Akkord
my $notestring = "";
map { $notestring = $notestring.$_ } sort { $a cmp $b } keys %chordnotes;
print "Der ermittelte Tonstring ist: $notestring\n\n";
## Ermitteln der Tonstrings aus den Modes
my %modenotesstrings;
foreach ( sort { $a <=> $b } keys %chroma_inv ) {
my $grundtonvalue_temp = $_;
print "\n\nMein temporärer Grundton-Wert: $grundtonvalue_temp\n";
my $grundton_temp = $chroma_inv{$grundtonvalue_temp};
print "Mein temporärer Grundton: $grundton_temp\n\n";
foreach ( sort { $a cmp $b } keys %modes ) {
my %modenotes_temp;
my $mode_temp = $_;
print "\nMein aktueller Modus: \"$grundton_temp\"-$mode_temp\n\n";
my $modenotesstring = "";
my $intervalle_temp_ref = $modes{$_};
my @intervalle = @$intervalle_temp_ref;
foreach ( @intervalle ) {
my $notevalue_temp = $grundtonvalue_temp + $_;
# Doppelt wegen "add9"
if ( $notevalue_temp > 12 ) { $notevalue_temp = $notevalue_temp - 12 }
if ( $notevalue_temp > 12 ) { $notevalue_temp = $notevalue_temp - 12 }
my $note_temp = $chroma_inv{$notevalue_temp};
print "Mein aktueller Ton: $note_temp\n";
if ( not exists $modenotes_temp{$note_temp} ) { $modenotes_temp{$note_temp} = 1 }
}
map { $modenotesstring = $modenotesstring.$_ } sort { $a cmp $b } keys %modenotes_temp;
print "\nMein erzeugter Tonstring zu \"$grundton_temp\"-$mode_temp:\n$modenotesstring\n\n";
if ( not exists $modenotesstrings{$grundton_temp.'-'.$mode_temp} ) {
$modenotesstrings{'"'.$grundton_temp.'"-'.$mode_temp} = $modenotesstring }
}
}
## Korrektur des Bug-1111 ( "C-" = "B" & vice versa )
foreach ( keys %modenotesstrings ) {
my $string_temp = $_;
if ( $string_temp =~ m/^"C-"/ ) { delete $modenotesstrings{$string_temp} }
}
### Kontrolldruck der Modalton-Strings
print "\nMeine ", scalar keys %modenotesstrings, " Modalton-Strings:\n\n";
print join ("\n", map { $_." = ".$modenotesstrings{$_} } sort { $a cmp $b } keys %modenotesstrings);
print "\n\n";
## Vergleich des Akkordstrings mit den Modalton-Strings
my @matchmode;
my $string2compare_regex = $notestring;
$string2compare_regex =~ s/([ABCDEFGA][-]*)/$1,.*/g;
$string2compare_regex =~ s/(.*)/.*$1/;
print "\nMein zu vergleichender Regex-Ton-String: $string2compare_regex\n\n";
foreach ( keys %modenotesstrings ) {
my $string_temp = $modenotesstrings{$_};
$string_temp =~ s/([ABCDEFGA][-]*)/$1,/g;
my $mode_temp = $_;
if ( $string_temp =~ m/$string2compare_regex/ ) {
print "Hiphip-hooray! ";
print "$mode_temp ist möglich!\n";
print "Modal-Ton-String: $string_temp\n";
print "Ton-String: $notestring\n\n";
push @matchmode, $mode_temp;
}
}
## Ausgabe der Möglichkeiten
my $grundton_readable = $grundton;
$grundton_readable =~ s/-/b/;
print "\nEs gibt ", scalar @matchmode, " Modus-Möglichkeiten für \"$grundton_readable\"-$akkord!\n\n";
print "Davon sind ...\n\nAeolisch:\n";
foreach ( @matchmode ) {
my $mode_temp = $_;
$mode_temp =~ s/-"-/b"-/;
if ( $mode_temp =~ m/Aeolisch/ ) {
print $mode_temp, "\n"
}
}
print "\nIonisch:\n";
foreach ( @matchmode ) {
my $mode_temp = $_;
$mode_temp =~ s/-"-/b"-/;
if ( $mode_temp =~ m/Ionisch/ ) {
print $mode_temp, "\n"
}
}
print "\nDorisch:\n";
foreach ( @matchmode ) {
my $mode_temp = $_;
$mode_temp =~ s/-"-/b"-/;
if ( $mode_temp =~ m/Dorisch/ ) {
print $mode_temp, "\n"
}
}
print "\nMixolydisch:\n";
foreach ( @matchmode ) {
my $mode_temp = $_;
$mode_temp =~ s/-"-/b"-/;
if ( $mode_temp =~ m/Mixolydisch/ ) {
print $mode_temp, "\n"
}
}
print "\nVermindert:\n";
foreach ( @matchmode ) {
my $mode_temp = $_;
$mode_temp =~ s/-"-/b"-/;
if ( $mode_temp =~ m/Vermindert/ ) {
print $mode_temp, "\n"
}
}
print "\nAlteriert:\n";
foreach ( @matchmode ) {
my $mode_temp = $_;
$mode_temp =~ s/-"-/b"-/;
if ( $mode_temp =~ m/Alteriert/ ) {
print $mode_temp, "\n"
}
}
print "\n";
## Einen Modus auswählen
print "Bitte einen Modus aus der folgenden Liste auswählen ( Nummer + Return! )\n\n";
my $mode_no = 1;
foreach ( @matchmode ) {
print "Nummer: $mode_no Modus: $_\n";
$mode_no++
}
print "\n";
my $mode_no_choice = <STDIN>;
chomp $mode_no_choice;
$mode_no_choice--;
my $mode = $matchmode[$mode_no_choice];
my $mode_readable = $mode;
$mode_readable =~ s/-"-/b"-/;
print "\nAusgewählter Modus ist: $mode_readable\n\n";
## Akkorde ermitteln, die zu dem ausgewählten Modus passen
my @matchchords;
my %chords_n_strings;
my $modenotesstring = $modenotesstrings{$mode};
print "Er enthält die Töne: $modenotesstring\n\n";
for ( my $noteno = 1; $noteno < 13; $noteno++ ) {
my $grundton_value = $noteno;
my $grundton = $chroma_inv{$grundton_value};
foreach ( @chordtypes ) {
my $chordtype = $_;
my $chordintervall_ref = $chordtypes{$chordtype};
my @chordintervall = @$chordintervall_ref;
my %notes_temp;
my $notestring = "";
foreach ( @chordintervall ) {
if ( $_ eq $chordintervall[0] ) { print "Akkordtyp: $_\n"; next }
print "Intervall-Wert: $_\n";
my $note_value = $grundton_value + $_;
print "Noten-Wert: $note_value\n";
# Doppelt wegen "add9"
if ( $note_value > 12 ) { $note_value = $note_value - 12 }
if ( $note_value > 12 ) { $note_value = $note_value - 12 }
print "Noten-Wert nach Korrektur: $note_value\n";
my $note = $chroma_inv{$note_value};
if ( not exists $notes_temp{$note} ) { $notes_temp{$note} = 1 }
}
map { $notestring = $notestring.','.$_ } sort { $a cmp $b } keys %notes_temp;
$notestring =~ s/^,//;
if ( not exists $chords_n_strings{'"'.$grundton.'"-'.$chordtype} ) {
$chords_n_strings{'"'.$grundton.'"-'.$chordtype} = $notestring
}
}
}
print "\nAlle Akkorde:\n\n";
print map { "Akkord: $_ Tonstring: $chords_n_strings{$_}\n" } keys %chords_n_strings;
print "\n";
### Vergleich der Akkordstrings mit dem Mode-Ton-String
my $modenotesstring_temp = $modenotesstring;
$modenotesstring_temp =~ s/([ABCDEFGA][-]*)/$1,/g;
foreach ( sort { $a cmp $b } keys %chords_n_strings ) {
my $string_temp = $chords_n_strings{$_};
my $string2compare_regex = $string_temp;
# print "\nMein zu vergleichender Regex-Akkordton-String: $string2compare_regex\n";
$string2compare_regex =~ s/,/,.*/g;
$string2compare_regex =~ s/(.*)/.*$1,.*/;
# print "\nMein zu vergleichender Regex-Akkordton-String: $string2compare_regex\n";
# print "Vergleich mit Modal-Ton-String: $modenotesstring_temp\n";
my $chord_temp = $_;
# print "$chord_temp\n";
$chord_temp =~ s/-"-/b"-/;
if ( $modenotesstring_temp =~ m/$string2compare_regex/ ) {
print "Hiphip-hooray! ";
print "$chord_temp ist möglich!\n";
print "\nMein zu vergleichender Regex-Akkordton-String: $string2compare_regex\n";
print "Vergleich mit Modal-Ton-String: $modenotesstring_temp\n";
print "Modal-Ton-String: $string_temp\n";
print "Ton-String: $notestring\n\n";
push @matchchords, $chord_temp;
}
}
## Ausgabe der Möglichkeiten
print "\n\n";
print " ++++ *** ~~~ Ausgangsakkord ist/war: \"$grundton_readable\"-$akkord ~~~ *** ++++ \n\n\n";
print "Es gibt ", scalar @matchchords, " Akkord-Möglichkeiten für:\n\nModus $mode_readable!\n\n";
print "Es sind die folgenden Akkorde:\n\n";
print map { $_, "\n" } @matchchords;
print "\n\n";
Kommentare
Kommentar veröffentlichen