Hi people. I am strugling to get my combobox to show a new selection by code.
When creting the cox, I use outputSelector.setSelectedId(1); which nicely shows the 1st item in the list when the program is “build”.
At certain point, I want the shown output to change via outputSelector…setSelectedId(newselection, , juce::dontSendNotification); after that I change my midioutput via midiOutput = juce::MidiOutput::openDevice(outputSelector.getSelectedId() - 1);
The weird thing is, that it opens the correct port and sends a message, but the combobox isn’t updated. Changing the Notification doesn’t help either.
After this routine is done, I press a key on my midi controller and notice that midiOutput has “changed back” to the actual visible one, whithout my changing the code.
Here is some of the code:
[code] {
// part of creation of the combobox
outputSelector.addItemList(midiOutputs, 1);
outputSelector.setSelectedId(1);
outputSelector.setEnabled(true);
juce::MidiOutput::openDevice(outputSelector.getText());
void sendMidiMessage(int outChannel, int cc0, int cc32, int pc, juce::String outPort)
{
int outID = midiOutputs.indexOf(outPort);
if (outID >= 0)
{
outputSelector.setSelectedId(outID, juce::dontSendNotification);
midiOutput = juce::MidiOutput::openDevice(outputSelector.getSelectedId() - 1);
}
if (midiOutput != nullptr)
{
juce::MidiMessage msg;
if (cc0 >= 0)
msg = juce::MidiMessage::controllerEvent(outChannel, 0, cc0);
if (cc32 >= 0)
msg = juce::MidiMessage::controllerEvent(outChannel, 32, cc32);
if (pc >= 0)
msg = juce::MidiMessage::programChange(outChannel, pc);
midiOutput->sendMessageNow(msg);
}
}
void handleIncomingMidiMessage(juce::MidiInput* source, const juce::MidiMessage& message) override
{
if (midiOutput != nullptr)
{
midiOutput->sendMessageNow(message);
}
}
}[/code]