home *** CD-ROM | disk | FTP | other *** search
/ PC Musician 2000 / PC_Musician_2000.iso / PCMUSIC / MISC / PAREQ12A / PNOTE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-09  |  8.1 KB  |  284 lines

  1. /*
  2.  * Pnote.c
  3.  *
  4.  * Routine to print correct note and accidental given the
  5.  * midi note value and track.
  6.  *
  7.  */
  8. #include "mtm.h"
  9. #include "version.h"
  10.  
  11. pnote(nval, trck)
  12. short nval;
  13. int trck;
  14. {
  15.  
  16.         int i, acc, ncc;
  17.  
  18.     trck++;
  19.     acc = 0;
  20.     ncc = 0;
  21.     i = 0;
  22.  
  23.         /*
  24.          * Confused?  Aren't we all.  Here's what's going on.  We're trying to
  25.          * avoid placing two accidentals on the same note in the same measure.
  26.          * accnote is filled by donote(), after pnote() prints a note.  The
  27.          * tied[] array simply keeps track of whether the last note printed
  28.          * had a tie coming from it.  If it did, then no accidentals should be
  29.          * printed.  Okay, now to the code immedaitely below.  We don't care
  30.          * if there was a tie from the last note.  If there was, that's nice.
  31.          * but if there wasn't, that's okay too.  If we find the current note
  32.          * in accnote[], then set tie[trck]=1 so no accidental gets printed.
  33.          * Remember that tied[] really has *nothing* to do with ties.  It simply
  34.          * governs how the current note is printed.  Got it?  
  35.      *
  36.      * Now for the "else"s.  We've got to know not only when there are two
  37.      * notes of the same accidental in the measure, but when a note was
  38.      * flatted or sharped and now, in the same measure, is a natural.
  39.      * So we check to see if we're only one away from our current value.
  40.      * If so, we set acc -- positive if we're in a sharp key, negative if
  41.      * we're in a flat key.  We need to keep the keys seperate, because
  42.      * some notes are never flated (c, f) and some are never sharped
  43.      * (b, e), and while adding a natural to an already natural note isn't
  44.      * wrong, it's unpleasant.
  45.          */
  46.         for(i = 0; i <= accwhre; i++) {
  47.                 if(accnotes[i] == nval) {
  48.                 tied[trck] = 1;
  49.         } else if((accnotes[i] == nval - 1) && key[trck] <= 0) {
  50.             acc =  0 - nval;
  51.             tied[trck] = 0;
  52.         } else if((accnotes[i] == nval + 1) && key[trck] > 0) {
  53.             acc = nval;
  54.             tied[trck] = 0;
  55.         } else if((accnotes[i] == nval + 1) && key[trck] <= 0) {
  56.             ncc =  0 - nval;
  57.             tied[trck] = 0;
  58.         } else if((accnotes[i] == nval - 1) && key[trck] > 0) {
  59.             ncc = nval;
  60.             tied[trck] = 0;
  61.         }
  62.     }
  63.  
  64.     /*
  65.      * Figured out the above.. and now you want to know what this does?
  66.      * Let me try to explain.  The idea here is that depending on the
  67.      * key signature, we may want to output either a flat or a sharp.
  68.      * My algorhytm isn't perfect.. if someone wants to write a better
  69.      * one, feel free.
  70.      *
  71.      * Think of these notes as the white and black notes on a keyboard.
  72.      * No white note will ever be called a flat or a sharp.  I know this
  73.      * goes against some notation conventions, but tough.  As for black
  74.      * notes, it's fairly simple.  Here's the basic algorhythm:
  75.      *    Are we in a flat key?
  76.      *      yes:  Is the note flatted within the key signature?
  77.      *         yes:  the output the note without a flat
  78.      *         no:  put a flat on the note
  79.      *      no:  Is the note sharped within the key signature?
  80.      *         yes: output the note without a sharp
  81.      *         no: put a sharp on the thing.
  82.      */
  83. /*
  84. printf("\nval = %d, trck = %d, key[trck] = %d, acc = %d, tied[trck] = %d\n", nval, trck, key[trck], acc, tied[trck]);
  85. */
  86.     sccwhre++;
  87.     sccnotes[sccwhre][2] = goctave(trck, nval);
  88.         switch(nval % 12) {
  89.         case 0:
  90.             if((key[trck] > 1 || key[trck] < -5 || acc == nval) && tied[trck] != 1) {
  91.                 printf("cn");
  92.                 sccnotes[sccwhre][0] = 0;
  93.                 sccnotes[sccwhre][1] = 1;
  94.             } else {
  95.                 printf("c");
  96.                 sccnotes[sccwhre][0] = 0;
  97.                 sccnotes[sccwhre][1] = 0;
  98.             }
  99.             break;
  100.         case 1:
  101.             if(key[trck] <= 0) {
  102.                 if((key[trck] < -3 || tied[trck] == 1) && ncc != 0 - nval) {
  103.                     printf("d");
  104.                     sccnotes[sccwhre][0] = 1;
  105.                     sccnotes[sccwhre][1] = 0;
  106.                 } else {
  107.                     printf("d&");
  108.                     sccnotes[sccwhre][0] = 1;
  109.                     sccnotes[sccwhre][1] = 2;
  110.                 }
  111.             } else {
  112.                 if((key[trck] > 1 || tied[trck] == 1) && ncc != nval) {
  113.                     printf("c");
  114.                     sccnotes[sccwhre][0] = 0;
  115.                     sccnotes[sccwhre][1] = 0;
  116.                 } else {
  117.                     printf("c#");
  118.                     sccnotes[sccwhre][0] = 0;
  119.                     sccnotes[sccwhre][1] = 3;
  120.                 }
  121.             }
  122.             break;
  123.         case 2:
  124.             if((key[trck] > 3 || key[trck] < -3 || acc == nval || acc == 0 - nval) && tied[trck] != 1) {
  125.                 printf("dn");
  126.                 sccnotes[sccwhre][0] = 1;
  127.                 sccnotes[sccwhre][1] = 1;
  128.             } else {
  129.                 printf("d");
  130.                 sccnotes[sccwhre][0] = 1;
  131.                 sccnotes[sccwhre][1] = 0;
  132.             }
  133.             break;
  134.         case 3:
  135.             if(key[trck] <= 0) {
  136.                 if((key[trck] < -1 || tied[trck] == 1) && ncc != 0 - nval) {
  137.                     printf("e");
  138.                     sccnotes[sccwhre][0] = 2;
  139.                     sccnotes[sccwhre][1] = 0;
  140.                 } else {
  141.                     printf("e&");
  142.                     sccnotes[sccwhre][0] = 2;
  143.                     sccnotes[sccwhre][1] = 2;
  144.                 }
  145.             } else {
  146.                 if((key[trck] > 3 || tied[trck] == 1) && ncc != nval) {
  147.                     printf("d");
  148.                     sccnotes[sccwhre][0] = 1;
  149.                     sccnotes[sccwhre][1] = 0;
  150.                 } else {
  151.                     printf("d#");
  152.                     sccnotes[sccwhre][0] = 1;
  153.                     sccnotes[sccwhre][1] = 3;
  154.                 }
  155.             }
  156.             break;
  157.         case 4:
  158.             if((key[trck] > 5 || key[trck] < -1 || acc == 0 - nval) && tied[trck] != 1) {
  159.                 printf("en");
  160.                 sccnotes[sccwhre][0] = 2;
  161.                 sccnotes[sccwhre][1] = 1;
  162.             } else {
  163.                 printf("e");
  164.                 sccnotes[sccwhre][0] = 2;
  165.                 sccnotes[sccwhre][1] = 0;
  166.             }
  167.             break;
  168.         case 5:
  169.             if((key[trck] > 0 || key[trck] < -6 || acc == nval) && tied[trck] != 1) {
  170.                 printf("fn");
  171.                 sccnotes[sccwhre][0] = 3;
  172.                 sccnotes[sccwhre][1] = 1;
  173.             } else {
  174.                 printf("f");
  175.                 sccnotes[sccwhre][0] = 3;
  176.                 sccnotes[sccwhre][1] = 0;
  177.             }
  178.             break;
  179.         case 6:
  180.             if(key[trck] <= 0) {
  181.                 if((key[trck] < -4 || tied[trck] == 1) && ncc != 0 - nval) {
  182.                     printf("g");
  183.                     sccnotes[sccwhre][0] = 4;
  184.                     sccnotes[sccwhre][1] = 0;
  185.                 } else {
  186.                     printf("g&");
  187.                     sccnotes[sccwhre][0] = 4;
  188.                     sccnotes[sccwhre][1] = 2;
  189.                 }
  190.             } else {
  191.                 if((key[trck] > 0 || tied[trck] == 1) && ncc != nval) {
  192.                     printf("f");
  193.                     sccnotes[sccwhre][0] = 3;
  194.                     sccnotes[sccwhre][1] = 0;
  195.                 } else {
  196.                     printf("f#");
  197.                     sccnotes[sccwhre][0] = 3;
  198.                     sccnotes[sccwhre][1] = 3;
  199.                 }
  200.             }
  201.             break;
  202.         case 7:
  203.             if((key[trck] > 2 || key[trck] < -4 || acc == nval || acc == 0 - nval) && tied[trck] != 1) {
  204.                 printf("gn");
  205.                 sccnotes[sccwhre][0] = 4;
  206.                 sccnotes[sccwhre][1] = 1;
  207.             } else {
  208.                 printf("g");
  209.                 sccnotes[sccwhre][0] = 4;
  210.                 sccnotes[sccwhre][1] = 0;
  211.             }
  212.             break;
  213.         case 8:
  214.             if(key[trck] <= 0) {
  215.                 if((key[trck] < -2 || tied[trck] == 1)  && ncc != 0 - nval) {
  216.                     printf("a");
  217.                     sccnotes[sccwhre][0] = 5;
  218.                     sccnotes[sccwhre][1] = 0;
  219.                 } else {
  220.                     printf("a&");
  221.                     sccnotes[sccwhre][0] = 5;
  222.                     sccnotes[sccwhre][1] = 2;
  223.                 }
  224.             } else {
  225.                 if((key[trck] > 2 || tied[trck] == 1)  && ncc != nval) {
  226.                     printf("g");
  227.                     sccnotes[sccwhre][0] = 4;
  228.                     sccnotes[sccwhre][1] = 0;
  229.                 } else {
  230.                     printf("g#");
  231.                     sccnotes[sccwhre][0] = 4;
  232.                     sccnotes[sccwhre][1] = 2;
  233.                 }
  234.             }
  235.             break;
  236.         case 9:
  237.             if((key[trck] > 4 || key[trck] < -2 || acc == nval || acc == 0 - nval) && tied[trck] != 1) {
  238.                 printf("an");
  239.                 sccnotes[sccwhre][0] = 5;
  240.                 sccnotes[sccwhre][1] = 1;
  241.             } else {
  242.                 printf("a");
  243.                 sccnotes[sccwhre][0] = 5;
  244.                 sccnotes[sccwhre][1] = 0;
  245.             }
  246.             break;
  247.         case 10:
  248.             if(key[trck] <= 0) {
  249.                 if((key[trck] < 0 || tied[trck] == 1)  && ncc != 0 - nval) {
  250.                     printf("b");
  251.                     sccnotes[sccwhre][0] = 6;
  252.                     sccnotes[sccwhre][1] = 0;
  253.                 } else {
  254.                     printf("b&");
  255.                     sccnotes[sccwhre][0] = 6;
  256.                     sccnotes[sccwhre][1] = 2;
  257.                 }
  258.             } else {
  259.                 if((key[trck] > 4 || tied[trck] == 1) && ncc != nval) {
  260.                     printf("a"); 
  261.                     sccnotes[sccwhre][0] = 5;
  262.                     sccnotes[sccwhre][1] = 0;
  263.                 } else {
  264.                     printf("a#");
  265.                     sccnotes[sccwhre][0] = 5;
  266.                     sccnotes[sccwhre][1] = 3;
  267.                 }
  268.             }
  269.             break;
  270.         case 11:
  271.             if((key[trck] > 6 || key[trck] < 0 || acc == 0 - nval) && tied[trck] != 1) {
  272.                 printf("bn");
  273.                 sccnotes[sccwhre][0] = 6;
  274.                 sccnotes[sccwhre][1] = 1;
  275.             } else {
  276.                 printf("b");
  277.                 sccnotes[sccwhre][0] = 6;
  278.                 sccnotes[sccwhre][1] = 0;
  279.             }
  280.             break;
  281.     }
  282.         tied[trck] = 0;
  283. }
  284.