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

2024-04-21 08:28:48 浏览数 (2)

一、运行效果

【C 的魅力】:用C 演奏歌曲《起风了》

二、代码实现
1. 引入部分
代码语言:javascript复制
#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. 枚举
代码语言:javascript复制
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
};
  1. enum Scale:这行代码声明了一个名为 Scale 的枚举类型。
  2. Rest = 0:定义了一个名为 Rest 的枚举项,它代表一个休止符(即在音乐中不发音的部分),赋值为0。
  3. C8 = 108, B7 = 107, …:这些行定义了一系列以音乐音阶中的音符命名的枚举项,每个音符后面紧跟一个整数值。这些值通常对应于MIDI音符编号,这是一种在 MIDI(音乐器数字接口) 消息中表示音符的标准方式。例如,C8 = 108 表示最高八度中的C音符。
  4. A7s = 106, A7 = 105:这里展示了一个音符的两种形式,A7s 表示A7的升半音(sharp),而 A7 表示标准的A7音符。在音乐理论中,升半音是指将音符的音高提高半音步。
  5. G7s = 104, G7 = 103, …:以相同的方式,定义了G7的升半音和标准版本。
  6. F7s = 102, F7 = 101, E7 = 100, …:继续定义了F7的升半音和标准版本,以及其他音符。
  7. D7s = 99, D7 = 98, …:以此类推,定义了D7的升半音和标准版本。
  8. C7s = 97, C7 = 96, …:定义了C7的升半音和标准版本。

  • 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音符,没有升半音或降半音。

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

  • 带有 s 的音符名称(如 A7s)表示该音符是升半音,即该音符和下一个音符之间的黑键。
  • 没有 s 的音符名称(如 A7)表示该音符是标准音高,没有升或降。
  • 音符名称后面的数字(如 C8 中的 8)表示该音符所在的八度。数字越大,音高越高。
3. 音色定义
代码语言:javascript复制
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,处于较高音区,用于模拟高音乐器,如小号或短笛。
4. 演奏速度定义
  1. LOW_SPEED:值为 500,表示一个较慢的演奏速度,单位可能是毫秒。在MIDI音乐中,这个值可能用来设置较长的音符间隔,以产生较慢的旋律或节奏。
  2. MIDDLE_SPEED:值为 400,表示中等速度,比 LOW_SPEED 稍快,用于设置适中的音符间隔。
  3. HIGH_SPEED:值为 300,表示一个较快的演奏速度,用于快速连续的音符,产生快速的旋律或节奏。
5. 特殊定义
  1. _:值为 0XFF,十六进制的255。在许多上下文中,这个值用作一个特殊的标记或作为“终止”或“静音”的指示。在MIDI上下文中,它表示一个特殊的控制指令,如终止当前音符的演奏。

具体作用

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

6. 模拟风声
代码语言:javascript复制
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输出设备,释放资源。

三、完整代码
代码语言:javascript复制
#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;
}

0 人点赞