mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-26 00:58:37 +02:00
DeviceToolBar.cpp: Better event handling -
Make OnChoice only do the action associated with the combo box being interacted with. Also refactor associated input and output device code into new function.
This commit is contained in:
parent
046593405f
commit
a9437f795b
@ -675,7 +675,7 @@ int DeviceToolBar::ChangeHost()
|
|||||||
hostSelectionIndex = mHost->GetSelection();
|
hostSelectionIndex = mHost->GetSelection();
|
||||||
|
|
||||||
wxString oldHost = gPrefs->Read(wxT("/AudioIO/Host"), wxT(""));
|
wxString oldHost = gPrefs->Read(wxT("/AudioIO/Host"), wxT(""));
|
||||||
wxString newHost = hostSelectionIndex >= 0 ? mHost->GetString(mHost->GetSelection()) :
|
wxString newHost = hostSelectionIndex >= 0 ? mHost->GetString(hostSelectionIndex) :
|
||||||
oldHost;
|
oldHost;
|
||||||
|
|
||||||
if (oldHost == newHost)
|
if (oldHost == newHost)
|
||||||
@ -757,57 +757,54 @@ void DeviceToolBar::SetDevices(DeviceSourceMap *in, DeviceSourceMap *out)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceToolBar::OnChoice(wxCommandEvent &event)
|
void DeviceToolBar::ChangeDevice(bool isInput)
|
||||||
{
|
{
|
||||||
int inputSelectionIndex;
|
int newIndex = -1;
|
||||||
int outputSelectionIndex;
|
wxChoice *combo = isInput ? mInput :mOutput;
|
||||||
int channelsSelectionIndex;
|
|
||||||
|
|
||||||
//if we've changed hosts, we've handled the device switching already.
|
|
||||||
if (!ChangeHost()) {
|
|
||||||
inputSelectionIndex = mInput->GetSelection();
|
|
||||||
outputSelectionIndex = mOutput->GetSelection();
|
|
||||||
channelsSelectionIndex = mInputChannels->GetSelection();
|
|
||||||
|
|
||||||
if (channelsSelectionIndex >= 0) {
|
|
||||||
gPrefs->Write(wxT("/AudioIO/RecordChannels"),
|
|
||||||
channelsSelectionIndex + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString host = gPrefs->Read(wxT("/AudioIO/Host"), wxT(""));
|
|
||||||
int newInIndex = -1, newOutIndex = -1;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
int selectionIndex = mInput->GetSelection();
|
||||||
|
std::vector<DeviceSourceMap> &maps = isInput ? mInputDeviceSourceMaps : mOutputDeviceSourceMaps;
|
||||||
|
|
||||||
|
wxString host = gPrefs->Read(wxT("/AudioIO/Host"), wxT(""));
|
||||||
// Find device indices for input and output
|
// Find device indices for input and output
|
||||||
if (inputSelectionIndex >= 0 ) {
|
if (selectionIndex >= 0 ) {
|
||||||
wxString newInput = mInput->GetStringSelection();
|
wxString newDevice = combo->GetStringSelection();
|
||||||
for (i = 0; i < mInputDeviceSourceMaps.size(); ++i) {
|
for (i = 0; i < maps.size(); ++i) {
|
||||||
wxString name;
|
wxString name;
|
||||||
name = MakeDeviceSourceString(&mInputDeviceSourceMaps[i]);
|
name = MakeDeviceSourceString(&maps[i]);
|
||||||
if (name == newInput && mInputDeviceSourceMaps[i].hostString == host) {
|
if (name == newDevice && maps[i].hostString == host) {
|
||||||
newInIndex = i;
|
newIndex = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputSelectionIndex >= 0) {
|
if (newIndex < 0) {
|
||||||
wxString newOutput = mOutput->GetStringSelection();
|
|
||||||
for (i = 0; i < mOutputDeviceSourceMaps.size(); ++i) {
|
|
||||||
wxString name;
|
|
||||||
name = MakeDeviceSourceString(&mOutputDeviceSourceMaps[i]);
|
|
||||||
if (name == newOutput && mOutputDeviceSourceMaps[i].hostString == host)
|
|
||||||
newOutIndex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This shouldn't happen for new choices (it's OK for old ones)
|
|
||||||
if (newInIndex < 0 || newOutIndex < 0) {
|
|
||||||
wxLogDebug(wxT("DeviceToolBar::OnChoice(): couldn't find device indices"));
|
wxLogDebug(wxT("DeviceToolBar::OnChoice(): couldn't find device indices"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDevices(newInIndex >= 0 ? &mInputDeviceSourceMaps[newInIndex] : NULL,
|
SetDevices(isInput ? &maps[newIndex] : NULL,
|
||||||
newOutIndex >= 0 ? &mOutputDeviceSourceMaps[newOutIndex] : NULL);
|
isInput ? NULL : &maps[newIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceToolBar::OnChoice(wxCommandEvent &event)
|
||||||
|
{
|
||||||
|
int outputSelectionIndex;
|
||||||
|
|
||||||
|
wxObject *eventObject = event.GetEventObject();
|
||||||
|
//if we've changed hosts, we've handled the device switching already.
|
||||||
|
if (eventObject == mHost) {
|
||||||
|
ChangeHost();
|
||||||
|
} else if (eventObject == mInputChannels) {
|
||||||
|
int channelsSelectionIndex = mInputChannels->GetSelection();
|
||||||
|
if (channelsSelectionIndex >= 0)
|
||||||
|
gPrefs->Write(wxT("/AudioIO/RecordChannels"),channelsSelectionIndex + 1);
|
||||||
|
} else if (eventObject == mInput) {
|
||||||
|
ChangeDevice(true);
|
||||||
|
}
|
||||||
|
else if (eventObject == mOutput) {
|
||||||
|
ChangeDevice(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gAudioIO) {
|
if (gAudioIO) {
|
||||||
@ -884,6 +881,7 @@ void DeviceToolBar::ShowComboDialog(wxChoice *combo, const wxString &title)
|
|||||||
if (dlg.ShowModal() == wxID_OK)
|
if (dlg.ShowModal() == wxID_OK)
|
||||||
{
|
{
|
||||||
wxCommandEvent dummyEvent;
|
wxCommandEvent dummyEvent;
|
||||||
|
dummyEvent.SetEventObject(combo);
|
||||||
// SetSelection() doesn't send an event, so we call OnChoice explicitly
|
// SetSelection() doesn't send an event, so we call OnChoice explicitly
|
||||||
combo->SetSelection(c->GetSelection());
|
combo->SetSelection(c->GetSelection());
|
||||||
OnChoice(dummyEvent);
|
OnChoice(dummyEvent);
|
||||||
|
@ -65,6 +65,7 @@ class DeviceToolBar:public ToolBar {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int ChangeHost();
|
int ChangeHost();
|
||||||
|
void ChangeDevice(bool isInput);
|
||||||
void FillHostDevices();
|
void FillHostDevices();
|
||||||
void FillInputChannels();
|
void FillInputChannels();
|
||||||
void SetDevices(DeviceSourceMap *in, DeviceSourceMap *out);
|
void SetDevices(DeviceSourceMap *in, DeviceSourceMap *out);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user