Your first posted code does NOT show anything in the loop.
do { // and space bar
} while (!midipedalflag);
Did you remove code that was in that loop?
Otherwise why have an empy loop?
but how I get out of the run() method?
If there is no code in the run() method, it will execute and exit very quickly.