USB MIDI on patch_sm

Hello everyone, first post here. A bit easier for me to follow info on a forum than on discord so here I go.

Currently looking to get usb midi working on the daisy patch.init. This is mostly for development purposes/ having an under the hood interface that speaks to a max patch using midi sysex messages but will eventually get wrapped into some other projects that I want to use with usb MIDI on the daisy submodule so I want to make sure I know how to do this properly.

I have slightly modified the usb_midi example that was made for the daisy seed but it seems like there are some bits that are either not needed anymore (thinking specifically of the “hw.Configure()” function) or some bits that are done differently now (thinking of the “DaisySeed hw;” declaration) but I might have done those parts wrong as well. I have my code compiling and loading correctly to the daisy but don’t see a usb midi device showing up in any software that speaks MIDI.

I tried reinstalling the driver for the daisy using zadig/ WinUSB and the daisy shows up under the “USB Serial Bus Devices” category on my Device Manager but I don’t see it under the normal “sound, video and game controllers” category where a MIDI device would normally show up.

Here is my modified code for reference, any suggestions on what I could be doing wrong?

#include "daisy_patch_sm.h"
#include "daisysp.h"

using namespace daisy;
using namespace patch_sm;
using namespace daisysp;

DaisyPatchSM patch;
MidiUsbHandler midi;
Oscillator   osc;

void AudioCallback(AudioHandle::InputBuffer  in,
                   AudioHandle::OutputBuffer out,
                   size_t                    size)
{
    for(size_t i = 0; i < size; i++)
        out[0][i] = out[1][i] = osc.Process();
}

int main(void)
{

    //the line below is from the example code but I get an error saying that DaisyPatchSM has no member "configure"
    //patch.Configure();
    patch.Init();

    MidiUsbHandler::Config midi_cfg;
    midi_cfg.transport_config.periph = MidiUsbTransport::Config::INTERNAL;
    midi.Init(midi_cfg);

    osc.Init(patch.AudioSampleRate());
    osc.SetWaveform( 2 ) ;
    //osc.SetAmp ( 1 ) ;
    patch.StartAudio(AudioCallback);

    while(1) {
         /** Listen to MIDI for new changes */
        midi.Listen();

        /** When there are messages waiting in the queue... */
        while(midi.HasEvents())
        {
            /** Pull the oldest one from the list... */
            auto msg = midi.PopEvent();
            switch(msg.type)
            {
                case NoteOn:
                {
                    /** and change the frequency of the oscillator */
                    auto note_msg = msg.AsNoteOn();
                    if(note_msg.velocity != 0)
                        osc.SetFreq(mtof(note_msg.note));
                }
                break;
                    // Since we only care about note-on messages in this example
                    // we'll ignore all other message types
                default: break;
            }
        }
    }
}

As you can see I have barely changed anything in the examples, basically just changing the harware declarations to match the patch_sm instead of the seed and commenting out a line that was causing errors but according to the documentation the “Configure” function has been deprecated.

Thank you for your time and any help.

1 Like

So Windows can get a little confused when you’re reprogramming the same USB device with different functionality.

In either Zadig, or the Device Manager, can you try manually updating the driver to USB Audio Device?
Once you’ve done that, it should show up okay, and function as a MIDI device.

Unfortunately I am not seeing that as an option either in zadig or in the device manager. In zadig I get the following options:

WinUSB
USBserial (CDC)
libusbk
libusb-win32

I’m guessing that none of these are the right choice. Do you have a suggestions for a 3rd party driver or another process by which to get the right driver installed? I tried uninstalling the driver and plugging it in to see if it would select the correct one but I only see “STM electronics virtual COM port” in the device manager.

I’m guessing once I get this working it will make it harder to use DFM to reprogram the daisy? If so that’s fine I have an STM programmer that I can use.

FWIW I tried all four options on zadig, no change.

Hey I just got it to work, I feel silly because very detailed instructions were in the readme that I did not see at first. Apologies for taking up your time, usb MIDI is working now!

Congratulations, and no apologies are necessary, at least for me, certainly. But, in order to be forgiven, and perhaps in the spirit of penance, could you post a link the readme file here, to help the motivationally challenged who may follow us?

2 Likes

Apologies I just saw this, here is the contents of the readme for anyone who this might help:

# USB_MIDI

**Author**: shensley

## Description

When the project boots up, a 100Hz sine wave will emit from both outputs,
and the Daisy should appear as an Audio/MIDI device on a connected host.

The oscillator is an always-on, sine wave that will update based on note on messages.

## Troubleshooting

When using Windows, there can be an issue with the device showing up if a non-standard driver has been used for an STM32H7 (like the one used to load boards with the ST dFuse software).

If this is the case follow the following steps to fix it:

* Go to Device Manager
* The Daisy will likely be showing up as a STM32 Virtual COM Port with a yellow warning sign.
* Right click that entry in the COM Ports list, and select "Update Driver"
* Select, "Browse My Computer for Drivers. . ."
* Then Select, "Let me pick from a list of available. . ."
* Then choose "USB Audio Device" from the list
* Unplug, and replug the device, and it should now show up correctly

1 Like

At the risk of repeating myself, no apologies needed, thanks for the link!