]> git.sesse.net Git - nageru/blobdiff - alsa_input.cpp
Actually set the fader positions when making the views for each audio bus.
[nageru] / alsa_input.cpp
index 7594bbbd463b08ef7525c5859b500a7cab3b531e..0f8e99c95b9b0d536451f26c85bc1fa3142a9003 100644 (file)
@@ -1,9 +1,11 @@
 #include "alsa_input.h"
 #include "audio_mixer.h"
 #include "defs.h"
+#include "state.pb.h"
 
 #include <sys/inotify.h>
 
+#include <algorithm>
 #include <functional>
 #include <unordered_map>
 
@@ -454,6 +456,7 @@ ALSAPool::ProbeResult ALSAPool::probe_device_once(unsigned card_index, unsigned
        string info = snd_pcm_info_get_name(pcm_info);
 
        unsigned internal_dev_index;
+       string display_name;
        {
                lock_guard<mutex> lock(mu);
                internal_dev_index = find_free_device_index(name, info, num_channels, address);
@@ -462,6 +465,8 @@ ALSAPool::ProbeResult ALSAPool::probe_device_once(unsigned card_index, unsigned
                devices[internal_dev_index].info = info;
                devices[internal_dev_index].num_channels = num_channels;
                // Note: Purposefully does not overwrite held.
+
+               display_name = devices[internal_dev_index].display_name();
        }
 
        fprintf(stderr, "%s: Probed successfully.\n", address);
@@ -469,7 +474,7 @@ ALSAPool::ProbeResult ALSAPool::probe_device_once(unsigned card_index, unsigned
        reset_device(internal_dev_index);  // Restarts it if it is held (ie., we just replaced a dead card).
 
        DeviceSpec spec{InputSourceType::ALSA_INPUT, internal_dev_index};
-       global_audio_mixer->set_name(spec, name + " (" + info + ")");
+       global_audio_mixer->set_display_name(spec, display_name);
        global_audio_mixer->trigger_state_changed_callback();
 
        return ALSAPool::ProbeResult::SUCCESS;
@@ -642,6 +647,43 @@ unsigned ALSAPool::find_free_device_index(const string &name, const string &info
        return devices.size() - 1;
 }
 
+unsigned ALSAPool::create_dead_card(const string &name, const string &info, unsigned num_channels)
+{
+       lock_guard<mutex> lock(mu);
+
+       // See if there are any empty slots. If not, insert one at the end.
+       vector<Device>::iterator free_device =
+               find_if(devices.begin(), devices.end(),
+                       [](const Device &device) { return device.state == Device::State::EMPTY; });
+       if (free_device == devices.end()) {
+               devices.push_back(Device());
+               inputs.emplace_back(nullptr);
+               free_device = devices.end() - 1;
+       }
+
+       free_device->state = Device::State::DEAD;
+       free_device->name = name;
+       free_device->info = info;
+       free_device->num_channels = num_channels;
+       free_device->held = true;
+
+       return distance(devices.begin(), free_device);
+}
+
+void ALSAPool::serialize_device(unsigned index, DeviceSpecProto *serialized)
+{
+       lock_guard<mutex> lock(mu);
+       assert(index < devices.size());
+       assert(devices[index].held);
+       serialized->set_type(DeviceSpecProto::ALSA_INPUT);
+       serialized->set_index(index);
+       serialized->set_display_name(devices[index].display_name());
+       serialized->set_alsa_name(devices[index].name);
+       serialized->set_alsa_info(devices[index].info);
+       serialized->set_num_channels(devices[index].num_channels);
+       serialized->set_address(devices[index].address);
+}
+
 void ALSAPool::free_card(unsigned index)
 {
        DeviceSpec spec{InputSourceType::ALSA_INPUT, index};