Repository navigation
thanks4opensource_aconnect_py - #31
thanks4opensource wants to merge 6 commits into
Conversation
Parses various input overloads such as 'client-name:port_name',
('client-name','port-name), etc., returns Address. Raises exception
if Address(client_id, port_id) doesn't exist. Added new fd() public
accessor. Added tests/test_sequencer_address.py. Modified
examples/connect.py to accept 'client-name:port-name'.
New aconnect.py, improved replacement for alsa-utils aconnect (aconnect.c). New SequencerClientBase.list_clients() and modified .list_ports() with include_kernel parameter. SequencerClientBase.fd property and .get_address() changed to .resolve_address(). Code formatting changes to pass flake8 checks. Added port.py PortDirection. Revert examples/connect.py to accept client/port by id only. Modified tests/test_sequencer_address() to run under pytest, and excluded from flake8.
Adds new aconnect.py, full replacement for alsa-utils/.../aconnect.c, including SequencerClientBase.resolve_address(), and output and usability improvments. New SequencerClientBase::list_clients(), port.py class PortDirection, and other additions to support aconnect.py functionality. Small updates to tests/test_port_query.py for new SequencerClientBase::list_clients() parameter. Incorporates large Jajcus commit 716751 (typing modernizations). Reverted examples/connect.py to original without resolve_address().
|
Looks good. There are just a few problems: Some unused variables, as reported by the pre-commit hook: The package won't build with alsa-lib < v1.2.10 any more, as the I have not tried it with actual MIDI devices and software – will do that when I am around the hardware. I have merged changes for main – there was one conflict to resolve (proper handling of all AddressType objects). |
|
One more thing: I really appreciate your work here. This seems to fix everything I didn't like in the original aconnect. This should be listed as an installed script in |
Adds new aconnect.py, full replacement for alsa-utils/.../aconnect.c, including SequencerClientBase.resolve_address(), and output and usability improvments. New SequencerClientBase::list_clients(), port.py class PortDirection, and other additions to support aconnect.py functionality. Small updates to tests/test_port_query.py for new SequencerClientBase::list_clients() parameter. Incorporates large Jajcus commit 716751 (typing modernizations). Reverted examples/connect.py to original without resolve_address(). Update: - Reverted additions of PortDirection, direction, snd_seq_port_info_get_direction(), PortDirection(), snd_seq_port_info_set_direction(), SND_SEQ_PORT_DIR_*, "PortDirection" as per request to allow building with alsa-lib < v1.2.10. - Replaced with `PortCaps.READ` and `.WRITE` for determining port input/output/bidirectional. - Removed redundant `global` declarations and unused `Exception as e` variables. - Improved error messages in aconnect.py
…connect_py' into thanks4opensource_aconnect_py
|
Glad you like aconnect.py. "Great minds think alike" ;) I removed the dependencies on I don't understand the syntax and semantics of I too am not completely happy with the I think I fixed many of the Related, the commit still passes the Finally: I ran into many problems that were beyond my "git knowledge" when trying to push these changes. I had to do a sequence of git "remote add", "fetch", "pull", and "merge" commands before |
This pull request adds a new
utilssubdirectory withaconnect.py.aconnect.pyis intended as an improved replacement foraconnect(compiled from https://github.com/alsa-project/alsa-utils/blob/master/seq/aconnect/aconnect.c). Its main feature is the use of the newSequencerClientBase.resolve_address()method allowing specification of client:port addresses by name, numeric ID, or any combination thereof. The UI was designed with usability as its first priority, strict adherence to orthogonality second, and backwards compatibility withaconnectthird, although no changes were made unless in support of the first two goals.The first and most obvious change is that
aconnect.pywithout any options outputs a default listing of clients, ports, and connections:This differs from
aconnectwhich prints its help message by default, but matches most other UNIX utilities such asls, etc. Any user of the shell commandline will certainly know to use-h,--help, etc., andaconnect.pynot only prints the canonical Pythonargparseusage message if given bad options but also "'aconnect.py -h' for help and options" after any error (thusaconnect.py somerandomjunkwill provide that information).The help message itself, listing the program's many features, is:
A few of these will be described here, but first note in the default output:
aconnect.aconnect's misleading `Connecting To". (The connection has been made and exists, not "is in the process of connecting but not finished yet".)The various options provide enhanced control of the output listing. For example, only the clients themselves without their ports/connections (but reports number of ports for each client):
Include kernel ("system") and/or PipeWire clients (illustrated here with
--clientsbut works equally well with normal clients+ports+connections display):Also
-f,--fullfor extra information:Of course the second most frequent use of the utility is likely connecting ports together, thus no
--connector similar is required (as peraconnect). But any combination of client:port names or numeric IDs is accepted, along with the convention that a client without ":port" (or ".port") implies port 0, and is accepted (as long as the client has a port 0, and its input, output, or bidirectional gender is appropriate for the connection being made). All of the following (any many other variations) produce the same result:Removing (deleting) connections is another departure from
aconnect, although the most canonical case of removing a single connection between two ports remains the same (except for the additional name-instead-of-numerical-port capability).The
-d,--deleteoption behaves polymorphically depending on the number and types of arguments given. Again, all name/ID/abbreviation/implicit0 variations produce the same result:The differences arise with the other
-dmodes. Given a single client:port address it will delete all connections to/from the port. However it first reports the existing connections, and asks for user confirmation before deleting them. This is not implemented in the explicitaconnect.py -d clientA:portB clientC:portDcase because that can easily be "undone" by repeating without the-doption. The report/confirmation happens in the following cases because the user may not remember the existing connections or have done a plainaconnect.pybefore deleting them, thus recreating them if a mistake was made might be difficult. (But the-D,--DELETEoptions, intended for non-interactive shell scripts, override this behavior.)The same is implemented for removing all connections to/from all of a single client's ports:
And all connections between all clients' ports (completely removing the need for
aconnect's specific-x,--removalloption):Finally, any subset of existing clients/ports/connections can be listed:
although if exactly two clients are requested an explicit
-l,--listflag must be provided to distinguish the command from connecting two client's ports (including use of implicit port 0):Notes on the code:
I cannot provide a unittest for
aconnect.pyat this time. Unittests for interactive programs are notoriously hard and time consuming to write. I have tested the code continuously during a long period of incremental development, and will be using it extensively in my own day-to-day work. I'll attempt to fix any bugs I find and/or ones that are reported to me.The large changes from commit 716751 were manually merged here to ease merging this into main if and when desired.
toxstill runstests/*without errors, despite the small additions and changes made inalsa_util/port.pyandtests/test_port_query.py. See the commit message.aconnect.pywas formatted viaautopep8to meet approved standards.mypy utils/aconnect.pyreports "Success: no issues found in 1 source file".mypy utils/aconnect.py alsa_midi(which showed some issues inaconnect.py, now fixed) reports "Found 86 errors in 7 files (checked 12 source files)", none of them inaconnect.py.I am fairly sure the
aconnect.py--updateand--realoptions are implemented and call SequencerClientBase.subscribe_port() and _subunsub_port() correctly, and that the latter callsalsa.snd_seq_port_subscribe_set_time_update()andalsa.snd_seq_port_subscribe_set_time_real()correctly. Nevertheless,--realhas no effect, and--updatesets thetime_updateandtime_realin the connection both to True. I'm convinced this is a bug or mis-feature in the ALSA util library. Note thataconnect.chas some strange code implementing its own analogous options.