在 OS X、C++ 中播放 MIDI

发布于 2024-08-22 09:55:04 字数 286 浏览 3 评论 0原文

如何从 C++ 程序发送 MIDI 消息并让它们播放通用 MIDI 库中的声音?

我环顾四周,似乎没有一个简单的答案,在阅读了有关 CoreMIDI 之类的长篇手册后,我的大脑开始融化。

我有一个简单的 C++ 游戏/合成器项目,我想做的就是,例如,当这个球击中地板时,触发大钢琴库中的 C4。我对程序的大部分内容都满意,但到目前为止,完整的 MIDI 部分对我来说是完全不透明的。

我想使用 CoreMIDI,因为它看起来可能是最简单的,但多平台的东西会是一个额外的好处。

非常感谢您的帮助!

How can I send MIDI messages out from a C++ program and have them play the sound from the General MIDI bank?

I've looked around and there doesn't seem to be a simple answer, and my brain starts to melt after reading long manuals about CoreMIDI and things like that.

I have a simple C++ game/synthesizer project, and all I want to do is, for example, when this ball hits the floor, trigger a C4 from the Grand Piano bank. I'm fine with the majority of the program, but the integral MIDI part has so far been utterly opaque to me.

I'd like to use CoreMIDI, because it seems like it might be simplest, but something multi-platform would be a bonus.

Thank you very much for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慕烟庭风 2024-08-29 09:55:04

另一个选择是 rtmidi

它的目标是简单且跨平台,

我使用过类似的rtaudio用于实时音频I/O,并且相对容易使用。

您应该能够使用示例代码列出所有 MIDI 设备,然后选择 GM 库,并在使用程序更改消息选择钢琴后发送相应的 MIDI 消息(音符开/关消息)。维基百科有一个帮助页面来入门

Another option would be rtmidi

It's aimed to be simple and crossplatform

I've used the similar rtaudio for realtime audio i/o, and it was relatively easy to use.

You should be able to list all midi devices with the example code, then select the GM bank, and send the appropriate MIDI message (note on/off message), after you select the piano with a program change message. Wikipedia has a helpful page to get started

满天都是小星星 2024-08-29 09:55:04

我写了一个教程,可以帮助那些使用 CoreMIDI 遇到同样问题的人。它解释了如何读取 MIDI 文件并使用声音字体文件中的声音效果通过 AUGraph 输出。它还解释了如何使用虚拟端点实时访问 MIDI 消息。 此处

要执行您想要执行的操作,您可以修改我提供的示例项目,内容如下:

result = MusicDeviceMIDIEvent ([AUSampler], midiStatus, note, velocity, 0);

其中 AUSampler 是指向 AUSampler 的指针,即 AUGraph 中的起点。您可以使用以下命令发送要播放的 MIDI 音符,而不是从文件中读取。

I've written a tutorial which might help someone who comes across the same problem using CoreMIDI. It explains how to read a MIDI file and output the through an AUGraph using sound effects from a Sound Font file. It also explains how to use a virtual end point to get access to the midi messages in real-time. Here.

To do what you're looking to do you could modify the sample project I provide with the following:

result = MusicDeviceMIDIEvent ([AUSampler], midiStatus, note, velocity, 0);

Where AUSampler is a pointer to the AUSampler i.e. the start point in the AUGraph. Rather than reading from a file you could use the following command to send one MIDI note to be played.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文