Skip to content

Support for MIDI ports - #2

Merged
mgeier merged 7 commits into
masterfrom
midi
Feb 19, 2015
Merged

mgeier merged 7 commits into
masterfrom
midi

Conversation

@mgeier

@mgeier mgeier commented Jan 8, 2015

Copy link
Copy Markdown
Member

This was brought up in #1, but I think it deserves a separate issue.

I initially only thought about audio ports, but of course it would also be nice to support JACK MIDI ports.

In this issue I'd like to collect some ideas about how to extend the current module to support MIDI ports in a meaningful, easy-to-use way.

@mgeier

mgeier commented Dec 26, 2014

Copy link
Copy Markdown
Member Author

If I'm not mistaken, the main difference between audio and MIDI ports is the "port type".
This is one of the strings available as JACK_DEFAULT_AUDIO_TYPE and JACK_DEFAULT_MIDI_TYPE.

Is there any other "port type" used anywhere?

If not, I think we shouldn't expose the "port type" string (nor the "port type id", which doesn't seem to be used anywhere at all), we should rather find a more Pythonic abstraction.

One possibility would be to have two classes, AudioPort and MidiPort (and also OwnAudioPort and OwnMidiPort).
Instead of checking the "port type" string, a user could test with isinstance(myport, jack.MidiPort).

Alternatively (or additionally?), we could also extend the port properties with is_audio and is_midi, similar to is_physical et al.
Something like this could also be used in Client.get_ports().

For creating ports, we currently use myclient.inports.register("my_port_name") and similar for output ports.
I wouldn't want to create a MIDI port by merely passing an argument (like is_midi=True) to the same function.
I also wouldn't like to have audio and MIDI ports all mixed up in Client.inports and Client.outports.
The whole reason why I created two separate "containers" was to avoid using an is_input/is_output argument all the time.
I think the same should happen with MIDI ports, so I guess we'll need 4 different containers: 2 for audio/MIDI times 2 for input/output.
The question, as always: how should they be called?

Client.audioinports, Client.audiooutports, Client.midiinports, Client.midioutports?
Something with more underscores?
Something completely different?

@mgeier mgeier mentioned this pull request Dec 26, 2014
@mgeier

mgeier commented Jan 4, 2015

Copy link
Copy Markdown
Member Author

Probably it's better (as @amstan suggested in #1 (comment)) to keep Port for audio ports and just derive MidiPort from it.
The same could be done for OwnPort and OwnMidiPort. But get_buffer() and get_array() would have to be disabled, because they cannot be used for MIDI ports.

Then we could also keep Client.inports and Client.outports for audio ports and add Client.midi_inports and Client.midi_outports for MIDI ports.

@mgeier

mgeier commented Jan 8, 2015

Copy link
Copy Markdown
Member Author

I added a commit with a possible implementation (14b43b9).

Now all types of ports can be compared.
A Port instance is equal to an OwnPort instance, if they wrap the
same port pointer (which can happen if multiple client objects were
created).
Before, it was only working for MIDI channel 1!
@amstan

amstan commented Jan 17, 2015

Copy link
Copy Markdown
Contributor

This looks pretty good, feel free to merge it.

Is there any other "port type" used anywhere?

Interesting thought but:

 jack.JackError: 'midi_out': port registration failed

gPortTypes only has 2 elements. What if i want to use jack to transport my own weird data?? heh

Something with more underscores?

That might be nice. midi_in_ports, and rename inports to be audio_in_ports (input perhaps?)

@mgeier

mgeier commented Jan 18, 2015

Copy link
Copy Markdown
Member Author

I don't understand your comment about the port registration failure, can you please clarify?

I don't know if one can actually invent a new port type as a user.
I've only seen audio and MIDI; and no trace of anything else.

If someone points out a use case I'm willing to consider it, but for now I think I'll stick with audio and MIDI and not exposing the actual "port type" and "port type ID" in the API.

About the list names ... I thought a bit about this and my current standpoint is this:

It seems that MIDI ports are kind of an add-on to JACK, and not really first-class citizens like audio ports.
Therefore, I think it makes sense to call the lists of audio ports inports and outports and then, as an add-on, call the MIDI ports midi_inports and midi_outports.
The same reasoning can be used for Port vs. MidiPort and OwnPort vs. OwnMidiPort.

IMHO, the names with one underscore look better than the ones with two underscores.

@amstan

amstan commented Feb 18, 2015

Copy link
Copy Markdown
Contributor
 jack.JackError: 'midi_out': port registration failed

I don't understand your comment about the port registration failure, can you please clarify?

I don't know if one can actually invent a new port type as a user.
I've only seen audio and MIDI; and no trace of anything else.

That was me trying to see if i can get another type of port that's not midi nor audio. Jack didn't let me and returned an error instead.

I'm ok with your other decisions. What I was saying about naming were mostly nits, feel free to ignore them.

Let's merge this pull request.

mgeier added a commit that referenced this pull request Feb 19, 2015
Support for MIDI ports

See #2.
@mgeier
mgeier merged commit 81c5a77 into master Feb 19, 2015
@mgeier
mgeier deleted the midi branch February 19, 2015 16:55
@mgeier mgeier added this to the 0.2.0 milestone May 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants