Steps to Save Audio Device

Way back at the beginning of my DAW project I worked out how to save the selected Audio Device so that it loads at next startup. Now, it is no longer working.

I have a passion for refactoring to get the same work in fewer lines of code. Sometimes this results in shooting myself in the foot. And that applies this time because, somewhere along the line, I refactored and my DAW lost the ability for the Audio Device to persist.

I am doing a very ordinary device selection as shown.

DialogWindow::LaunchOptions o;
o.dialogTitle = "Audio Device Settings";
o.dialogBackgroundColour = Colours::darkgrey;
o.content.setOwned(new AudioDeviceSelectorComponent(engine.getDeviceManager().deviceManager,
				0, 256, 0, 256, true, true, true, false));
o.content->setSize(500, 700);

So that I can figure out what is missing, what are the minimum steps required to have the selected Audio Device saved for use the next time the DAW starts?

Look at the AudioDeviceManager class.

You can save the current device state using createXml.

Then, on the next startup, you can pass that previously saved XML to initialise

That certainly looks like the way to do it. I will implement that.

Still, I do not remember ever having that code in my DAW, which suggests that there is another way to accomplish the Audio Device persistance.

But, for now, I am content to use your suggestion.

Thank you!

For the benefit of others;

// load Audio Device settings
auto deviceXML{ XmlDocument::parse(File("yourPath/AudioDevice.xml")) };
engine.getDeviceManager().deviceManager.initialise(numInputs, numOutputs, deviceXML.get(), true);

and to save;

//save Audio Device settings
auto deviceXML{ engine.getDeviceManager().deviceManager.createStateXml() };
if (deviceXML)
	File deviceXMLFile( "yourPath/AudioDevice.xml");

I’ve noticed this too recently when working on a new example. I don’t recall anything changing in Tracktion Engine though and the device settings should be saved with the app-settings.
I have a feeling something has changed in JUCE in the past several months which changes this behaviour subtly so we’ll need to figure out how to get that behaviour back.

Thank you! At least now I know I am not completely crazy!..still, partially crazy, it goes without saying…anyway…

I do not know exactly when the behavior changed, but it was in the last few months. I know before then, my DAW would “remember” the selected Audio Device. And, as you said, saving with the App-settings sounds right. Plus, I certainly do not remember implementing the code above to retain that information. Although that code certainly does the job, while also feeling redundant.

Perhaps the JUCE devs can recall what has changed?..and perhaps unintentional?