在C 项目中使用(OSX)Core MIDI
Using (OSX) Core MIDI in a c++ project
这是核心MIDI的(目标C)文档:https://developer.apple.com/documentation/coremidi
我如何了解我能够在C 项目中使用它的期望?
(我猜一个更基本的问题也是:可以在C 项目中使用Core Midi? - 但是我已经看到了其他stackoverflow问题要成为"是"(然后,那是几年前...])
)我需要做些什么才能使此设置 - 到可以开始使用API的地步?该文档并不是显示使用了哪些框架,需要哪些标头文件等等。
...那么,开始的步骤是什么?
理想情况下,我希望能够从简单的makefile中编译。
大多数Coremidi API都是旧的。
(Apple文档在" Swift"answers" Objective-C"之间有一种语言,但不要从字面上看" Objective-C"。这确实是指" C家族,C或Objective-C"。切换Swift向您显示了相同的API,但以Swift可见的翻译形式。)
具体来说,请参见Coremidi/Midiservices.H。
实际上是C 的最古老,最简单的Coremidi样品代码" echo.cpp"。它读取所有来源的MIDI输入,并将该MIDI数据发送到第一个可用目的地(在频道1上)。这很粗糙,但是您必须从某个地方开始。
编译:
clang Echo.cpp -framework CoreMIDI -framework CoreFoundation -o Echo
代码:
/* Copyright © 2007 Apple Inc. All Rights Reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by
Apple Inc. ("Apple") in consideration of your agreement to the
following terms, and your use, installation, modification or
redistribution of this Apple software constitutes acceptance of these
terms. If you do not agree with these terms, please do not use,
install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc.
may be used to endorse or promote products derived from the Apple
Software without specific prior written permission from Apple. Except
as expressly stated in this notice, no other rights or licenses, express
or implied, are granted by Apple herein, including but not limited to
any patent rights that may be infringed by your derivative works or by
other works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <CoreMIDI/MIDIServices.h>
#include <CoreFoundation/CFRunLoop.h>
#include <stdio.h>
// ___________________________________________________________________________________________
// test program to echo MIDI In to Out
// ___________________________________________________________________________________________
MIDIPortRef gOutPort = NULL;
MIDIEndpointRef gDest = NULL;
int gChannel = 0;
static void MyReadProc(const MIDIPacketList *pktlist, void *refCon, void *connRefCon)
{
if (gOutPort != NULL && gDest != NULL) {
MIDIPacket *packet = (MIDIPacket *)pktlist->packet; // remove const (!)
for (unsigned int j = 0; j < pktlist->numPackets; ++j) {
for (int i = 0; i < packet->length; ++i) {
// printf("%02X ", packet->data[i]);
// rechannelize status bytes
if (packet->data[i] >= 0x80 && packet->data[i] < 0xF0)
packet->data[i] = (packet->data[i] & 0xF0) | gChannel;
}
// printf("n");
packet = MIDIPacketNext(packet);
}
MIDISend(gOutPort, gDest, pktlist);
}
}
int main(int argc, char *argv[])
{
if (argc >= 2) {
// first argument, if present, is the MIDI channel number to echo to (1-16)
sscanf(argv[1], "%d", &gChannel);
if (gChannel < 1) gChannel = 1;
else if (gChannel > 16) gChannel = 16;
--gChannel; // convert to 0-15
}
// create client and ports
MIDIClientRef client = NULL;
MIDIClientCreate(CFSTR("MIDI Echo"), NULL, NULL, &client);
MIDIPortRef inPort = NULL;
MIDIInputPortCreate(client, CFSTR("Input port"), MyReadProc, NULL, &inPort);
MIDIOutputPortCreate(client, CFSTR("Output port"), &gOutPort);
// enumerate devices (not really related to purpose of the echo program
// but shows how to get information about devices)
int i, n;
CFStringRef pname, pmanuf, pmodel;
char name[64], manuf[64], model[64];
n = MIDIGetNumberOfDevices();
for (i = 0; i < n; ++i) {
MIDIDeviceRef dev = MIDIGetDevice(i);
MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &pname);
MIDIObjectGetStringProperty(dev, kMIDIPropertyManufacturer, &pmanuf);
MIDIObjectGetStringProperty(dev, kMIDIPropertyModel, &pmodel);
CFStringGetCString(pname, name, sizeof(name), 0);
CFStringGetCString(pmanuf, manuf, sizeof(manuf), 0);
CFStringGetCString(pmodel, model, sizeof(model), 0);
CFRelease(pname);
CFRelease(pmanuf);
CFRelease(pmodel);
printf("name=%s, manuf=%s, model=%sn", name, manuf, model);
}
// open connections from all sources
n = MIDIGetNumberOfSources();
printf("%d sourcesn", n);
for (i = 0; i < n; ++i) {
MIDIEndpointRef src = MIDIGetSource(i);
MIDIPortConnectSource(inPort, src, NULL);
}
// find the first destination
n = MIDIGetNumberOfDestinations();
if (n > 0)
gDest = MIDIGetDestination(0);
if (gDest != NULL) {
MIDIObjectGetStringProperty(gDest, kMIDIPropertyName, &pname);
CFStringGetCString(pname, name, sizeof(name), 0);
CFRelease(pname);
printf("Echoing to channel %d of %sn", gChannel + 1, name);
} else {
printf("No MIDI destinations presentn");
}
CFRunLoopRun();
// run until aborted with control-C
return 0;
}
相关文章:
- OSX MetalKit CVMetalTextureCacheCreateTextureFromImage失败,状态:
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- C++包含来自 #include "DevEngine/Core.h" 的错误
- OSX蓝牙打开RFCOMMChannelAsync声称已连接,但未建立连接,并且从未调用过委托
- 在OSX上使用CMake将Adobe的XMP工具包构建为共享库的最简单方法是什么?
- C ++是否有C ++ 17 OSX 10.13.6的标志
- 是否可以在Linux上使用.Net Core 3.1创建C++/CLI代码的C#DLL
- 构建 TensorFlow r1.14 C++文件时缺少文件"tensorflow/core/framework/types.pb.h"
- 各种版本的 Mac OSX 向后兼容性如何?(Xcode C++
- 不要使用静态强制转换进行算术转换(cpp-core-guidelines)
- C++ DLL(不是 CLI)是否可以调用 .NET Core 3.0 委托?
- OSX clang++:用于 cpp 文件中显式实例化模板的体系结构x86_64的未定义符号
- C++/CLI targetting .NET Core 3.1
- 同时使用Opengl CORE函数以及Comptability Profile - GLFW
- 是否有可能构建面向Linux和Windows的.Net Core C++ / CLI应用程序?
- 在 OSX 上打开 SDL 窗口时不要打开终端窗口
- 如何在 OSX 10.15 中使用 Clang -Wno-nullability-completeness 选项编译整个
- 如何在OSX上导航到用户输入站点?
- 在C 项目中使用(OSX)Core MIDI
- Mac OSX:构建opencv_contrib致命错误:找不到文件 opencv2/core.hpp