Package javax.sound.midi

Examples of javax.sound.midi.Synthesizer


public class Main {

  public static void main(String[] args) throws MidiUnavailableException, InterruptedException {

    Synthesizer synth = MidiSystem.getSynthesizer();
    synth.open();

    MidiChannel[] channels = synth.getChannels();
    MidiChannel channel = channels[0];

    Instrument[] instr = synth.getDefaultSoundbank().getInstruments();
    synth.loadInstrument(instr[0]);

    Piano piano = new Piano(3, -1, channel);

    PianoFrame frame = new PianoFrame(piano);
    frame.setVisible(true);
View Full Code Here


        ret.init();
        return ret;
    }

    public static String[] getInstruments() {
        Synthesizer synthesizer = null;
        try {
            synthesizer = MidiSystem.getSynthesizer();
            synthesizer.open();
            synthesizer.loadAllInstruments(synthesizer.getDefaultSoundbank());
        } catch (MidiUnavailableException ex) {
            ex.printStackTrace();
        }
        Instrument in[] = synthesizer.getLoadedInstruments();
        String ret[] = new String[in.length];
        for (int x = 0; x < in.length; x++) {
            ret[x] = in[x].getName();
        }
        return ret;
View Full Code Here

    }

    public void init() {
        try {
            // events directly to the Synthesizer instead.
            Synthesizer synthesizer = MidiSystem.getSynthesizer();
            synthesizer.open();

            synthesizer.loadAllInstruments(synthesizer.getDefaultSoundbank());
            Instrument in[] = synthesizer.getLoadedInstruments();

            synthesizer.loadInstrument(in[70]);
            channel = synthesizer.getChannels()[0];
        } catch (MidiUnavailableException ex) {
            ex.printStackTrace();
        }
    }
View Full Code Here

    /*
     * Find available AudioSynthesizer.
     */
    public static AudioSynthesizer findAudioSynthesizer() throws MidiUnavailableException, IOException, InvalidMidiDataException {
        // First check if default synthesizer is AudioSynthesizer.
        Synthesizer synth = MidiSystem.getSynthesizer();
        if (synth instanceof AudioSynthesizer) {
            return (AudioSynthesizer) synth;
        }

        // If default synhtesizer is not AudioSynthesizer, check others.
View Full Code Here

            try {
                synth.play(null);
            } catch (Exception ex){};
            Field synthField = ReflectionUtils.findField(MidiSynth.class, "m_synth");
            ReflectionUtils.makeAccessible(synthField);
            Synthesizer synthsizer = (Synthesizer) synthField.get(synth);
            loadSoundbankInstruments(synthsizer);
        } catch (Exception ex) {
            throw new IllegalStateException(ex);
        }
View Full Code Here

  public static void main(String[] args) throws Exception {
        Field f = SoftSynthesizer.class.getDeclaredField("testline");
        f.setAccessible(true);
        f.set(null, new DummySourceDataLine());
       
    Synthesizer synth = new SoftSynthesizer();
       
    ReferenceCountingDevice rcd = (ReferenceCountingDevice)synth;   
         
    // Test single open/close cycle
   
    Receiver recv = rcd.getReceiverReferenceCounting();
    if(!synth.isOpen())
      throw new Exception("Synthesizer not open!");
    recv.close();
    if(synth.isOpen())
      throw new Exception("Synthesizer not closed!");

    // Test using 2 receiver cycle
   
    Receiver recv1 = rcd.getReceiverReferenceCounting();
    if(!synth.isOpen())
      throw new Exception("Synthesizer not open!");   
    Receiver recv2 = rcd.getReceiverReferenceCounting();
    if(!synth.isOpen())
      throw new Exception("Synthesizer not open!");

    recv2.close();
    if(!synth.isOpen())
      throw new Exception("Synthesizer was closed!");
    recv1.close();
    if(synth.isOpen())
      throw new Exception("Synthesizer not closed!");
   
    // Test for explicit,implicit conflict
   
    synth.open();
    Receiver recv3 = rcd.getReceiverReferenceCounting();
    if(!synth.isOpen())
      throw new Exception("Synthesizer not open!");
    recv3.close();
    if(!synth.isOpen())
      throw new Exception("Synthesizer was closed!");
    synth.close();
    if(synth.isOpen())
      throw new Exception("Synthesizer not closed!");

    // Test for implicit,explicit conflict
   
    recv3 = rcd.getReceiverReferenceCounting();
    synth.open();
    if(!synth.isOpen())
      throw new Exception("Synthesizer not open!");
    recv3.close();
    if(!synth.isOpen())
      throw new Exception("Synthesizer was closed!");
    synth.close();
    if(synth.isOpen())
      throw new Exception("Synthesizer not closed!");
   
  }
View Full Code Here

TOP

Related Classes of javax.sound.midi.Synthesizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.