List of usage examples for javax.sound.midi Sequencer setTrackMute
void setTrackMute(int track, boolean mute);
From source file:MidiTest.java
public void run() { player = new MidiPlayer(); // load a sequence Sequence sequence = player.getSequence("../sounds/music.midi"); // play the sequence player.play(sequence, true);// w w w . j a va 2s .c o m // turn off the drums System.out.println("Playing (without drums)..."); Sequencer sequencer = player.getSequencer(); sequencer.setTrackMute(DRUM_TRACK, true); sequencer.addMetaEventListener(this); }
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 va 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 w w w.ja v 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); } } }