c++ - JUCE 框架中 MIDI 音符打开和音符关闭消息之间的延迟

标签 c++ midi juce

我正在使用 JUCE 框架在 C++ 中制作一个小工具。 它发出 MIDI 但我遇到了问题。 我想向我的 DAW 发送和弦,方法是先发送消息注释,然后发送消息关闭消息。 noteOn 代码如下所示:

        void MainContentComponent::handleNoteOn (MidiKeyboardState*, int 
        midiChannel, int midiNoteNumber, float velocity)
        {
            timestamp = (Time::getMillisecondCounterHiRes() * 0.001);
            MidiMessage m (MidiMessage::noteOn  (midiChannel, midiNoteNumber , velocity));
            MidiMessage m2 (MidiMessage::noteOn  (midiChannel, midiNoteNumber + 3, velocity));
            MidiMessage m3 (MidiMessage::noteOn (midiChannel, midiNoteNumber + 7, velocity));
            m.setTimeStamp (timestamp);
            m2.setTimeStamp (timestamp);
            m3.setTimeStamp (timestamp);
            sendToOutputs (m);
            sendToOutputs (m2);
            sendToOutputs (m3);

            handleNoteOff(midiChannel, midiNoteNumber, velocity)
        }

问题是,note off 消息紧跟在 note on 消息之后。我想要音符打开和音符关闭消息之间的延迟。 关于如何做到这一点的任何想法?我在考虑延迟选项,但据我所知它们会卡住整个程序。 JUCE 有什么内置的东西可以帮助我吗?我没能在网上找到它。

最佳答案

聚思Tutorial: Create MIDI data 显示如何延迟发送消息:

The MidiBuffer class provides functions for iterating over buffers of MIDI messages based on their timestamps. To illustrate this we will set up a simple scheduling system where we add MidiMessage objects with specific timestamps to a MidiBuffer object. Then we use a Timer object that checks regularly whether any MIDI messages are due to be delivered.

Warning

The Timer class is not suitable for high-precision timing. This is used to keep the example simple by keeping all function calls on the message thread. For more robust timing you should use another thread (in most cases the audio thread is appropriate for rendering MidiBuffer objects in to audio).

关于c++ - JUCE 框架中 MIDI 音符打开和音符关闭消息之间的延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46415332/

相关文章:

c++ - 静态成员变量的返回引用c++

c++ - "string.h"在为 iOS 构建 qt 应用程序时未找到消息

c++ - 动态生成声音

Java:在 JAR 中嵌入 Soundbank 文件

python - 使用 pygame 从流中播放 MIDI 文件

c++ - 没有嵌入文件的 JUCE 图像按钮

c++ - 在 Lion 的 32 位 Xcode4.1 上编译 OpenCV 和 Juce 的问题

c++ - 有没有办法从更简洁的东西中获得 (*pointer)[ index ] 功能?

c++ - 从配置为生成 DLL 的 visual studio 项目创建 lib 文件

ios - ld : framework not found AudioUnit, ios9