Writing a Sequencer, outputting MIDI messages?

Programming applications for making music on Linux.

Moderators: MattKingUSA, khz

Post Reply
jwhitmore
Established Member
Posts: 23
Joined: Sat Feb 01, 2020 9:50 am

Writing a Sequencer, outputting MIDI messages?

Post 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/
User avatar
SpotlightKid
Established Member
Posts: 260
Joined: Sun Jul 02, 2017 1:24 pm
Has thanked: 57 times
Been thanked: 61 times

Re: Writing a Sequencer, outputting MIDI messages?

Post 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.
jwhitmore
Established Member
Posts: 23
Joined: Sat Feb 01, 2020 9:50 am

Re: Writing a Sequencer, outputting MIDI messages?

Post 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.
User avatar
SpotlightKid
Established Member
Posts: 260
Joined: Sun Jul 02, 2017 1:24 pm
Has thanked: 57 times
Been thanked: 61 times

Re: Writing a Sequencer, outputting MIDI messages?

Post 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.
User avatar
SpotlightKid
Established Member
Posts: 260
Joined: Sun Jul 02, 2017 1:24 pm
Has thanked: 57 times
Been thanked: 61 times

Re: Writing a Sequencer, outputting MIDI messages?

Post 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.
User avatar
milkii
Established Member
Posts: 477
Joined: Tue Jan 05, 2016 9:08 am
Location: Edinburgh
Has thanked: 92 times
Been thanked: 91 times
Contact:

Re: Writing a Sequencer, outputting MIDI messages?

Post by milkii »

they/them ta / libreav.org / wiki.thingsandstuff.org/Audio and related pages / gh

jwhitmore
Established Member
Posts: 23
Joined: Sat Feb 01, 2020 9:50 am

Re: Writing a Sequencer, outputting MIDI messages?

Post 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!
MusicMan74
Established Member
Posts: 15
Joined: Sat Nov 15, 2014 1:44 am
Has thanked: 1 time
Been thanked: 5 times

Re: Writing a Sequencer, outputting MIDI messages?

Post by MusicMan74 »

Maybe a stretch, but is there something of value you could learn/use from:

http://www.mikekohn.net/music/drumsplusplus.php
j_e_f_f_g
Established Member
Posts: 2032
Joined: Fri Aug 10, 2012 10:48 pm
Been thanked: 358 times

Re: Writing a Sequencer, outputting MIDI messages?

Post by j_e_f_f_g »

Here's a tutorial I wrote about the rawmidi API.
Attachments
rawmidi.zip
(87.22 KiB) Downloaded 144 times

Author of BackupBand at https://sourceforge.net/projects/backupband/files/
My fans show their support by mentioning my name in their signature.

User avatar
digitsun
Established Member
Posts: 91
Joined: Thu Mar 04, 2021 1:50 am
Has thanked: 13 times
Been thanked: 14 times

Re: Writing a Sequencer, outputting MIDI messages?

Post 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.
User avatar
Linuxmusician01
Established Member
Posts: 1547
Joined: Mon Feb 23, 2015 2:38 pm
Location: Holland (Europe)
Has thanked: 784 times
Been thanked: 144 times

Re: Writing a Sequencer, outputting MIDI messages?

Post 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).
User avatar
SpotlightKid
Established Member
Posts: 260
Joined: Sun Jul 02, 2017 1:24 pm
Has thanked: 57 times
Been thanked: 61 times

Re: Writing a Sequencer, outputting MIDI messages?

Post by SpotlightKid »

Seq66 is its modern successor.
User avatar
Linuxmusician01
Established Member
Posts: 1547
Joined: Mon Feb 23, 2015 2:38 pm
Location: Holland (Europe)
Has thanked: 784 times
Been thanked: 144 times

Re: Writing a Sequencer, outputting MIDI messages?

Post 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.
jwhitmore
Established Member
Posts: 23
Joined: Sat Feb 01, 2020 9:50 am

Re: Writing a Sequencer, outputting MIDI messages?

Post 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.
Post Reply