Blog

Working On Things: Fluidsynth and WxWidgets

Category: Programming
By: Sam Matucheski
12/13/19



Life's been a little tumultuous right now. I'm trying to work on things in my spare time. It's hard folks. But I've got somethings going that I've wanted to get working on for a while now so that's pretty cool. (Wow I really don't know how to right these things.)

FluidSynth

FluidSynth is a synthesizer that generates sound from SoundFont 2 files. SoundFont 2 files are files of digital sound samples typically but not always organized following the General MIDI specification. FluidSynth itself is found in popular audio applications like the open source music notation software MuseScore as the primary synthesizer. This is because all of the sounds used for the instruments can be easily contained in one file that can be easily swapped out by the user. SoundFont 2 files are so ubiquitous one can find SoundFont 2 files containing samples from various popular retro video games that used sampling as their primary method of creating music. Thus instantly giving you access to every sound from the game to be used however you like, commonly used to create covers of other songs in the musical styles.

FluidSynth is both a command line program and a API. The command line program seems to mostly be a demo for the API but it does have some real world uses. If you want to quickly transfer a MIDI file to an actual sound file you can feed the MIDI file and a SoundFont to FluidSynth and it will give you can audio rendition of that MIDI file no problem.

The API is the real draw here, allowing you to add a SoundFont font synthesizer pretty easily to your program. FluidSynth is written in C which means if you're writing in C++ and doing OO you're probably going to spend a good chunk of time just writing your own wrapper classes. (This is a huge complaint I have with using C libraries with C++ and I could probably do a who article about it and get some C/C++ people mad at me.) Of course you might also be spending a lot of your time just compiling it. FluidSynth does not provide any binaries itself. There are 4 ways to compile on Windows and I personally had difficulties with each. (This is another thing I could write an article on but smarter people have complained about the song and dance of compiling.) Lucky a nice fellow has uploaded Windows binaries of many major version of FluidSynth. Nice!

I think in the future I'll write more on actually using FluidSynth since hey I'm all about programming and music, it's the subtitle of the dang site after all. The other thing I've been working with is-

WxWidgets

WxWidgets is a cross platform GUI library written in C++. It's main draw is that applications retain their native OS looks despite coming from the same library. One of the more notable applications that uses WxWidgets is funnily enough another audio application, Audacity.

Being written in C++ means I can save some time not writing wrapper classes. WxWidgets does provide a Windows binary, but building it from source isn't that difficult. A Visual Studio project is provided and all I had to do was just hit Build. Again, later I would like to write about actually using it but right now I'm just talking about what I've been doing, so if you want to get into the nitty gritty, sorry it'll have to wait.

So I decided to use FluidSynth to make a program that just plays different instruments from a SoundFont when given input from a MIDI device and uses WxWidgets for a graphical interface. And I was thankfully able to get both libraries to play together. I was afraid I'd run into threading issues for the audio routines of FluidSynth and the drawing routines of WxWidgets (especially since WxWidgets commands a lot of control over the flow of your program) but I had no issue on that front.

The program loads SoundFonts by selecting them with a standard open file dialog, you know the way you normally expect to choose and load a file. You can have multiple SoundFonts loaded, you then just chose the one you want to use and then chose the instrument bank you'd like. I even put a keyboard display to show what notes are being played.

There are some quirks and problems that I'm stilling working out. Right now the MIDI device needs to be on before the program is run and I haven't really figured out how FluidSynth chooses MIDI devices. I've only gotten it working with my MIDI keyboard and nothing else. Also the keyboard display has rendering issues because I haven't figured out the best way to render thing keys and the images of the keys pressed in a way that looks good. If only WxWidgets had a Z-order in it's rendering or if alpha channels in images working a little differently I think it be easy. The current layout is also garbage so sorry about that.

Oh well I think it's an OK project. You can grab it here if you want. I'll try and work on it more. Until next time!