如何读取 MIDI 脚踏控制器的初始状态? [英] How to read the initial state of a MIDI Foot Controller?

查看:58
本文介绍了如何读取 MIDI 脚踏控制器的初始状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 MIDI 允许我通过捕获指示控制更改的 MIDI 消息来读取 MIDI 踏板控制器的状态.但是如果用户还没有触摸/更改控件呢?我还能读取状态/值吗?这样做的方法是什么?

I know MIDI allows me to read the state of a MIDI Foot Controller by catching a MIDI Message indicating a Control Change. But what if the user has not touched/changed the control yet? Am I still able to read the state/value? What would be the way to do that?

这是我使用 OSX CoreMIDI 捕获 Midi 消息的代码

This is my code for catching Midi Messages using OSX CoreMIDI

void initMidi()
{
    MIDIClientRef   midiClient;
    MIDIPortRef     inputPort;
    OSStatus        status;
    MIDIEndpointRef src;

    status = MIDIClientCreate(CFSTR("testing"), NULL, NULL, &midiClient);
    if (status != noErr)
        NSLog(@"Error creating MIDI client: %d", status);

    status = MIDIInputPortCreate(midiClient, CFSTR("Input"), midiInputCallback, NULL, &inputPort);
    if (status != noErr)
        NSLog(@"Error creating MIDI input port: %d", status);

    ItemCount numOfDevices = MIDIGetNumberOfDevices();

    // just try to connect to every device
    for (ItemCount i = 0; i < numOfDevices; i++) {
        src = MIDIGetSource(i);
        status = MIDIPortConnectSource(inputPort, src, NULL);
    }
}

void midiInputCallback(const MIDIPacketList *list,
    void *procRef,
    void *srcRef)
{
    for (UInt32 i = 0; i < list->numPackets; i++) {
        const MIDIPacket *packet = &list->packet[i];

        for (UInt16 j = 0, size = 0; j < packet->length; j += size) {
            UInt8 status = packet->data[j];

            if (status <  0xC0)  size = 3;
            else if (status <  0xE0)  size = 2;
            else if (status <  0xF0)  size = 3;
            else if (status <  0xF3)  size = 3;
            else if (status == 0xF3)  size = 2;
            else                      size = 1;

            switch (status & 0xF0) {
            case 0xb0:
                NSLog(@"MIDI Control Changed: %d %d", packet->data[j + 1], packet->data[j + 2]);
                break;
            }
        }
    }
}

推荐答案

如果您没有重置设备,也没有更改控件,那么您的程序在收到消息之前不会知道控件的状态.

If you did not reset the device, and did not change a control, then your program does not know the state of a control until it receives a message.

某些设备可能具有供应商特定的命令来读取控件的当前状态或转储整个状态.

Some devices might have vendor-specific commands to read the current state of a control, or to dump the entire state.

这篇关于如何读取 MIDI 脚踏控制器的初始状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆