home *** CD-ROM | disk | FTP | other *** search
- /*
- * Pnote.c
- *
- * Routine to print correct note and accidental given the
- * midi note value and track.
- *
- */
- #include "mtm.h"
- #include "version.h"
-
- pnote(nval, trck)
- short nval;
- int trck;
- {
-
- int i, acc, ncc;
-
- trck++;
- acc = 0;
- ncc = 0;
- i = 0;
-
- /*
- * Confused? Aren't we all. Here's what's going on. We're trying to
- * avoid placing two accidentals on the same note in the same measure.
- * accnote is filled by donote(), after pnote() prints a note. The
- * tied[] array simply keeps track of whether the last note printed
- * had a tie coming from it. If it did, then no accidentals should be
- * printed. Okay, now to the code immedaitely below. We don't care
- * if there was a tie from the last note. If there was, that's nice.
- * but if there wasn't, that's okay too. If we find the current note
- * in accnote[], then set tie[trck]=1 so no accidental gets printed.
- * Remember that tied[] really has *nothing* to do with ties. It simply
- * governs how the current note is printed. Got it?
- *
- * Now for the "else"s. We've got to know not only when there are two
- * notes of the same accidental in the measure, but when a note was
- * flatted or sharped and now, in the same measure, is a natural.
- * So we check to see if we're only one away from our current value.
- * If so, we set acc -- positive if we're in a sharp key, negative if
- * we're in a flat key. We need to keep the keys seperate, because
- * some notes are never flated (c, f) and some are never sharped
- * (b, e), and while adding a natural to an already natural note isn't
- * wrong, it's unpleasant.
- */
- for(i = 0; i <= accwhre; i++) {
- if(accnotes[i] == nval) {
- tied[trck] = 1;
- } else if((accnotes[i] == nval - 1) && key[trck] <= 0) {
- acc = 0 - nval;
- tied[trck] = 0;
- } else if((accnotes[i] == nval + 1) && key[trck] > 0) {
- acc = nval;
- tied[trck] = 0;
- } else if((accnotes[i] == nval + 1) && key[trck] <= 0) {
- ncc = 0 - nval;
- tied[trck] = 0;
- } else if((accnotes[i] == nval - 1) && key[trck] > 0) {
- ncc = nval;
- tied[trck] = 0;
- }
- }
-
- /*
- * Figured out the above.. and now you want to know what this does?
- * Let me try to explain. The idea here is that depending on the
- * key signature, we may want to output either a flat or a sharp.
- * My algorhytm isn't perfect.. if someone wants to write a better
- * one, feel free.
- *
- * Think of these notes as the white and black notes on a keyboard.
- * No white note will ever be called a flat or a sharp. I know this
- * goes against some notation conventions, but tough. As for black
- * notes, it's fairly simple. Here's the basic algorhythm:
- * Are we in a flat key?
- * yes: Is the note flatted within the key signature?
- * yes: the output the note without a flat
- * no: put a flat on the note
- * no: Is the note sharped within the key signature?
- * yes: output the note without a sharp
- * no: put a sharp on the thing.
- */
- /*
- printf("\nval = %d, trck = %d, key[trck] = %d, acc = %d, tied[trck] = %d\n", nval, trck, key[trck], acc, tied[trck]);
- */
- sccwhre++;
- sccnotes[sccwhre][2] = goctave(trck, nval);
- switch(nval % 12) {
- case 0:
- if((key[trck] > 1 || key[trck] < -5 || acc == nval) && tied[trck] != 1) {
- printf("cn");
- sccnotes[sccwhre][0] = 0;
- sccnotes[sccwhre][1] = 1;
- } else {
- printf("c");
- sccnotes[sccwhre][0] = 0;
- sccnotes[sccwhre][1] = 0;
- }
- break;
- case 1:
- if(key[trck] <= 0) {
- if((key[trck] < -3 || tied[trck] == 1) && ncc != 0 - nval) {
- printf("d");
- sccnotes[sccwhre][0] = 1;
- sccnotes[sccwhre][1] = 0;
- } else {
- printf("d&");
- sccnotes[sccwhre][0] = 1;
- sccnotes[sccwhre][1] = 2;
- }
- } else {
- if((key[trck] > 1 || tied[trck] == 1) && ncc != nval) {
- printf("c");
- sccnotes[sccwhre][0] = 0;
- sccnotes[sccwhre][1] = 0;
- } else {
- printf("c#");
- sccnotes[sccwhre][0] = 0;
- sccnotes[sccwhre][1] = 3;
- }
- }
- break;
- case 2:
- if((key[trck] > 3 || key[trck] < -3 || acc == nval || acc == 0 - nval) && tied[trck] != 1) {
- printf("dn");
- sccnotes[sccwhre][0] = 1;
- sccnotes[sccwhre][1] = 1;
- } else {
- printf("d");
- sccnotes[sccwhre][0] = 1;
- sccnotes[sccwhre][1] = 0;
- }
- break;
- case 3:
- if(key[trck] <= 0) {
- if((key[trck] < -1 || tied[trck] == 1) && ncc != 0 - nval) {
- printf("e");
- sccnotes[sccwhre][0] = 2;
- sccnotes[sccwhre][1] = 0;
- } else {
- printf("e&");
- sccnotes[sccwhre][0] = 2;
- sccnotes[sccwhre][1] = 2;
- }
- } else {
- if((key[trck] > 3 || tied[trck] == 1) && ncc != nval) {
- printf("d");
- sccnotes[sccwhre][0] = 1;
- sccnotes[sccwhre][1] = 0;
- } else {
- printf("d#");
- sccnotes[sccwhre][0] = 1;
- sccnotes[sccwhre][1] = 3;
- }
- }
- break;
- case 4:
- if((key[trck] > 5 || key[trck] < -1 || acc == 0 - nval) && tied[trck] != 1) {
- printf("en");
- sccnotes[sccwhre][0] = 2;
- sccnotes[sccwhre][1] = 1;
- } else {
- printf("e");
- sccnotes[sccwhre][0] = 2;
- sccnotes[sccwhre][1] = 0;
- }
- break;
- case 5:
- if((key[trck] > 0 || key[trck] < -6 || acc == nval) && tied[trck] != 1) {
- printf("fn");
- sccnotes[sccwhre][0] = 3;
- sccnotes[sccwhre][1] = 1;
- } else {
- printf("f");
- sccnotes[sccwhre][0] = 3;
- sccnotes[sccwhre][1] = 0;
- }
- break;
- case 6:
- if(key[trck] <= 0) {
- if((key[trck] < -4 || tied[trck] == 1) && ncc != 0 - nval) {
- printf("g");
- sccnotes[sccwhre][0] = 4;
- sccnotes[sccwhre][1] = 0;
- } else {
- printf("g&");
- sccnotes[sccwhre][0] = 4;
- sccnotes[sccwhre][1] = 2;
- }
- } else {
- if((key[trck] > 0 || tied[trck] == 1) && ncc != nval) {
- printf("f");
- sccnotes[sccwhre][0] = 3;
- sccnotes[sccwhre][1] = 0;
- } else {
- printf("f#");
- sccnotes[sccwhre][0] = 3;
- sccnotes[sccwhre][1] = 3;
- }
- }
- break;
- case 7:
- if((key[trck] > 2 || key[trck] < -4 || acc == nval || acc == 0 - nval) && tied[trck] != 1) {
- printf("gn");
- sccnotes[sccwhre][0] = 4;
- sccnotes[sccwhre][1] = 1;
- } else {
- printf("g");
- sccnotes[sccwhre][0] = 4;
- sccnotes[sccwhre][1] = 0;
- }
- break;
- case 8:
- if(key[trck] <= 0) {
- if((key[trck] < -2 || tied[trck] == 1) && ncc != 0 - nval) {
- printf("a");
- sccnotes[sccwhre][0] = 5;
- sccnotes[sccwhre][1] = 0;
- } else {
- printf("a&");
- sccnotes[sccwhre][0] = 5;
- sccnotes[sccwhre][1] = 2;
- }
- } else {
- if((key[trck] > 2 || tied[trck] == 1) && ncc != nval) {
- printf("g");
- sccnotes[sccwhre][0] = 4;
- sccnotes[sccwhre][1] = 0;
- } else {
- printf("g#");
- sccnotes[sccwhre][0] = 4;
- sccnotes[sccwhre][1] = 2;
- }
- }
- break;
- case 9:
- if((key[trck] > 4 || key[trck] < -2 || acc == nval || acc == 0 - nval) && tied[trck] != 1) {
- printf("an");
- sccnotes[sccwhre][0] = 5;
- sccnotes[sccwhre][1] = 1;
- } else {
- printf("a");
- sccnotes[sccwhre][0] = 5;
- sccnotes[sccwhre][1] = 0;
- }
- break;
- case 10:
- if(key[trck] <= 0) {
- if((key[trck] < 0 || tied[trck] == 1) && ncc != 0 - nval) {
- printf("b");
- sccnotes[sccwhre][0] = 6;
- sccnotes[sccwhre][1] = 0;
- } else {
- printf("b&");
- sccnotes[sccwhre][0] = 6;
- sccnotes[sccwhre][1] = 2;
- }
- } else {
- if((key[trck] > 4 || tied[trck] == 1) && ncc != nval) {
- printf("a");
- sccnotes[sccwhre][0] = 5;
- sccnotes[sccwhre][1] = 0;
- } else {
- printf("a#");
- sccnotes[sccwhre][0] = 5;
- sccnotes[sccwhre][1] = 3;
- }
- }
- break;
- case 11:
- if((key[trck] > 6 || key[trck] < 0 || acc == 0 - nval) && tied[trck] != 1) {
- printf("bn");
- sccnotes[sccwhre][0] = 6;
- sccnotes[sccwhre][1] = 1;
- } else {
- printf("b");
- sccnotes[sccwhre][0] = 6;
- sccnotes[sccwhre][1] = 0;
- }
- break;
- }
- tied[trck] = 0;
- }