grame-cncm / faust

Functional programming language for signal processing and sound synthesis
http://faust.grame.fr
Other
2.59k stars 326 forks source link

faust2daisy generated code does not compile for -pod or -patch option #1089

Open ghoppla opened 4 days ago

ghoppla commented 4 days ago

faust2daisy generated code does not compile for -pod or -patch option

When compiling code using faust2daisy with option -pod or -patch the code does not compile. Only -patchsm is working.

The problem is that somehow ValueConverter.h is not included in the generated cpp file.

Steps for reproduction

Versions Used:

Daisy Toolchain Setup on Linux:

  1. Create a folder, e.g.

    $ mkdir ~/daisy
  2. Get arm-none-eabi:

  3. Get libDaisy:

    $ git clone --recurse-submodules https://github.com/electro-smith/libDaisy
  4. Create environment.rc file with the following content:

    export LIBDAISY_DIR=~/daisy/libDaisy
    
    GCC_PATH=~/daisy/gcc-arm-none-eabi-10-2020-q4-major/bin
    export PATH=$GCC_PATH:$PATH
  5. Compile libDaisy:

    $ source environment.rc
    $ cd libDaisy
    $ make

Compilation:

  1. dsp file minimal_example.dsp
    
    import("stdfaust.lib");
    declare name "Daisy Seed Bug";
    declare options "[midi:on]";

gate = button("gate"); vel = hslider("gain", 0, 0, 1, .01); freq = hslider("freq", 440, 0, 20000, 0.01);

process = os.triangle(freq) vel : _en.adsr(.1,.1,.7,.2, gate) <: ,;


2. Generated cpp code with:
```bash
$ faust2daisy -patch -midi -sr 48000 -bs 32 -uim -source minimal_example.dsp

when running make within the generated folder

$ cd minimal_example
$ make

a lot of the compilation errors appear, since ValueConverter.h is not included:

ex_faust.cpp:1220:1: error: expected class-name before '{' token
 1220 | {
      | ^
ex_faust.cpp:1265:29: error: 'ValueConverter' was not declared in this scope
 1265 |             std::unique_ptr<ValueConverter> fConverter;
      |                             ^~~~~~~~~~~~~~
ex_faust.cpp:1265:43: error: template argument 1 is invalid
 1265 |             std::unique_ptr<ValueConverter> fConverter;
      |                                           ^
ex_faust.cpp:1265:43: error: template argument 2 is invalid
ex_faust.cpp:1267:76: error: 'ValueConverter' was not declared in this scope; did you mean 'fConverter'?
 1267 |             AnalogKnob(uint16_t* adcptr, FAUSTFLOAT* zone, std::unique_ptr<ValueConverter>& converter, int rate)
      |                                                                            ^~~~~~~~~~~~~~
      |                                                                            fConverter
ex_faust.cpp:1267:90: error: template argument 1 is invalid
 1267 |             AnalogKnob(uint16_t* adcptr, FAUSTFLOAT* zone, std::unique_ptr<ValueConverter>& converter, int rate)
      |                                                                                          ^
ex_faust.cpp:1267:90: error: template argument 2 is invalid
ex_faust.cpp: In member function 'virtual void DaisyControlUI::AnalogKnob::update()':
ex_faust.cpp:1275:36: error: base operand of '->' is not a pointer
 1275 |                 *fZone = fConverter->ui2faust(Process());
      |                                    ^~
ex_faust.cpp: In member function 'void DaisyControlUI::InitKnobs()':
ex_faust.cpp:1320:33: error: 'ValueConverter' was not declared in this scope
 1320 |                 std::unique_ptr<ValueConverter> converter;
      |                                 ^~~~~~~~~~~~~~
ex_faust.cpp:1320:47: error: template argument 1 is invalid
 1320 |                 std::unique_ptr<ValueConverter> converter;
      |                                               ^
ex_faust.cpp:1320:47: error: template argument 2 is invalid
ex_faust.cpp:1322:50: error: 'LogValueConverter' was not declared in this scope
 1322 |                     converter = std::make_unique<LogValueConverter>(0., 1., fKnobs[i].fMin, fKnobs[i].fMax);
      |                                                  ^~~~~~~~~~~~~~~~~
ex_faust.cpp:1322:107: error: no matching function for call to 'make_unique<<expression error> >(double, double, float&, float&)'
 1322 |                     converter = std::make_unique<LogValueConverter>(0., 1., fKnobs[i].fMin, fKnobs[i].fMax);

.
.
.
ghoppla commented 4 days ago

In this part of the daisy architecture (ex_faust.cpp) the corresponding gui source files are included.

#include "faust/gui/meta.h"
#include "faust/gui/UI.h"
#if defined PATCHSM
#include "faust/gui/DaisyPatchInitControlUI.h"
#else
#include "faust/gui/DaisyControlUI.h"
#endif
#include "faust/dsp/dsp.h"

ValueConverter.h is included in DaisyControlUI.h and DaisyPatchInitControlUI.h I don't understand why the ValueConverter.h gets included for DaisyPatchInitControlUI.h only.

sletz commented 4 days ago

Well DaisyPatchInitControlUI was developed after DaisyControlUI with an external contribution, and looking at the file, a lot of code is actually duplicated. So I guess the proper way would be to rework all of that, and put the new code of DaisyPatchInitControlUI in DaisyControlUI to finally keep a unique DaisyControlUI file, and possibly use #if defined PATCHSM ....some code... #endif inside it.

But this means a bit of work ((-;

ghoppla commented 4 days ago

hmmm... unfortunately I don't have this hardware to verify that stuff finally, since I've built my own hw interface for the raw daisy seed board. I could do it in blind mode without testing on the patch / pod only but thats not that good idea I think.

ghoppla commented 4 days ago

Despite the fact that the code is duplicated, from the preprocessor logic the the weird thing is that ValueConverter.h is not included for the -pod and -patch Option. Don't get it why...

sletz commented 4 days ago

. I could do it in blind mode without testing on the patch / pod only but thats not that good idea I think.

But you could at least test if the restructured code would compile right ?

ghoppla commented 3 days ago

. I could do it in blind mode without testing on the patch / pod only but thats not that good idea I think.

But you could at least test if the restructured code would compile right ?

lol... you owned me. Okay, I do my best, but it may need some days till I find the time. I hope someone can then test the code on hardware.