c - 用 C midi 编程

标签 c midi

我的代码如下:

    #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;
}

关于我设置的选项的选择似乎一切正常,但是没有播放 midi 音符。

我可能哪里出错了?如果这真的很愚蠢,我真诚地道歉,因为我还没睡,现在这对我来说真的很累。

谢谢大家的宝贵时间!

最佳答案

playing (scale, key) 函数中的 if 条件错误,拼写错误 == 例如:

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

应该是:

if (choice.scale == 1){

此外,学习Indenting C Programs .

关于c - 用 C midi 编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21107814/

相关文章:

c++ - 无法读取 midi 文件? [扩展规范?]

c - 避免翘曲发散

midi - 将 MIDI 节拍转换为实际播放秒数

python - 需要帮助将 C 函数移植到 Python

c++ - while 循环是否总是占用全部 CPU 资源?

ios - 当 MIDI 目标或源更改时收到通知

events - 在 MIDI channel 事件中解码 RPN

midi - 在 Gervill SF2Soundbank 中将多个样本添加到一个乐器

c - 循环显示菜单永无止境

c - 使用数组作为 c 中结构体的元素来初始化结构体数组