diff --git a/src/core/AudioInterface.cpp b/src/core/AudioInterface.cpp index 2f8efef3..d512a905 100644 --- a/src/core/AudioInterface.cpp +++ b/src/core/AudioInterface.cpp @@ -7,13 +7,18 @@ using namespace rack; +static bool initialized = false; void audioInit() { + if (initialized) + return; + PaError err = Pa_Initialize(); if (err) { fprintf(stderr, "Failed to initialize PortAudio: %s\n", Pa_GetErrorText(err)); return; } + initialized = true; } @@ -80,6 +85,7 @@ AudioInterface::AudioInterface() { params.resize(NUM_PARAMS); inputs.resize(NUM_INPUTS); outputs.resize(NUM_OUTPUTS); + audioInit(); } AudioInterface::~AudioInterface() { diff --git a/src/core/MidiInterface.cpp b/src/core/MidiInterface.cpp index 487c10ce..78a2735d 100644 --- a/src/core/MidiInterface.cpp +++ b/src/core/MidiInterface.cpp @@ -7,13 +7,18 @@ using namespace rack; +static bool initialized = false; void midiInit() { + if (initialized) + return; + PmError err = Pm_Initialize(); if (err) { printf("Failed to initialize PortMidi: %s\n", Pm_GetErrorText(err)); return; } + initialized = true; } @@ -56,6 +61,7 @@ MidiInterface::MidiInterface() { params.resize(NUM_PARAMS); inputs.resize(NUM_INPUTS); outputs.resize(NUM_OUTPUTS); + midiInit(); } MidiInterface::~MidiInterface() { diff --git a/src/core/core.cpp b/src/core/core.cpp index bc41fd68..7ffabf10 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -12,8 +12,5 @@ struct CorePlugin : Plugin { Plugin *init() { - audioInit(); - midiInit(); - return new CorePlugin(); } diff --git a/src/core/core.hpp b/src/core/core.hpp index bf43aeef..a38a592e 100644 --- a/src/core/core.hpp +++ b/src/core/core.hpp @@ -3,9 +3,6 @@ using namespace rack; -void audioInit(); -void midiInit(); - //////////////////// // module widgets ////////////////////