Magic Squares

Moderator: kcleung

Locked
vinteuil
Groundskeeper
Posts: 1445
Joined: Sun Oct 05, 2008 3:01 pm
notabot: YES
notabot2: Bot
Location: U.S.A.
Contact:

Magic Squares

Post by vinteuil »

OK, so I made a Perl (surprise, surprise) script to manufacture 12-tone "Magic Squares." Another surprise: it doesn't work, and I don't really like to debug (which is why I haven't asked to do coding for IMSLP... :roll: ).
But if this works...major labor saver.

Code: Select all

#!/usr/bin/perl
@row={};
print "Enter tone row/series, one at a time. Sharps only, represented as '-s;' e.g. Cs.\n";
for($i=0;$i=11;$i++){ 
 push(@row, <>); ##Entering Row.
}
%notes=( ##Establishing Notes to Numbers.
 C=>0,
 Cs=>1,
 D=>2,
 Ds=>3,
 E=>4,
 F=>5,
 Fs=>6,
 G=>7,
 Gs=>8,
 A=>9,
 As=>10,
 B=>11,
);
%pitches=( ##Establishing the commutative property.
 0=>C,
 1=>Cs,
 2=>D,
 3=>Ds,
 4=>E,
 5=>F,
 6=>Fs,
 7=>G,
 8=>Gs,
 9=>A,
 10=>As,
 11=>B,
);
$value=NULL;
foreach $note (keys %notes){
 if ($note=~ m/row[0]/){
  $value=$note;
  %notes=(%notes, $note, 0);
 }
}
foreach $note (keys %notes){
 %notes=($note,($notes{$note}+12-$value)%12); ##Changing the values for the actual row
}
%series=();
foreach $tone(@row){
 $series{$tone}=$notes{tone};  ##Making the Series
};
%series1=(); ##P1
%series2=();
%series3=();
%series4=();
%series5=();
%series6=();
%series7=();
%series8=();
%series9=();
%series10=();
%series11=();
@numseries=();
foreach $note (keys %series){
 push(@numseries, $series{$note});
}
foreach $note (keys %series){
 $series1{$series{$note}}=$pitches{$series{$note}+(12-$numseries[1])};
 $series2{$series{$note}}=$pitches{$series{$note}+(12-$numseries[2])};
 $series3{$series{$note}}=$pitches{$series{$note}+(12-$numseries[3])};
 $series4{$series{$note}}=$pitches{$series{$note}+(12-$numseries[4])};
 $series5{$series{$note}}=$pitches{$series{$note}+(12-$numseries[5])};
 $series6{$series{$note}}=$pitches{$series{$note}+(12-$numseries[6])};
 $series7{$series{$note}}=$pitches{$series{$note}+(12-$numseries[7])};
 $series8{$series{$note}}=$pitches{$series{$note}+(12-$numseries[8])};
 $series9{$series{$note}}=$pitches{$series{$note}+(12-$numseries[9])};
 $series10{$series{$note}}=$pitches{$series{$note}+(12-$numseries[10])};
 $series11{$series{$note}}=$pitches{$series{$note}+(12-$numseries[11])};
}
print "  I0 I1 I2 I3 I4 I5 I6 I7 I8 I9 I10 I11 ";
print "P0", join("  ",@row), "R0\n";
print "P1", join("  ",%series1), "R1\n";
print "P2", join("  ",%series2), "R2\n";
print "P3", join("  ",%series3), "R3\n";
print "P4", join("  ",%series4), "R4\n";
print "P5", join("  ",%series5), "R5\n";
print "P6", join("  ",%series6), "R6\n";
print "P7", join("  ",%series7), "R7\n";
print "P8", join("  ",%series8), "R8\n";
print "P9", join("  ",%series9), "R9\n";
print "P10", join("  ",%series10), "R10\n";
print "P11", join("  ",%series11), "R11\n";
print "  IR0IR1IR2IR3IR4IR5IR6IR7IR8IR9IR10IR11\n";
Formerly known as "perlnerd666"
sbeckmesser
active poster
Posts: 501
Joined: Tue May 19, 2009 5:23 pm
notabot: 42
notabot2: Human

Re: Magic Squares

Post by sbeckmesser »

Is the intention here to have a complete 12-pitch-class tone-row in each column and row of the square? What about the diagonals? Are there any other restrictions or requirements?

--Sixtus
reinhold
forum adept
Posts: 54
Joined: Mon Jun 02, 2008 6:00 am
notabot: YES
notabot2: Bot
Location: Vienna, Austria
Contact:

Re: Magic Squares

Post by reinhold »

sbeckmesser wrote:Is the intention here to have a complete 12-pitch-class tone-row in each column and row of the square?
Basically, yes. That's a consequence of how these matrices in 12-tone music are constructed. They are one approach to 12-tone composing...

See http://www2.nau.edu/~krr2/12tone/12tone1.html
sbeckmesser wrote:What about the diagonals? Are there any other restrictions or requirements?
The diagonals are not restricted, however each row is just a translation (modulo 12) of the first row, where the shift for the n-th row is taken as (12-kn), where kn is th n-th note in the original sequence of tones.

Cheers,
REinhold
vinteuil
Groundskeeper
Posts: 1445
Joined: Sun Oct 05, 2008 3:01 pm
notabot: YES
notabot2: Bot
Location: U.S.A.
Contact:

Re: Magic Squares

Post by vinteuil »

Right, thus the first note of the row P0 becomes the diagonal from top left to bottom right.
However, it still doesn't work.
And I just found out that Sibelius does this...I'm using the wrong program...
Formerly known as "perlnerd666"
Locked