it's not actually that straightforward, because the underrun is detected in the backend. One solution is to use a global variable to record the latest count of available messages and then print it out if there was an underrun.
Edit the file in core/PRU.cpp
(on the board) as follows (add the lines with a leading +
, remove the line with a leading -
):
diff --git a/core/PRU.cpp b/core/PRU.cpp
index 65f74f95..10d484d7 100644
--- a/core/PRU.cpp
+++ b/core/PRU.cpp
@@ -854,6 +854,7 @@ int PRU::testPruError()
}
}
+unsigned int gGlobal;
// Main loop to read and write data from/to PRU
void PRU::loop(void *userData, void(*render)(BelaContext*, void*), bool highPerformanceMode)
{
@@ -1450,7 +1451,7 @@ void PRU::loop(void *userData, void(*render)(BelaContext*, void*), bool highPerf
// don't print a warning if we are stopping
if(!gShouldStop)
{
- rt_fprintf(stderr, "Underrun detected: %u blocks dropped\n", (pruFrameCount - expectedFrameCount) / pruFramesPerBlock);
+ rt_fprintf(stderr, "Underrun detected: %u blocks dropped. Value: %u\n", (pruFrameCount - expectedFrameCount) / pruFramesPerBlock, gGlobal);
if(underrunLed.enabled())
underrunLed.set();
Then in render()
, your approach above would work, but it's probably easier to just call getNumMessages()
one more time, before the while()
:
gGlobal = midi[port]->getParser()->numAvailableMessages();
while((num = midi[port]->getParser()->numAvailableMessages()) > 0)
{
...
}
Does it make sense?