Page 1 of 1

Writing a Sequencer, outputting MIDI messages?

Posted: Sun Feb 06, 2022 2:52 pm
by jwhitmore
I'm trying to write a simple MIDI sequencer on OpenSUSE Tumbleweed, at the moment, writing in C++. To start with I was just outputting text messages to the terminal window to see that things were behaving, as I'd expect them to. Having gotten that far I decided that I'd try outputting MIDI messages that I might be able to connect to a simple synth like qsynth.

I haven't gotten to installing qsynth as yet, probably need Jack and a few things to get all that working. For the moment I found a library, RtMidi [1] which looked like a good way to simplify things. OpenSUSE Tumbleweed had a package for install, (rtmidi-devel) which got me the necessary header file to compile against, but I can't see any library, '*.so' file, to link against.

So there's a number of questions, firstly is there a better way then using RtMidi [1], which is more 'standard'? Instead of chasing a non existent library for OpenSUSE Tumbleweed I see that RtMidi is on github so I guess I can just pull that into my source tree and compile and link from there. The first question though is have I gone down the wrong route to doing this with RtMidi?

[1] http://www.music.mcgill.ca/~gary/rtmidi/

Re: Writing a Sequencer, outputting MIDI messages?

Posted: Sun Feb 06, 2022 3:01 pm
by SpotlightKid
If you want cross-platform support RtMidi is a good choice. If you are only developing for Linux, using the ALSA or JACK API directly is not that hard either.

RtMidi can be used by just dropping the RtMidi.cpp and .h file into your project and compiling it in statically. Details are at the bottom of the home page.

The debian package probably just install the static library (librtmidi.a or similar). You should be able to just add that to the list of objects for your linking stage.

Re: Writing a Sequencer, outputting MIDI messages?

Posted: Sun Feb 06, 2022 3:56 pm
by jwhitmore
Thank you SpotlightKid.

I actually headed off and did what you suggested, pulling the two RtMidi files into my project and just compiling from there. Unfortunately when I executed the example MIDI out section of code I got the result:

MidiOutDummy: This class provides no functionality.
There are 0 MIDI output ports available.

I'm guessing that if I plugged in a USB MIDI cable that result would change, but I was hoping to have a connection appear in Jack so that I could connect that to qsynth. I guess Jack API is the way to go, so I'll do a bit of searching. Kinda answers my questions about RtMidi though.

Thanks again.

Re: Writing a Sequencer, outputting MIDI messages?

Posted: Sun Feb 06, 2022 3:59 pm
by SpotlightKid
jwhitmore wrote: Sun Feb 06, 2022 3:56 pm MidiOutDummy: This class provides no functionality.
There are 0 MIDI output ports available.
You have to set the right compiler defines. Again, read the "Compiling" section at the end of the RtMidi homepage.

Re: Writing a Sequencer, outputting MIDI messages?

Posted: Sun Feb 06, 2022 4:05 pm
by SpotlightKid
jwhitmore wrote: Sun Feb 06, 2022 3:56 pm I was hoping to have a connection appear in Jack so that I could connect that to qsynth.
For that you need to compile in JACK support (see answer above) and then use the openVirtualPort method of you MidiOut instance.

Re: Writing a Sequencer, outputting MIDI messages?

Posted: Sun Feb 06, 2022 5:56 pm
by milkii

Re: Writing a Sequencer, outputting MIDI messages?

Posted: Sun Feb 06, 2022 8:45 pm
by jwhitmore
Sorry I flew though that virtual port section, of documentation, and only when you pointed it out did the penny drop. So thanks again. It works have a MIDI port showing up in qjackctl!

Re: Writing a Sequencer, outputting MIDI messages?

Posted: Mon Feb 07, 2022 3:25 am
by MusicMan74
Maybe a stretch, but is there something of value you could learn/use from:

http://www.mikekohn.net/music/drumsplusplus.php

Re: Writing a Sequencer, outputting MIDI messages?

Posted: Mon Feb 07, 2022 4:43 am
by j_e_f_f_g
Here's a tutorial I wrote about the rawmidi API.

Re: Writing a Sequencer, outputting MIDI messages?

Posted: Tue Feb 08, 2022 10:44 pm
by digitsun
Congratulations for your effort @jwhitmore.

I consider that in GNU/Linux audio space lacks a good and dedicated (only) MIDI sequencer. Let me explain the actual situation.
  • Ardour has a unique MIDI style: awful. But Ardour has a good performance, is stable, plugin friendly, has a lot of functionalities (for audio) and huge community.
  • Qtractor follows the standard MIDI workflow, has a good performance and the plugin compatibility is not so good like Ardour. The problem is that Qtractor don't has all the possibilities of Ardour, also the development depends of only one man: Rui.
  • Muse is good with MIDI and audio, but, again, Ardour is more complete (consequently has a big community and big development team)
  • Zrythm is still apha.
I think there's a big hole for fill: a dedicated MIDI sequencer. With Jack you can work with Ardour for to sequence audio and to manage plugins, and with a external MIDI sequencer you can edit all midi stuff.

The most important thing is keep it simple: only MIDI.

Re: Writing a Sequencer, outputting MIDI messages?

Posted: Wed Feb 09, 2022 9:59 am
by Linuxmusician01
@digitsun: and there's good old Seq24 as well. Nowadays you need very strong reading glasses for it's interface but it does one single job without distractions: sequence Midi (notes).

Re: Writing a Sequencer, outputting MIDI messages?

Posted: Wed Feb 09, 2022 10:02 am
by SpotlightKid
Seq66 is its modern successor.

Re: Writing a Sequencer, outputting MIDI messages?

Posted: Wed Feb 09, 2022 10:40 am
by Linuxmusician01
SpotlightKid wrote: Wed Feb 09, 2022 10:02 am Seq66 is its modern successor.
Thanks! There's also Seq64 which is in the KXStudio repository. I think they're all the same. Maybe some of 'm have a scaling option for the interface if you've got a large screen.

Re: Writing a Sequencer, outputting MIDI messages?

Posted: Thu Feb 17, 2022 12:36 pm
by jwhitmore
So I have made progress on my sequencer and I'm outputting MIDI messages which I'm connecting with Jack, running on pipewire, to QSynth.

The next question is how to schedule these MIDI messages accurately so that it's actually music. The scheduling is doing to depend on the tempo of the music but regardless needs to be accurate, to some level. I guess I could set up a regular expiring timer and fire messages on expiration. Set a timer for 24 times per quarter note, figuring out for tempo. That seems like the most obvious method and probably a good place to start.