Getting the jdksmidi library to work with pio

I have a very specific use-case, but you can probably help me without knowing anything about this first paragraph. Using Faust, a domain specific language for DSP (https://faust.grame.fr/) I generate an audio engine that I want to run on an ESP32 with an audio codec. All of this is described in this article DSP on the ESP-32 With Faust - Faust Documentation The generated code is C++ and requires the jdksmidi library respectively this fork GitHub - thopman/jdksmidi: c++ MIDI library

Adding the github repo to the lib_deps of my platformio.ini didn’t work. I get the error src/dsp/Engine.cpp:5224:28: fatal error: jdksmidi/world.h: No such file or directory

Manually downloading the repository, removing -master from its name and putting it into the lib folder is a different story. Now I get all a ton of errors of these three kinds:

  • non-member function 'bool jdksmidi::IsSysExURT()' cannot have cv-qualifier
  • lib/jdksmidi/src/jdksmidi_msg.cpp:372:5: error: 'jdksMIDIMessage' has not been declared
  • lib/jdksmidi/src/jdksmidi_msg.cpp:409:14: error: 'status' was not declared in this scope

How can I get this library to work? What am I missing?

When I only try and use the library GitHub - thopman/jdksmidi: c++ MIDI library in a pure ESP-IDF project (since github page says "midi parser component for esp-idf (esp32). ") I get the same weird errors. The project has a weird include file structure in which you must be very careful regarding which file is included first. I e.g. wrote my src\main.cpp file as

#include "jdksmidi/parser.h"

and that threw a lot of errors, because one is supposed to do

#include "jdksmidi/world.h"

before that. But later, compilation fails completely in lib/jdksmidi/src/jdksmidi_msg.cpp.

The file is also different in content. Compare the original jdksmidi/jdksmidi_msg.cpp at master · jdkoftinoff/jdksmidi · GitHub version to jdksmidi/jdksmidi_msg.cpp at master · thopman/jdksmidi · GitHub – all the types were renamed from e.g. MIDIMessage to jdksMIDIMessage but I don’t find the corresponding header for it, there it’s still called MIDIMessage.

If I do a dirty hack in the platformio.ini by adding

build_flags = -DjdksMIDIMessage=MIDIMessage

a minimal example compiles.

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   5.0% (used 16364 bytes from 327680 bytes)
Flash: [====      ]  37.7% (used 395152 bytes from 1048576 bytes)
esptool.py v3.0
======================== [SUCCESS] Took 51.65 seconds ========================

which feels very weird.

(standard PIO Home → Create Project → ESP-WROVER-KIT + ESP-IDF, change main.c to main.cpp with code

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "jdksmidi/world.h"
#include "jdksmidi/parser.h"

/* entry point has to have C linkage */
extern "C" void app_main() {
    /* call test function */
    jdksmidi::MIDIParser parser {};
    jdksmidi::MIDIMessage msg {};
    
    bool parse_ok = parser.Parse(0x00, &msg);
}

and full platformio.ini

[env:esp-wrover-kit]
platform = espressif32
board = esp-wrover-kit
framework = espidf
build_flags = -DjdksMIDIMessage=MIDIMessage

)

Are you 100% sure you need that fork? Do you work with ESP-IDF or Arduino?

1 Like

Hi Max, thank you for your thorough answer!

I’ve been trying you the build flag and the c linkage solution, both with the regular and the hacked lib, but no luck.

I’m not 100% certain about having to use the hacked library. I asked in the Faust Slack channel and the author told me that he made the fork because of a “conflict between faust’s MIDIMessage and jsdkMIDI’s MIDIMessage”. Unfortunately, nobody there seems to be using pio which is a shame.

I am using Arduino Framework so far, but if I have to I’ll start dipping my toes into ESP-IDF.

Well one thing I can definitely say is that when I download the ZIP file at DSP on the ESP-32 With Faust - Faust Documentation and put it in the src/ folder of a newly-created ESP32Dev + Arduino project, it compiles without any problems or extra options.

RAM:   [          ]   4.2% (used 13780 bytes from 327680 bytes)
Flash: [==        ]  23.2% (used 304208 bytes from 1310720 bytes)
esptool.py v3.0
====================== [SUCCESS] Took 9.77 seconds ======================

and that has also 0 library dependencies to jdksmidi or anything else.

I also noticed that the article you’ve linked doesn’t mention jdskmidi.

Do you have the exact project files which don’t compile? What steps do you do / options do you set to generate the code that you’re trying to compile?

Yes, I’ve also managed to compile it and get it to make sound. MIDI is the problem.

Compiling my Faust like this faust2esp32 -lib -ac101 -midi -nvoices 8 Engine.dsp does result in a Engine.cpp and Engine.h which require that library. -lib is optional, -ac101 is the codec.

In Faust, MIDI is implemented by using the naming convention gate, freq and gain. I’m trying it with the additive synthesizer example.

Currently, everything in a private repository on Bitbucket. If you send me your mail via a PM I’d be happy to invite you. But it’s really just bare bones right now.

Hi guys, any news on this? it looks that I ran into similar problems. I try work in ESP-IDF and try to implement polyphony with midi on a TTGO TAudio board. Midi, not because I definitely need it but because I consider this as a stepping stone to other work. I also tried to get on via the #ESP32 channel on Faust Slack. Without succes yet…