Comments (5)
Can you show your code? Where do you get this '10' from? And what are the exact sequences you get in python-Jackclient?
The ControlChangeEvent object should contain all the data sent by the keyboard with the ControlChange MIDI message. In some cases one parameter change can cause two events being sent (for 14 bit values).
If it is more convenient for you to work with midi bytes you can pass prefer_bytes=True to event_input() method to receive MidiBytesEvent instead of ControlChangeEvent.
from python-alsa-midi.
I just started learnig Python and PyQt and I'd like to make some midi stuff with both backends, so I'm trying to get same results from both.
10 comes from event.param. Code:
client = SequencerClient("my client")
port = client.create_port("output", caps=READ_PORT)
dest_port = client.list_ports(output=True)[0]
inport = client.create_port("inout")
#parse input event
while True:
event = client.event_input()
print(repr(event))
etype = str(event.type).split('.')[1]
if etype == 'NOTEON':
print(event.note)
if etype == 'CONTROLLER':
print('CTRL: '+ str(event.param) + ' Value: '+str(event.value))
Code for jackClient it's almost this: https://jackclient-python.readthedocs.io/en/0.5.3/examples.html#midi-chord-generator
for offset, indata in inport.incoming_midi_events():
if len(indata) == 3:
status, pitch, vel = struct.unpack('3B', indata)
status = 176, pitch = 10 and vel is the value like event.value
I just need a way to indentify the controller with both backends
Thanks.
from python-alsa-midi.
First (off-topic, sorry), you are testing event type in a very convoluted (and inefficient) way. Doing (str) on an object and then parsing the result is probably never the right way. The Python way to do it would be:
if isinstance(event, NoteOnEvent):
...
elif isinstance(event, ControlChangeEvent):
...
or:
if event.type == EventType.NOTEON:
...
elif event.type == EventType.CONTROLLER:
...
Second: Your 'status' as read from Jack includes channel number. Control change status byte is 0xBn where 'n' is channel number. So byte sequence '176 10 22' is a control change message in channel 0 (or 1 – MIDI channels can be numbered either way), for controller 10 with value 22. And '177 10 66' is control change message in channel 1 (or 2, depending how you count), controller 10 and value 66.
The channel number is available in the channel attribute of the ControlChangeEvent:
if isinstance(event, ControlChangeEvent):
print(f"Control change received on channel {event.channel}: controller {event.param} value: {event.value}")
from python-alsa-midi.
Thanks for the explanation (also for hints about code) but I still don't understand how to get compatible results between alsa and jack. Sorry if this has become more of a request for help than an issue..
Thanks.
EDIT: found this: ei = int('0xb'+str(event.channel),0) # match jackClient output
from python-alsa-midi.
Please, no str() + int(), that is a huge 'code smell'.
If you want convert this way (from ControlChangeEvent to the status code like you get from jack), then try this:
status = 0x0b + event.channel
Or, the same without hex:
status = 176 + event.channel
from python-alsa-midi.
Related Issues (3)
- Not receiving MIDI port events HOT 2
- Support python 3.11? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-alsa-midi.