Java Code Examples for javax.sound.midi.MidiChannel#getController()

The following examples show how to use javax.sound.midi.MidiChannel#getController() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsynchronousMidiChannel.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void doIt(String args[]) {
    Synthesizer synth = null;
    MidiChannel mChanArr[];
    MidiChannel chan = null;
    boolean failed = false;
    int i = 0;
    int chanNum = 0;

    int val = 1;
    int contr = 0;
    Soundbank sBank;
    Instrument[] insArr;
    Instrument instr = null;
    Object ev = new Object();

    try {
        synth = MidiSystem.getSynthesizer();
        System.out.println("Got synth: "+synth);
        synth.open();

        int latency = (int) synth.getLatency();
        System.out.println("  -> latency: "
                           +latency
                           +" microseconds");

        mChanArr = synth.getChannels();
        while ((i < mChanArr.length) && (chan == null)) {
            chanNum = i;
            chan = mChanArr[i++];
        }
        if (chan == null) {
            System.out.println("No channels in "
                               +"this synthesizer!");
            return;
        }
        System.out.println("Got MidiChannel: "+chan);


        sBank = synth.getDefaultSoundbank();
        if (sBank == null) {
            System.out.println("No default sound bank!");
            return;
        }


        insArr = sBank.getInstruments();
        for (int j = 0; j < insArr.length; j++) {
            if (insArr[j].getPatch().getBank() == val) {
                instr = insArr[j];
                synth.loadInstrument(instr);
            }
        }
        if (instr == null) {
            System.out.println("No instr. with this bank!");
            return;
        }

        chan.controlChange(contr, val);

        // need to respect the synthesizer's latency
        if (latency > 0) {
            try {
                Thread.sleep(latency/1000);
            } catch (InterruptedException inEx) {
            }
        }

        if (chan.getController(contr) != val) {
            failed = true;
            System.err.println("getController() does not "
                               +"return proper value: "
            + chan.getController(contr));
        }  else {
            System.out.println("getController("
            + contr + ") returns proper value: "
            + chan.getController(contr));
        }

    } catch (MidiUnavailableException mue) {
        System.err.println("MidiUnavailableException was "
                           +"thrown: " + mue);
        System.out.println("could not test.");
        return;
    } catch(SecurityException se) {
        se.printStackTrace();
        System.err.println("Sound access is not denied but "
        + "SecurityException was thrown!");
        return;

    } finally {
        if (synth != null) synth.close();
    }


    if (failed == true) {
        System.out.println("test failed");
    } else {
        System.out.println("OKAY");
    }
    return;
}
 
Example 2
Source File: MidiSynthesizerManager.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public int findCurrentBank(int channel) {
	if( channel == PERCUSSION_CHANNEL ) {
		return PERCUSSION_BANK;
	}
	MidiChannel midiChannel = this.getChannel(channel);
	if( midiChannel != null ) {
		return midiChannel.getController(MidiControllers.BANK_SELECT);
	}
	return 0;
}