Midi Note Calculator

Hey guys, I am new to this forum and love it so far. I am attempting to write a program where the user inserts 2 midi notes between 21 and 108 and calculate the note on a keyboard i.e. C4, D5, E6 etc. and the frequency.

I am having trouble with how to set up the case statement to print out the note and the pitch class. Could someone help me organize this?

I am using this page as a reference:

http://newt.phys.unsw.edu.au/jw/notes.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/* This program will process midi notes (between 21 and 108) and then print out their corresponding note names (from A0 to C8) and frequencies */

float midiNote1, midiNote2;
char dummy;
int pc1, pc2;

int main()
{


    printf("\nBruh... \t\nEnter a midi note number between 21 and 108. (0 to exit duder)\n");
    scanf("%f, %c", &midiNote1, dummy);

    { switch(pc1)

    {

    case 0: (pc1 = 0); break;
    case 1: (pc1 = 1); break;
    case 2: (pc1 = 2); break;
    case 3: (pc1 = 3); break;
    case 4: (pc1 = 4); break;
    case 5: (pc1 = 5); break;
    case 6: (pc1 = 6); break;
    case 7: (pc1 = 7); break;
    case 8: (pc1 = 8); break;

    default: /* error code */ return 100;

    }

    }

    if(midiNote1 < 23)
    pc1 = 0;
    else if(midiNote1 => 23  && <36)
    pc1 = 1;
                                                                                               
    printf("But like... \t\nEnter another midi note number between 21 and 108. (still 0 to exit ma man)\n");
    scanf("%f, %c", &midiNote2, dummy);

    {
    if(midiNote2 < 21 || midiNote2 > 109)
    printf("Come on man... Can you read?\n");

    }

    //printf("%.0f\n", midiNote1);
    //printf("%.0f\n", midiNote2);





    return 0;
}
My approach would be to store the midi notes, keyboard notes, and frequencies in arrays. Then, I would search the arrays using the given midi notes and use the arrays as a lookup table.
So what is wrong with my math here?

n[ i ] = i + i^(1/12) for each step in the array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main ()
{
   int n[ 87 ];
   int i,j;

   for ( i = 21; i < 109; i++ )
   {
      n[ i ] = i + pow(i, 1/12);
   }

   for (j = 21; j < 109; j++ )
   {

        printf("Midi Note[%d] = %d\n", j, n[j] );
   }

   return 0;
}
Topic archived. No new replies allowed.