Midi moose, revision 2
One night I was jamming with my synthesizers. Digitakt was generating beats and sending midi to Acid Moose. I also added modular synth to the mix but getting it in sync with the rest of the gear was cumbersome. I had to connect midi to my midi2cv module, program a midi track with steady 16th notes and use the gate signal as a clock. I started wondering why isn't it as easy as syncing a midi device to Digitakt? I pretty soon realized it can be! I already have an arduino doing other midi stuff inside my midi thru magic box and it had plenty of io pins free! Drill a hole for the connector, solder some wires and write some code and the modular will be in sync with midi! Original Midi Moose post is available here: http://noiseembedded.blogspot.com/2019/04/midi-moose-midi-thru-with-twist.html
I had some cd4050 hex buffer ICs and decided to try those out. It's not perfect for this task but adding more complex buffers would have required more space and the box was already out of circuit board space and full of wires. I could have probably managed to get a way with just driving the outputs directly with the atmega microcontroller but it felt risky. I took a small piece of strip board, soldered the buffer ic and 1k resistors for each output. Then soldered microcontroller pins to the extra board and outputs to the new output jacks. It became a horrible ball of wires and I hope I will never ever need to open the box again. But it works!
Arduino IDE is definitely an easy way for a newcomer to enter the world of embedded hacking but for a professional software engineer it's really annoying. The normal practice of dumping all code into one .ino file is so painful, there's no way to add unit tests, etc. It's of course possible to move parts of the code into a library but managing libraries is a mess too.
Luckily there's now an arduino command line tool available. It's still in alpha level but seems to work just fine. Now i'm able to initiate new projects, configure libraries, compile and build the code from my favorite programming environment, the unix command line. I can also split the code into multiple files any way I like and add more tools if needed. For this project I also wrote some unit tests with GTest and configured CMake to build the tests. It would have been cool to integrate arduino_cli also into the same CMake setup but I didn't bother finding out how to do it. I already have some other ideas in mind and wanted to move on as soon as possible.
Analog circuits are simple. The moment you have the schematic ready the feature set is fixed. But if the board happens to have a microcontroller the amount of possibilities explodes. It's all too easy to get carried away with adding all kinds of complexity to the software and make the device almost unusable.
The principle is simple. Midi clock master sends 96 clock messages per quarter note so all we have to do is count those messages and toggle an output pin high or low based on the count.
Unfortunately the traditional clock pulse interfaces are not as strictly standardized as midi clock is. What notes the outputs should send? Many devices expect 16th note clock pulse, some have a config option and some don't. I also figured out that it would be easy to implement a simple integrated clock divider. I first thought it might be a good idea to have a dedicated output for each clock division. After some thinking I figured out I will need more 16th outputs than half note outputs so it might be better to make it dynamically configurable. Updating the atmega firmware to change the output settings felt too difficult so I decided to make it configurable over midi.
I ended up with a solution where each output is configurable with midi CC messages. Settings are stored in EEPROM so configuration will stay the same over resets. Time will tell what setup I will be needing the most. Now it's anyway trivial to change. I might even modulate the clock division with digitakt for some odd polyrhythmic stuff!
Anyway, now my little midi box is even more useful. Code and schematic is available in https://github.com/tvainio/midimoose if you are interested. Time to do some complex patching!
If it's worth doing it's worth overdoing!
As there was plenty of io pins free and I have plenty of gear to sync I decided to add more than one clock output. I could also sync the pocket operator po-32 drum machine and SQ-1 sequencer with this. I started drilling the plastic box and managed to fit 6 outputs before it started looking too crowded. 6 was also nice number because I wanted to add some buffering to the outputs and many buffer chips happen to have 6 buffers.The output circuit
New buffer board |
Horrible ball of wires! I hope I will never need to open this can of worms again. |
Arduino from command line
I love arduino and I hate arduino. It's the only embedded platform with proper user community and support. Readymade code exists for pretty much everything and there's always a blog post or discussion board thread available when needed.Arduino IDE is definitely an easy way for a newcomer to enter the world of embedded hacking but for a professional software engineer it's really annoying. The normal practice of dumping all code into one .ino file is so painful, there's no way to add unit tests, etc. It's of course possible to move parts of the code into a library but managing libraries is a mess too.
Luckily there's now an arduino command line tool available. It's still in alpha level but seems to work just fine. Now i'm able to initiate new projects, configure libraries, compile and build the code from my favorite programming environment, the unix command line. I can also split the code into multiple files any way I like and add more tools if needed. For this project I also wrote some unit tests with GTest and configured CMake to build the tests. It would have been cool to integrate arduino_cli also into the same CMake setup but I didn't bother finding out how to do it. I already have some other ideas in mind and wanted to move on as soon as possible.
The Software. Too many options!
I made a simple dev board setup with midi input and one clock output to develop the software. |
The principle is simple. Midi clock master sends 96 clock messages per quarter note so all we have to do is count those messages and toggle an output pin high or low based on the count.
Unfortunately the traditional clock pulse interfaces are not as strictly standardized as midi clock is. What notes the outputs should send? Many devices expect 16th note clock pulse, some have a config option and some don't. I also figured out that it would be easy to implement a simple integrated clock divider. I first thought it might be a good idea to have a dedicated output for each clock division. After some thinking I figured out I will need more 16th outputs than half note outputs so it might be better to make it dynamically configurable. Updating the atmega firmware to change the output settings felt too difficult so I decided to make it configurable over midi.
I ended up with a solution where each output is configurable with midi CC messages. Settings are stored in EEPROM so configuration will stay the same over resets. Time will tell what setup I will be needing the most. Now it's anyway trivial to change. I might even modulate the clock division with digitakt for some odd polyrhythmic stuff!
Anyway, now my little midi box is even more useful. Code and schematic is available in https://github.com/tvainio/midimoose if you are interested. Time to do some complex patching!
Comments
Post a Comment