1 #include "core/window.hpp"
2 #include "core/audioapi.hpp"
4 #include "platform/wxwidgets/platform.hpp"
8 #include <wx/control.h>
9 #include <wx/combobox.h>
11 class wxeditor_sounddev
: public wxDialog
14 wxeditor_sounddev(wxWindow
* parent
);
15 bool ShouldPreventAppExit() const;
16 void on_cancel(wxCommandEvent
& e
);
17 void on_ok(wxCommandEvent
& e
);
25 wxeditor_sounddev::wxeditor_sounddev(wxWindow
* parent
)
26 : wxDialog(parent
, wxID_ANY
, wxT("lsnes: Choose sound device"), wxDefaultPosition
, wxSize(-1, -1))
29 wxFlexGridSizer
* top_s
= new wxFlexGridSizer(2, 1, 0, 0);
32 auto pdev_map
= audioapi_driver_get_devices(false);
33 auto rdev_map
= audioapi_driver_get_devices(true);
34 std::string current_pdev
= pdev_map
[audioapi_driver_get_device(false)];
35 std::string current_rdev
= rdev_map
[audioapi_driver_get_device(true)];
36 std::vector
<wxString
> available_pdevs
;
37 std::vector
<wxString
> available_rdevs
;
38 for(auto i
: pdev_map
)
39 available_pdevs
.push_back(towxstring(i
.second
));
40 for(auto i
: rdev_map
)
41 available_rdevs
.push_back(towxstring(i
.second
));
43 wxFlexGridSizer
* c_s
= new wxFlexGridSizer(2, 2, 0, 0);
44 c_s
->Add(new wxStaticText(this, wxID_ANY
, wxT("Input device:")), 0, wxGROW
);
45 c_s
->Add(rdev
= new wxComboBox(this, wxID_ANY
, towxstring(current_rdev
), wxDefaultPosition
,
46 wxSize(400, -1), available_rdevs
.size(), &available_rdevs
[0], wxCB_READONLY
), 1, wxGROW
);
47 c_s
->Add(new wxStaticText(this, wxID_ANY
, wxT("Output device:")), 0, wxGROW
);
48 c_s
->Add(pdev
= new wxComboBox(this, wxID_ANY
, towxstring(current_pdev
), wxDefaultPosition
,
49 wxSize(400, -1), available_pdevs
.size(), &available_pdevs
[0], wxCB_READONLY
), 1, wxGROW
);
52 if(available_pdevs
.size() < 2)
54 if(available_rdevs
.size() < 2)
57 wxBoxSizer
* pbutton_s
= new wxBoxSizer(wxHORIZONTAL
);
58 pbutton_s
->AddStretchSpacer();
59 pbutton_s
->Add(okbutton
= new wxButton(this, wxID_OK
, wxT("OK")), 0, wxGROW
);
60 pbutton_s
->Add(cancel
= new wxButton(this, wxID_CANCEL
, wxT("Cancel")), 0, wxGROW
);
61 okbutton
->Connect(wxEVT_COMMAND_BUTTON_CLICKED
,
62 wxCommandEventHandler(wxeditor_sounddev::on_ok
), NULL
, this);
63 cancel
->Connect(wxEVT_COMMAND_BUTTON_CLICKED
,
64 wxCommandEventHandler(wxeditor_sounddev::on_cancel
), NULL
, this);
65 top_s
->Add(pbutton_s
, 0, wxGROW
);
67 c_s
->SetSizeHints(this);
68 top_s
->SetSizeHints(this);
72 bool wxeditor_sounddev::ShouldPreventAppExit() const
77 void wxeditor_sounddev::on_cancel(wxCommandEvent
& e
)
79 EndModal(wxID_CANCEL
);
82 void wxeditor_sounddev::on_ok(wxCommandEvent
& e
)
84 std::string newpdev
= tostdstring(pdev
->GetValue());
85 std::string newrdev
= tostdstring(rdev
->GetValue());
86 std::string _newpdev
= "null";
87 std::string _newrdev
= "null";
88 for(auto i
: audioapi_driver_get_devices(false))
89 if(i
.second
== newpdev
)
91 for(auto i
: audioapi_driver_get_devices(true))
92 if(i
.second
== newrdev
)
94 platform::set_sound_device(_newpdev
, _newrdev
);
98 void wxeditor_sounddev_display(wxWindow
* parent
)
100 modal_pause_holder hld
;
103 editor
= new wxeditor_sounddev(parent
);