Hey, this is a pretty obscure topic and of very limited use.
BUT
you're a bunch of smart people so you might find it interesting and I'm sure you can give me some ideas.
A 12 tone matrix is something used in atonal music, and it bears a striking resemblance to a Sudoku puzzle except the digits run 0 - 11 rather than 0 - 9.
I'm hoping for some input on the following:
//Future improvements will include 1] completing the matrix,
//2] playing the initial row via MIDI, and
//3] saving to disk as a text file. [I can figure this one out easily enough.]
Here's what I've got so far:
Code:
//The latest incarnation of my ongoing tonerow programming efforts (12/17/06)
//Currently generates P0 and I0 and prints them as the top and left side
//of an incomplete matrix. Also plays P0 and I0 with the cheesey 'Beep' command.
//Future improvements will include 1] completing the matrix,
//2] playing the initial row via MIDI, and
//3] saving to disk as a text file.
#include <iostream>
#include<cstdlib>
#include<ctime>
#include<iomanip>
#include <cmath>
#include <windows.h>
using namespace std;
int main()
{
//Set constants
double Semitone = pow(2.0, (1.0/12.0));
double C = 261.626 * 2;
double pitch;
int delay = 500;
//Initialize chromatic scale
int row[12]={0,1,2,3,4,5,6,7,8,9,10,11};
//Shuffle into a tone row
srand(time(0));
for (int i = 0; i<12; ++i)
{
int index1 = (rand()%12);
int index2 = (rand()%12);
int temp = row[index1];
row[index1] = row[index2];
row[index2] = temp;
}
//Print the row
for (int x = 0; x<12; x++)
cout<<setw(4)<<row[x];
cout<<endl;
//Play P0
for (int tone = 0; tone<12; tone++)
{ pitch = C*(pow(Semitone,row[tone]));
Beep(pitch, delay);}
//Initialize I0
int I0[12]={row[0]};
//Generate IO !!YES IT WORKS!!
for (int i = 1; i<12; i++)
{int temp =row[0]+(row[0]-row[i]);
if (temp<0)
temp = temp + 12;
I0[i]=temp%12;}
//Display I0
for (int x = 1; x<12; x++)
cout<<setw(4)<<endl<<I0[x]<<endl;
//Play I0
for (int tone = 0; tone<12; tone++)
{ pitch = C*(pow(Semitone,I0[tone]));
Beep(pitch, delay);}
cin.get();
return 0;
}
Any input appreciated, thanks!
- JM