1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-17 16:50:26 +02:00

bug 11 - Use const references when returning the map vector to ensure the device maps are not modified. I don't expect this to fix the bug behavior, but am committing because some testers see bad behavior that suggests the maps are modified between scans.

This commit is contained in:
mchinen 2011-03-20 22:20:41 +00:00
parent a3a3230347
commit c1cf9b4a76
5 changed files with 24 additions and 22 deletions

View File

@ -44,13 +44,13 @@ void DeviceManager::Destroy()
}
std::vector<DeviceSourceMap> &DeviceManager::GetInputDeviceMaps()
const std::vector<DeviceSourceMap> &DeviceManager::GetInputDeviceMaps()
{
if (!m_inited)
Init();
return mInputDeviceSourceMaps;
}
std::vector<DeviceSourceMap> &DeviceManager::GetOutputDeviceMaps()
const std::vector<DeviceSourceMap> &DeviceManager::GetOutputDeviceMaps()
{
if (!m_inited)
Init();
@ -58,7 +58,7 @@ std::vector<DeviceSourceMap> &DeviceManager::GetOutputDeviceMaps()
}
wxString MakeDeviceSourceString(DeviceSourceMap *map)
wxString MakeDeviceSourceString(const DeviceSourceMap *map)
{
wxString ret;
ret = map->deviceString;

View File

@ -32,7 +32,7 @@ typedef struct DeviceSourceMap {
wxString hostString;
} DeviceSourceMap;
wxString MakeDeviceSourceString(DeviceSourceMap *map);
wxString MakeDeviceSourceString(const DeviceSourceMap *map);
class DeviceManager
{
@ -50,8 +50,8 @@ class DeviceManager
DeviceSourceMap* GetDefaultOutputDevice(int hostIndex);
DeviceSourceMap* GetDefaultInputDevice(int hostIndex);
std::vector<DeviceSourceMap> &GetInputDeviceMaps();
std::vector<DeviceSourceMap> &GetOutputDeviceMaps();
const std::vector<DeviceSourceMap> &GetInputDeviceMaps();
const std::vector<DeviceSourceMap> &GetOutputDeviceMaps();
protected:
//private constructor - Singleton.

View File

@ -189,8 +189,8 @@ void DevicePrefs::OnHost(wxCommandEvent & e)
mHost->SetSelection(0);
}
std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
wxArrayString playnames;
wxArrayString recordnames;
@ -208,7 +208,9 @@ void DevicePrefs::OnHost(wxCommandEvent & e)
if (index == inMaps[i].hostIndex) {
device = MakeDeviceSourceString(&inMaps[i]);
devindex = mRecord->Append(device);
mRecord->SetClientData(devindex, &inMaps[i]);
// We need to const cast here because SetClientData is a wx function
// It is okay beause the original variable is non-const.
mRecord->SetClientData(devindex, const_cast<DeviceSourceMap *>(&inMaps[i]));
if (device == recDevice) { /* if this is the default device, select it */
mRecord->SetSelection(devindex);
}
@ -220,7 +222,7 @@ void DevicePrefs::OnHost(wxCommandEvent & e)
if (index == outMaps[i].hostIndex) {
device = MakeDeviceSourceString(&outMaps[i]);
devindex = mPlay->Append(device);
mPlay->SetClientData(devindex, &outMaps[i]);
mPlay->SetClientData(devindex, const_cast<DeviceSourceMap *>(&outMaps[i]));
if (device == mPlayDevice) { /* if this is the default device, select it */
mPlay->SetSelection(devindex);
}

View File

@ -223,8 +223,8 @@ void DeviceToolBar::UpdatePrefs()
wxString devName;
wxString sourceName;
wxString desc;
std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
int hostSelectionIndex = mHost->GetSelection();
@ -465,8 +465,8 @@ void DeviceToolBar::FillHosts()
wxArrayString hosts;
size_t i;
std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
// go over our lists add the host to the list if it isn't there yet
for (i = 0; i < inMaps.size(); i++)
if (hosts.Index(inMaps[i].hostString) == wxNOT_FOUND)
@ -484,8 +484,8 @@ void DeviceToolBar::FillHosts()
void DeviceToolBar::FillHostDevices()
{
std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
//read what is in the prefs
wxString host = gPrefs->Read(wxT("/AudioIO/Host"), wxT(""));
@ -578,7 +578,7 @@ int DeviceToolBar::ChangeHost()
void DeviceToolBar::FillInputChannels()
{
std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
const std::vector<DeviceSourceMap> &inMaps = DeviceManager::Instance()->GetInputDeviceMaps();
wxString host = gPrefs->Read(wxT("/AudioIO/Host"), wxT(""));
wxString device = gPrefs->Read(wxT("/AudioIO/RecordingDevice"), wxT(""));
wxString source = gPrefs->Read(wxT("/AudioIO/RecordingSource"), wxT(""));
@ -622,7 +622,7 @@ void DeviceToolBar::FillInputChannels()
if (index == -1)
mInputChannels->Enable(false);
}
void DeviceToolBar::SetDevices(DeviceSourceMap *in, DeviceSourceMap *out)
void DeviceToolBar::SetDevices(const DeviceSourceMap *in, const DeviceSourceMap *out)
{
if (in) {
gPrefs->Write(wxT("/AudioIO/RecordingDevice"), in->deviceString);
@ -652,10 +652,10 @@ void DeviceToolBar::ChangeDevice(bool isInput)
size_t i;
int selectionIndex = mInput->GetSelection();
std::vector<DeviceSourceMap> &maps = isInput ? DeviceManager::Instance()->GetInputDeviceMaps()
: DeviceManager::Instance()->GetOutputDeviceMaps();
wxString host = gPrefs->Read(wxT("/AudioIO/Host"), wxT(""));
const std::vector<DeviceSourceMap> &maps = isInput ? DeviceManager::Instance()->GetInputDeviceMaps()
: DeviceManager::Instance()->GetOutputDeviceMaps();
wxString host = gPrefs->Read(wxT("/AudioIO/Host"), wxT(""));
// Find device indices for input and output
if (selectionIndex >= 0 ) {
wxString newDevice = combo->GetStringSelection();

View File

@ -61,7 +61,7 @@ class DeviceToolBar:public ToolBar {
void FillHosts();
void FillHostDevices();
void FillInputChannels();
void SetDevices(DeviceSourceMap *in, DeviceSourceMap *out);
void SetDevices(const DeviceSourceMap *in, const DeviceSourceMap *out);
void RepositionCombos();
void RegenerateTooltips();