Skip to content

Navigation Menu

Sign in
Sign up

Programmatically switching between jukebox and midi control #24

Answered by wdautrem
wdautrem asked this question in Q&A
Discussion options

I've been trying to get things set up so I can switch between jukebox mode and regular midi control mode via a digital input. I am able to compile fine with both JUKEBOX and MIDI_VIA_SERIAL2 defined. I was initially just going to put an IF statement in regular_checks() to run jukebox_tick() or MIDI2.read() based on the input value. This works, but adds a static chopping noise to the output. I'm guessing this is some sort of interrupt issue but I'm not sure where to check from here. Any ideas where I should look?

You must be logged in to vote

It was the ESP core code. Switched to 2.0.17 and everything works as expected. I am even able to put the digitalRead inside the regular_checks() function so I can switch between jukebox and midi mode on the fly. Thank you for the support and for being so responsive!

Replies: 5 comments 4 replies

Comment options

Please, provide a piece of code that you think to be guilty. It seems that there's no more CPU time to run extra logics.

You must be logged in to vote
0 replies
Comment options

Here was my initial attempt. midijack is set by a digital input in the setup routine. If I manually set midijack to a constant HIGH or LOW I still get significant distortion in the output. I have both MIDI_VIA_SERIAL2 and JUKEBOX defined in the config.h. Is there a different way I should be approaching this switch?

`void regular_checks() {
timer1_fired = false;

#ifdef MIDI_VIA_SERIAL
MIDI.read();
#endif

#ifdef MIDI_VIA_SERIAL2
if (midijack == LOW) MIDI2.read();
#endif

#ifdef JUKEBOX
if (midijack == HIGH) jukebox_tick();
#endif

}`

You must be logged in to vote
1 reply
Comment options

Unfortunately this may be because of 'if' itself. I don't have hardware by me, so I only can suggest the following minimal clean experiment.

//globally
bool sw = true;
//in regularChecks
if (sw) MIDI2.read();
else jukebox_tick();

Also try undefining DEBUG_ON.

Finally if it turns out that it's IF to blame, we can substitute it with a function pointer that changes only when switch state changes, and no logics applied when calling a placeholder function in a loop.

Comment options

Thanks for the suggestions. I had tried the if / else and it causes the same distortion as using two ifs. Double checked all my DEBUGs are undef. I also tried making two different regular_check functions, one for midi control, and one for jukebox and doing the switch there, but that also created distortion. Finally, I tried just running both MIDI2.read() and jukebox_tick() at the same time. I was able to trigger notes via MIDI as the jukebox played, but the distortion was still present.

You must be logged in to vote
1 reply
Comment options

What version of ESP Arduino Core do you use? If it is 3.0.0+ then I would suggest to try your code in 2.0.17 or close to it. I haven't throughly tested 3.x.x.
Also please specify what environment do you have: board, IDE ver., ESP Arduino core ver.?

Comment options

I have ESP core 2.0.11 installed currently, I will bump that up to 2.0.17 and test. My IDE is currently 2.2.1. Hardware is a Wemos / lolin D32 Pro with 8MB of PSRAM. Using a PCM5102 with everything wired to the default pins.

You must be logged in to vote
1 reply
Comment options

BTW, are there some other code changes compared to the original repo?

Comment options

It was the ESP core code. Switched to 2.0.17 and everything works as expected. I am even able to put the digitalRead inside the regular_checks() function so I can switch between jukebox and midi mode on the fly. Thank you for the support and for being so responsive!

You must be logged in to vote
1 reply
Comment options

Great that the solution was so simple

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

AltStyle によって変換されたページ (->オリジナル) /