Bootstrap

【感受C++的魅力】:用C++演奏歌曲《起风了》——含完整源码

1 运行效果

用C++演奏歌曲《起风了》

2 代码实现

2.1 引入部分

#include <iostream>
#include <Windows.h>
#pragma comment(lib,"winmm.lib")
using namespace std;

iostream :包含标准输入输出流库,用于执行输入输出操作。
Windows.h:包含Windows API的头文件,用于访问Windows系统功能。
#pragma comment(lib,“winmm.lib”):这是一个特殊的预处理指令,用于告诉编译器在链接阶段将winmm.lib库与程序关联起来。winmm.lib是Windows多媒体库,它包含了用于音频和视频功能的函数,包括MIDI功能的实现。
using namespace std:这行代码告诉编译器在后续代码中使用标准命名空间(std)中的名称而不需要明确的命名空间前缀。例如,可以直接使用cout而不是std::cout。

2.2 枚举

enum Scale
{
    Rest = 0, C8 = 108, B7 = 107, A7s = 106, A7 = 105, G7s = 104, G7 = 103, F7s = 102, F7 = 101, E7 = 100,
    D7s = 99, D7 = 98, C7s = 97, C7 = 96, B6 = 95, A6s = 94, A6 = 93, G6s = 92, G6 = 91, F6s = 90, F6 = 89,
    E6 = 88, D6s = 87, D6 = 86, C6s = 85, C6 = 84, B5 = 83, A5s = 82, A5 = 81, G5s = 80, G5 = 79, F5s = 78,
    F5 = 77, E5 = 76, D5s = 75, D5 = 74, C5s = 73, C5 = 72, B4 = 71, A4s = 70, A4 = 69, G4s = 68, G4 = 67,
    F4s = 66, F4 = 65, E4 = 64, D4s = 63, D4 = 62, C4s = 61, C4 = 60, B3 = 59, A3s = 58, A3 = 57, G3s = 56,
    G3 = 55, F3s = 54, F3 = 53, E3 = 52, D3s = 51, D3 = 50, C3s = 49, C3 = 48, B2 = 47, A2s = 46, A2 = 45,
    G2s = 44, G2 = 43, F2s = 42, F2 = 41, E2 = 40, D2s = 39, D2 = 38, C2s = 37, C2 = 36, B1 = 35, A1s = 34,
    A1 = 33, G1s = 32, G1 = 31, F1s = 30, F1 = 29, E1 = 28, D1s = 27, D1 = 26, C1s = 25, C1 = 24, B0 = 23,
    A0s = 22, A0 = 21
};
代码标识表示含义
enum Scale这行代码声明了一个名为 Scale 的枚举类型;
Rest = 0这不是一个音符,而是表示音乐中的休止符,即在该位置不发音;
C8 = 108表示最高八度(第八个八度)的C音符。在MIDI中,C8是钢琴键盘上最高的标准C音符;
B7 = 107表示比C8低一个半音的B音符,属于同一个八度;
A7s = 106表示A7的升半音版本,即A7和B7之间的黑键;
A7 = 105表示标准音高的A7音符;
G7s = 104表示G7的升半音版本,即G7和A7之间的黑键;
G7 = 103表示标准音高的G7音符;
F7s = 102表示F7的升半音版本,即F7和G7之间的黑键;
F7 = 101表示标准音高的F7音符;
E7 = 100表示E7音符,没有升半音或降半音;
D7s = 99表示了D7的升半音版本,即D7和E7之间的黑键
D7 = 98表示了D7的标准版本;
C7s = 97表示了C7的升半音版本,即C7和D7之间的黑键;
C7 = 96表示了D7的标准版本。

以此类推,每个音符都有其对应的MIDI音符编号,其中:

  • 带有 s 的音符名称(如 A7s)表示该音符是升半音,即该音符和下一个音符之间的黑键。
  • 没有 s 的音符名称(如 A7)表示该音符是标准音高,没有升或降。
  • 音符名称后面的数字(如 C8 中的 8)表示该音符所在的八度。数字越大,音高越高。

2.3 音色定义

enum Voice
{
    X1 = C2, X2 = D2, X3 = E2, X4 = F2, X5 = G2, X6 = A2, X7 = B2,
    L1 = C3, L2 = D3, L3 = E3, L4 = F3, L5 = G3, L6 = A3, L7 = B3,
    M1 = C4, M2 = D4, M3 = E4, M4 = F4, M5 = G4, M6 = A4, M7 = B4,
    H1 = C5, H2 = D5, H3 = E5, H4 = F5, H5 = G5, H6 = A5, H7 = B5,
    LOW_SPEED = 500, MIDDLE_SPEED = 400, HIGH_SPEED = 300,
    _ = 0XFF
};
  1. X1 至 X7:这些音色从 C2 到 B2,表示较低音区的音符。这些是为了模拟某种低音乐器,如低音吉他或低音萨克斯风。
  2. L1 至 L7:这些音色从 C3 到 B3,处于中低音区,代表中音区的乐器,如中提琴或次中音萨克斯风。
  3. M1 至 M7:这些音色从 C4 到 B4,处于中央音区,通常用于模拟人声或中等音高的乐器,如小提琴或长笛。
  4. H1 至 H7:这些音色从 C5 到 B5,处于较高音区,用于模拟高音乐器,如小号或短笛。

2.4 演奏速度定义

  1. LOW_SPEED:值为 500,表示一个较慢的演奏速度,单位可能是毫秒。在MIDI音乐中,这个值可能用来设置较长的音符间隔,以产生较慢的旋律或节奏。
  2. MIDDLE_SPEED:值为 400,表示中等速度,比 LOW_SPEED 稍快,用于设置适中的音符间隔。
  3. HIGH_SPEED:值为 300,表示一个较快的演奏速度,用于快速连续的音符,产生快速的旋律或节奏。

2.5 特殊定义

  1. _:值为 0XFF,十六进制的255。在许多上下文中,这个值用作一个特殊的标记或作为“终止”或“静音”的指示。在MIDI上下文中,它表示一个特殊的控制指令,如终止当前音符的演奏。

具体作用

在MIDI音乐编程中,音色通常用来指定MIDI消息中的音色参数,以模拟不同的乐器声音。例如,X1 = C2 表示音色 X1 对应于音符 C2 的声音。演奏速度常量可能用来控制MIDI消息的发送间隔,从而影响音乐的节奏。
在实际应用中,这些常量的具体作用取决于程序的上下文和设计者的意图。例如,在创建一段MIDI音乐时,可能会根据 Voice 枚举中的音色来选择不同的乐器声音,并根据速度常量来控制音乐的节奏快慢。

2.6 模拟风声

void Wind()
{
    HMIDIOUT handle;
    midiOutOpen(&handle, 0, 0, 0, CALLBACK_NULL);
    // midiOutShortMsg(handle, 2 << 8 | 0xC0);
    int volume = 0x7f;
    int voice = 0x0;
    int sleep = 350;
    int wind[] =
    {
         400,0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,0,L7,M1,M2,M3,300,L2,0,M5,M3,M2,M3,M1,M2,L7,M1,300,L5,0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,0,L7,M1,M2,M3,300,L2,0,M5,M3,M2,M3,M1,M2,L7,M1,300,L5,
         0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,0,L7,M1,M2,M3,300,L2,0,M5,M3,M2,M3,M1,M2,L7,M1,300,L5,0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,
         0,M6,M3,M2,L6,M3,L6,M2,M3,L6,_,_,_,
         M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M1,300,M2,700,0,M1,M2,M3,M2,M1,300,L5,_,
         M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M3,300,M2,0,M1,700,300,M2,_,_,_,
         M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M3,300,M2,0,M1,700,300,L6,_,
         0,M3,M2,M1,M2,300,M1,_,0,M3,M2,M1,M2,300,M1,700,0,L5,M3,M2,M1,M2,300,M1,_,_,_,
         M1,M2,M3,M1,M6,0,M5,M6,300,_,700,0,M1,300,M7,0,M6,M7,300,_,_,M7,0,M6,M7,300,_,M3,0,H1,H2,H1,M7,300,M6,M5,M6,0,M5,M6,_,M5,M6,M5,300,M6,0,M5,M2,300,_,0,M5,700,300,M3,_,_,_,
         M1,M2,M3,M1,M6,0,M5,M6,300,_,700,0,M1,300,M7,0,M6,M7,300,_,_,M7,0,M6,M7,300,_,M3,0,H1,H2,H1,M7,300,M6,M5,M6,0,H3,H3,300,_,M5,M6,0,H3,H3,300,_,0,M5,700,300,M6,_,_,_,_,_,
         H1,H2,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H2,0,H1,M6,300,_,0,H1,H1,300,H2,0,H1,300,M6,700,0,_,300,H1,700,H3,_,0,H3,H4,H3,H2,H3,300,H2,700,
         H1,H2,H3,0,H6,H5,_,H6,H5,_,H6,H5,300,_,H3,H3,0,H6,H5,_,H6,H5,_,H6,H5,700,300,H3,700,H2,0,H1,M6,700,300,
         H3,700,H2,0,H1,300,M6,700,H1,H1,_,_,_,_,_,
         0,M6,300,H3,700,H2,0,H1,M6,700,300,H3,H2,700,300,0,H1,M6,300,700,H1,H1,_,_,
         0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,0,L7,M1,M2,M3,300,L2,0,M5,M3,M2,M3,M1,M2,L7,M1,300,L5,0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,
         0,M6,M3,M2,L6,M3,L6,M2,M3,L6,_,_,_,
         M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M1,300,M2,700,0,M1,M2,M3,M2,M1,300,L5,_,
         M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M3,300,M2,0,M1,700,300,M2,_,_,_,
         M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M3,300,M2,0,M1,700,300,L6,_,
         0,M3,M2,M1,M2,300,M1,_,0,M3,M2,M1,M2,300,M1,700,0,L5,M3,M2,M1,M2,300,M1,_,_,_,
         M1,M2,M3,M1,M6,0,M5,M6,300,_,700,0,M1,300,M7,0,M6,M7,300,_,_,M7,0,M6,M7,300,_,M3,0,H1,H2,H1,M7,300,M6,M5,M6,0,M5,M6,_,M5,M6,M5,300,M6,0,M5,M2,300,_,0,M5,700,300,M3,_,_,_,
         M1,M2,M3,M1,M6,0,M5,M6,300,_,700,0,M1,300,M7,0,M6,M7,300,_,_,M7,0,M6,M7,300,_,M3,0,H1,H2,H1,M7,300,M6,M5,M6,0,H3,H3,300,_,M5,M6,0,H3,H3,300,_,0,M5,700,300,M6,_,_,_,_,_,
         H1,H2,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H2,0,H1,M6,300,_,0,H1,H1,300,H2,0,H1,300,M6,700,0,_,300,H1,700,H3,_,0,H3,H4,H3,H2,H3,300,H2,700,
         H1,H2,H3,0,H6,H5,_,H6,H5,_,H6,H5,300,_,H3,H3,0,H6,H5,_,H6,H5,_,H6,H5,700,300,H3,700,H2,0,H1,M6,700,300,
         H3,700,H2,0,H1,300,M6,700,H1,H1,_,_,_,_,_,
         H1,H2,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H2,0,H1,M6,300,_,0,H1,H1,300,H2,0,H1,300,M6,700,0,_,300,H1,700,H3,_,0,H3,H4,H3,H2,H3,300,H2,700,
         H2,H3,0,H6,H5,_,H6,H5,_,H6,H5,300,_,H3,H3,0,H6,H5,_,H6,H5,_,H6,H5,700,300,H3,700,H2,0,H1,M6,700,300,
         H3,700,H2,0,H1,300,M6,700,H1,H1,_,_,_,_,_,
         H1,H2,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H2,0,H1,M6,300,_,0,H1,H1,300,H2,0,H1,300,M6,700,0,_,300,H1,700,H3,_,0,H3,H4,H3,H2,H3,300,H2,700,
         H1,H2,H3,0,H6,H5,_,H6,H5,_,H6,H5,300,_,H3,H3,0,H6,H5,_,H6,H5,_,H6,H5,700,300,H3,700,H2,0,H1,M6,700,300,
         H3,700,H2,0,H1,300,M6,700,H1,H1,_,_,_,_,_,
         0,M6,300,H3,700,H2,0,H1,M6,700,300,H3,H2,700,300,0,H1,M6,300,700,H1,H1,_,_,_,_,_,_,_,
    };

    for (auto i : wind) {
        if (i == 0) { sleep = 175; continue; }
        if (i == 700) { Sleep(175); continue; }
        if (i == 300) { sleep = 350; continue; }
        if (i == _) {
            Sleep(350);
            continue;
        }
        // if (i == 900) volume += 100;
        voice = (volume << 16) + ((i) << 8) + 0x90;
        midiOutShortMsg(handle, voice);
        cout << voice << endl;
        Sleep(sleep);// midiOutShortMsg(handle, 0x7BB0);
    }
    midiOutClose(handle);
}
  1. HMIDIOUT handle;:声明一个 HMIDIOUT 类型的句柄变量 handle,它将被用来引用一个MIDI输出设备。
  2. midiOutOpen(&handle, 0, 0, 0, CALLBACK_NULL);:调用 midiOutOpen 函数打开默认的MIDI输出设备。参数 0 表示使用默认设备,CALLBACK_NULL 表示不需要回调函数。
  3. int volume = 0x7f;:设置音量为 0x7f,这是MIDI中的一个常见值,表示最大音量。
  4. int voice = 0x0;:初始化 voice 变量,它将用来存储MIDI音符的消息。
  5. int sleep = 350;:设置一个初始的休眠时间(以毫秒为单位),用于控制音符之间的间隔。

wind函数里面使用了Windows的MIDI API来模拟风的声音:

  1. 音符编号:L7, M1, M2, M3, L3, M5, L2, L5 等,这些编号对应于 Voice 枚举中定义的音符,用于生成不同音高的音符。
  2. 节奏控制:数组中的 0 表示暂停,300 和 700 是控制指令,它们与 Sleep 函数一起工作,控制程序在发送MIDI消息之间的等待时间。数值越小,表示播放速度越快,从而模拟风声的快速变化。
  3. 特殊指令 _:这个指令在 Voice 枚举中被定义为 0XFF,通常用于表示序列的结束或一个占位符。在这里,它可能被用作一个较长的暂停,以模拟风声中的静默间隙。
  4. 音量控制:虽然 wind 数组本身不直接包含音量信息,但是 Wind 函数中的 volume 变量(初始化为 0x7f,MIDI的最大音量)会被用来设置每个MIDI消息的音量。
  5. MIDI消息构建:在 Wind 函数中,每个音符编号与音量和MIDI命令(通常是 0x90,表示音符开)结合,形成完整的MIDI消息,然后通过 midiOutShortMsg 函数发送出去。
  6. 模拟风的特性:风声通常是不规则且连续变化的,通过变化 wind 数组中的音符和节奏,可以模拟风声的这种特性。
  7. 重复模式:风声往往有重复的模式,wind 数组通过重复某些音符序列来模拟这一点。
  8. 动态变化:风声的强度和音调是变化的,wind 数组通过不同音符和节奏的组合来模拟这种动态变化。

midiOutClose(handle):在循环结束后,调用 midiOutClose 函数关闭MIDI输出设备,释放资源。

3 完整代码

#include <iostream>
#include <Windows.h>
#pragma comment(lib,"winmm.lib")
using namespace std;
enum Scale
{
    Rest = 0, C8 = 108, B7 = 107, A7s = 106, A7 = 105, G7s = 104, G7 = 103, F7s = 102, F7 = 101, E7 = 100,
    D7s = 99, D7 = 98, C7s = 97, C7 = 96, B6 = 95, A6s = 94, A6 = 93, G6s = 92, G6 = 91, F6s = 90, F6 = 89,
    E6 = 88, D6s = 87, D6 = 86, C6s = 85, C6 = 84, B5 = 83, A5s = 82, A5 = 81, G5s = 80, G5 = 79, F5s = 78,
    F5 = 77, E5 = 76, D5s = 75, D5 = 74, C5s = 73, C5 = 72, B4 = 71, A4s = 70, A4 = 69, G4s = 68, G4 = 67,
    F4s = 66, F4 = 65, E4 = 64, D4s = 63, D4 = 62, C4s = 61, C4 = 60, B3 = 59, A3s = 58, A3 = 57, G3s = 56,
    G3 = 55, F3s = 54, F3 = 53, E3 = 52, D3s = 51, D3 = 50, C3s = 49, C3 = 48, B2 = 47, A2s = 46, A2 = 45,
    G2s = 44, G2 = 43, F2s = 42, F2 = 41, E2 = 40, D2s = 39, D2 = 38, C2s = 37, C2 = 36, B1 = 35, A1s = 34,
    A1 = 33, G1s = 32, G1 = 31, F1s = 30, F1 = 29, E1 = 28, D1s = 27, D1 = 26, C1s = 25, C1 = 24, B0 = 23,
    A0s = 22, A0 = 21
};
enum Voice
{
    X1 = C2, X2 = D2, X3 = E2, X4 = F2, X5 = G2, X6 = A2, X7 = B2,
    L1 = C3, L2 = D3, L3 = E3, L4 = F3, L5 = G3, L6 = A3, L7 = B3,
    M1 = C4, M2 = D4, M3 = E4, M4 = F4, M5 = G4, M6 = A4, M7 = B4,
    H1 = C5, H2 = D5, H3 = E5, H4 = F5, H5 = G5, H6 = A5, H7 = B5,
    LOW_SPEED = 500, MIDDLE_SPEED = 400, HIGH_SPEED = 300,
    _ = 0XFF
};
void Wind()
{
    HMIDIOUT handle;
    midiOutOpen(&handle, 0, 0, 0, CALLBACK_NULL);
    // midiOutShortMsg(handle, 2 << 8 | 0xC0);
    int volume = 0x7f;
    int voice = 0x0;
    int sleep = 350;
    int wind[] =
    {
         400,0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,0,L7,M1,M2,M3,300,L2,0,M5,M3,M2,M3,M1,M2,L7,M1,300,L5,0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,0,L7,M1,M2,M3,300,L2,0,M5,M3,M2,M3,M1,M2,L7,M1,300,L5,
         0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,0,L7,M1,M2,M3,300,L2,0,M5,M3,M2,M3,M1,M2,L7,M1,300,L5,0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,
         0,M6,M3,M2,L6,M3,L6,M2,M3,L6,_,_,_,
         M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M1,300,M2,700,0,M1,M2,M3,M2,M1,300,L5,_,
         M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M3,300,M2,0,M1,700,300,M2,_,_,_,
         M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M3,300,M2,0,M1,700,300,L6,_,
         0,M3,M2,M1,M2,300,M1,_,0,M3,M2,M1,M2,300,M1,700,0,L5,M3,M2,M1,M2,300,M1,_,_,_,
         M1,M2,M3,M1,M6,0,M5,M6,300,_,700,0,M1,300,M7,0,M6,M7,300,_,_,M7,0,M6,M7,300,_,M3,0,H1,H2,H1,M7,300,M6,M5,M6,0,M5,M6,_,M5,M6,M5,300,M6,0,M5,M2,300,_,0,M5,700,300,M3,_,_,_,
         M1,M2,M3,M1,M6,0,M5,M6,300,_,700,0,M1,300,M7,0,M6,M7,300,_,_,M7,0,M6,M7,300,_,M3,0,H1,H2,H1,M7,300,M6,M5,M6,0,H3,H3,300,_,M5,M6,0,H3,H3,300,_,0,M5,700,300,M6,_,_,_,_,_,
         H1,H2,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H2,0,H1,M6,300,_,0,H1,H1,300,H2,0,H1,300,M6,700,0,_,300,H1,700,H3,_,0,H3,H4,H3,H2,H3,300,H2,700,
         H1,H2,H3,0,H6,H5,_,H6,H5,_,H6,H5,300,_,H3,H3,0,H6,H5,_,H6,H5,_,H6,H5,700,300,H3,700,H2,0,H1,M6,700,300,
         H3,700,H2,0,H1,300,M6,700,H1,H1,_,_,_,_,_,
         0,M6,300,H3,700,H2,0,H1,M6,700,300,H3,H2,700,300,0,H1,M6,300,700,H1,H1,_,_,
         0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,0,L7,M1,M2,M3,300,L2,0,M5,M3,M2,M3,M1,M2,L7,M1,300,L5,0,L7,M1,M2,M3,300,L3,0,M5,M3,300,L2,L5,2,_,
         0,M6,M3,M2,L6,M3,L6,M2,M3,L6,_,_,_,
         M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M1,300,M2,700,0,M1,M2,M3,M2,M1,300,L5,_,
         M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M3,300,M2,0,M1,700,300,M2,_,_,_,
         M2,700,0,M1,300,M2,700,0,M1,300,M2,M3,M5,0,M3,700,300,M2,700,0,M3,300,M2,0,M1,700,300,L6,_,
         0,M3,M2,M1,M2,300,M1,_,0,M3,M2,M1,M2,300,M1,700,0,L5,M3,M2,M1,M2,300,M1,_,_,_,
         M1,M2,M3,M1,M6,0,M5,M6,300,_,700,0,M1,300,M7,0,M6,M7,300,_,_,M7,0,M6,M7,300,_,M3,0,H1,H2,H1,M7,300,M6,M5,M6,0,M5,M6,_,M5,M6,M5,300,M6,0,M5,M2,300,_,0,M5,700,300,M3,_,_,_,
         M1,M2,M3,M1,M6,0,M5,M6,300,_,700,0,M1,300,M7,0,M6,M7,300,_,_,M7,0,M6,M7,300,_,M3,0,H1,H2,H1,M7,300,M6,M5,M6,0,H3,H3,300,_,M5,M6,0,H3,H3,300,_,0,M5,700,300,M6,_,_,_,_,_,
         H1,H2,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H2,0,H1,M6,300,_,0,H1,H1,300,H2,0,H1,300,M6,700,0,_,300,H1,700,H3,_,0,H3,H4,H3,H2,H3,300,H2,700,
         H1,H2,H3,0,H6,H5,_,H6,H5,_,H6,H5,300,_,H3,H3,0,H6,H5,_,H6,H5,_,H6,H5,700,300,H3,700,H2,0,H1,M6,700,300,
         H3,700,H2,0,H1,300,M6,700,H1,H1,_,_,_,_,_,
         H1,H2,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H2,0,H1,M6,300,_,0,H1,H1,300,H2,0,H1,300,M6,700,0,_,300,H1,700,H3,_,0,H3,H4,H3,H2,H3,300,H2,700,
         H2,H3,0,H6,H5,_,H6,H5,_,H6,H5,300,_,H3,H3,0,H6,H5,_,H6,H5,_,H6,H5,700,300,H3,700,H2,0,H1,M6,700,300,
         H3,700,H2,0,H1,300,M6,700,H1,H1,_,_,_,_,_,
         H1,H2,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H3,0,H6,H5,300,_,0,H6,H5,300,_,0,H6,H5,300,_,0,H2,H3,300,H2,0,H1,M6,300,_,0,H1,H1,300,H2,0,H1,300,M6,700,0,_,300,H1,700,H3,_,0,H3,H4,H3,H2,H3,300,H2,700,
         H1,H2,H3,0,H6,H5,_,H6,H5,_,H6,H5,300,_,H3,H3,0,H6,H5,_,H6,H5,_,H6,H5,700,300,H3,700,H2,0,H1,M6,700,300,
         H3,700,H2,0,H1,300,M6,700,H1,H1,_,_,_,_,_,
         0,M6,300,H3,700,H2,0,H1,M6,700,300,H3,H2,700,300,0,H1,M6,300,700,H1,H1,_,_,_,_,_,_,_,
    };

    for (auto i : wind) {
        if (i == 0) { sleep = 175; continue; }
        if (i == 700) { Sleep(175); continue; }
        if (i == 300) { sleep = 350; continue; }
        if (i == _) {
            Sleep(350);
            continue;
        }
        // if (i == 900) volume += 100;
        voice = (volume << 16) + ((i) << 8) + 0x90;
        midiOutShortMsg(handle, voice);
        cout << voice << endl;
        Sleep(sleep);// midiOutShortMsg(handle, 0x7BB0);
    }
    midiOutClose(handle);
}

int main()
{
    Wind();
    return 0;
}

文章已获作者授权转载,版权归原作者所有,如有侵权,与本账号无关,可联系删除。 原文作者:爱喝兽奶的荒天帝

原文链接:https://zhang-xu.blog.csdn.net/article/details/137933624

在这里插入图片描述

;