FortySevenEffects/arduino_midi_library

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

KarolPtak opened this issue · 1 comments

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 <MIDI.h>
extern MidiInterface MIDI;

and 'global.cpp' with

#include <MIDI.h>
MidiInterface MIDI = MIDI_CREATE_DEFAULT_INSTANCE();

but the result is

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

Sorry, seems to be explained in #165 :)

so in my case:

'global.h' should be:

#include <MIDI.h>
extern MIDI_NAMESPACE::SerialMIDI serialMIDI;
extern MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI> MIDI;

and 'main.ino':

#include "global.h"
MIDI_CREATE_DEFAULT_INSTANCE();