Trying my hand at device drivers (MPD218)

Thought I’d share this and ask a question or 2.

So, I made some patterns, they sounded good, but I wanted to take it to the next level and do some clip launching (or whatever the equivalent term is for the Zynthian).

I was bummed to see the MPC mk3 is supported, but I have the mk2. I copied the file, changed a bunch of constants, and tried it! But, it turned out, as I used it I’m not in love with the button mappings. But it totally wasn’t obvious to me how it would feel until I tried it and scrutinized the diagrams on the wiki.

All in all, how its done makes sense to control the device, but I really want something that functions as a headless pad/sequence launcher. And then I realized, I don’t know that there’s really a sane way to use the MPK for what I want.

I also have the MPD218. It’s a drum pad, and has a nice 4x4 grid that can match the pads view. For this one I started from scratch and I think it’s working fairly well! Compared to the others, it’s pretty simple. But I did add the dials to control the volume of each track, so that’s nice.

What I really want working is my APC40. But that thing is a beast and I wanted to start small with the MPD218. So that’s up next!

Anyway, I thought I’d share: GitHub - bengfarrell/zynthian-hardware: Some experimental Zynthian hardware device drivers

My main question on this is about contributing back. As I’m getting stuff working, it all seems so personal to how an individual wants to use the Zynthian with their chosen device. I’ll certainly have opinions, and for me it’s really not about controlling the whole OS, but for specific parts that I want to control in a live environment when I don’t want to look at the screen. Is that something ya’ll would even want a PR for to check boxes on new devices? Or should this just stay separate and available if folks want to drop it into their file system?

My second question is about a warning I get. I think it’s my fault because I don’t see it if I don’t have my MPD218 plugged in. It all seems to work fine, but I should probably ask all the same. I do use the zynmixer to control volume, so it makes sense. Just not sure what I’m doing wrong:

Jun 23 21:31:58 synth startx[944]: WARNING:zynthian_gui_mixer.midi_cc_cb: tuple.index(x): x not in tuple

Lastly, I’m not a walking MIDI encyclopedia and needed some help for this. So I created my first vibe coded app in Cursor. Plug in your device, and watch the MIDI data flow: MIDI Display

2 Likes

The APC Key 25 and MPK Mini Mk3 device drivers in zynthian are exceptions. @oscaracena did some fantastic work implementing extensive control of zynthian with these drivers and we would really like to see this code abstracted to allow it to be applied to more hardware controllers. The norm is for simple pad launchers, CC mapping, transport control, etc. to be implemented. If you look at the Launchpad Mini driver, you will see this far simpler implementation.

Whoever writes the code can decide what they want it to do. If others think it could be enhanced, they will comment but it takes actual human effort to implement so, unless someone else is willing to do that work, the coder wins! So you are free to implement what you think to be the best device driver. @jofemodo may decide there is a better implementation and give that feedback (and occasionally implement such an overriding change).

Please submit PR for new device drivers. We are not always very prompt to deal with PRs but it is the right way to request your enhanced code be included and we love it when someone else does the work!!! :wink:

What does your zynthian_gui_mixer.midi_cc_cb() look like? There is a try/except around the tuple.index in the current version of zynthian. I wonder which version you are using and whether this is a previously fixed issue?

Your MIDI Display looks interesting. I don’t have a MIDI device connected to my laptop so can’t test it but will try to remember to have a play…

2 Likes

Here’s the midi_cc_cb function:

    def midi_cc_cb(self, izmip, chan, num, val):
        try:
            index = (64, 66, 67, 69).index(num)
            flags = lib_zyncore.get_cc_pedal(index)
            for strip in self.visible_mixer_strips:
                if strip.chain and strip.chain.is_midi():
                    if flags & (1 << strip.chain.zmop_index):
                        self.main_canvas.itemconfig(strip.pedals[index], state=tkinter.NORMAL)
                    else:
                        self.main_canvas.itemconfig(strip.pedals[index], state=tkinter.HIDDEN)
        except Exception as e:
            logging.warning(e)

Really I’m not sure what this function does. I might guess a MIDI control change, but given that I had to parse the midi event to know what a control change even was in my code, I don’t know if this concept is baked into the underlying code. I have other devices that support pedals - this one doesn’t, so maybe it failing to get the pedal, and the error is fine? Not really sure.

And sounds good on contributing. I need to play a lot more to make sure I like what I did, then I’d be happy to submit a PR.

1 Like