Thread: 12 tone matrix

  1. #1
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79

    12 tone matrix

    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
    Huh?

  2. #2
    Optics with a Twist skewray's Avatar
    Join Date
    Dec 2006
    Location
    South Pasadena, CA
    Posts
    36
    "double C = 261.626 * 2;" is not the best programming style. "261.626" is a completely arbitrary number. Better is:
    Code:
    double A1 = 440.0;                                             // standard tuning anchored to A1 = 440 Hz.
    double C0 = A1 * pow( Semitone, -17 );            // 17 is number of semitones between C0 and A1
    This defines C0 as 17 semitones (do I have that number right?) below A440.

  3. #3
    Registered Usurer
    Join Date
    Apr 2005
    Location
    upstate NY
    Posts
    79
    Yeah, you're right, good call...

    I changed it to

    Code:
      double A = 440.0;
      double C = A * pow(Semitone, -9);
    and it works fine - (C is nine half steps below A).


    I still haven't completed the 12 x 12 matrix (confused by the 'clock math') or figured out any musical applications.

    Lord knows if I laid any of this stuff on my high school band they'd run away screaming!

    Thanks for the input

    -JM
    Huh?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Is this me or Windows?
    By carrotcake1029 in forum C Programming
    Replies: 9
    Last Post: 05-07-2008, 09:18 AM
  3. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  4. What is a matrix's purpose in OpenGL
    By jimboob in forum Game Programming
    Replies: 5
    Last Post: 11-14-2004, 12:19 AM