void MidiIODeviceManager::setMidiNoteEnabled (const String& midiDeviceName, bool input, bool enabled) { if(input) { appProperties->getUserSettings()->setValue(midiDeviceName + "noteInputEnabled", enabled); // lets see if we need to turn the inputs on or off if(enabled == true && isMidiInputEnabled(midiDeviceName) == false) { // we want to start listening to midi from this input setMidiInputEnabled(midiDeviceName, true); } else if(enabled == false && isMidiInputEnabled(midiDeviceName) == true && appProperties->getUserSettings()->getBoolValue(midiDeviceName + "noteInputEnabled") == false && appProperties->getUserSettings()->getBoolValue(midiDeviceName + "ccInputEnabled") == false) { // no one is listening to this midi device, so lets turn it off setMidiInputEnabled(midiDeviceName, false); } } else if(!input) { appProperties->getUserSettings()->setValue(midiDeviceName + "noteOutputEnabled", var(enabled)); // lets see if we need to turn the outputs on or off if(enabled == true && appProperties->getUserSettings()->getBoolValue(midiDeviceName + "noteOutputEnabled") == false) { // we want to start sending midi to this output appProperties->getUserSettings()->setValue(midiDeviceName + "outputEnabled", var(true)); } else if(enabled == false && appProperties->getUserSettings()->getBoolValue(midiDeviceName + "outputEnabled") == true && appProperties->getUserSettings()->getBoolValue(midiDeviceName + "noteOutputEnabled") == false && appProperties->getUserSettings()->getBoolValue(midiDeviceName + "ccOutputEnabled") == false) { // no one wants to send to this midi device, so lets turn it off appProperties->getUserSettings()->setValue(midiDeviceName + "outputEnabled", var(false)); } sendChangeMessage (); appProperties->saveIfNeeded(); } }
//============================================================================== String AudioDeviceManager::initialise (const int numInputChannelsNeeded, const int numOutputChannelsNeeded, const XmlElement* const e, const bool selectDefaultDeviceOnFailure, const String& preferredDefaultDeviceName, const AudioDeviceSetup* preferredSetupOptions) { scanDevicesIfNeeded(); numInputChansNeeded = numInputChannelsNeeded; numOutputChansNeeded = numOutputChannelsNeeded; if (e != nullptr && e->hasTagName ("DEVICESETUP")) { lastExplicitSettings = new XmlElement (*e); String error; AudioDeviceSetup setup; if (preferredSetupOptions != nullptr) setup = *preferredSetupOptions; if (e->getStringAttribute ("audioDeviceName").isNotEmpty()) { setup.inputDeviceName = setup.outputDeviceName = e->getStringAttribute ("audioDeviceName"); } else { setup.inputDeviceName = e->getStringAttribute ("audioInputDeviceName"); setup.outputDeviceName = e->getStringAttribute ("audioOutputDeviceName"); } currentDeviceType = e->getStringAttribute ("deviceType"); if (findType (currentDeviceType) == nullptr) { AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName); if (type != nullptr) currentDeviceType = type->getTypeName(); else if (availableDeviceTypes.size() > 0) currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName(); } setup.bufferSize = e->getIntAttribute ("audioDeviceBufferSize"); setup.sampleRate = e->getDoubleAttribute ("audioDeviceRate"); setup.inputChannels .parseString (e->getStringAttribute ("audioDeviceInChans", "11"), 2); setup.outputChannels.parseString (e->getStringAttribute ("audioDeviceOutChans", "11"), 2); setup.useDefaultInputChannels = ! e->hasAttribute ("audioDeviceInChans"); setup.useDefaultOutputChannels = ! e->hasAttribute ("audioDeviceOutChans"); error = setAudioDeviceSetup (setup, true); midiInsFromXml.clear(); forEachXmlChildElementWithTagName (*e, c, "MIDIINPUT") midiInsFromXml.add (c->getStringAttribute ("name")); const StringArray allMidiIns (MidiInput::getDevices()); for (int i = allMidiIns.size(); --i >= 0;) setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i])); if (error.isNotEmpty() && selectDefaultDeviceOnFailure) error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0, false, preferredDefaultDeviceName); setDefaultMidiOutput (e->getStringAttribute ("defaultMidiOutput")); return error; } else { AudioDeviceSetup setup; if (preferredSetupOptions != nullptr) { setup = *preferredSetupOptions; } else if (preferredDefaultDeviceName.isNotEmpty()) { for (int j = availableDeviceTypes.size(); --j >= 0;) { AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j); StringArray outs (type->getDeviceNames (false)); int i; for (i = 0; i < outs.size(); ++i) { if (outs[i].matchesWildcard (preferredDefaultDeviceName, true)) { setup.outputDeviceName = outs[i]; break; } } StringArray ins (type->getDeviceNames (true)); for (i = 0; i < ins.size(); ++i) { if (ins[i].matchesWildcard (preferredDefaultDeviceName, true)) { setup.inputDeviceName = ins[i]; break; } } } } insertDefaultDeviceNames (setup); return setAudioDeviceSetup (setup, false); } }
String AudioDeviceManager::initialiseFromXML (const XmlElement& xml, const bool selectDefaultDeviceOnFailure, const String& preferredDefaultDeviceName, const AudioDeviceSetup* preferredSetupOptions) { lastExplicitSettings = new XmlElement (xml); String error; AudioDeviceSetup setup; if (preferredSetupOptions != nullptr) setup = *preferredSetupOptions; if (xml.getStringAttribute ("audioDeviceName").isNotEmpty()) { setup.inputDeviceName = setup.outputDeviceName = xml.getStringAttribute ("audioDeviceName"); } else { setup.inputDeviceName = xml.getStringAttribute ("audioInputDeviceName"); setup.outputDeviceName = xml.getStringAttribute ("audioOutputDeviceName"); } currentDeviceType = xml.getStringAttribute ("deviceType"); if (findType (currentDeviceType) == nullptr) { if (AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName)) currentDeviceType = type->getTypeName(); else if (availableDeviceTypes.size() > 0) currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName(); } setup.bufferSize = xml.getIntAttribute ("audioDeviceBufferSize", setup.bufferSize); setup.sampleRate = xml.getDoubleAttribute ("audioDeviceRate", setup.sampleRate); setup.inputChannels .parseString (xml.getStringAttribute ("audioDeviceInChans", "11"), 2); setup.outputChannels.parseString (xml.getStringAttribute ("audioDeviceOutChans", "11"), 2); setup.useDefaultInputChannels = ! xml.hasAttribute ("audioDeviceInChans"); setup.useDefaultOutputChannels = ! xml.hasAttribute ("audioDeviceOutChans"); error = setAudioDeviceSetup (setup, true); midiInsFromXml.clear(); forEachXmlChildElementWithTagName (xml, c, "MIDIINPUT") midiInsFromXml.add (c->getStringAttribute ("name")); const StringArray allMidiIns (MidiInput::getDevices()); for (int i = allMidiIns.size(); --i >= 0;) setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i])); if (error.isNotEmpty() && selectDefaultDeviceOnFailure) error = initialise (numInputChansNeeded, numOutputChansNeeded, nullptr, false, preferredDefaultDeviceName); setDefaultMidiOutput (xml.getStringAttribute ("defaultMidiOutput")); return error; }
MidiIODeviceManager::MidiIODeviceManager() { StringArray midiInputList = MidiInput::getDevices(); for(int i = 0; i < midiInputList.size(); i++) { if(!appProperties->getUserSettings()->containsKey(midiInputList[i] + "noteInputEnabled")) { appProperties->getUserSettings()->setValue(midiInputList[i] + "noteInputEnabled", var(false)); } else if (appProperties->getUserSettings()->getBoolValue(midiInputList[i] + "noteInputEnabled")) { setMidiInputEnabled(midiInputList[i], var(true)); } if (!appProperties->getUserSettings()->containsKey(midiInputList[i] + "ccInputEnabled")) { appProperties->getUserSettings()->setValue(midiInputList[i] + "ccInputEnabled", var(false)); } else if (appProperties->getUserSettings()->getBoolValue(midiInputList[i] + "ccInputEnabled")) { setMidiInputEnabled(midiInputList[i], var(true)); } } StringArray midiOutputList = MidiOutput::getDevices(); for(int i = 0; i < midiOutputList.size(); i++) { if(!appProperties->getUserSettings()->containsKey(midiOutputList[i] + "noteOutputEnabled")) { appProperties->getUserSettings()->setValue(midiOutputList[i] + "noteOutputEnabled", var(false)); } else if (appProperties->getUserSettings()->getBoolValue(midiInputList[i] + "noteOutputEnabled")) { appProperties->getUserSettings()->setValue(midiOutputList[i] + "outputEnabled", var(true)); } if (!appProperties->getUserSettings()->containsKey(midiOutputList[i] + "ccOutputEnabled")) { appProperties->getUserSettings()->setValue(midiOutputList[i] + "ccOutputEnabled", var(false)); } else if (appProperties->getUserSettings()->getBoolValue(midiInputList[i] + "ccOutputEnabled")) { appProperties->getUserSettings()->setValue(midiOutputList[i] + "outputEnabled", var(true)); } if (!appProperties->getUserSettings()->containsKey(midiOutputList[i] + "outputEnabled")) { appProperties->getUserSettings()->setValue(midiOutputList[i] + "outputEnabled", var(false)); } else if (appProperties->getUserSettings()->getBoolValue(midiInputList[i] + "outputEnabled")) { appProperties->getUserSettings()->setValue(midiOutputList[i] + "outputEnabled", var(true)); } } if(!appProperties->getUserSettings()->containsKey("midiInputChannel")) { int ch = 1; appProperties->getUserSettings()->setValue("midiInputChannel", var(ch)); } if(!appProperties->getUserSettings()->containsKey("midiOutputChannel")) { int ch = 1; appProperties->getUserSettings()->setValue("midiOutputChannel", var(ch)); } appProperties->saveIfNeeded(); }