void DeviceToolBar::RefillCombos() { FillHosts(); FillHostDevices(); FillInputChannels(); // make the device display selection reflect the prefs if they exist UpdatePrefs(); }
//return 1 if host changed, 0 otherwise. int DeviceToolBar::ChangeHost() { int hostSelectionIndex; hostSelectionIndex = mHost->GetSelection(); wxString oldHost = gPrefs->Read(wxT("/AudioIO/Host"), wxT("")); wxString newHost = hostSelectionIndex >= 0 ? mHost->GetString(hostSelectionIndex) : oldHost; if (oldHost == newHost) return 0; //change the host and switch to correct devices. gPrefs->Write(wxT("/AudioIO/Host"), newHost); // populate the devices FillHostDevices(); return 1; }
void DeviceToolBar::UpdatePrefs() { wxString hostName; wxString devName; wxString sourceName; wxString desc; const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps(); const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps(); int hostSelectionIndex = mHost->GetSelection(); wxString oldHost = hostSelectionIndex >= 0 ? mHost->GetString(hostSelectionIndex) : wxT(""); hostName = gPrefs->Read(wxT("/AudioIO/Host"), wxT("")); // if the prefs host name doesn't match the one displayed, it changed // in another project's DeviceToolBar, so we need to repopulate everything. if (oldHost != hostName) FillHostDevices(); devName = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT("")); sourceName = gPrefs->Read(wxT("/AudioIO/RecordingSource"), wxT("")); if (sourceName == wxT("")) desc = devName; else desc = devName + wxT(": ") + sourceName; if (mInput->GetStringSelection() != desc && mInput->FindString(desc) != wxNOT_FOUND) { mInput->SetStringSelection(desc); FillInputChannels(); } else if (mInput->GetStringSelection() != desc && mInput->GetCount()) { for (size_t i = 0; i < inMaps.size(); i++) { if (inMaps[i].hostString == hostName && MakeDeviceSourceString(&inMaps[i]) == mInput->GetString(0)) { // use the default. It should exist but check just in case, falling back on the 0 index. DeviceSourceMap *defaultMap = DeviceManager::Instance()->GetDefaultInputDevice(inMaps[i].hostIndex); if (defaultMap) { mInput->SetStringSelection(MakeDeviceSourceString(defaultMap)); SetDevices(defaultMap, NULL); } else { //use the first item (0th index) if we have no familiar devices mInput->SetSelection(0); SetDevices(&inMaps[i], NULL); } break; } } } devName = gPrefs->Read(wxT("/AudioIO/PlaybackDevice"), wxT("")); sourceName = gPrefs->Read(wxT("/AudioIO/PlaybackSource"), wxT("")); if (sourceName == wxT("")) desc = devName; else desc = devName + wxT(": ") + sourceName; if (mOutput->GetStringSelection() != desc && mOutput->FindString(desc) != wxNOT_FOUND) { mOutput->SetStringSelection(desc); } else if (mOutput->GetStringSelection() != desc && mOutput->GetCount()) { for (size_t i = 0; i < outMaps.size(); i++) { if (outMaps[i].hostString == hostName && MakeDeviceSourceString(&outMaps[i]) == mOutput->GetString(0)) { // use the default. It should exist but check just in case, falling back on the 0 index. DeviceSourceMap *defaultMap = DeviceManager::Instance()->GetDefaultOutputDevice(outMaps[i].hostIndex); if (defaultMap) { mOutput->SetStringSelection(MakeDeviceSourceString(defaultMap)); SetDevices(NULL, defaultMap); } else { //use the first item (0th index) if we have no familiar devices mOutput->SetSelection(0); SetDevices(NULL, &outMaps[i]); } break; } } } long oldChannels, newChannels; oldChannels = mInputChannels->GetSelection() + 1; gPrefs->Read(wxT("/AudioIO/RecordChannels"), &newChannels, 0); if (newChannels > 0 && oldChannels != newChannels) mInputChannels->SetSelection(newChannels - 1); if (hostName != wxT("") && mHost->GetStringSelection() != hostName) mHost->SetStringSelection(hostName); RegenerateTooltips(); // Set label to pull in language change SetLabel(_("Device")); // Give base class a chance ToolBar::UpdatePrefs(); Layout(); Refresh(); }