【问题标题】:MIDI Note Counting Program producing incorrect resultsMIDI 音符计数程序产生不正确的结果
【发布时间】:2017-11-12 21:42:36
【问题描述】:

我用 C++ 编写了一个程序,它计算 .mid 文件中的音符数量,输出每个音符的数量(A 到 G#),然后将其输出到文件中。它没有找到足够的笔记,但我不知道为什么。我是根据 midi.org 的 MIDI 文件文档构建的。

在读取文件时,它所做的只是查找状态字节,1001nnnn,然后读取下一个字节作为注释。我使用 Anvil Studio 制作了一个只有 1 个音符的 MIDI 文件,并使用程序对其进行分析,发现它只有 1 个音符是正确的,但是当我在更大的文件(2000 多个音符)上使用它时,它不会找到几乎所有的,有时它会发现 90%+ 的音符是一两个音高。

这是搜索笔记的程序段。文件以 ios::binary 字节模式打开

//Loop through every byte of the file
        for (int i = 0; i <= size; i++) {

            //Read next byte of file to tempblock
            myfile.read(tempblock, 1);

            //Put int value of byte in b
            int b = tempblock[0];


            //x = first 4 binary digits of b, appended with 0000
            unsigned int x = b & 0xF0;

            //If note is next, set the next empty space of notearray to the notes value, and then set notenext to 0
            if (notenext) {

                myfile.read(tempblock, 1);
                int c = tempblock[0];
                i++;

                //Add the note to notearray if the velocity data byte is not set to 0
                if (c != 0) {
                    notearray[notecount] = b;
                    notenext = 0;
                    notecount++;
                }


            }

            //If note is not next, and x is 144 (int of 10010000, status byte for MIDI "Note on" message), set note next to true
            else if (x == 144) {

                notenext = 1;

            }

        }

有人知道怎么回事吗?我只是缺少文件类型的一个组件,还是我正在使用的文件有问题?我主要看古典钢琴作品,从 midi 存储库下载

【问题讨论】:

    标签: c++ midi


    【解决方案1】:

    当频道消息状态字节与最后一个相同时,可以省略;这称为运行状态。

    此外,1001nnnn 字节可能出现在增量时间值内。

    您必须正确解析所有消息才能检测到笔记。

    【讨论】:

    • 好的,我会阅读增量时间来尝试解决这个问题。我选择了我的实现,因为大多数 midi 事件与音符值无关。在您说完之后,也许我会将其更改为所选字节上的 switch() ,并为每个相关的状态字节提供一个案例。谢谢
    【解决方案2】:

    问题很可能是您的 MIDI 编辑器创建文件的方式。许多 MIDI 编辑器实际上并没有关闭音符 - 他们只是将他们的力度设置为 0。这会让他们难以解析。

    查看文件中包含的原始 MIDI 消息,您应该会看到很多速度消息。

    【讨论】:

    • 我已经检查了 0 速度的音符: if (c != 0) { notearray[notecount] = b;下一个 = 0;记数++; } 因为音高后的字节是速度
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-14
    • 2015-10-12
    • 2015-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多