Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Dear @lathoub,

after I solved the basic MIDI connection problems to the Vox Adio Amp with your help my next challenge will be to build a hybrid client for my "Nux Mighty Plug" and "Vox Adio Air GT" MIDI devices. I guess that there are two possible approaches to implement this functionality:

  • determine the name of the MIDI device that the client established a connection to in the client code in order to distinguish what MIDI messages to send to the external device: SysEx-Messages for the Vox Amp or ControlChange-Messages for the Nux Mighty plug
  • try to establish a parallel BT-MIDI connection to both devices based on their MIDI-names and send the appropriate MIDI messages on the respective MIDI channel

Is there a way to figure out the MIDI-name of the connected device in the client code ... or even a way to work with two MIDI channels in parallel? I hope that I don't bother you not to much with my questions - I started with the Arduino-Platform a month ago and I'm still a novice with all that technology and Arduino-coding.

Thanks again for your help and greetings from Germany

Bernd

You must be logged in to vote

... "learn something new every day" - this is what I've been told by @lathoub some weeks ago - and actually I spent hours for a task that could be implemented within a minute. But finally I made it as I understood, that "BLEMIDI_Transport.h" just implements the callback declaration without code and "BLEMIDI_Client_ESP32.h" the callback implementation.
So in the end this turned out as a very trivial change:

  • Add a new callback declaration in "BLEMIDI_Transport.h":
// callbacks
    void (*_connectedCallbackDeviceName)(char *) = nullptr;
  • ... and assign the function pointer to this callback with (char *)-parameter
    BLEMIDI_Transport &setHandleConnected(void (*fptr)(char*))
    {
      …

Replies: 3 comments · 3 replies

Comment options

Hi @MicroMidi

You might have answered the question yourself :-)
Look at the log from issue #40

This is an extract of the log-messages on the serial port:
**__Advertised Device found: Name: ES3-249F, Address: e4:b3:89:86🆎f8, serviceUUID: 6acc5540-e631-4069-944d-b8ca7598ad50
Advertised Device found: Name: Adio Air GT MIDI, Address: 44:91:60:00:8c:35, serviceUUID: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
Found MIDI Service
---------CONNECTED---------
Connected to: Adio Air GT MIDI / 44:91:60:00:8c:35
First run

The logs contain device names of the device you are connecting to.

void onResult(NimBLEAdvertisedDevice *advertisedDevice)

advertisedDevice might contain the info you are looking for.

You must be logged in to vote
1 reply
@MicroMidi
Comment options

Thanks for your reply, @lathoub! You're right - the log provides the necessary information - but the "advertisedDevice"-object is instantiated in the "BLEMIDI_Client_ESP32.h" code and I wasn't able to get access to this object from my own client code. Is there a global object at my client code level that provides me with access to this information?

Comment options

You can expose the advertisedDevice object (or elements of it) to the connected callback (currently no connection param is passed).

void (*_connectedCallback)() = nullptr;

Forwarding the advertisedDevice as-is might not be a good idea, but take element(s) from the objects (eg device names) and pass that onwards.

Feel free to suggest, so we have something to start from

You must be logged in to vote
2 replies
@MicroMidi
Comment options

Having access to the MIDI device name in the client code would solve my problem to be able to distinguish between the different MIDI servers that the client connects to.

I tried some simple experiments with passing parameters to the suggested callback method on my own - but I'm already failing with syntactical errors that I'm not able to solve myself. I'm afraid that this is much to sophisticated for my basic C++ knowledge.,,

@MicroMidi
Comment options

I finally finished my project at least for one MIDI footswitch device (https://github.com/MicroMidi/NUX-MIDI-Footswitch) based on your brilliant library - and now got back to issue to enhance the code for another MIDI-Server based on its device name. This time I started the other way round - on client side, based on your example "MidiBle_Client.ino":

  • First of all I enhanced the setHandleConnected() callback method by a string argument for receiving the device-name:
    BLEMIDI.setHandleConnected([] (*char myDeviceName)
  • then I adjusted the callback respective method in "BLEMIDI_Transport.h" (Line 187) with the "char " argument
    void (
    _connectedCallback)(char *) = nullptr;
  • in the implementation of the callback-method (line 197) I tried to catch the string argument "BLEDeviceName" and pass it to the "connectedCallback"-method in "BLEMIDI_Client_ESP32.h" where the device name is accessible:
    BLEMIDI_Transport &setHandleConnected(void (*fptr)(char *BLEDeviceName))
    {
    _connectedCallback(BLEDeviceName) = fptr;
    return *this;
    }
    This leads to a compile error:
    :\Users\b.liesner\Documents\Arduino\libraries\BLE-MIDI\src/BLEMIDI_Transport.h:199:22: error: 'BLEDeviceName' was not declared in this scope
    _connectedCallback(BLEDeviceName) = fptr;

    I don't know why as "BLEDeviceName" was declared as an argument in this method
  • Finally my idea was to determine the device name in the "connected()"-method of "BLEMIDI_Client_ESP32.h" (line 200) like this:
    void connected()
    {
    if (_bleMidiTransport->_connectedCallback)
    {
    char myDeviceName[100];
    stpcpy(myDeviceName, myAdvCB.advDevice.getName().c_str());
    _bleMidiTransport->_connectedCallback(myDeviceName);
    }
    firstTimeSend = true;
    }

Unfortunately I found no way to get rid of this compile error and I'm stuck with my DIY-approach to solve this problem. I assume that I made a syntactical mistake in passing arguments to callback-methods. May I ask if you or anybody else can have a brief look what could cause the compile-error or if my approach is completely wrong in general?

Thanks in advance for any hint on my issue!!!

Comment options

... "learn something new every day" - this is what I've been told by @lathoub some weeks ago - and actually I spent hours for a task that could be implemented within a minute. But finally I made it as I understood, that "BLEMIDI_Transport.h" just implements the callback declaration without code and "BLEMIDI_Client_ESP32.h" the callback implementation.
So in the end this turned out as a very trivial change:

  • Add a new callback declaration in "BLEMIDI_Transport.h":
// callbacks
    void (*_connectedCallbackDeviceName)(char *) = nullptr;
  • ... and assign the function pointer to this callback with (char *)-parameter
    BLEMIDI_Transport &setHandleConnected(void (*fptr)(char*))
    {
        _connectedCallbackDeviceName= fptr;
        return *this;
    }
  • in file "BLEMIDI_Client_ESP32.h" the connected() function must be enhanced by the new callback:
void connected()
    {
        if (_bleMidiTransport->_connectedCallback)
        {
            _bleMidiTransport->_connectedCallback();
        }

        if (_bleMidiTransport->_connectedCallbackDeviceName)
        {
            char connectedDeviceName[24];
            strncpy(connectedDeviceName, myAdvCB.advDevice.getName().c_str(), strlen(myAdvCB.advDevice.getName().c_str()));
            connectedDeviceName[strlen(myAdvCB.advDevice.getName().c_str())] = '\0';
            _bleMidiTransport->_connectedCallbackDeviceName(connectedDeviceName);
        }
        firstTimeSend = true;
    }

I assume that it is better to define the "connectedDeviceName"-variable as a private member in the "BLEMIDI_Client_ESP32"-class as memory is only allocated once ...

Maybe this little enhancement could be a candidate to be incorporated in the BLE-MIDI library as it is an added functionality and doesn't collide with any exisiting code leveraging this library, though. This provides an easy approach to decide how to deal with the connected BLE-MIDI-server based on the name of the MIDI device. My MIDI footswith now supports two different MIDI-effect devices in a common code base - and this is what I tried to achieve ...

You must be logged in to vote
0 replies
Answer selected by MicroMidi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #42 on December 20, 2021 08:51.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.