Constrain VCA slave value to controllable range
[ardour.git] / libs / ardouralsautil / devicelist.cc
index 31957a80cf9a24cceae60523505feb81d77f5647..f642733182f1926e8f025620498e83f32b53a705 100644 (file)
  */
 
 #include <alsa/asoundlib.h>
+#include <glib.h>
+
 #include "pbd/convert.h"
 #include "ardouralsautil/devicelist.h"
 
 using namespace std;
 
 void
-ARDOUR::get_alsa_audio_device_names (std::map<std::string, std::string>& devices)
+ARDOUR::get_alsa_audio_device_names (std::map<std::string, std::string>& devices, AlsaDuplex duplex)
 {
        snd_ctl_t *handle;
        snd_ctl_card_info_t *info;
@@ -34,6 +36,14 @@ ARDOUR::get_alsa_audio_device_names (std::map<std::string, std::string>& devices
        string devname;
        int cardnum = -1;
        int device = -1;
+       const char* fixed_name;
+
+       if ((fixed_name = g_getenv ("ARDOUR_ALSA_DEVICE"))) {
+               devices.insert (make_pair<string,string> (fixed_name, fixed_name));
+               return;
+       }
+
+       assert (duplex > 0);
 
        while (snd_card_next (&cardnum) >= 0 && cardnum >= 0) {
 
@@ -63,7 +73,7 @@ ARDOUR::get_alsa_audio_device_names (std::map<std::string, std::string>& devices
                                snd_pcm_info_set_subdevice (pcminfo, 0);
                                snd_pcm_info_set_stream (pcminfo, SND_PCM_STREAM_CAPTURE);
 
-                               if (snd_ctl_pcm_info (handle, pcminfo) < 0) {
+                               if (snd_ctl_pcm_info (handle, pcminfo) < 0 && (duplex & HalfDuplexIn)) {
                                        continue;
                                }
 
@@ -71,7 +81,7 @@ ARDOUR::get_alsa_audio_device_names (std::map<std::string, std::string>& devices
                                snd_pcm_info_set_subdevice (pcminfo, 0);
                                snd_pcm_info_set_stream (pcminfo, SND_PCM_STREAM_PLAYBACK);
 
-                               if (snd_ctl_pcm_info (handle, pcminfo) < 0) {
+                               if (snd_ctl_pcm_info (handle, pcminfo) < 0 && (duplex & HalfDuplexOut)) {
                                        continue;
                                }
                                devname += ',';
@@ -170,6 +180,58 @@ ARDOUR::get_alsa_rawmidi_device_names (std::map<std::string, std::string>& devic
        }
 }
 
+void
+ARDOUR::get_alsa_sequencer_names (std::map<std::string, std::string>& devices)
+{
+       snd_seq_t *seq= NULL;
+       snd_seq_client_info_t *cinfo;
+       snd_seq_port_info_t *pinfo;
+
+       snd_seq_client_info_alloca (&cinfo);
+       snd_seq_port_info_alloca (&pinfo);
+
+       if (snd_seq_open (&seq, "hw", SND_SEQ_OPEN_DUPLEX, 0) < 0) {
+               return;
+       }
+
+       snd_seq_client_info_set_client(cinfo, -1);
+       while (snd_seq_query_next_client (seq, cinfo) >= 0) {
+               int client = snd_seq_client_info_get_client (cinfo);
+               if (client == SND_SEQ_CLIENT_SYSTEM) {
+                       continue;
+               }
+               if (!strcmp (snd_seq_client_info_get_name(cinfo), "Midi Through")) {
+                       continue;
+               }
+               snd_seq_port_info_set_client (pinfo, client);
+               snd_seq_port_info_set_port (pinfo, -1);
+
+               while (snd_seq_query_next_port (seq, pinfo) >= 0) {
+                       int caps = snd_seq_port_info_get_capability(pinfo);
+                       if (0 == (caps & (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_WRITE))) {
+                               continue;
+                       }
+                       if (caps & SND_SEQ_PORT_CAP_NO_EXPORT) {
+                               continue;
+                       }
+                       std::string card_name;
+                       card_name = snd_seq_port_info_get_name (pinfo);
+
+                       card_name += " (";
+                       if (caps & SND_SEQ_PORT_CAP_READ) card_name += "I";
+                       if (caps & SND_SEQ_PORT_CAP_WRITE) card_name += "O";
+                       card_name += ")";
+
+                       std::string devname;
+                       devname = PBD::to_string(snd_seq_port_info_get_client (pinfo), std::dec);
+                       devname += ":";
+                       devname += PBD::to_string(snd_seq_port_info_get_port (pinfo), std::dec);
+                       devices.insert (std::make_pair (card_name, devname));
+               }
+       }
+       snd_seq_close (seq);
+}
+
 int
 ARDOUR::card_to_num(const char* device_name)
 {