public Sequencer(int instrument, int tempo) { // Set up initial settings for the sequencer this.instrument = instrument; this.tempo = tempo; Synthesizer synth; ticks = 0; velocity = 64; // Mid volume try { // Setup values to create sequencer sequence = new Sequence(Sequence.PPQ, 16); sequencer = MidiSystem.getSequencer(); sequencer.open(); synth = MidiSystem.getSynthesizer(); synth.open(); sequencer.getTransmitter().setReceiver(synth.getReceiver()); sequencer.setTempoInBPM(tempo); track = sequence.createTrack(); } catch (InvalidMidiDataException e) { e.printStackTrace(); } catch (MidiUnavailableException e) { e.printStackTrace(); } }
public boolean init(int nbells) { fNBells = nbells; try { fSequencer = MidiSystem.getSequencer(); fSequencer.addMetaEventListener(fListener); fSynthesizer = MidiSystem.getSynthesizer(); fMidiOut = fSynthesizer.getReceiver(); fSequencer.getTransmitter().setReceiver(fMidiOut); /* System.out.println(" Listing available midi devices: "); MidiDevice.Info[] info = MidiSystem.getMidiDeviceInfo(); for (int i=0; i<info.length; i++) { Class c = MidiSystem.getMidiDevice(info[i]).getClass(); System.out.println(" MIDI device "+i+": "+info[i]+" is a "+c); } System.out.println("Using Sequencer "+fSequencer.getClass()+" and receiver "+fMidiOut.getClass()); */ } catch (MidiUnavailableException e) { System.out.println("Could not obtain MIDI device: " + e); return false; } return true; }
{ try { sq = MidiSystem.getSequencer(); } catch (MidiUnavailableException e) { e.printStackTrace(); } }
public void PlayMidiFile(String name, String filename) { Sequencer seq = null; Transmitter seqTrans = null; Synthesizer synth; Receiver synthRcvr = null; File midiFile = null; try { seq = MidiSystem.getSequencer(); seqTrans = seq.getTransmitter(); synth = MidiSystem.getSynthesizer(); synthRcvr = synth.getReceiver(); midiFile = new File(filename); if (seq == null) { Debug.showMessage("MidiCSD::PlayMidiFile: Sequencer nicht gefunden!"); } else { seq.open(); seqTrans.setReceiver(synthRcvr); Sequence mySeq; mySeq = MidiSystem.getSequence(midiFile); new Player(name, seq, mySeq, synth, m_playing).start(); } } catch (MidiUnavailableException e) { Debug.showException(e, "MidiCSD::PlayMidiFile: MidiUnavailable" + e.getMessage()); } catch (InvalidMidiDataException e) { Debug.showException(e, "MidiCSD::PlayMidiFile: InvalidMidiDataException" + e.getMessage()); } catch (IOException e) { Debug.showException(e, "MidiCSD::PlayMidiFile:IOException (fn:" + filename + ")"); } }
public void los() { guiErstellen(); try { Sequencer sequencer = MidiSystem.getSequencer(); sequencer.open(); sequencer.addControllerEventListener(ml, new int[] {127}); Sequence seq = new Sequence(Sequence.PPQ, 4); Track track = seq.createTrack(); int r = 0; for (int i = 0; i < 60; i += 4) { r = (int) ((Math.random() * 50) + 1); track.add(eventErzeugen(144, 1, r, 100, i)); track.add(eventErzeugen(176, 1, 127, 0, i)); track.add(eventErzeugen(128, 1, r, 100, i + 2)); } sequencer.setSequence(seq); sequencer.setTempoInBPM(120); sequencer.start(); Thread.sleep(5000); sequencer.close(); } catch (Exception ex) { ex.printStackTrace(); } }
public void go() { setUpGui(); try { Sequencer sequencer = MidiSystem.getSequencer(); sequencer.open(); // make a sequencer and open sequencer.addControllerEventListener(m1, new int[] {127}); Sequence seq = new Sequence(Sequence.PPQ, 4); Track track = seq.createTrack(); int r = 0; for (int i = 0; i < 300; i += 4) { r = (int) ((Math.random() * 50) + 1); track.add(makeEvent(144, 1, r, 100, i)); track.add(makeEvent(176, 1, 127, 0, i)); track.add(makeEvent(128, 1, r, 100, i + 2)); } // end loop sequencer.setSequence(seq); sequencer.start(); sequencer.setTempoInBPM(120); } catch (Exception ex) { ex.printStackTrace(); } } // close method
public void play(int instrument, int note) { try { Sequencer player = MidiSystem.getSequencer(); player.open(); Sequence seq = new Sequence(Sequence.PPQ, 4); Track track = seq.createTrack(); MidiEvent event = null; ShortMessage first = new ShortMessage(); first.setMessage(192, 1, instrument, 0); MidiEvent changeInstrument = new MidiEvent(first, 1); track.add(changeInstrument); ShortMessage a = new ShortMessage(); a.setMessage(144, 1, note, 100); MidiEvent noteOn = new MidiEvent(a, 1); track.add(noteOn); ShortMessage b = new ShortMessage(); b.setMessage(128, 1, note, 100); MidiEvent noteOff = new MidiEvent(b, 16); track.add(noteOff); player.setSequence(seq); player.start(); } catch (Exception ex) { ex.printStackTrace(); } } // close play
public boolean initialize() { boolean success = true; try { sequencer = MidiSystem.getSequencer(); sequencer.addMetaEventListener(this); if (synthesizer == null) { if ((synthesizer = MidiSystem.getSynthesizer()) == null) { Application.debug("getSynthesizer() failed!"); return false; } Soundbank sb = synthesizer.getDefaultSoundbank(); if (sb != null) { instruments = synthesizer.getDefaultSoundbank().getInstruments(); synthesizer.loadInstrument(instruments[0]); } channels = synthesizer.getChannels(); } } catch (MidiUnavailableException e) { e.printStackTrace(); return false; } catch (Exception e) { e.printStackTrace(); return false; } return success; }
/** * Creates a WAV file based on a MIDI file, using the default sound bank. * * @param midiFile The MIDI file. * @param outputFile An output file. * @throws MidiUnavailableException When the synthesizer is not available. * @throws InvalidMidiDataException When the MIDI data is invalid. * @throws IOException If the WAV file can not be written. */ public void createWavFile(final File midiFile, final File outputFile) throws MidiUnavailableException, InvalidMidiDataException, IOException { // Create a AdvancedAudioPlayer with this Synthesizer, and get a Sequence final Sequence sequence = MidiSystem.getSequence(midiFile); final Sequencer sequencer = MidiSystem.getSequencer(false); sequencer.getTransmitter().setReceiver(synth.getReceiver()); createWavFile(sequence, outputFile); }
public void play() { try { Sequencer player = MidiSystem.getSequencer(); System.out.println("Successfully got a sequencer"); } catch (MidiUnavailableException ex) { System.out.println("Bummer"); } }
public MidiPlayer() throws MidiUnavailableException { this.c(); this.c = MidiSystem.getReceiver(); this.sequencer = MidiSystem.getSequencer(false); this.sequencer.getTransmitter().setReceiver(this); this.sequencer.open(); this.a(-1L); }
public MidiPlayer() { try { sequencer = MidiSystem.getSequencer(); sequencer.open(); sequencer.addMetaEventListener(this); } catch (MidiUnavailableException ex) { sequencer = null; } }
public void playMusic() { if (judgetone == true) { System.out.print("Make Cheerful Song.\r\n"); try { sequence = new Sequence(Sequence.PPQ, 24, 3); MelodyMaker.setCheerfulMelody(sequence, length, velocity); AccompanimentMaker.makeCheerfulAccompaniment(sequence, length, velocity); sequencer = MidiSystem.getSequencer(); sequencer.open(); sequencer.setSequence(sequence); sequencer.start(); while (sequencer.isRunning()) Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } catch (MidiUnavailableException e) { e.printStackTrace(); } catch (InvalidMidiDataException e) { e.printStackTrace(); } finally { if (sequencer != null && sequencer.isOpen()) sequencer.close(); } } else if (judgetone == false) { System.out.print("Make Gloomy Song.\r\n"); try { sequence = new Sequence(Sequence.PPQ, 24, 3); MelodyMaker.setGloomyMelody(sequence, length, velocity); AccompanimentMaker.makeGloomyAccompaniment(sequence, length, velocity); sequencer = MidiSystem.getSequencer(); sequencer.open(); sequencer.setSequence(sequence); sequencer.start(); while (sequencer.isRunning()) Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } catch (MidiUnavailableException e) { e.printStackTrace(); } catch (InvalidMidiDataException e) { e.printStackTrace(); } finally { if (sequencer != null && sequencer.isOpen()) sequencer.close(); } } }
/** * @param key is the note that this starts with. 60 is middle C. * @param tempo is measured in beats per second */ public MidiFileGenerator(int key, int tempo, int resolution) throws MidiUnavailableException, InvalidMidiDataException { this.resolution = resolution; Sequence sequence = new Sequence(Sequence.PPQ, resolution); track = sequence.createTrack(); // makeSong(key); sequencer = MidiSystem.getSequencer(); sequencer.open(); sequencer.setSequence(sequence); sequencer.setTempoInBPM(tempo); }
public void setUpMidi() { try { sequencer = MidiSystem.getSequencer(); sequencer.open(); sequence = new Sequence(Sequence.PPQ, 4); track = sequence.createTrack(); sequencer.setTempoInBPM(120); } catch (Exception e) { e.printStackTrace(); } } // close method
public MidiReceiverForTransmitterDevice() { parser = new MidiParser(); renderer = new MusicStringRenderer(); parser.addParserListener(renderer); try { sequencer = MidiSystem.getSequencer(); sequencerReceiver = sequencer.getReceiver(); } catch (MidiUnavailableException e) { e.printStackTrace(); } }
public Jams() { try { // From file sequence = MidiSystem.getSequence(new File("images/tunes.mid")); // Create a sequencer for the sequence sequencer = MidiSystem.getSequencer(); sequencer.open(); sequencer.setSequence(sequence); } catch (IOException e) { } catch (MidiUnavailableException e) { } catch (InvalidMidiDataException e) { } }
public MIDIReader(String filename) { this.filename = filename; try { this.recebedor = MidiSystem.getReceiver(); this.sequencia = MidiSystem.getSequence(new File(filename)); this.tempoProcessor = new MidiUtils.TempoCache(sequencia); this.player = MidiSystem.getSequencer(true); this.player.setSequence(sequencia); this.player.open(); this.interval = 0.5f; this.loadNotes(); this.duration = this.getRealDuration(); } catch (Exception ex) { Utilidades.alertar(ex.getMessage()); } }
/** * Instantiates a new Player object, which is used for playing music. The <code>connected</code> * parameter is passed directly to MidiSystem.getSequencer. Pass false when you do not want to * copy a live synthesizer - for example, if your Player is on a server, and you don't want to * create new synthesizers every time the constructor is called. */ public Player(boolean connected) { try { // Get default sequencer. setSequencer(MidiSystem.getSequencer(connected)); // use non // connected // sequencer so // no copy of // live // synthesizer // will be // created. } catch (MidiUnavailableException e) { throw new JFugueException( JFugueException.SEQUENCER_DEVICE_NOT_SUPPORTED_WITH_EXCEPTION + e.getMessage()); } initParser(); }
/** * Sets up the sequencer with a given sequence. * * @param sequenceToUse * @throws MidiUnavailableException */ private void setUpSequencer() throws MidiUnavailableException { // First, get the system's default sequencer. try { sequencer = MidiSystem.getSequencer(); } catch (MidiUnavailableException ex) { // Something went wrong. ex.printStackTrace(); System.exit(1); } // If there is none, throw an exception. if (sequencer == null) { String msg = "Cannot find a sequencer"; throw new MidiUnavailableException(msg); } // Set up the transmitter and receiver of the synth to play the song. linkTransmitterToReceiver(); }
/** * Returns an instance of a Sequencer that uses the provided Synthesizer as its receiver. This is * useful when you have made changes to a specific Synthesizer--for example, you've loaded in new * patches--that you want the Sequencer to use. You can then pass the Sequencer to the Player * constructor. * * @param synth The Synthesizer to use as the receiver for the returned Sequencer * @return a Sequencer with the provided Synthesizer as its receiver * @throws MidiUnavailableException * @version 4.0 */ public static Sequencer getSequencerConnectedToSynthesizer(Synthesizer synth) throws MidiUnavailableException { Sequencer sequencer = MidiSystem.getSequencer(false); // Get Sequencer // which is not // connected to // new // Synthesizer. sequencer.open(); if (!synth.isOpen()) { synth.open(); } sequencer.getTransmitter().setReceiver(synth.getReceiver()); // Connect // the // Synthesizer // to // our // synthesizer // instance. return sequencer; }
private void setAudioSequencer() { InputStream audioSrc = AgentUtilOperations.class.getResourceAsStream("/" + AgentConstants.AUDIO_FILE_NAME); Sequence sequence; try { sequence = MidiSystem.getSequence(audioSrc); sequencer = MidiSystem.getSequencer(); sequencer.open(); sequencer.setSequence(sequence); } catch (InvalidMidiDataException e) { log.error("AudioReader: Error whilst setting MIDI Audio reader sequence"); } catch (IOException e) { log.error("AudioReader: Error whilst getting audio sequence from stream"); } catch (MidiUnavailableException e) { log.error("AudioReader: Error whilst openning MIDI Audio reader sequencer"); } sequencer.setLoopCount(Clip.LOOP_CONTINUOUSLY); }
static void playMidiFile(String filename) { try { // From file sequence = MidiSystem.getSequence(new File(filename)); // Create a sequencer for the sequence sequencer = MidiSystem.getSequencer(); sequencer.open(); sequencer.setSequence(sequence); // Start playing sequencer.start(); } catch (Exception e) { } // QTPlayer.display(population[i]); // Instrument inst = new SimpleSineInst(44100); // Write.au(population[i], inst); // Play.midi(population[i]); }
private static void playMidi(String name, boolean loop, double volume) throws MidiUnavailableException, FileNotFoundException, IOException, InvalidMidiDataException { // Obtains the default Sequencer connected to a default device. Sequencer sequencer = MidiSystem.getSequencer(); // Opens the device, indicating that it should now acquire any system resources it requires and // become operational. sequencer.open(); // create a stream from a file InputStream is = new BufferedInputStream(new FileInputStream(new File(path + name))); // Sets the current sequence on which the sequencer operates. // The stream must point to MIDI file data. sequencer.setSequence(is); // Set looping if (loop) { sequencer.setLoopCount(LOOP_CONTINUOUSLY); } // Starts playback of the MIDI data in the currently loaded sequence. sequencer.start(); midiMap.put(name, sequencer); }
public void actionPerformed(ActionEvent ev) { try { // make (and open) a sequencer, make a sequence and track Sequencer sequencer = MidiSystem.getSequencer(); sequencer.open(); sequencer.addControllerEventListener(myPanel, new int[] {127}); Sequence seq = new Sequence(Sequence.PPQ, 4); Track track = seq.createTrack(); // now make two midi events (containing a midi message) for (int i = 0; i < 100; i += 4) { int rNum = (int) ((Math.random() * 50) + 1); if (rNum < 38) { // so now only do it if num <38 (75% of the time) track.add(makeEvent(144, 1, rNum, 100, i)); track.add(makeEvent(176, 1, 127, 0, i)); track.add(makeEvent(128, 1, rNum, 100, i + 2)); } } // end loop // add the events to the track // add the sequence to the sequencer, set timing, and start sequencer.setSequence(seq); sequencer.start(); sequencer.setTempoInBPM(220); } catch (Exception ex) { ex.printStackTrace(); } } // close actionperformed
public boolean open() { try { if (synthesizer == null) { if ((synthesizer = MidiSystem.getSynthesizer()) == null) { System.out.println("getSynthesizer() failed!"); return false; } } synthesizer.open(); sequencer = MidiSystem.getSequencer(); sequencer.addMetaEventListener(new ProcessMeta()); sequence = new Sequence(Sequence.PPQ, 10); } catch (Exception ex) { System.out.println("midi exception 1 "); ex.printStackTrace(); return false; } System.out.println("midi opening"); Soundbank sb = synthesizer.getDefaultSoundbank(); if (sb != null) { instruments = synthesizer.getDefaultSoundbank().getInstruments(); synthesizer.loadInstrument(instruments[0]); } MidiChannel midiChannels[] = synthesizer.getChannels(); numChannels = midiChannels.length; channels = new ChannelData[midiChannels.length]; if (channels.length == 0) return false; for (int i = 0; i < channels.length; i++) { channels[i] = new ChannelData(midiChannels[i], i); } cc = channels[0]; return true; }
private synchronized void startMidi(InputStream bis, InputStream in) throws InvalidMidiDataException, MidiUnavailableException { Sequencer sequencer = null; Info info = null; // sequencer = MidiSystem.getSequencer( null ); sequencer = MidiSystem.getSequencer(); sequencer.open(); try { sequencer.setSequence(bis); } catch (IOException e) { throw new InvalidMidiDataException(e.getMessage()); } info = new Info(sequencer, in, null); infos.addElement(info); // fix for bug 4302884: Audio device is not released when AudioClip stops sequencer.addMetaEventListener(info); sequencer.start(); }
public void los() { guiErstellen(); try { // einen Sequencer erzeugen (und öffnen), // eine Sequence und einen Track erzeugen Sequencer sequencer = MidiSystem.getSequencer(); sequencer.open(); sequencer.addControllerEventListener(ml, new int[] {127}); Sequence seq = new Sequence(Sequence.PPQ, 4); Track track = seq.createTrack(); // jetzt werden MidiEvents (die eine // MidiMessage enthalten) erzeugt int r = 0; for (int i = 0; i < 60; i += 4) { r = (int) ((Math.random() * 50) + 1); track.add(eventErzeugen(144, 1, r, 100, i)); track.add(eventErzeugen(176, 1, 127, 0, i)); track.add(eventErzeugen(128, 1, r, 100, i + 2)); } // Ende der for-Schleife // Hinzufügen der Events zum Track und der Sequence // zum Sequencer, Setzen der Zeiten und Starten sequencer.setSequence(seq); sequencer.start(); sequencer.setTempoInBPM(120); } catch (Exception ex) { ex.printStackTrace(); } } // Methode los schließen
public static void init(GraphicsConfiguration gc, SonarSoundEngine sound) { try { mario = cutImage(gc, PREFIX + "/mariosheet.png", 32, 32); smallMario = cutImage(gc, PREFIX + "/smallmariosheet.png", 16, 16); fireMario = cutImage(gc, PREFIX + "/firemariosheet.png", 32, 32); enemies = cutImage(gc, PREFIX + "/enemysheet.png", 16, 32); items = cutImage(gc, PREFIX + "/itemsheet.png", 16, 16); level = cutImage(gc, PREFIX + "/mapsheet.png", 16, 16); map = cutImage(gc, PREFIX + "/worldmap.png", 16, 16); particles = cutImage(gc, PREFIX + "/particlesheet.png", 8, 8); bg = cutImage(gc, PREFIX + "/bgsheet.png", 32, 32); logo = getImage(gc, PREFIX + "/logo.gif"); titleScreen = getImage(gc, PREFIX + "/title.gif"); font = cutImage(gc, PREFIX + "/font.gif", 8, 8); endScene = cutImage(gc, PREFIX + "/endscene.gif", 96, 96); gameOver = cutImage(gc, PREFIX + "/gameovergost.gif", 96, 64); keys = getImage(gc, PREFIX + "/keys.png"); abkey = getImage(gc, PREFIX + "/abkey.png"); if (sound != null) { samples[SAMPLE_BREAK_BLOCK] = sound.loadSample(PREFIX + "/snd/breakblock.wav"); samples[SAMPLE_GET_COIN] = sound.loadSample(PREFIX + "/snd/coin.wav"); samples[SAMPLE_MARIO_JUMP] = sound.loadSample(PREFIX + "/snd/jump.wav"); samples[SAMPLE_MARIO_STOMP] = sound.loadSample(PREFIX + "/snd/stomp.wav"); samples[SAMPLE_MARIO_KICK] = sound.loadSample(PREFIX + "/snd/kick.wav"); samples[SAMPLE_MARIO_POWER_UP] = sound.loadSample(PREFIX + "/snd/powerup.wav"); samples[SAMPLE_MARIO_POWER_DOWN] = sound.loadSample(PREFIX + "/snd/powerdown.wav"); samples[SAMPLE_MARIO_DEATH] = sound.loadSample(PREFIX + "/snd/death.wav"); samples[SAMPLE_ITEM_SPROUT] = sound.loadSample(PREFIX + "/snd/sprout.wav"); samples[SAMPLE_CANNON_FIRE] = sound.loadSample(PREFIX + "/snd/cannon.wav"); samples[SAMPLE_SHELL_BUMP] = sound.loadSample(PREFIX + "/snd/bump.wav"); samples[SAMPLE_LEVEL_EXIT] = sound.loadSample(PREFIX + "/snd/exit.wav"); samples[SAMPLE_MARIO_1UP] = sound.loadSample(PREFIX + "/snd/1-up.wav"); samples[SAMPLE_MARIO_FIREBALL] = sound.loadSample(PREFIX + "/snd/fireball.wav"); } } catch (Exception e) { e.printStackTrace(); } try { sequencer = MidiSystem.getSequencer(); sequencer.open(); songs[0] = MidiSystem.getSequence( ResourcesManager.class.getResourceAsStream(PREFIX + "/mus/smb3map1.mid")); songs[1] = MidiSystem.getSequence( ResourcesManager.class.getResourceAsStream(PREFIX + "/mus/smwovr1.mid")); songs[2] = MidiSystem.getSequence( ResourcesManager.class.getResourceAsStream(PREFIX + "/mus/smb3undr.mid")); songs[3] = MidiSystem.getSequence( ResourcesManager.class.getResourceAsStream(PREFIX + "/mus/smwfortress.mid")); songs[4] = MidiSystem.getSequence( ResourcesManager.class.getResourceAsStream(PREFIX + "/mus/smwtitle.mid")); } catch (Exception e) { sequencer = null; e.printStackTrace(); } }
public static void playSound() throws MidiUnavailableException { Sequencer sequencer = MidiSystem.getSequencer(); System.out.println("Obtained a sequencer..."); }