user3186187
user3186187

Reputation: 17

Programming in C midi

My code is as follows:

    #include <conio.h>
    #include <stdio.h>
    #include <stdlib.h>

    int natural_minor_scale [8] = {0, 2, 3, 5, 7, 8, 10, 12};  /* The Natural Minor scale we will be using in the code*/
    int harmonic_minor_scale [8] = {0, 2, 3, 5, 7, 8, 11, 12}; /* The Harmonic Minor scale we will be using in the code*/
    int major_scale [8] = {0, 2, 4, 5, 7, 9, 11, 12};          /* The Major scale we will be using in the code*/
    int scale(void);
    int key(void);
    void welcome_screen(void);

    struct musical_choice                                      /* Building of a structure taken from lecture notes 6.Structures */
{                                                          /* from http://www.elec.york.ac.uk/internal_web//meng/yr1/modules/Maths_and_Programming/CProgramming/c-lecture6.pdf */
    int decision;
    int scale;
    int key;

    };
    struct musical_choice choice;            /*We will use a structure to get information easier here */

    int main(void)
    {
    welcome_screen(); /* Open the Console and display the first message, so as to introduce the program to the user and to wish the user a nice day*/
    scanf("%i", &choice.decision);
     while(choice.decision!=1 && choice.decision!=2){ /* To choose between just 1 and 2 */

         printf("\nPlease, select one of the options offered above.\n");
         scanf("%i", &choice.decision);
    }
    if (choice.decision==1){
    scale();
    key();
    printf("I will now play what you wish");
    playing(choice.scale, choice.key);
    }
    else if (choice.decision==2){
    choice.scale=random_number(1, 3);
    choice.key=random_number(1, 3);
    }
    return 0;
    }


    void (welcome_screen())  /* This is the function for the welcoming screen */
      {
      printf("Welcome to this new piece of software. \nIt will help you decide what you want me, your Software Guitarist, to play. \nHave a nice day!\nFor me to play based on your desires, press 1.\nIf you would like me to prove my talent and improvise, press 2\n");
      }



    int scale(void)          /* Receive input for which scale you want to have played */
    {
    printf("\nPress a number to choose whether you want me to play in:\nThe Major Scale, which requires you to press 1;\nThe Natural Minor scale, which requires you to press 2;\nThe Harmonic Minor scale, which requires you to press 3;\n");
    scanf("%i", &choice.scale);
    while(choice.scale != 1 && choice.scale != 2 && choice.scale != 3){          /* This command makes it so that you can't choose a letter or a number higher than 3 or lower than 1 */
        printf("\nPlease, pick a number between 1 and 3.\n");
        scanf("%i", &choice.scale);

        }
         return choice.scale;
    }
    int key(void)          /* Receive input for which key you want to have played */
    {
        printf("\nNow choose between the music being played in\nThe key of A for which you press 1 \nThe key of C for which you press 2 \nThe key of E for which you press 3.\n");
    scanf("%i", &choice.key);
    while(choice.key != 1 && choice.key !=2 && choice.key !=3){
        printf("\nPlease, pick a number between 1 and 3.\n");
        scanf("%i", &choice.key);

        }
        return choice.key;
}

    int playing (scale, key){
    int key_note;
    int scale_chosen;

    int velocity = random_number (60-110);
    if (choice.scale=1){
    scale_chosen=major_scale;}
    else if (choice.scale=2){
    scale_chosen=natural_minor_scale;}
    else if (choice.scale=3){
    scale_chosen=harmonic_minor_scale;}
    if (choice.key=1){
    key_note=57;}
    else if (choice.key=2){
    key_note=60;}
    else if (choice.key=3){
    key_note=64;}

    do{
    midi_note(key_note+scale_chosen, 26, velocity); }

    while (kbhit()==0);
    return 0;
}

Everything seems to be working regarding the choice of options I have set up, however no midi notes are playing.

Where may I be making a mistake? I sincerely apologize if it's something really silly, as I haven't still slept and this is really tiring for me now.

Thank you all for your time!

Upvotes: 1

Views: 1744

Answers (1)

Grijesh Chauhan
Grijesh Chauhan

Reputation: 58271

Your if conditions in playing (scale, key) function are wrong, misspelled == e.g:

if (choice.scale=1){
//              ^  ??  it should be ==

should be:

if (choice.scale == 1){

Additionally, learn Indenting C Programs.

Upvotes: 3

Related Questions