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

news2024/11/15 2:10:09

先从 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

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

一文读懂Vue生命周期(Vue2)

一文读懂Vue生命周期&#xff08;Vue2&#xff09; 目录 一文读懂Vue生命周期&#xff08;Vue2&#xff09;1 前言2 Vue生命周期2.1 基本生命周期2.1.1 8个生命周期2.1.2 案例 2.2 组件生命周期2.2.1 父子生命周期2.2.2 案例 2.3 keep-alive生命周期2.3.1 案例 2.4 其他 3 总结…

【Linux 基础 IO】文件系统

文章目录 1.初步理解文件2. fopen ( )的详解 1.初步理解文件 &#x1f427;① 打开文件&#xff1a; 本质是进程打开文件&#xff1b; &#x1f427;②文件没有被打开的时候在哪里呢&#xff1f; ----- 在磁盘中&#xff1b; &#x1f427;③进程可以打开很多个文件吗&#xff…

鸿蒙内核源码分析(消息队列篇) | 进程间如何异步传递大数据

基本概念 队列又称消息队列&#xff0c;是一种常用于任务间通信的数据结构。队列接收来自任务或中断的不固定长度消息&#xff0c;并根据不同的接口确定传递的消息是否存放在队列空间中。 任务能够从队列里面读取消息&#xff0c;当队列中的消息为空时&#xff0c;挂起读取任务…

408数据结构-树与森林 自学知识点整理

前置知识&#xff1a;树的基本概念与性质 树的存储结构 树既可以采用顺序存储结构&#xff0c;又可采用链式存储结构。但无论采取哪种方式&#xff0c;都要求能够唯一地反映树中各结点之间的逻辑关系。 1. 双亲表示法 这种存储结构采用一组连续空间来存储每个结点&#xff0…

模拟电路设计与分析——电流

&#x1f3ac; 秋野酱&#xff1a;《个人主页》 &#x1f525; 个人专栏:《Java专栏》《Python专栏》 ⛺️心若有所向往,何惧道阻且长 文章目录 原子电流的产生电流的单位电流的方向直流电交流电直流&交流对比开路&闭路 原子 世界万物都是由原子构成&#xff0c;那么…

Pytorch实现图片异常检测

图片异常检测 异常检测指的是在正常的图片中找到异常的数据&#xff0c;由于无法通过规则进行识别判断&#xff0c;这样的应用场景通常都是需要人工进行识别&#xff0c;比如残次品的识别&#xff0c;图片异常识别模型的目标是可以代替或者辅助人工进行识别异常图片。 AnoGAN…

P8800 [蓝桥杯 2022 国 B] 卡牌

P8800 [蓝桥杯 2022 国 B] 卡牌 分析 “最多” -- 二分 1.二分区间&#xff08;凑齐的卡牌套数&#xff09;&#xff1a; l&#xff1a;a[]min&#xff1b;r&#xff1a;(a[]b[])max 2.check(x)&#xff1a; &#xff08;1&#xff09;for循环内&#xff1a; 判断x - a[i…

ComfyUI 基础教程(十三):ComfyUI-Impact-Pack 面部修复

SD的WebUI 中的面部修复神器 ADetailer,无法在ComfyUI 中使用。那么如何在ComfyUI中进行面部处理呢?ComfyUI 中也有几个面部修复功能,比如ComfyUI Impact Pack(FaceDetailer),以及换脸插件Reactor和IPAdapter。 ComfyUI-Impact-Pack 是一个功能强大的插件,专为 ComfyUI …

矩池云jupyter运行opengait代码 未完成版

文章目录 前言——矩池云的使用技巧1.切换源 一、下载数据集二、下载模型三、环境配置1.查看python、torch、torchvision版本2.查看一些包版本是否过高3.下载包 四、开始训练1.设置环境变量2.遇到的问题&#xff08;1&#xff09;torch.cuda.is_available()返回false&#xff0…

《第一行代码》第二版学习笔记(8)——网络技术

文章目录 一、Http1、HttpURLConnection2、OKHttp 二、解析JSON格式数据1、使用JSONObject2、使用GSON解析JSON数据 一、Http 1、HttpURLConnection public void run() {HttpURLConnection connection null;BufferedReader reader null;try {URL url new URL("http://…

springboot版本升级,及解决springsecurity漏洞问题

背景&#xff1a; 项目中要解决 Spring Security RegexRequestMatcher 认证绕过漏洞&#xff08;CVE-2022-22978&#xff09; 漏洞问题&#xff0c;并且需要将项目的版本整体升级到boot版本2.1.7&#xff0c;升级改造过程非常的痛苦&#xff0c;一方面对整个框架的代码不是很熟…

嵌入式复习重点

嵌入式系统有多种表现形式&#xff0c;包括计算机MCU、SOC片上系统、SOPC片上系统、GPU和FPGA等。 MCU(微控制器): 是最基本也是最常见的嵌入式系统形式,是集成了CPU、ROM、RAM、IO口、定时器、中断控制器等组件的单一芯片。MCU广泛用于电器电子产品的控制。SoC(系统片上芯片):…

vivado UltraScale 比特流设置

下表所示 UltraScale ™ 器件的器件配置设置可搭配 set_property <Setting> <Value> [current_design] Vivado 工具 Tcl 命令一起使用。

地下管线管网三维参数化建模软件MagicPipe3D V3.5

经纬管网建模系统MagicPipe3D&#xff08;www.magic3d.net&#xff09;自主安全可控&#xff0c;本地离线参数化构建三维管网模型&#xff08;管道、接头、附属物等&#xff09;&#xff0c;输出标准3DTiles、Obj等格式&#xff0c;支持Cesium、Unreal、Unity等引擎可视化查询分…

09_电子设计教程基础篇(电阻)

文章目录 前言一、电阻原理二、电阻种类1.固定电阻1、材料工艺1、线绕电阻2、非线绕电阻1、实心电阻1、有机实心电阻2、无机实心电阻 2、薄膜电阻&#xff08;常用&#xff09;1、碳膜电阻2、合成碳膜电阻3、金属膜电阻4、金属氧化膜电阻5、玻璃釉膜电阻 3、厚膜电阻&#xff0…

Jenkins 2.164.3 安装插件(当前官网正式版本: 2.440.3 LTS)

Jenkins 2.164.3安装插件 1. 安装jenkins1.1 宿主机安装1.2 docker安装(linux) 2. 登录jenkins3. 修改配置文件 这篇文章如果放在5、6年前写出来毫无意义&#xff0c;因为安装2.164.3之后&#xff0c;推荐的插件即可自动安装。但是在2024年&#xff0c;当前正式版本是2.440.3 L…

武汉星起航:跨境电商行业领航者,一站式孵化服务引领全球趋势

在全球化日益深入的今天&#xff0c;跨境电商作为连接各国市场的桥梁&#xff0c;其重要性日益凸显。在这一潮流中&#xff0c;武汉星起航电子商务有限公司以其前瞻性的战略眼光和丰富的运营经验&#xff0c;迅速崛起为跨境电商行业的领军者。公司不仅自营亚马逊跨境电商业务&a…

echarts柱状图实现左右横向对比

实现效果如上图 其实是两组数据&#xff0c;其中一组数据改为负数&#xff0c;然后 在展示的时候&#xff0c;在将负数取反 第一处修改坐标轴 xAxis: [{type: value,axisLabel: {formatter: function (value) {if (value < 0) {return -value;}else{return value;}}}}], 第…

书客大路灯Sun自掀起护眼新浪潮以来,纷纷直呼“真香现场”

随着科技时代与人们生活水平需求的日益增长&#xff0c;加上网课学习和居家办公的普及&#xff0c;各大灯具厂商都开始搭建起自家的生态&#xff0c;尤其是大路灯这个以外不被重视的品类&#xff0c;也开始找到了自身的定位与价值。 尤其在2024年上半年发布的——SUKER书客护眼…

截取字符串的3种方法

一、截取字符串的实现 在C语言中&#xff0c;没有直接截取字符串的库函数&#xff0c;但是咱们可以借助其他函数实现这个功能。 1&#xff0e;最简单的方法 如果只是直接输出一个字符串的子串&#xff0c;只需要一个简单的printf函数即可。 #include <stdio.h> int m…