Results 1 to 2 of 2
  1. #1
    nicocannon is offline Member
    Join Date
    Dec 2014
    Posts
    30
    Rep Power
    0

    Default Java Midi Help: No Receivers & Transmitters for Midi Devices

    SOLVED

    Hey I've googled my errors from the console but have found no solution and have looked through the official midi tutorial but have still not found a solution.
    What Im trying to do: Play a midi sequence from a sample .mid file using default sequencer and synth with java
    Problem:The synth(Gervill) has no receivers (getMaxReceivers returns -1) also the sequencer has no transmitters (getMaxTransmitters returns -1)
    Error Output:
    Java Code:
    Exception in thread "Java Sound Sequencer" java.lang.IllegalStateException: Receiver is not open
    	at com.sun.media.sound.SoftReceiver.send(Unknown Source)
    	at com.sun.media.sound.AbstractMidiDevice$TransmitterList.sendMessage(Unknown Source)
    	at com.sun.media.sound.RealTimeSequencer$DataPump.notesOff(Unknown Source)
    	at com.sun.media.sound.RealTimeSequencer$PlayThread.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    How can I fix this issue?

    JAVA CODE:
    Java Code:
    import java.io.File;
    import javax.sound.midi.MidiSystem;
    import javax.sound.midi.Sequence;
    import javax.sound.midi.Sequencer;
    import javax.sound.midi.Synthesizer;
    
    public class MidFilePlayback {
    	
    	public static void main(String[] args) {
    		try {
    			File midiFile = new File("F:/Java Desktop Apps/JavaSoundStuff/src/MIDI_Stuff/sample.mid");
    			
    			Sequence mySeq = MidiSystem.getSequence(midiFile);
    			
    			Sequencer sequencer = MidiSystem.getSequencer();
    			sequencer.open();
    			
    			Synthesizer synth = MidiSystem.getSynthesizer();
    			synth.open();
    			
    			sequencer.getTransmitter().setReceiver(synth.getReceiver());
    			
    			sequencer.setSequence(mySeq);
    			
    			sequencer.start();
    			
    			System.out.println("Closing");
    			
                            synth.close();
    			sequencer.close();
    			
    		} catch(Exception e) {
    			e.printStackTrace();
    		}
    	}
    }
    Last edited by nicocannon; 12-28-2015 at 11:35 AM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Java Midi Help: No Receivers & Transmitters for Midi Devices

    This is too hard for me to explain in this forum (you need to read the tutorials and also the midi website mentioned in the Java API documentation). Then you need to experiment (however, imho the Java tutorials and the API on this topic can be confusing).

    Java Code:
    import java.io.File;
    import java.io.IOException;
    
    import javax.sound.midi.InvalidMidiDataException;
    import javax.sound.midi.MetaEventListener;
    import javax.sound.midi.MetaMessage;
    import javax.sound.midi.MidiSystem;
    import javax.sound.midi.MidiUnavailableException;
    import javax.sound.midi.Receiver;
    import javax.sound.midi.Sequence;
    import javax.sound.midi.Sequencer;
    
    public class MidFilePlayback {
       Sequencer sequencer;
    
       public static void main(String[] args) {
          new MidFilePlayback().start(); // just to get into an instance method.
       }
    
       public void start() {
          try {
             File midiFile = new File(
                   "F:/Java Desktop Apps/JavaSoundStuff/src/MIDI_Stuff/sample.mid");
             Sequence mySeq = MidiSystem.getSequence(midiFile);
             sequencer = MidiSystem.getSequencer(false);
             Receiver rcv = MidiSystem.getReceiver();
             sequencer.getTransmitter().setReceiver(rcv);
             sequencer.addMetaEventListener(new MyListener());
    
             sequencer.open();
             sequencer.setSequence(mySeq);
             sequencer.start();
    
          }
          catch (IOException | MidiUnavailableException
                | InvalidMidiDataException e) {
             e.printStackTrace();
          }
       }
    
       public class MyListener implements MetaEventListener {
          public void meta(MetaMessage msg) {
             if ((msg.getType()&0xFF) == 0x2F) { // end of track
                System.out.println("Track over");
                sequencer.close();
             }
          }
       }
    
    }
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Java Midi help
    By nicocannon in forum New To Java
    Replies: 2
    Last Post: 08-08-2016, 08:44 AM
  2. midi sequencer with java
    By jon in forum Advanced Java
    Replies: 1
    Last Post: 01-13-2012, 03:36 PM
  3. Adding midi devices to and array
    By grahamcrackeh in forum New To Java
    Replies: 10
    Last Post: 03-28-2011, 04:45 AM
  4. Sensing MIDI devices fails on OSX 10.6.6
    By grrreg in forum New To Java
    Replies: 1
    Last Post: 02-07-2011, 11:01 PM
  5. Getting input from MIDI devices on a Mac
    By Ben Wheatley in forum Advanced Java
    Replies: 1
    Last Post: 08-05-2009, 06:08 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •