Logo Search packages:      
Sourcecode: patchage version File versions  Download package

void AlsaDriver::refresh_ports (  )  [private]

Refresh all Alsa Midi ports.

Definition at line 98 of file AlsaDriver.cpp.

Referenced by refresh().

{
      snd_seq_client_info_t* cinfo;
      snd_seq_client_info_alloca(&cinfo);
      snd_seq_client_info_set_client(cinfo, -1);

      snd_seq_port_info_t * pinfo;
      snd_seq_port_info_alloca(&pinfo);
      
      string client_name;
      string port_name;
      bool is_input;
      bool is_duplex;
      bool is_application;
      
      while (snd_seq_query_next_client (m_seq, cinfo) >= 0) {
            snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo));
            snd_seq_port_info_set_port(pinfo, -1);

            client_name = snd_seq_client_info_get_name(cinfo);

            while (snd_seq_query_next_port(m_seq, pinfo) >= 0) {
                  int caps = snd_seq_port_info_get_capability(pinfo);
                  int type = snd_seq_port_info_get_type(pinfo);

                  // Skip ports we shouldn't show
                  if (caps & SND_SEQ_PORT_CAP_NO_EXPORT)
                        continue;
                  else if ( !( (caps & SND_SEQ_PORT_CAP_READ)
                                    || (caps & SND_SEQ_PORT_CAP_WRITE)
                                    || (caps & SND_SEQ_PORT_CAP_DUPLEX)))
                        continue;
                  else if (type == SND_SEQ_PORT_SYSTEM_TIMER)
                        continue;
                  else if (type == SND_SEQ_PORT_SYSTEM_ANNOUNCE)
                        continue;
                  
                  const snd_seq_addr_t addr = *snd_seq_port_info_get_addr(pinfo);
                  
                  is_duplex = false;

                  // FIXME: Should be CAP_SUBS_READ etc?
                  if ((caps & SND_SEQ_PORT_CAP_READ) && (caps & SND_SEQ_PORT_CAP_WRITE))
                        is_duplex = true;
                  else if (caps & SND_SEQ_PORT_CAP_READ)
                        is_input = false;
                  else if (caps & SND_SEQ_PORT_CAP_WRITE)
                        is_input = true;

                  is_application = (type & SND_SEQ_PORT_TYPE_APPLICATION);
                  port_name = snd_seq_port_info_get_name(pinfo);
                  PatchageModule* m = NULL;
                  
                  //cout << client_name << " : " << port_name << " is_application = " << is_application
                  //    << " is_duplex = " << is_duplex << endl;

                  // Application input/output ports go on the same module
                  if (is_application) {
                        m = (PatchageModule*)m_patch_bay->find_module(client_name, InputOutput);
                        if (m == NULL) {
                              m = new PatchageModule(m_app, client_name, InputOutput);
                              m->load_location();
                              m->store_location();
                              m_patch_bay->add_module(m);
                        }
                        
                        if (!is_duplex) {
                              m->add_patchage_port(port_name, is_input, ALSA, addr);
                        } else {
                              m->add_patchage_port(port_name, true, ALSA, addr);
                              m->add_patchage_port(port_name, false, ALSA, addr);
                        }
                  } else { // non-application input/output ports (hw interface, etc) go on separate modules
                        PatchageModule* m = NULL;
                        ModuleType type = InputOutput;
                        
                        // The 'application' hint isn't always set by clients, so this bit
                        // is pretty nasty...

                        if (!is_duplex) {  // just one port to add
                              if (is_input) type = Input;
                              else type = Output;
                              
                              // See if an InputOutput module exists (maybe with Jack ports on it)
                              m = (PatchageModule*)m_patch_bay->find_module(client_name, InputOutput);
                        
                              if (m == NULL)
                                    m = (PatchageModule*)m_patch_bay->find_module(client_name, type);
                              if (m == NULL) {
                                    m = new PatchageModule(m_app, client_name, type);
                                    m->load_location();
                                    m->store_location();
                                    m_patch_bay->add_module(m);
                              }
                              m->add_patchage_port(port_name, is_input, ALSA, addr);
                        } else {  // two ports to add
                              type = Input;
                              
                              // See if an InputOutput module exists (maybe with Jack ports on it)
                              m = (PatchageModule*)m_patch_bay->find_module(client_name, InputOutput);
                              
                              if (m == NULL)
                                    m = (PatchageModule*)m_patch_bay->find_module(client_name, type);
                              if (m == NULL) {
                                    m = new PatchageModule(m_app, client_name, type);
                                    m->load_location();
                                    m->store_location();
                                    m_patch_bay->add_module(m);
                              }
                              m->add_patchage_port(port_name, true, ALSA, addr);

                              type = Output;
                              
                              // See if an InputOutput module exists (maybe with Jack ports on it)
                              m = (PatchageModule*)m_patch_bay->find_module(client_name, InputOutput);
                              
                              if (m == NULL)
                                    m = (PatchageModule*)m_patch_bay->find_module(client_name, type);
                              if (m == NULL) {
                                    m = new PatchageModule(m_app, client_name, type);
                                    m->load_location();
                                    m->store_location();
                                    m_patch_bay->add_module(m);
                              }
                              m->add_patchage_port(port_name, false, ALSA, addr);
                        }
                  }
            }
      }
}


Generated by  Doxygen 1.6.0   Back to index