Example usage for javax.sound.midi Sequencer getTrackMute

List of usage examples for javax.sound.midi Sequencer getTrackMute

Introduction

In this page you can find the example usage for javax.sound.midi Sequencer getTrackMute.

Prototype

boolean getTrackMute(int track);

Source Link

Document

Obtains the current mute state for a track.

Usage

From source file:MidiTest.java

/**
 * This method is called by the sound system when a meta event occurs. In
 * this case, when the end-of-track meta event is received, the drum track
 * is turned on.//from w  w w .j a  v a 2 s . c  om
 */
public void meta(MetaMessage event) {
    if (event.getType() == MidiPlayer.END_OF_TRACK_MESSAGE) {
        Sequencer sequencer = player.getSequencer();
        if (sequencer.getTrackMute(DRUM_TRACK)) {
            // turn on the drum track
            System.out.println("Turning on drums...");
            sequencer.setTrackMute(DRUM_TRACK, false);
        } else {
            // close the sequencer and exit
            System.out.println("Exiting...");
            player.close();
            System.exit(0);
        }
    }
}

From source file:SoundManagerTest.java

/**
 * Performs actions when a button is pressed.
 *///from  www. j  av  a  2 s  .c  om
public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    AbstractButton button = (AbstractButton) e.getSource();
    if (command == EXIT) {
        midiPlayer.close();
        soundManager.close();
        stop();
    } else if (command == PAUSE) {
        // pause the sound
        soundManager.setPaused(button.isSelected());
        midiPlayer.setPaused(button.isSelected());
    } else if (command == PLAY_MUSIC) {
        // toggle music on or off
        if (button.isSelected()) {
            midiPlayer.play(music, true);
        } else {
            midiPlayer.stop();
        }
    } else if (command == MUSIC_DRUMS) {
        // toggle drums on or off
        Sequencer sequencer = midiPlayer.getSequencer();
        if (sequencer != null) {
            boolean mute = sequencer.getTrackMute(DRUM_TRACK);
            sequencer.setTrackMute(DRUM_TRACK, !mute);
        }
    } else if (command == PLAY_SOUND) {
        // play a normal sound
        soundManager.play(boop);
    } else if (command == PLAY_ECHO_SOUND) {
        // play a sound with an echo
        EchoFilter filter = new EchoFilter(11025, .6f);
        soundManager.play(boop, filter, false);
    } else if (command == PLAY_LOOPING_SOUND) {
        // play or stop the looping sound
        if (button.isSelected()) {
            lastloopingSound = soundManager.play(bzz, null, true);
        } else if (lastloopingSound != null) {
            try {
                lastloopingSound.close();
            } catch (IOException ex) {
            }
            lastloopingSound = null;
        }
    } else if (command == PLAY_MANY_SOUNDS) {
        // play several sounds at once, to test the system
        for (int i = 0; i < MANY_SOUNDS_COUNT; i++) {
            soundManager.play(boop);
        }
    }
}