Repository navigation
Implement Port.alias() property. - #45
Conversation
+ uses "int jack_port_get_aliases(const jack_port_t * port, char *const aliases[2])" from the jack C library.
|
Thanks for this PR! What about adding There seem to be up to two aliases per port, what about returning a |
| out-hw-2-0-0-MK-249C-USB-MIDI-keyboard-MIDI- | ||
|
|
||
| """ | ||
| aliases=[_ffi.new("char[0xff]"), _ffi.new("char[0xff]")] |
There was a problem hiding this comment.
You should probably use port_name_size() instead of 0xff?
There was a problem hiding this comment.
I think port_name_size() return the size of the "name", not the alias. I've not found any way of getting the alias size, so i decided to use 255, that should be enough ... i hope ;-)
There was a problem hiding this comment.
Sorry, i just read the "set_alias" documentation and it says:
Set alias as an alias for port. May be called at any time. If the alias is longer than jack_port_name_size(), it will be truncated.
So i think you are right. I will change the code ;-)
|
I've implemented this feature because i need it. I've no need for the set_alias and unset_alias functions, although it's pretty simple to implement. I will do. Also, i will return a list of aliases ;-) |
+ Change the name of property alias to aliases. Now it returns a list of 2 strings. + Use jack_port_name_size() for correctly set the size of strings in aliases property getter.
|
Done! ;-) |
|
Thanks a lot for the changes! |
|
I just added a little test to examples for easier reviewing ;-) |
|
The API of Returning a list which may have empty strings in it (or even |
|
Another thought: We could even return a |
…nstead of a 2-elements hardcoded list.
|
OK to the first part. Returning a set is not a good idea because the aliases sorting is lost. |
|
Thanks for the changes! Does a "sorted list of aliases" even make sense? How would you use the Anyway, I'm not totally convinced about using a |
| aliasesptr=_ffi.new("char *[]", aliases) | ||
| result=[] | ||
| if (_lib.jack_port_get_aliases(self._ptr, aliasesptr) > 0): | ||
| alias1=_ffi.string(aliases[0]).decode() |
There was a problem hiding this comment.
You could reduce the duplication by using something like
for i in 0, 1:
alias = ... aliases[i] ...
if alias:
result.append(alias)|
OK! I've improved the code, reducing the redundance. |
|
OK, thanks for the changes, let's keep the Now there are just a few formal issues left, regarding PEP-8 and PEP-257. Please rename the example file, because files starting and ending with "test" should be reserved for automated tests (e.g. py.test looks for those files). |
|
|
||
| @property | ||
| def aliases(self): | ||
| """A list of 2 strings containing the aliases for the JACK port.""" |
There was a problem hiding this comment.
Please updated the docstring to reflect the changed code.
| aliases=[_ffi.new(ctype), _ffi.new(ctype)] | ||
| aliasesptr=_ffi.new("char *[]", aliases) | ||
| result=[] | ||
| if (_lib.jack_port_get_aliases(self._ptr, aliasesptr) > 0): |
There was a problem hiding this comment.
The outer parentheses are not necessary.
The "> 0" isn't strictly necessary either, but you can keep it if you think it makes the situation clearer.
| @property | ||
| def aliases(self): | ||
| """A list of 2 strings containing the aliases for the JACK port.""" | ||
| ctype="char[%d]" % _lib.jack_port_name_size() |
There was a problem hiding this comment.
Please use .format(), because that's used in the rest of the code, too.
| ports = client.get_ports() | ||
|
|
||
| print('Testing set_alias() ...') | ||
| i=0 |
There was a problem hiding this comment.
Classic case for enumerate(): https://docs.python.org/3/library/functions.html#enumerate.
|
OK @mgeier! I hope everything is OK now ;-) |
|
Thanks for the changes! Did you consider these comments of mine?
You are using tabs in the example file, which is a no-go. You should check for PEP-8 issues (e.g. with Finally, please also use |
|
OK! Let's see now ... cross my fingers ;-D |
|
Thanks a lot @jofemodo! |
|
It's been a pleasure, @mgeier ;-) |
Uses "int jack_port_get_aliases(const jack_port_t * port, char *const aliases[2])" from the jack C library.