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!

New Site Version Officially Live!

Category: Site
By: Sam Matucheski
10/28/19



After some minor technical difficulties the new version of the site is up and running! We've got HTTPS, we've got a backend, it's a brave new world.

Sorry if you visited any old versions of the site, you totally got ripped off 'cause this new version is so much better.

Yet Another Redesign of the Site

Category: Site
By: Sam Matucheski
10/27/19



Hi everyone. Yes I you can see I've done some more redesigning of the site. A good chunk of it still looks the same, like the home page and the programs page. The blog now finally looks harmonious with the rest of the site, I even got my own database set up. Yes, that means no more static site generators!

I'm gonna be honest. I don't know what I'm doing anymore, not that I knew a whole lot before. This site only really exists so I can have my own presence online and to be a portfolio for employers online. I'm not good at all of that, or confident in myself! And this site hasn't led to anything yet. I know it's not the most impressive thing anyone has ever created but... I don't know it's something.

Oh well.

Let's Transcribe and Arrange: MOTHER Intro

Category: Music
By: Sam Matucheski
12/29/18



I’ve got a fun idea for some #content, a series going through transcribing and arranging music in the vain of a text let’s play or let’s code. It’ll be fun, I hope…

Let’s inaugurate this series with the opening music from the 1989 Famicom game MOTHER (now officially referred to as Earthbound Beginnings in America). I’m not actually sure if this piece actually has an official title (this can be very common with video game music). I’ve seen it called “Introduction”or “Mother Earth”, I’m simply calling it “Title Screen” a very common term to name game music and since, well it plays at the title screen.

A couple quick notes about the NES/Famicom sound chip. It has 5 channels consisting of 2 square waves (sometimes more correctly referred to as pulse waves), a triangle wave, a noise channel,and a DPCM sample channel. This piece uses the first 4 channels but I’ve chosen to omit the noise channel as it’s just a percussive hit on beat 4 for the entire duration of the piece.

Like a cooking show, here’s one I've prepared before! (Apparently embedded PDFs won't work on some mobile browsers so use this link instead.)

Let’s dive right in!

Probably the most noticeable part of the piece is the ostinato part in the triangle channel. {% asset_img "mother_intro_ostinato.png" "Ostinato" %} It spans 3 octaves and starts out in the treble register which is kind of unusual for the triangle wave in a lot of music for the NES/Famicom. It’s most common role being the bass. Looking at this ostinato along with the eighth to quarter note motif in square 1 we can pretty firmly conclude the piece is in G major but the F natural does take some interest. It makes the ostinato a fully chromatic walkdown and leaves some wonder about how flat 7 is going to be used in the piece. The typically unusual sound of the high register triangle wave with this chromatic walkdown with the motif in the square being reminiscent of something played on perhaps bells or a glockenspiel gives the piece a mysterious air of wonder.

Square 2 comes in helps outline the intended chord progression before switching to melody in the next phrase. The progression ends up being G, D/F#, F, Em which is I, V6, bVII, vi in G major.

Now let’s turn this collection of electronic beeps and boops into something for the piano. For the arrangement, I’m going to be taking some heavy influence (read, ripping off) from a video by a piano player know as Professor Sakamoto. He has an excellent medley of MOTHER music. The intro/title screen music is surprise, right at the beginning of the video.

Here's what I've come up with.

The first two phrases are easy and can be played on the piano just as is (although you do need to use the pedal for the second phrase, but I'm sure an actual pianist could figure that out). I also think they are fine without any extra embleshments, I like retaining the openness of the original 3 voices to set the mood of the piece. The next phrase I do want to embellish though is the third phrase. After all, we've kept in the same for this long, but we're playing the piano now. There are a lot of notes we can play at once.

Here's the original phrase. Phrase 3

One of the things we want to maintain when when embelleshing is to maintain the voicing in the melody. When adding extra notes to fill out the intended chords we don't want to put anything above the melody or we're going to end up hiding it. This means we want the notes from square 2 to be the highest (for this arrangment I'm just going to omit square 1's part from this phrase).

Phrase 3 with embellishments

You can see what I'm talking about now. The first note in the melody is a B and the implied chord is obviously a G major triad so to embellish it we can play a very quick arpeggio of a third inversion G major triad so we end on that B. (This appargio style embellishment was totally taken from Prof. Sakamoto's cover by the way, same thing with the triplets in the final measures. They were too cool not to add.) We do the same with the other notes in the melodies, find which inversion has the melody note on the top.

If you're an actual pianist and you think I'm bad at writing for the piano send me an email and tell me, please!

VS Code Tutorial: Remote Folder as Workspace with SSH

Category: Programming
By: Sam Matucheski
12/21/18



EDIT 11-11-19 There seems to be an official extension to due this now, but I haven't tried it yet. When I get around to it try to write about it. This post will still remain up for hisorical reasons. Original post following:

If you are doing something like web development over on a server and you’d like to do it on your own computer with a handy code editor it’s quite easy to do with the right extension for VS Code.

First go on over to extensions and search for “ssh”. The first extension that appears should be the one we want, SSH FS by Kevin Schoofs.

step1

Download it and reload VS code. Go to your User Settings, found by selecting File > Preferences > Settings. Edit your User Settings and add

“sshfs.configs”: [

]

For every different folder/connection you want to use as a workspace, add it within the configs sections in their own set of curly braces . Depending on the settings of your server you will have need to add different parameters. A common setup will look like this.

“sshfs.configs”: [
{
	“name”: “MySSHWorkspace”,
	“root”: “/path/to/root/folder”,
	“host”: “111.111.1.111”,
	“port”:  22,
	“username”:  “username”,
	“password”:  “password12345”
}
]

A couple things to note: every configuration MUST have a name parameter. Host may either by an IP address or if you have a domain and DNS setup it can be a url. Password can alternatively be set to true (without quotes) to have be prompted instead of being stored in your User Settings. If your server use a private key instead of a password you can use that as well. The best way is to use the parameter “privateKeyPath” which simply takes the path to the key on your machine. If the key is encrypted and requires a passphrase simply use the parameter “passphrase”.

You should now see a SSH FILE SYSTEMS section in the Explorer. All of your configs will appear here.

step3a

Right click on the one you want to use and select “Connect as Workspace Folder”.

step3b

And that should be it. You can now view and edit all the files and folders that fall under the path you specified.

I hope people will find this useful. Happy coding!