【发布时间】: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 存储库下载
【问题讨论】: