FortySevenEffects / arduino_midi_library

MIDI for Arduino
MIT License
1.56k stars 252 forks source link

allow different name for namespace #273

Open modularev opened 2 years ago

franky47 commented 2 years ago

How would that work in practice?

A #define MIDI_NAMESPACE foo before including MIDI.h would only apply to the current compilation unit, and not to MIDI.cpp for example.

If you're thinking of defining it as a compiler flag (which would apply everywhere), could you add documentation on how to proceed?

modularev commented 2 years ago

I did not think of that.. I am working on a project which depends on another class named midi - I think in my case it seems having done the trick - although I certainly need to read up on the usage of namespace...

adding a compiler flag would certainly be possible. However, would you have another in-code solution in mind?

franky47 commented 2 years ago

Your suggestion could work in combination with a platform.local.txt, an undocumented override to the Arduino compiler, which could set the value of MIDI_NAMESPACE as a preprocessor flag:

compiler.cpreprocessor.flags=-DMIDI_NAMESPACE=mycustommidinamespace

https://github.com/arduino/Arduino/issues/3371 https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html