clang:在 Win10 上编译 MIDI 音乐程序(一)

先从 Microsoft C++ Build Tools - Visual Studio

下载 1.73GB 安装 "Microsoft C++ Build Tools“

访问 Swift.org - Download Swift
找到 Windows 10:x86_64
下载 swift-5.10-RELEASE-windows10.exe  大约490MB
建议安装在 D:\Swift\ ,安装后大约占2.56GB

简单来说,Clang是一个编译器,目前用来编译C、C++、Objective-C语言。

where clang
D:\Swift\Toolchains\5.10.0+Asserts\usr\bin\clang.exe

cd D:\Swift\testc

短笛伴奏《荒天帝》的专属bgm《我曾爱过一个人》,编辑  huangtiandi.cpp  如下

#include <iostream>
#include <windows.h>  
#include <mmsystem.h>
#pragma comment(lib,"winmm.lib")

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
{
    H1 = C4, H2 = D4, H3 = E4, H4 = F4, H5 = G4, H6 = A4, H7 = B4,
    J1 = C5, J2 = D5, J3 = E5, J4 = F5, J5 = G5, J6 = A5, J7 = B5,
    K1 = C6, K2 = D6, K3 = E6, K4 = F6, K5 = G6, K6 = A6, K7 = B6,
    L1 = C7, L2 = D7, L3 = E7, L4 = F7, L5 = G7, L6 = A7, L7 = B7,
};
// 《荒天帝》的专属bgm《我曾爱过一个人》
int htd[] = {
    J1,H7,J1,H6,J5,J6,J5,J2,J4,J3,J3,J2,J3,J2,J1,
    J1,H7,H6,H6,J6,J5,J2,J2,J4,J3,
    J1,H7,J1,H6,J5,J6,J5,J2,J4,J3,J3,J2,J3,J2,J1,
    J1,H7,H6,J2,J3,J2,J3,J5,H5,H6,
    J1,H7,J1,H6,J5,J6,J5,J2,J4,J3,J3,J2,J3,J2,J1,
    J1,H7,H6,H6,J6,J5,J2,J2,J4,J3,
    J1,H7,J1,H6,J5,J6,J5,J2,J4,J3,J3,J2,J3,J2,J1,
    J1,H7,H6,J3,J2,J5,H5,H6,
};
// 时长数组
int shichang[] = {
    250,250,250,500,250,250,500,250,250,250,250,250,125,125,500,
    250,250,500,250,250,250,250,250,250,1000,
    250,250,250,500,250,250,250,250,250,250,250,250,125,125,500,
    250,250,500,250,250,250,250,250,250,1000,
    250,250,250,500,250,250,250,250,250,250,250,250,125,125,500,
    250,250,500,250,250,250,250,250,250,1000,
    250,250,250,500,250,250,250,250,250,250,250,250,125,125,500,
    250,250,500,500,500,250,250,1250,
};
// 力度
int lidu[] = {
    1,0,0,2,0,0,1,1,0,2,2,0,0,0,1,
    0,0,2,0,0,1,1,0,0,2,
    1,0,0,2,0,0,1,1,0,2,2,0,0,0,1,
    0,0,2,0,0,1,1,0,0,2,
    1,0,0,2,0,0,1,1,0,2,2,0,0,0,1,
    0,0,2,0,0,1,1,0,0,2,
    1,0,0,2,0,0,1,1,0,2,2,0,0,0,1,
    0,0,2,0,1,1,0,0,
};
// 演奏 《我曾爱过一个人》
void huangtiandi()
{
    HMIDIOUT handle;
    midiOutOpen(&handle, 0, 0, 0, CALLBACK_NULL); // 打开midi设备
    midiOutShortMsg(handle, 72 << 8 | 0xC2); // 设置通道2的乐器为 短笛
    unsigned char sd = 0x90 | (2 & 0x0F); // statusByte: 0为声道
    unsigned short note = 0;    //音符编号
    unsigned short v = 120; // velocity 力度值,范围通常在0-127
     
    for (int i=0; i < 98; i++) {
        note = htd[i];
        if (lidu[i] ==0) v = 40;
        else if(lidu[i] ==1) v = 80;
        else if (lidu[i] ==2) v = 120;

        unsigned long noteOnMsg = (((unsigned long)v <<16) | (((unsigned long)note) <<8) | (unsigned long)sd);
        midiOutShortMsg(handle, noteOnMsg); // 发送MIDI消息
        Sleep(shichang[i]); // 停顿,给音节演奏的时间
        midiOutShortMsg(handle, 0x7BB2); // 停止通道2上的演奏
    }
    midiOutShortMsg(handle, 0x7BB2); // 停止通道2上的演奏
    midiOutClose(handle); // 关闭midi设备
}

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

编译  clang huangtiandi.cpp -o huangtiandi.exe

运行  huangtiandi.exe

详细参阅:《荒天帝》专属BGM——midi笛子音乐谱曲


钢琴伴奏《起风了》,编写  qifengle.cpp  如下

#include <iostream>
#include <windows.h>  
#include <mmsystem.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 // F大调
{
    H1 = F2, H2 = G2, H3 = A2, H4 = B2, H5 = C3, H6 = D3, H7 = E3,
    J1 = F3, J2 = G3, J3 = A3, J4 = B3, J5 = C4, J6 = D4, J7 = E4,
    K1 = F4, K2 = G4, K3 = A4, K4 = B4, K5 = C5, K6 = D5, K7 = E5,
    L1 = F5, L2 = G5, L3 = A5, L4 = B5, L5 = C6, L6 = D6, L7 = E6,
    LOW_SPEED = 500, MIDDLE_SPEED = 400, HIGH_SPEED = 300,
    _ = 0//XFF
};
// 歌词
char geci[58][40] = {
    "这一路上走走停停",
    "顺着少年漂流的痕迹",
    "迈出车站的前一刻",
    "竟有些犹豫",
    "不禁笑这近乡情怯",
    "仍无可避免",
    "而长野的天",
    "依旧那么暖",
    "风吹起了从前\n",
    "从前初识这世间 万般流连",
    "看着天边似在眼前",
    "也甘愿赴汤蹈火去走它一遍",
    "如今走过这世间 万般流连",
    "翻过岁月不同侧脸",
    "措不及防闯入你的笑颜\n",
    "我曾难自拔于世界之大",
    "也沉溺于其中梦话",
    "不得真假 不做挣扎 不惧笑话",
    "我曾将青春翻涌成她",
    "也曾指尖弹出盛夏",
    "心之所动 且就随缘去吧",
    "逆着光行走 任风吹雨打", 
    "",
    "短短的路走走停停",
    "也有了几分的距离",
    "不知抚摸的是故事", 
    "还是段心情",
    "也许期待的不过是", 
    "与时间为敌",
    "再次看到你",
    "微凉晨光里",
    "笑得很甜蜜\n",
    "从前初识这世间 万般流连",
    "看着天边似在眼前",
    "也甘愿赴汤蹈火去走它一遍",
    "如今走过这世间 万般流连",
    "翻过岁月不同侧脸",
    "措不及防闯入你的笑颜\n",
    "我曾难自拔于世界之大",
    "也沉溺于其中梦话",
    "不得真假 不做挣扎 不惧笑话",
    "我曾将青春翻涌成她",
    "也曾指尖弹出盛夏",
    "心之所动 且就随缘去吧",
    "",
    "晚风吹起你鬓间的白发",
    "抚平回忆留下的疤",
    "你的眼中 明暗交杂 一笑生花",
    "暮色遮住你蹒跚的步伐",
    "走进床头藏起的画",
    "画中的你 低着头说话\n",
    "我仍感叹于世界之大",
    "也沉醉于儿时情话",
    "不剩真假 不做挣扎 无谓笑话\n" ,
    "我终将青春还给了她",
    "连同指尖弹出的盛夏",
    "心之所动 就随风去了",
    "以爱之名 你还愿意吗\n" 
};
// 歌曲《起风了》The Wind Rises
int qfl[] = {
    H7,J1,J2,J3, _,H5,J5,J3,J3, _, _, _,H7, _, _, _,
    H7,J1,J2,J3, _,H5,J5,J3,J2,J3,J1,J2,H7,J1,H5, _,
    H7,J1,J2,J3, _,H5,J5,J3,J3, _, _, _,H7, _, _, _,
    H7,J1,J2,J3, _,H5,J5,J3,J2,J3,J1,J2,H7,J1,H5, _,
    J7,K1,K2,K3, _,J5,K5,K3,K3, _, _, _,
    J7,K1,K2,K3, _,J5,K5,K3,K2,K3,K1,K2,J7,K1,J5, _,
    J7,K1,K2,K3, _,J5,K5,K3,K3, _, _, _, _, 
    K6,K3,K2,J6,J3,H6,J2,J3,H6, _, _, _,9, // 前奏
    J2, _, _,J1,J2, _,J1,J2, _,J3, _,J5, _,J3, _,9, // 这一路上走走停停
    J2, _, _,J1,J2, _,J1,J2,J3,J2,J1,H6, _, _, _,9, // 顺着少年漂流的痕迹
    J2, _, _,J1,J2, _,J1,J2, _,J3, _,J5, _,J3, _,9, // 迈出车站的前一刻
    J2, _, _,J3,J2, _,J1,J2,J2, _, _, _,9, // 竟有些犹豫
    J2, _, _,J1,J2, _,J1,J2, _,J3, _,J5, _,J3, _,9, // 不禁笑这近乡情怯
    J2, _, _,J3,J2, _,J1, _,H6, _, _, _,9, // 仍无可避免
    J3,J2,J1,J2,J1, _, _, _,9, // 而长野的天
    J3,J2,J1,J2,J1, _, _, _,9, // 依旧那么暖
    H5,J3,J2,J1,J2, _,J1, _, _, _, _, _,9, // 风吹起了从前
    J1, _,J2, _,J3, _,J1, _,J6, _,J5,J6, _, _,J2,J7, _,J6,J7, _, _,9, // 从前初识这世间 万般流连
    J7, _,J6,J7, _,J3, _,K1,K2,K1,J7,J6, _, _,9, // 看着天边似在眼前
    J5, _,J6, _,J5,J6,J5,J6,J5,J6, _,J5,J2, _,J5, _,J3, _, _, _,9, // 也甘愿赴汤蹈火去走它一遍
    J1, _,J2, _,J3, _,J1, _,J6, _,J5,J6, _, _,J2,J7, _,J6,J7, _, _,9, // 如今走过这世间 万般流连
    J7, _,J6,J7, _,J3, _,K1,K2,K1,J7,J6, _, _,9, // 翻过岁月不同侧脸
    J5, _,J6, _,K3,K3, _,J5, _,J6, _,K3,K3, _,J5,J6, _,J6, _, _, _,9, // 措不及防闯入你的笑颜
    K1, _,K2, _,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K2, _, _,9, // 我曾难自拔于世界之大
    K2,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K3, _, _,9, // 也沉溺于其中梦话
    K2,K1,K1,J6, _,K1, _,K1,K2, _,K1,J6, _,K1,K1, _,K3, _,K3,K2,K3, _,K2, _, _,9, // 不得真假 不做挣扎 不惧笑话
    K1, _,K2, _,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K2, _, _,9, // 我曾将青春翻涌成她
                K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K3, _, _,9, // 也曾指尖弹出盛夏
    K3,K2,K2,K1, _,J6, _,K3, _,K2, _,K1,J6, _,K1, _,K1, _, _, _,9, // 心之所动 且就随缘去吧
    J6, _,K3, _,K2, _,K1,J6, _,K3, _,K2, _,K1,J6, _,K1, _,K1, _, _, _, _, _,9, // 逆着光行走 任风吹雨打
    J7,K1,K2,K3, _,J5,K5,K3,K3, _, _, _,
    J7,K1,K2,K3, _,J5,K5,K3,K2,K3,K1,K2,J7,K1,J5, _,
    J7,K1,K2,K3, _,J5,K5,K3,K3, _, _, _, _,
    K6,K3,K2,J6,J3,H6,J2,J3,H6, _, _, _,9, // 间奏1
    J2, _, _,J1,J2, _,J1,J2, _,J3, _,J5, _,J3, _,9, // 短短的路走走停停
    J2, _, _,J1,J2, _,J1,J2,J3,J2,J1,H6, _, _, _,9, // 也有了几分的距离
    J2, _, _,J1,J2, _,J1,J2, _,J3, _,J5, _,J3, _,9, // 不知抚摸的是故事
    J2, _, _,J3,J2, _,J1,J2,J2, _, _, _,9, // 还是段心情
    J2, _, _,J1,J2, _,J1,J2, _,J3, _,J5, _,J3, _,9, // 也许期待的不过是
    J2, _, _,J3,J2, _,J1, _,H6, _, _, _,9, // 与时间为敌
    J3,J2,J1,J2,J1, _, _, _,9, // 再次看到你
    J3,J2,J1,J2,J1, _, _, _,9, // 微凉晨光里
    H5,J3,J2,J1,J2, _,J1, _, _, _, _, _,9, // 笑得很甜蜜
    J1, _,J2, _,J3, _,J1, _,J6, _,J5,J6, _, _,J2,J7, _,J6,J7, _, _,9, // 从前初识这世间 万般流连
    J7, _,J6,J7, _,J3, _,K1,K2,K1,J7,J6, _, _,9, // 看着天边似在眼前
    J5, _,J6, _,J5,J6,J5,J6,J5,J6, _,J5,J2, _,J5, _,J3, _, _, _,9, // 也甘愿赴汤蹈火去走它一遍
    J1, _,J2, _,J3, _,J1, _,J6, _,J5,J6, _, _,J2,J7, _,J6,J7, _, _,9, // 如今走过这世间 万般流连
    J7, _,J6,J7, _,J3, _,K1,K2,K1,J7,J6, _, _,9, // 翻过岁月不同侧脸
    J5, _,J6, _,K3,K3, _,J5, _,J6, _,K3,K3, _,J5,J6, _,J6, _, _, _,9, // 措不及防闯入你的笑颜
    K1, _,K2, _,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K2, _, _,9, // 我曾难自拔于世界之大
    K2,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K3, _, _,9, // 也沉溺于其中梦话
    K2,K1,K1,J6, _,K1, _,K1,K2, _,K1,J6, _,K1,K1, _,K3, _,K3,K2,K3, _,K2, _, _,9, // 不得真假 不做挣扎 不惧笑话
    K1, _,K2, _,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K2, _, _,9, // 我曾将青春翻涌成她
                K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K3, _, _,9, // 也曾指尖弹出盛夏
    K3,K2,K2,K1, _,J6, _,K3, _,K2, _,K1,J6, _,K1, _,K1, _, _, _, _, _,9, // 心之所动 且就随缘去吧
    K3,J2,K5,K3,K2,K3,K1,K2,J7,K1,J5, _,
    J7,K1,K2,K3, _,J3,K5,K3, _, _, _, _,
    J7,K1,K2,K3, _,J3,K5,K3, _, _, _, _,
    K2, _,H7, _,J6,K5, _,J5,K6, _, _,K1,K3,J6,K6,K5,K2, _, _, _,
    K2, _,H7, _,J4,K7, _,J7, _,K4,K7, _,J7, _,K4,K7, _,K6,K4, _,
    H1, _,K6, _,J5, _,K5, _,J4, _,K4, _,K3, _,K2, _,K1, _,
    K7,_, _, _,K7,_, _, _,K7,_, _, _,K7,_, _, _,9, // 间奏2
    K1, _,K2, _,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K2, _, _,9, // 晚风吹起你鬓间的白发
             K2,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K3, _, _,9, // 抚平回忆留下的疤
    K2,K1,K1,J6, _,K1, _,K1,K2, _,K1,J6, _,K1,K1, _,K3, _,K3,K2,K3, _,K2, _, _,9, // 你的眼中 明暗交杂 一笑生花
    K1, _,K2, _,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K2, _, _,9, // 暮色遮住你蹒跚的步伐
    K2,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K3, _, _,9, // 走进床头藏起的画
    K3,K2,K2,K1, _,J6, _,K3, _,K2, _,K1,J6, _,K1, _,K1, _, _, _, _, _, _,9, // 画中的你 低着头说话
    K1, _,K2, _,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K2, _, _,9, // 我仍感叹于世界之大
             K2,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K3, _, _,9, // 也沉醉于儿时情话
    K2,K1,K1,J6, _,K1, _,K1,K2, _,K1,J6, _,K1,K1, _,K3, _,K3,K2,K3, _,K2, _, _,9, // 不剩真假 不做挣扎 无谓笑话
    K1, _,K2, _,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K2, _, _,9, // 我终将青春还给了她
             K2,K3, _,K6,K5, _,K6,K5, _,K6,K5, _,K3, _, _,9, // 连同指尖弹出的盛夏
    K3,K2,K2,K1, _,J6, _,K3, _,K2, _,K1,J6, _,K1, _,K1, _, _, _,9, // 心之所动 就随风去了
    J6, _,K3, _,K2, _,K1,J6, _,K3, _,K2, _,K1,J6, _,K1, _,K1, _, _, _, _, _, // 以爱之名 你还愿意吗
};
// 用C++演奏歌曲《起风了》The Wind Rises
void qifengle()
{
    HMIDIOUT handle;
    midiOutOpen(&handle, 0, 0, 0, CALLBACK_NULL);
    midiOutShortMsg(handle, 0 << 8 | 0xC0); // 设置通道0的乐器为 大钢琴
    unsigned short note = 0;    // 音符编号
    unsigned short v = 100; // velocity 力度值,范围通常在0-127
    unsigned char sd = 0x90 | (0 & 0x0F);// statusByte: 0为声道
    int c = 0;
    for (int i=0; i < 1280; i++) {
        if (qfl[i] == 9)
        {
            cout << geci[c] << endl;
            c++;
        }
        else {
            Sleep(175);
            if (qfl[i]=='_') Sleep(110);
            else note = qfl[i];
        }
        // 组合3个字节的消息到一个DWORD值
        unsigned long noteOnMsg = (((unsigned long)v <<16) | (((unsigned long)note) <<8) | (unsigned long)sd);
        // 发送MIDI消息
        midiOutShortMsg(handle, noteOnMsg);
    }
    midiOutClose(handle);
}

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

编译  clang qifengle.cpp -o qifengle.exe 

运行 chcp 65001

运行 qifengle.exe

详细参阅:C语言midi编程钢琴演奏


钢琴伴奏《夏天》,编辑  Summer.cpp  如下

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

/*
 midi参数: 音量<<16 + 声调<<8 + 乐器类型
 音量范围: 0x0-0x7f
 乐器范围: 0x90-0x9f 其中0x99为鼓类,其余皆为钢琴
 音阶范围: 0x0-7f 以下为中音的音调16进制参数对照表
 (注意:以下数据仅为本人通过自己乐感来测试得出的,不一定正确,仅供参考)
 Do:0x3c Re:0x3e Mi:0x40 Fa:0x41 So:0x43 La:0x45 Xi:0x47 Do+1:0x48
*/
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
{
	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
};

int summer[] = {
	H1,_,M5,M1,H1,H2,M3,_,H5,_,H1,H2,_,H3,_,H1,H2,_,H3,_,
	H1,_,M5,M1,H1,H2,M3,_,H5,_,H2,H2,_,H3,_,H2,H3,_,H3,_,
	H3,H2,H1,_,H1,M5,M6,M3,M5,_,H3,H2,H1,_,H1,M5,M6,M3,M5,_,
	H3,H2,H2,_,H2,H1,M7,_,M6,M7,M5,M6,_,_,
	M6,M5,M6,_,
	M5,H1,H2,H5,M5,H1,H2,M5,H5,_,
	M5,H1,H2,M5,H5,M5,H1,M5,H2,M5,H5,_,
	M5,H1,H2,H5,M5,H1,H2,M5,H5,_,
	M5,H1,H2,H5,M5,H1,M5,H2,M5,H5,_,

	H1,_,M5,M1,H1,H2,M5,H3,_,H5,M5,H2,H2,_,H3,_,H1,H2,_,H3,_,
	H1,_,M5,M1,H1,H2,M5,H3,_,H5,_,H2,H2,_,H3,_,H2,M3,_,H3,_,
	H3,H2,M3,H1,_,H1,M5,M6,M3,M5,_,H3,H2,M3,H1,_,H1,M5,M6,M3,M5,_,
	H3,H2,H2,_,H2,H1,M7,_,M6,M7,M5,M6,_,_,_,

};

void Summer() {
	HMIDIOUT handle;
	midiOutOpen(&handle, 0, 0, 0, CALLBACK_NULL);
	int volume = 0x7f;
	int voice = 0x0;
	int s = 300; // sleep 毫秒

	for (auto i : summer) {
		if (i == LOW_SPEED || i == HIGH_SPEED || i == MIDDLE_SPEED) {
			s = i;
			continue;
		}
		if (i == _) {
			Sleep(300);
			continue;
		}
		voice = (volume << 16) + (i << 8) + 0x94;
		cout << hex << voice << endl; // 输出16进制
		midiOutShortMsg(handle, voice);
		Sleep(s);
	}
	midiOutClose(handle);
}

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

编译  clang Summer.cpp -o Summer.exe
运行  Summer.exe

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/595401.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

02 Activiti 7:环境

02 Activiti 7&#xff1a;环境 1. 开发环境2. 流程设计器2.1. 在线安装2.2. 离线安装2.3. 中文乱码 3. 数据库 1. 开发环境 这是我本地开发环境 软件版本Jdk17Mysql8.0.36tomcat10.1.23IDEA2024.1Activiti7.0 2. 流程设计器 2.1. 在线安装 在 Plugins 搜索 activiti &…

【数据结构】初识数据结构

引入&#xff1a; 哈喽大家好&#xff0c;我是野生的编程萌新&#xff0c;首先感谢大家的观看。数据结构的学习者大多有这样的想法&#xff1a;数据结构很重要&#xff0c;一定要学好&#xff0c;但数据结构比较抽象&#xff0c;有些算法理解起来很困难&#xff0c;学的很累。我…

图题目:最大网络秩

文章目录 题目标题和出处难度题目描述要求示例数据范围 解法思路和算法代码复杂度分析 题目 标题和出处 标题&#xff1a;最大网络秩 出处&#xff1a;1615. 最大网络秩 难度 4 级 题目描述 要求 由 n \texttt{n} n 座城市和一些连接这些城市的道路 roads \texttt{ro…

测径仪视窗镜片的维护和保养步骤

关键字:测径仪镜片,测径仪保养,测径仪维护,视窗镜片维护,视窗镜片擦拭保养,视窗镜片的检查, 视窗镜片定期保养 视窗镜片是保护光学镜头免受污染和损伤的光学平镜片&#xff0c;它的污染和破损会直接影响光学系统的测量结果。 视窗镜片一般在受到轻微污染&#xff08;指镜片上…

机器学习之SMOTE重采样--解决样本标签不均匀问题

一、SMOTE原理 通常在处理分类问题中数据不平衡类别。使用SMOTE算法对其中的少数类别进行过采样&#xff0c;以使其与多数类别的样本数量相当或更接近。SMOTE的全称是Synthetic Minority Over-Sampling Technique 即“人工少数类过采样法”&#xff0c;非直接对少数类进行重采…

.[[MyFile@waifu.club]].svh勒索病毒数据库恢复方案

.[[MyFilewaifu.club]].svh勒索病毒有什么特点&#xff1f; .[[MyFilewaifu.club]].svh是一种最近多发的勒索病毒&#xff0c;它通过加密受害者的文件并要求支付赎金来解锁&#xff0c;从而达到勒索钱财的目的。恢复重要数据请添加技术服务号(safe130)。以下是关于这种病毒的详…

如何压缩word文档的大小?6个方法教你方便的压缩word文档

如何压缩word文档的大小&#xff1f;6个方法教你方便的压缩word文档 以下是六个常用的软件和方法&#xff0c;可以帮助您方便地压缩Word文档大小&#xff1a; 使用Microsoft Word内置功能&#xff1a; 在Microsoft Word中&#xff0c;您可以使用内置的压缩功能来减小文档的大…

导数和偏导数练习

导数题目列表 偏导数题目列表 这里是上述50个导数和偏导数练习题的答案&#xff1a; 导数答案列表 偏导数答案列表 更多问题咨询 Cos机器人

Linux CPU 飙升 排查五步法

排查思路-五步法 1. top命令定位应用进程pid 找到最耗时的CPU的进程pid top2. top-Hp[pid]定位应用进程对应的线程tid 找到最消耗CPU的线程ID // 执行 top -Hp [pid] 定位应用进程对应的线程 tid // 按shift p 组合键&#xff0c;按照CPU占用率排序 > top -Hp 111683.…

纯血鸿蒙APP实战开发——短视频切换实现案例

短视频切换实现案例 介绍 短视频切换在应用开发中是一种常见场景&#xff0c;上下滑动可以切换视频&#xff0c;十分方便。本模块基于Swiper组件和Video组件实现短视频切换功能。 效果图预览 使用说明 上下滑动可以切换视频。点击屏幕暂停视频&#xff0c;再次点击继续播放…

安卓跑马灯效果

跑马灯效果 当一行文本的内容太多&#xff0c;导致无法全部显示&#xff0c;也不想分行展示时&#xff0c;只能让文字从左向右滚动显示&#xff0c;类 似于跑马灯。电视在播报突发新闻时经常在屏幕下方轮播消息文字&#xff0c;比如“ 快讯&#xff1a;我国选手 *** 在刚刚结束…

我独自升级崛起游戏账号登录注册教程 (5.8最新版)

新韩漫公司所发布的这项动作游戏已向玩家们敞开大门&#xff0c;为大家带来了前所未有的游戏体验和乐趣。这个游戏内包含了大量令人着迷的故事、令人印象深刻的战斗场景以及丰富多样的娱乐元素。在这其中最为引人注目的一点就是游戏内容中融入了“虚拟角色”的元素&#xff0c;…

使用PyQt5设计系统登录界面—了解界面布局

前言&#xff1a;自学的过程中充分认识到网络搜索的重要性&#xff0c;有时候一篇通俗易懂的文章会让我这种入门级的小白更易上手&#xff0c;俗话说“开头难&#xff0c;难开头”&#xff0c;只要开了一个好头就不怕知难而退。 如何安装QT Designer界面设计所需要的环境 1. 如…

华为手机连接电脑后电脑无反应、检测不到设备的解决方法

本文介绍华为手机与任意品牌电脑连接时&#xff0c;出现连接后电脑无反应、检测不到手机连接情况的解决方法。 最近&#xff0c;因为手机的存储空间愈发紧缺&#xff0c;所以希望在非华为电脑中&#xff0c;将华为手机内的照片、视频等大文件备份、整理一下。因此&#xff0c;需…

2024年化学材料、清洁能源与生物技术国际学术会议(ICCMCEB2024)

2024年化学材料、清洁能源与生物技术国际学术会议(ICCMCEB2024) 会议简介 2024国际化学材料、清洁能源和生物技术大会&#xff08;ICCMCEB2024&#xff09;将在长沙隆重举行。本次会议旨在汇聚来自世界各地的化学材料、清洁能源和生物技术领域的专家学者&#xff0c;共同探…

vue管理系统导航中添加新的iconfont的图标

1.在官网上将需要的图标&#xff0c;加入项目中&#xff0c;下载 2.下载的压缩包中&#xff0c;可以选择这两个&#xff0c;复制到项目目录中 3.如果和之前的iconfont有重复&#xff0c;那么就重新命名 4.将这里的.ttf文件&#xff0c;也重命名为自己的 5.在main文件中导入 6.在…

3W 3KVDC 隔离单输出 DC/DC 电源模块——TPG-3W 系列

TPG-3W系列是一款额定功率为3W的隔离产品&#xff0c;国际标准引脚&#xff0c;宽范围工作、温度–40℃ 到 105℃&#xff0c;在此温度范围内都可以稳定输出3W&#xff0c;并且效率非常高&#xff0c;高达88%&#xff0c;同时负载调整率非常低&#xff0c;对于有输出电压精度有…

音频可视化:原生音频API为前端带来的全新可能!

音频API是一组提供给网页开发者的接口&#xff0c;允许他们直接在浏览器中处理音频内容。这些API使得在不依赖任何外部插件的情况下操作和控制音频成为可能。 Web Audio API 可以进行音频的播放、处理、合成以及分析等操作。借助于这些工具&#xff0c;开发者可以实现自定义的音…

MySQL使用GROUP BY使用技巧和注意事项总结

⛰️个人主页: 蒾酒 &#x1f525;系列专栏&#xff1a;《mysql经验总结》 目录 写在前面 GROUP BY简介 基本用法 单列分组 多列分组 使用聚合函数 过滤分组结果 按表达式分组 使用 GROUP BY 的排序 注意事项 遵循原则 使用能够唯一标识每个分组的字段或字…

PCB 阻抗设置

凡亿电路有详细的阻抗设计 https://baijiahao.baidu.com/s?id1773006310888936808&wfrspider&forpc 差分基本上是100ohm, 单端是50ohm 布线阻抗通常是&#xff0c; -设置叠层关系 层的定义设计原则&#xff1a; 1&#xff09;主芯片相临层为地平面&#xff0c;提供器…