Skip to content

Declared "MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);" and MIDI is still Out Of Scope! #269

Answered by franky47
ruiseixasm asked this question in Q&A
Discussion options

You must be logged in to vote

That would be because the MIDI_CREATE_INSTANCE macro is called in a .cpp file, which limits the scope of the created MIDI object to that compilation unit.

To use it somewhere else, you'd have to declare it first as extern in MidiInclude.h, as such:

#ifndef MIDIINCLUDE_H_INCLUDED
#define MIDIINCLUDE_H_INCLUDED

#include <Arduino.h>
#include <MIDI.h>

namespace MidiProject {

    extern midi::MidiInterface<midi::SerialMIDI<HardwareSerial>> MIDI;

    // ↓ I assume there was a missing class or struct keyword here?
    class MidiClass {
        public:
            static void initiateMidi();
            static void sendMidi();
    };
}

#endif // MIDIINCLUDE_H_INCLUDED

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@ruiseixasm
Comment options

@franky47
Comment options

Answer selected by ruiseixasm
Comment options

You must be logged in to vote
2 replies
@franky47
Comment options

@fapplin
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants