FortySevenEffects / arduino_midi_library

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

How to make MIDI a global, shared between cpp files? #182

Closed KarolPtak closed 3 years ago

KarolPtak commented 3 years ago

I have 4 classes (each in separate cpp + h files), and I'd like to share the midi instance between them, but I'm stuck :( .

Basicly calling MIDI_CREATE_DEFAULT_INSTANCE(); in the main .ino file makes it unvisible to those classes.

I've tried to create say 'global.h' with

include

extern MidiInterface MIDI;

and 'global.cpp' with

include

MidiInterface MIDI = MIDI_CREATE_DEFAULT_INSTANCE();

but the result is

error: 'MidiInterface' does not name a type extern MidiInterface MIDI;

KarolPtak commented 3 years ago

Sorry, seems to be explained in https://github.com/FortySevenEffects/arduino_midi_library/issues/165 :)

so in my case:

'global.h' should be:

include

extern MIDI_NAMESPACE::SerialMIDI serialMIDI; extern MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI> MIDI;

and 'main.ino':

include "global.h"

MIDI_CREATE_DEFAULT_INSTANCE();