I believe that you are trying to use only smooth functions, but a non-smooth function such as abs() or sgn() appears to be necessary. You can try using a smooth limit approximation such as abs(x) = lim(((2*x)/pi)*atan(k*x), k = inf), keeping in mind that this limit may not exist at x = 0.
MidiSystem.getSequencer() returns an instance of RealTimeSequencer, which implements isRunning essentially as follows: private boolean running; public boolean isRunning () { return running; }. You can try declaring RealTimeSequencer.running volatile, but the correct solution is to use Sequencer.addM...
A simple but dirty solution is to sleep in the loop: while (sequencer.isRunning()) { Thread.sleep(10l) }. A cleaner solution is to add an event listener using Sequencer.addMetaEventListener() and communicate with your main thread using Object.wait() and Object.notify().