Using a MIDI Controller With Dyalog APL

Sam GutsellAPLLeave a Comment

As well as being a programmer, I am a hobbyist musician. At school and in my spare time I have studied music production and music theory. I occasionally write pieces of music and I recently received a MIDI controller as a gift. Being a programmer one of my initial thoughts was ‘how can I code an interface to this device?’, so I began my investigation.

Interfacing with MIDI in Windows

I started to investigate MIDI interfacing in APL, by looking for examples in other languages. I found examples in C#, so attempted to imitate the behaviour in APL, but to no avail.

After some more research, I found out that the C# example is using the UWP (Universal Windows Platform) interfacing library which, to my knowledge, is not accessible by default from Dyalog. I attempted to access the correct DLLs in Dyalog, but didn’t manage to get the connection working.

I then read up more on the UWP interface and found that this is used for Windows store and Xbox applications, and couldn’t find any reference to it being used outside of those environments.

Has it been done before?

After having spent some time trying to build an interface from scratch, I searched for MIDI interfacing in Dyalog APL and was surprised by what I found. My first discovery was a Vector article which was a Minnowbrook summary, but it only mentioned Stanley Jordan and his work with MIDI in passing. My second discovery was another Vector article, this time it had more detail.

The second article was written by Ray Cannon (who used to work for Optima!) and had some code examples. Ray’s work was inspired by Martin Neitzel’s article about MIDI interfacing in J, which also appeared in Vector. As a test I tried the methods manually and they worked, great, but then I realised the article is a scanned document, meaning no copy and paste. So, I started typing the first function out and then thought there must be an easier way. I did a quick Google and found an OCR (Optical character recognition) software online, which worked reasonably well, but would require a lot of work to rectify completely, it wasn’t recognising APL symbols, as they are non-standard Unicode characters. In doing this, I then saw the article mentioned a resource page on the Vector website. Given the article was from a January 2002 edition of Vector, I wasn’t holding my breath.

To my surprise, the resource associated with Ray’s article is still live, but the workspace was built in version 9 of Dyalog.

Reviving Ray’s workspace

I quickly found that you can’t open a Dyalog 9 workspace in Dyalog 16, my initial reaction was 'what is the earliest version available on Dyalog’s website?'. The oldest version readily available was Dyalog 13.1, so I chanced my arm and installed 13.1. I then tried loading the workspace and lo and behold it worked. This allowed me to save the workspace as a 13.1 workspace and then copy that into a Dyalog 16 workspace, ready for me to begin testing old code and writing new code.

Windows 10 issues and further complication

As I began my full testing of the methods from Ray’s workspace, I encountered some issues. The old code didn’t recognise my device correctly, as the name seemed to be a random set of characters, unrecognisable to the conditions laid out in the code. I forced the code to bypass the checks and test it as a specific MIDI device with input and output. The first test was for the output, as soon as I started testing, I realised that the MIDI controller wasn't receiving messages, however, it was able to send messages in other applications. I then did a bit of Googling and found that there's a fundamental flaw with Windows 10 and MIDI devices.

In Windows 10, the accepted range of addresses for MIDI devices is midi0 to midi9, but it offers up midi0 to midi19, my device was in midi10, meaning it was being ignored by Windows. I then tried uninstalling all MIDI drivers and following the installation guide for my MIDI controller once again, but it still installed into the midi10 address. My MIDI controller shows up as a device but is now not seen as a MIDI device by Windows 10. I attempted following some manufacturer guidelines to install a new driver, but I got to the point of selecting a new driver and Windows complained that there was missing information associated with the driver. This has, unfortunately, put a stop to my project for now as I have no other MIDI devices to test with.

What's the future of this project?

I am keen to continue the project and am eager to find out what I can achieve with a MIDI controller and an APL interface. I am in the process of getting a different MIDI controller, as after following the installation guide I now can’t use the one I had with any application, in any capacity.

About the Author

A picture of Sam Gutsell, the author of this blog

Sam Gutsell

APL Developer

Sam is an APL Developer at Optima Systems. He started at Optima in 2012 as an apprentice straight after finishing College. Sam decided to take Computing whilst studying at college, yet, he never intended to but, he thought it sounded interesting at the time. Sam’s original career plans involved studying Meteorology at university, to become a Meteorologist. His plans changed when he realised how much he enjoyed code. More about Sam.

More from Sam

Other Posts