public void close() {
        if (sequencer != null) {
            if (sequencer.isOpen() && sequencer.isRunning()) {
                sequencer.stop();
            }
            sequencer.close();
            sequencer = null;
        }

        if (synthesizer != null) {
            if (synthesizer.isOpen()) {
                synthesizer.close();
            }
            synthesizer = null;
        }
    }