gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 01:31:04 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com