11#include " settingswindow.h"
22
3+ #include < cassert>
34#include < variant>
45
6+ #include < alsa/asoundlib.h>
7+
58#include " gui/instance.h"
69
10+ #include " system/settings.h"
11+
712#include " theatre/management.h"
813
914namespace glight ::gui::windows {
@@ -15,6 +20,20 @@ using theatre::devices::OutputMapping;
1520using theatre::devices::UniverseMap;
1621
1722SettingsWindow::SettingsWindow () {
23+ MakeDmxPage ();
24+
25+ // notebook_.append_page(midi_page_, "MIDI");
26+
27+ MakeAudioPage ();
28+
29+ add (notebook_);
30+ notebook_.show_all ();
31+
32+ FillUniverses ();
33+ UpdateAfterSelection ();
34+ }
35+
36+ void SettingsWindow::MakeDmxPage () {
1837 universe_list_store_ = Gtk::ListStore::create (universe_columns_);
1938 universe_list_view_.set_model (universe_list_store_);
2039 universe_list_view_.append_column (" Universe" , universe_columns_.universe_ );
@@ -66,14 +85,62 @@ SettingsWindow::SettingsWindow() {
6685 dmx_output_rb_.signal_clicked ().connect (save_universe);
6786 dmx_page_.attach (dmx_output_rb_, 0 , 6 , 2 , 1 );
6887 notebook_.append_page (dmx_page_, " DMX" );
88+ }
6989
70- notebook_.append_page (midi_page_, " MIDI" );
71-
72- add (notebook_);
73- notebook_.show_all ();
74-
75- FillUniverses ();
76- UpdateAfterSelection ();
90+ void SettingsWindow::MakeAudioPage () {
91+ void ** hints = nullptr ;
92+ if (snd_device_name_hint (-1 , " pcm" , &hints) >= 0 ) {
93+ size_t hi = 0 ;
94+ output_devices_combo_.remove_all ();
95+ const std::string selected_input = Instance::Settings ().audio_input ;
96+ const std::string selected_output = Instance::Settings ().audio_output ;
97+ while (hints[hi] != nullptr ) {
98+ char * device_name = snd_device_name_get_hint (hints[hi], " NAME" );
99+ char * device_desc = snd_device_name_get_hint (hints[hi], " DESC" );
100+ char * input_or_output = snd_device_name_get_hint (hints[hi], " IOID" );
101+ const bool is_input = input_or_output == nullptr ||
102+ std::strcmp (input_or_output, " Input" ) == 0 ;
103+ const bool is_output = input_or_output == nullptr ||
104+ std::strcmp (input_or_output, " Output" ) == 0 ;
105+ assert (is_input || is_output);
106+ std::string device_desc_str (device_desc);
107+ const std::size_t new_line = device_desc_str.find (' \n ' );
108+ if (new_line != std::string::npos) {
109+ device_desc_str.resize (new_line);
110+ }
111+ const std::string description_with_name =
112+ device_desc_str + " (" + device_name + " )" ;
113+ if (is_input) {
114+ input_devices_combo_.append (description_with_name);
115+ input_devices_.emplace_back (device_name);
116+ }
117+ if (is_output) {
118+ output_devices_combo_.append (description_with_name);
119+ output_devices_.emplace_back (device_name);
120+ }
121+ if (selected_input == device_name) input_devices_combo_.set_active (hi);
122+ if (selected_output == device_name) output_devices_combo_.set_active (hi);
123+ free (input_or_output);
124+ free (device_desc);
125+ free (device_name);
126+ ++hi;
127+ }
128+ snd_device_name_free_hint (hints);
129+ }
130+ input_devices_combo_.signal_changed ().connect ([&]() { SetInputAudio (); });
131+ output_devices_combo_.signal_changed ().connect ([&]() { SetOutputAudio (); });
132+ audio_page_label_.set_line_wrap (true );
133+ audio_page_label_.set_max_width_chars (40 );
134+ audio_page_label_.set_margin_start (8 );
135+ audio_page_label_.set_margin_end (8 );
136+ audio_page_label_.set_margin_top (8 );
137+ audio_page_label_.set_margin_bottom (8 );
138+ audio_page_.attach (audio_page_label_, 0 , 0 , 2 , 1 );
139+ audio_page_.attach (input_devices_label_, 0 , 1 );
140+ audio_page_.attach (input_devices_combo_, 1 , 1 );
141+ audio_page_.attach (output_devices_label_, 0 , 2 );
142+ audio_page_.attach (output_devices_combo_, 1 , 2 );
143+ notebook_.append_page (audio_page_, " Audio" );
77144}
78145
79146void SettingsWindow::FillUniverses () {
@@ -263,4 +330,17 @@ void SettingsWindow::ReloadOla() {
263330 UpdateAfterSelection ();
264331}
265332
333+ void SettingsWindow::SetInputAudio () {
334+ const std::string& selected_device =
335+ input_devices_[input_devices_combo_.get_active_row_number ()];
336+ Instance::Settings ().audio_input = selected_device;
337+ Instance::Management ().StartBeatFinder ();
338+ }
339+
340+ void SettingsWindow::SetOutputAudio () {
341+ const std::string& selected_device =
342+ output_devices_[output_devices_combo_.get_active_row_number ()];
343+ Instance::Settings ().audio_output = selected_device;
344+ }
345+
266346} // namespace glight::gui::windows
0 commit comments