Change the MidiBuffer Output from Code?

HI, I am outputting Midi Data using the MidiBuffer and the processBlock() and everything is fine with that.

But at the moment the only way I have of changing the MidiOutput Device that the MidiBuffer is sent to, is via the the normal default Options Menu.

How would I change that Midi Output Device in code, I tried:

        audioProcessor.midiOutputDevice = midiOutputComboBox.getSelectedItemIndex();
        juce::String selectedOutputName = juce::MidiOutput::getAvailableDevices()[audioProcessor.midiOutputDevice].name;
        DBG("Output " << selectedOutputName);

        auto outputList = juce::MidiOutput::getAvailableDevices();
        auto newOutput = outputList[audioProcessor.midiOutputDevice];

        deviceManager.setDefaultMidiOutputDevice(newOutput.identifier);

This attempts to change the DefaultMidiOutputDevice from whatever the user selects from a ComboBox I created, there are no crashes but it has no effect on where the Midi Messages are going from the MidiBuffer in the processBlock().

Could someone please be so kind as to point me in the right direction?

The reason is that ideally since I am building a MIDI only program, I would like the Options menu to be hidden and for Midi Channel, Midi Input and Midi Output Devices to be selectable from my ComboBoxes.

Bump!

        deviceManager.setDefaultMidiOutputDevice(newOutput.identifier);

        deviceManager.setDefaultMidiOutput(newOutput.identifier);

I’ve tried both of these but nothing seems to override what you set as MIDI Output in the Options Menu???

How do I set the MIDI Output without using the Options Menu?

To do this, you’ll need to use a custom standalone window.

There’s a good overview of how to get that up and running here:

You can get a handle to the standalone plugin holder by including “juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h” and then doing something like this after an output is selected:

if (auto* holder = StandalonePluginHolder::getInstance())
    holder->player.setMidiOutput (selectedOutput);

You may also need to call holder->deviceManager.setDefaultMidiOutputDevice (...) in order to ensure that the selected midi output is saved properly when quitting the app.

I tried to follow that but juce_StandaloneFilterApp.cpp file does not appear to exist anymore, the JUCE structure must have changed in the last 5 years?

I found juce_StandaloneFilterApp.cpp in an older version of JUCE so I tried to use that file and follow the procedure but when I try to build I get:

2>include_juce_audio_plugin_client_Standalone.cpp
2>include_juce_audio_plugin_client_Standalone.obj : error LNK2019: unresolved external symbol "class juce::JUCEApplicationBase * __cdecl juce_CreateApplication(void)" (?juce_CreateApplication@@YAPEAVJUCEApplicationBase@juce@@XZ) referenced in function WinMain
2>C:\Users\spiff\OneDrive\Documents\Coding\Juce-Test\Custom_Options_Menu\Builds\VisualStudio2022\x64\Debug\Standalone Plugin\\Custom_Options_Menu.exe : fatal error LNK1120: 1 unresolved externals

Not exactly sure what that means?

I think the files are here now:

modules\juce_audio_plugin_client\juce_audio_plugin_client_Standalone.cpp
modules\juce_audio_plugin_client\Standalone\juce_StandaloneFilterWindow.h

I found those files thanks!

I’m getting the same issue that a couple of people had. At the end of the audio_plugin_Standalone.cpp file I now have the issue of

juce_CreateApplication() function definition not found!

The solution listed in the original thread was:

Adding JUCE_CREATE_APPLICATION_DEFINE(StandaloneFilterApp) to the end of StandaloneFilterApp.cpp solved this issue.

I’m not sure what that means exactly, could someone spell it out for me?

There’s a good overview of how to get that up and running here:

I’ve tried to follow this but I just get very similar compiler errors to the others who comment afterwards, unfortunately I cannot follow their solutions, there’s not quite enough detail.

I’ve uploaded the files in the vain hope that someone will take pity on me and have a look, there’s definitely something wrong at the end of the StandaloneFilterApp.cpp, what else I’m not sure?

PluginEditor.cpp (1.5 KB)
PluginEditor.h (1.2 KB)
PluginProcessor.cpp (6.4 KB)
PluginProcessor.h (2.3 KB)
StandaloneFilterApp.cpp (5.6 KB)
StandaloneFilterWindow.h (43.1 KB)

I’d just like to customize the Window of a Plugin’s Standalone App a little bit, nothing major, just maybe hide / unhide the Options Menu, customize what it displays a bit maybe, change some colours, etc… really basic stuff.

Have you tried opening a plugin project with Projucer and selecting “Standalone” in plugin formats?

(In Projucer you can create a plugin project with File>New Project>Open Examples>Plugins>GainPluginDemo)

This will generate source files to create a Standalone app from the plugin and then you can compare them to your code to see what is missing/wrong.