使用 RtMidi 解包 Midi 时间码 [英] Unpacking Midi Timecode with RtMidi

查看:120
本文介绍了使用 RtMidi 解包 Midi 时间码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力研究如何使用 RtMidi C++ 获取 Midi 时间码 (MTC).到目前为止,RtMdid 回调似乎只处理 uchar,所以我的猜测是它接收多个消息以获得完整的 uint(32 位)时间码.我正在努力弄清楚如何重新组合数据.我的第一个问题是,是否可以使用 RtMidi 读取 MTC 或者我在这里打败了一匹死马?

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?

谢谢,

推荐答案

Quater-frames,但我不确定.这是一个工作示例:

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;
        }
        }
    }
}

这篇关于使用 RtMidi 解包 Midi 时间码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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