Comments (5)
Thanks for this code example!
It doesn't quite work, though. It seems to work, but it doesn't actually forward all messages.
The problem is that you are accessing and modifying the Python list
s midiInBuffer
and midiOutBuffer
from two different threads.
If you want to transport events from one thread to another, you should use something like jack.RingBuffer
from this module or queue.Queue
from the Python standard library.
Also, it is unclear to me why you transfer the messages out of the callback into the main thread, just to transfer them back into the callback without doing anything else?
Why don't you just forward the messages in the callback?
Then you'll have an example very similar to midi_chords.py. If you remove about half of the process function, you'll get just the forwarding feature:
jackclient-python/examples/midi_chords.py
Lines 23 to 28 in 3462e73
from jackclient-python.
Related issue #47.
from jackclient-python.
You are so right ! I changed the example as follows:
import jack
import struct
client = jack.Client('jack')
midi_in = client.midi_inports.register('midi_in')
midi_out = client.midi_outports.register('midi_out')
@client.set_process_callback
def process(frames):
midi_out.clear_buffer()
#forward received MIDI data
for offset, data in midi_in.incoming_midi_events():
midi_out.write_midi_event(offset, data)
#unpack data for printing
msg = struct.unpack('3B', data)
print('MIDI rcvd = ', msg)
client.activate()
#print all ports
print(client.get_ports())
#print client ports
#print(client.midi_inports)
#print(client.midi_outports)
#connect to MIDI data source
#client.connect('MyMIDISoftware:midi_out', midi_in)
#connect to MIDI data destination
#client.connect(midi_out, MyOtherMIDISoftware:midi_in')
#do something else like running a GUI to configure MIDI source/destination connections
with client:
print('#' * 80)
print('press Return to quit')
print('#' * 80)
input()
from jackclient-python.
Yes, now it nearly works. You are only missing an import
statement:
import struct
And please note that you are waiting in a so-called "tight loop", that means the while
loop is executed as fast as the CPU is able to. You should look at a CPU meter while your program is running!
Have a look at my examples for other ways of waiting that don't use all available CPU power.
Now your example is very close to my midi_chords.py
example, isn't it?
BTW, I've just uploaded a new MIDI example: #61
What do you think about it?
from jackclient-python.
Ah yes, I forgot to copy the struct stmt over from my RPi where I was working on this. The while loop is bad indeed so I copied your code from midi_chords.py. And yes the example is very close to your midi_chords.py now. Not sure why I wasn't able to understand how to use write_midi_event from midi_chords.py back in November when I was working on this, see https://github.com/I-CubeX/PythonExamples/blob/master/AnalogReadMIDI.py. Thanks again for your help, and for the new example (one can't have enough examples .. ) !
from jackclient-python.
Related Issues (20)
- Audio + MIDI HOT 13
- More than one callback in `jack.Client.set_process_callback` HOT 3
- Jack keeps sending last MIDI messages HOT 1
- negative xrun times HOT 4
- Real-time plotting example HOT 4
- Wrong kind of system capture HOT 2
- FR: jack.Ringbuffer example HOT 6
- Anyway to check if client is activated HOT 2
- Is there a way to get the precise time that each period is played? HOT 4
- Example program for playing audio data from memory? HOT 2
- Library not found on Apple silicon HOT 7
- plot get_array() data in real-time HOT 5
- jack client closes itself just after start HOT 13
- playing sound in 3 speaker devices HOT 2
- "operands could not be broadcast together with shapes" error playing sound HOT 6
- How To Access Multiple Soundcard? HOT 4
- API for starting and controlling a JACK server? HOT 21
- Segfault during import HOT 5
- JackOpenError when (re)creating clients with identical name HOT 3
- midi_file_player.py + multiprocessing HOT 7
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 jackclient-python.