我正在尝试将 midi 音符编号打印到 Juce 音频应用程序中的标签中,因为它们被按下。这是我目前拥有的代码:
在 MainComponent 头文件中:
class MainComponent : public Component,
public MidiInputCallback
{
public:
//==============================================================================
MainComponent();
~MainComponent();
void resized() override;
void handleIncomingMidiMessage (MidiInput*, const MidiMessage&);
private:
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
AudioDeviceManager audioDeviceManager;
Label midiLabel;
};
在 MainComponent.cpp 构造函数中:
MainComponent::MainComponent()
{
setSize (500, 400);
audioDeviceManager.setMidiInputEnabled("USB Axiom 49 Port 1", true);
audioDeviceManager.addMidiInputCallback (String::empty, this);
//midiLabel
midiLabel.setText("midiText", sendNotification);
addAndMakeVisible(midiLabel);
}
最后在 handleIncomingMidiMessage 函数中:
void MainComponent::handleIncomingMidiMessage(MidiInput*, const MidiMessage&)
{
DBG("MIDI Message Recieved\n");
//display label text
String midiText;
MidiMessage message;
if (message.isNoteOnOrOff()) {
midiText << "NoteOn: Channel " << message.getChannel();
midiText << ":Number" << message.getNoteNumber();
midiText << ":Velocity" << message.getVelocity();
}
midiLabel.getTextValue() = midiText;
}
当我运行它时,可以看到一个标有“midiText”的标签,当我按下 midi 键盘上的一个键时,文本就会消失。有任何想法吗?