Unpacking Midi Timecode with RtMidi

大城市里の小女人 提交于 2021-01-29 11:19:12

问题


I've been hard at work trying to figure how to grab Midi Timecode (MTC) with RtMidi C++. So far, it seems that the RtMdid callback only deal with uchar so my guess is that it receives multiple messages for a complete uint (32bit) timecode. I'm struggling to figure how to reassemble the data. My first question is, is it even possible to read MTC with RtMidi or I'm beating a dead horse here?

Thank you,


回答1:


Quater-frames that is but I was not sure. Here's a working exemple:

void ZMidiIn::UpdatePort(double in_deltaTime, std::vector<UChar> *in_message, void *in_userData)
{
    UInt l_size = (UInt)in_message->size();

    if (l_size == 0)
    {
        return;
    }

    for (UInt i = 0; i < l_size; ++i)
    {
        UChar l_byte = in_message->at(i);

        switch (l_byte)
        {
        case 0xf1: /// Midi Time Code (MTC)
        {
            ZTimecode &l_timecode = zMidi->GetTimeCode();
            l_byte = in_message->at(++i); /// Get next byte.

            Int l_type = (l_byte >> 4) & 0xf;
            Int l_val = (l_byte & 0xf);

            switch (l_type)
            {
            case 0:
            {
                l_timecode.SetFrameTens(l_val);
                break;
            }
            case 1:
            {
                l_timecode.SetFrameUnits(l_timecode.GetFrameTens() + (l_val * 16));
                break;
            }
            case 2:
            {
                l_timecode.SetSecondTens(l_val);
                break;
            }
            case 3:
            {
                l_timecode.SetSecondUnits(l_timecode.GetSecondTens() + (l_val * 16));
                break;
            }
            case 4:
            {
                l_timecode.SetMinuteTens(l_val);
                break;
            }
            case 5:
            {
                l_timecode.SetMinuteUnits(l_timecode.GetMinuteTens() + (l_val * 16));
                break;
            }
            case 6:
            {
                l_timecode.SetHourTens(l_val & 31);
                break;
            }
            case 7:
            {
                l_timecode.SetHourUnits(l_timecode.GetHourTens() + ((l_val * 16) & 31));
                break;
            }
            }
            break;
        }
        }
    }
}


来源:https://stackoverflow.com/questions/59258387/unpacking-midi-timecode-with-rtmidi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!