Enrico Zini: Generating MIDI events with JACK and Python
I had a go at trying to figure out how to generate arbitrary MIDI events and
send them out over a JACK MIDI channel.
Setting up JACK and Pipewire
Pipewire has a JACK interface, which in theory means one could use JACK clients
out of the box without extra setup.
In practice, one need to tell JACK clients which set of libraries to use to
communicate to servers, and Pipewire's JACK server is not the default choice.
To tell JACK clients to use Pipewire's server, you can either:
Running the example
I ran the
- on a client-by-client basis, wrap the commands with pw-jack
- to change the system default:
cp /usr/share/doc/pipewire/examples/ld.so.conf.d/pipewire-jack-*.conf /etc/ld.so.conf.d/and runldconfig(see the Debian wiki for details)
play method converts delays in seconds to frame counts, and the
on_process callback moves events from the queue to the jack output.
Here's an example script that plays a simple drum pattern:
#!/usr/bin/python3
# Example JACK midi event generator
#
# Play a drum pattern over JACK
import time
from pyeep.jackmidi import MidiPlayer
# See:
# https://soundprogramming.net/file-formats/general-midi-instrument-list/
# https://www.pgmusic.com/tutorial_gm.htm
DRUM_CHANNEL = 9
with MidiPlayer("pyeep drums") as player:
beat: int = 0
while True:
player.play("note_on", velocity=64, note=35, channel=DRUM_CHANNEL)
player.play("note_off", note=38, channel=DRUM_CHANNEL, delay_sec=0.5)
if beat == 0:
player.play("note_on", velocity=100, note=38, channel=DRUM_CHANNEL)
player.play("note_off", note=36, channel=DRUM_CHANNEL, delay_sec=0.3)
if beat + 1 == 2:
player.play("note_on", velocity=100, note=42, channel=DRUM_CHANNEL)
player.play("note_off", note=42, channel=DRUM_CHANNEL, delay_sec=0.3)
beat = (beat + 1) % 4
time.sleep(0.3)
jack_drums script, and of course not much happened.
First I needed a MIDI synthesizer. I installed
fluidsynth, and ran it on the
command line with no arguments. it registered with JACK, ready to do its thing.
Then I connected things together. I used
qjackctl, opened the graph view, and
connected the MIDI output of "pyeep drums" to the "FLUID Synth input port".
fluidsynth's output was already automatically connected to the audio card and I
started hearing the drums playing!








February ended up being a very short work month as I made a last minute decision to travel to Adelaide for the first 2 weeks of the month to help my brother with some house renovations he was undertaking. I thought I might be able to keep up with some work and my writing goals in the evenings while I was there, but days of hard manual labour are such an unfamiliar routine for me that I didn t have any energy left to make good on that intention.
The majority of my time and focus for the remaining one and half weeks of the month was catching up on the consulting work that I had pushed back while in Adelaide.
So while it doesn t make for a thrilling first month to look back and report on, overall I m not unhappy with what I achieved given the time available. Next month, I hope to be able to report some more exciting progress on the product development front as well.
Hello World! I haven't really had time to blog here since the start of the
semester, as I've been pretty busy at work
You should try to
Thunderbird, srsly?
5MB (or 4.8MiB) import limit. Sure. My modest pubring (111 keys) is 18MB. The
in the
A new minor release of our
This release adds a versioned dependency on the just released
Icy morning Witch Wells Az
),
and from time-to-time I ve made sure that my code runs on OpenBSD
too.
Platforms beyond that will likely not be supported at the expense of either
of those two. I ll take fixes for bugs that fix a problem on another
platform, but not damage the code to work around issues / lack of features
on other platforms (like Windows).
Like each month, have a look at the work funded by
Back in September last year I chose to back the
I haven t seen any actual stability problems, but I wouldn t want to run for any length of time like that. I ve ordered a heatsink and also realised that the board supports a Raspberry Pi style PoE Hat , so I ve got one of those that includes a fan ordered (I am a complete convert to PoE especially for small systems like this).
With the desk fan setup I ve been able to run the board for extended periods under load (I did a full recompile of the Debian 6.1.12-1 kernel package and it took about 10 hours). The M.2 slot is unfortunately only a single PCIe v2 lane, and my testing topped out at about 180MB/s. IIRC that is about half what the slot should be capable of, and less than a 10th of what the SSD can do. Ethernet testing with
I have mentioned several times in this blog, as well as by other
communication means, that I am very happy with the laptop I bought
(used) about a year and a half ago:
Yes, I knew from the very beginning that using this laptop would pose
a challenge to me in many ways, as full hardware support for ARM
laptops are nowhere as easy as for plain boring x86 systems. But the
advantages far outweigh the inconvenience (i.e. 
I love free software and I OSUOSL
So in December 2018 I was approached somewhat out of the blue by someone from
OSUOSL who offered eight servers to the Reproducible Builds project and as these
machines had 32 cores and 144 GB Ram each (plus 3 TB on a single HDD) and
they also offered free hosting, I very happyly said yes.
And since them I'm a very happy Oregon State University Open Source Labs user,
and these days we're switching the setup to different machines, which
is another story to tell some other time...!
My point now is: since 2018 I got to know OSUOSL and every year I like them more.
They are super friendly, reliable (a working ticket system and a great IRC channel), offer help in various ways, be it with DNS names (and renamings...) or
finding new hardware suited to our needs or whatever else we come up with. They are really dedicated to help free software projects
and I'm grateful having the privilege to enjoy this since more than four years now.
To quote
Thank you, everybody at OSUOSL! You rock and make a big difference for many projects!