<div dir="ltr">Well, it depends on what you mean with "programmatically".<div>If you just need automatic connections and you run jack, you can use jack-plumbing.</div><div>You could also use aplaymidi/arecordmidi outputs and then use aconnect, as pointed out by Clemens.</div><div><br></div><div>If, otherwise, you need much more control, you'll need to interface with the pyalsa's alsaseq python module, possibly using an event loop (I used to interface with a Qt's QThread).</div><div>Unfortunally, pyalsa doesn't support python 3 yet (and I really hope they'll fix it).</div><div><br></div><div>You have to create an input "monitor" port, and connect it to the alsaseq system client and its system announce port, which notifies of every change in the alsa MIDI graph.</div><div>Have a look at this: <a href="https://github.com/MaurizioB/MidiGraph/blob/master/midigraph/__init__.py#L93">https://github.com/MaurizioB/MidiGraph/blob/master/midigraph/__init__.py#L93</a></div><div><br></div><div>Then, within the thread you use to monitor the graph changes, you can connect ports if their names/properties suit your needs.</div><div>Remember that alsaseq creates an event for every client created (alsaseq.SEQ_EVENT_CLIENT_START) and then an event for each port created (alsaseq.SEQ_EVENT_PORT_START). Also, when a client is "killed", usually you will receive a port exit for each port (alsaseq.SEQ_EVENT_PORT_EXIT) and, finally, a client exit (alsaseq.SEQ_EVENT_CLIENT_EXIT).</div><div>You will be probably interested in newly created port events, which have a python dict containing addr.client:client_id and addr.port:port_id items.</div><div>You can access client names using alsaseq.Sequencer().get_client_info(client_id) and port names with alsaseq.Sequencer().get_port_info(port_id, client_id) (be careful about the order of parameters): they will return dictionaries containing different values, but both of them will have a "name" key (AFAIR, the ID is not implicit for ports, which means that you might find that a client has 2 ports, and the second port's id is 2 because the port_id 1 has been destroyed).</div><div>Finally, the connections are made using alsaseq.Sequencer().connect_ports((client_id, port_id), (client_id, port_id)).<br><br>I know that this isn't the easiest method to get things done (pyalsa support and documentation are not very clear nor simple), but, as far as I've seen, it's the better and less error-prone I've found yet for this kind of needs...</div><div><br></div><div>Best regards,</div><div>Maurizio</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-01-28 21:52 GMT+01:00 Jonathan E. Brickman <span dir="ltr"><<a href="mailto:jeb@ponderworthy.com" target="_blank">jeb@ponderworthy.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>I need to connect ALSA MIDI programmatically, and will prefer to use Python.  I perused a number of libraries, did not find an obvious great or best.  Recommends?</div><span class="HOEnZb"><font color="#888888"><div><br></div><div><span><pre>-- <br></pre><span style="color:rgb(153,51,0);font-size:14px;font-style:italic;background-color:rgb(255,255,255)">Jonathan E. Brickman   </span><a class="m_-4843912771475955611moz-txt-link-abbreviated" href="mailto:jeb@ponderworthy.com" style="font-size:14px;font-style:italic" target="_blank">jeb@ponderworthy.<wbr>com</a><span style="color:rgb(153,51,0);font-size:14px;font-style:italic;background-color:rgb(255,255,255)">   (785)233-9977</span><br style="color:rgb(153,51,0);font-size:14px;font-style:italic"><span style="color:rgb(153,51,0);font-size:14px;font-style:italic;background-color:rgb(255,255,255)">Hear us at </span><a href="http://ponderworthy.com/" style="font-size:14px;font-style:italic" target="_blank">http://ponderworthy.com</a><span style="color:rgb(153,51,0);font-size:14px;font-style:italic;background-color:rgb(255,255,255)"> -- CDs and MP3 </span><a href="http://ponderworthy.com/ad-astra/ad-astra.html" style="font-size:14px;font-style:italic" target="_blank">now available!</a><br style="color:rgb(153,51,0);font-size:14px;font-style:italic"><span style="color:rgb(153,51,0);font-size:14px;font-style:italic;background-color:rgb(255,255,255)">Music of compassion; fire, and life!!!</span></span></div></font></span></div><br>______________________________<wbr>_________________<br>
Linux-audio-dev mailing list<br>
<a href="mailto:Linux-audio-dev@lists.linuxaudio.org">Linux-audio-dev@lists.<wbr>linuxaudio.org</a><br>
<a href="https://lists.linuxaudio.org/listinfo/linux-audio-dev" rel="noreferrer" target="_blank">https://lists.linuxaudio.org/<wbr>listinfo/linux-audio-dev</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>
</div>