当前位置: 首页>>代码示例>>Java>>正文


Java Transmitter.setReceiver方法代码示例

本文整理汇总了Java中javax.sound.midi.Transmitter.setReceiver方法的典型用法代码示例。如果您正苦于以下问题:Java Transmitter.setReceiver方法的具体用法?Java Transmitter.setReceiver怎么用?Java Transmitter.setReceiver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sound.midi.Transmitter的用法示例。


在下文中一共展示了Transmitter.setReceiver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMidiInput

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
/**
 * Capture midi input events, dispatching them to given Receiver.
 * The MidiDevice returned is the device providing the input, and
 * should be closed when input events are no longer needed.
 * Note that this method returns the first MidiDevice which
 * has at least one transmitter.
 * 
 * @param receiver the Receiver to which midi input events should be dispatched
 * @return the MidiDevice providing the input events
 * @throws MidiUnavailableException if midi input can't be found
 */
public static MidiDevice getMidiInput(Receiver receiver) throws MidiUnavailableException {
	MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
	for (MidiDevice.Info info : infos) {
		MidiDevice device;
		device = MidiSystem.getMidiDevice(info);
		if (DEBUG) {
			System.out.println("Found: " + device);
		}
		
		int maxTransmitters = device.getMaxTransmitters();
		if (DEBUG) {
			System.out.println("  Max transmitters: " + maxTransmitters);
		}
		
		if (maxTransmitters == -1 || maxTransmitters > 0) {
			Transmitter transmitter = device.getTransmitter();
			transmitter.setReceiver(receiver);
			device.open();
			return device;
		}
	}
	
	throw new MidiUnavailableException("Could not find any midi input sources");
}
 
开发者ID:daveho,项目名称:Gervill4Beads,代码行数:36,代码来源:CaptureMidiMessages.java

示例2: openInput

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
public static void openInput() throws Exception {
	setup();

	if (bUseDefaultSynthesizer) {
		Synthesizer synth = MidiSystem.getSynthesizer();
		synth.open();
		r = synth.getReceiver();
		try {
			Transmitter t = launchpad_s_plus.Launchpad.getInputDevice()
					.getTransmitter();
			t.setReceiver(r);
		} catch (MidiUnavailableException e) {
			out("wasn't able to connect the device's Transmitter to the default Synthesizer:");
			out(e);
			launchpad_s_plus.Launchpad.getInputDevice().close();
			System.exit(1);
		}
	}

	out("\nNow taking input.");

}
 
开发者ID:helionmusic,项目名称:launchpad_s_plus,代码行数:23,代码来源:MidiInDump.java

示例3: listenStart

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
public static void listenStart(){
		close();
		openedDevices.clear();
		MidiDevice device;
		MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
		for (int i = 0; i < infos.length; i++) {
			try {
				device = MidiSystem.getMidiDevice(infos[i]);
				System.out.println(infos[i] +" -- "+ infos[i].getDescription());
				java.util.List<Transmitter> transmitters = device.getTransmitters();
				for(int j = 0; j<transmitters.size();j++) {
					transmitters.get(j).setReceiver(receiver);
				}

				Transmitter trans = device.getTransmitter();
				trans.setReceiver(receiver);

				device.open();
				openedDevices.add(device);
				System.out.println(device.getDeviceInfo()+" Was Opened");
			} catch (MidiUnavailableException e) {
//				e.printStackTrace();
			}
		}
	}
 
开发者ID:soma-arc,项目名称:K-Visions,代码行数:26,代码来源:MidiHandler.java

示例4: MidiReciever

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
public MidiReciever()
    {
        MidiDevice device;
        MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
        for (int i = 0; i < infos.length; i++) {
            try {
            device = MidiSystem.getMidiDevice(infos[i]);
            //does the device have any transmitters?
            //if it does, add it to the device list
            System.out.println(infos[i]);

            //get all transmitters
            List<Transmitter> transmitters = device.getTransmitters();
            //and for each transmitter

            for(int j = 0; j<transmitters.size();j++) {
                //create a new receiver
                transmitters.get(j).setReceiver(
                        //using my own MidiInputReceiver
                        new MidiInputReceiver(device.getDeviceInfo().toString())
                );
            }

            Transmitter trans = device.getTransmitter();
            trans.setReceiver(new MidiInputReceiver(device.getDeviceInfo().toString()));

            //open each device
            device.open();
            //if code gets this far without throwing an exception
            //print a success message
            System.out.println(device.getDeviceInfo()+" Was Opened");


        } catch (MidiUnavailableException e) {}
    }


}
 
开发者ID:JorenSix,项目名称:Panako,代码行数:39,代码来源:MidiReciever.java

示例5: setup

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
public static void setup() {
	try {
		Transmitter t = launchpad_s_plus.Launchpad.getInputDevice()
				.getTransmitter();
		t.setReceiver(r);
	} catch (MidiUnavailableException e) {
		out("wasn't able to connect the device's Transmitter to the Receiver:");
		out(e);
		System.exit(1);
	}
}
 
开发者ID:helionmusic,项目名称:launchpad_s_plus,代码行数:12,代码来源:MidiInDump.java

示例6: setReceiverToDevice

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
/**
 * Sets a midi receiver to a midi device
 * 
 * @param device
 *            The midi device
 * @param receiver
 *            The midi receiver
 * @throws MidiUnavailableException
 *             If midi device is not available
 */
public static void setReceiverToDevice(MidiDevice device, Receiver receiver)
		throws MidiUnavailableException {

	// check if Receiver was already connected
	List<Transmitter> transmitters = device.getTransmitters();
	for (Transmitter existingTransmitter : transmitters) {
		if (receiver.equals(existingTransmitter.getReceiver())) {
			return;
		}
	}

	Transmitter t = device.getTransmitter();
	t.setReceiver(receiver);
}
 
开发者ID:aguelle,项目名称:MIDI-Automator,代码行数:25,代码来源:MidiUtils.java

示例7: removeReceiverFromDevice

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
/**
 * Removes a midi receiver from a midi device
 * 
 * @param device
 *            The midi device
 * @param receiver
 *            The midi receiver
 * @throws MidiUnavailableException
 *             If midi device is not available
 */
public static void removeReceiverFromDevice(MidiDevice device,
		String receiverName) throws MidiUnavailableException {

	List<Transmitter> transmitters = device.getTransmitters();
	for (Transmitter transmitter : transmitters) {
		if (receiverName.equals(transmitter.getReceiver().getClass()
				.getName())) {
			transmitter.getReceiver().close();
			transmitter.setReceiver(null);
			transmitter.close();
		}
	}
}
 
开发者ID:aguelle,项目名称:MIDI-Automator,代码行数:24,代码来源:MidiUtils.java

示例8: addTransceiver

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
public void addTransceiver(Transceiver transceiver)
{
	Transmitter lastTransmitter = transmitter;
	if (!transceivers.isEmpty())
		lastTransmitter = transceivers.get(transceivers.size() - 1);

	// Hook up the transceiver in the chain
	lastTransmitter.setReceiver(transceiver);
	transceiver.setReceiver(receiver);

	transceivers.add(transceiver);
}
 
开发者ID:digero,项目名称:maestro,代码行数:13,代码来源:SequencerWrapper.java

示例9: loadInputDevices

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
private boolean loadInputDevices() {
	MidiDevice device = null;
	MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
	boolean deviceLoaded = false;
	
	for (int i = 0; i < infos.length; i++) {
		System.out.println(i + ": " + infos[i].getName());
		try {
			device = MidiSystem.getMidiDevice(infos[i]);
			System.out.println("  " + i + " class: " + device.getClass().getName());
			System.out.println("  " + i + " receivers: " + device.getMaxReceivers());
			System.out.println("  " + i + " transmitters: " + device.getMaxTransmitters());
			
			if (device.getClass().getName().equalsIgnoreCase("com.sun.media.sound.MidiInDevice")) {
				System.out.println("MIDI In Found!");
				if (!device.isOpen() && device.getMaxTransmitters() != 0) {
					device.open();
					openDevices.addLast(device);
					
					Transmitter t = device.getTransmitter();
					transmitters.addLast(t);
					t.setReceiver(this);
					
					deviceLoaded = true;
				}
			}
	    	device = null;
		}
		catch (MidiUnavailableException e) {
			System.out.println("Error loading device " + i + " " + e);
	    }
	}
	return deviceLoaded;
}
 
开发者ID:mikelduke,项目名称:LedTable,代码行数:35,代码来源:LedTable_Midi.java

示例10: MidiInput

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
/**
 * Create a MidiInput from a javax.sound.midi.MidiDevice . Don't use this unless you know what you are doing.
 * @param dev2
 * @throws MidiUnavailableException
 */
public MidiInput(javax.sound.midi.MidiDevice dev2) throws MidiUnavailableException {
	this.jDevice = dev2;
	if (!dev2.isOpen())
		dev2.open();
	Transmitter trsmt = dev2.getTransmitter();
	trsmt.setReceiver(this);
	plugList = new ArrayList<Plug>();
	currentMessage = new ArrayList();
}
 
开发者ID:dearmash,项目名称:Processing,代码行数:15,代码来源:MidiInput.java

示例11: setMidiInputSelection

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
private void setMidiInputSelection(int inputDeviceID, MidiDevice.Info[] info) {
    try {
        // inut setup
        MidiDevice inputPort = MidiSystem.getMidiDevice (info [inputDeviceID]);
        //System.out.println (inputPort);
        inputPort.open ();
        Transmitter t = inputPort.getTransmitter ();
        t.setReceiver(this);
    } catch (Exception e) {
        // Oops! Should never get here
        System.out.println ("Exception in PlumStone main ()");
        System.out.println (e);
        System.exit (0);
    }
}
 
开发者ID:Armaxis,项目名称:jmg,代码行数:16,代码来源:MidiCommunication.java

示例12: initSequencer

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
/**
 * Set up the MIDI sequencer, and the sequencer's meta-event listener. No
 * synthesizer is used here.
 */
private void initSequencer()
{
	try {
		sequencer = MidiSystem.getSequencer();
		if (sequencer == null) {
			System.out.println("Cannot get a sequencer");
			return;
		}

		sequencer.open();
		sequencer.addMetaEventListener(this);

		// maybe the sequencer is not the same as the synthesizer
		// so link sequencer --> synth (this is required in J2SE 1.5)
		if (!(sequencer instanceof Synthesizer)) {
			System.out
					.println("Linking the MIDI sequencer and synthesizer");
			Synthesizer synthesizer = MidiSystem.getSynthesizer();
			Receiver synthReceiver = synthesizer.getReceiver();
			Transmitter seqTransmitter = sequencer.getTransmitter();
			seqTransmitter.setReceiver(synthReceiver);
		}
	} catch (MidiUnavailableException e) {
		System.out.println("No sequencer available");
		sequencer = null;
	}
}
 
开发者ID:nhydock,项目名称:revert,代码行数:32,代码来源:MidisLoader.java

示例13: getSequencer

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
/**
	 * Returns a {@link Sequencer} to play a {@link Sequence}.
	 *
	 * @param sequence for {@link Sequencer}
	 * @return MIDI {@link Sequencer}
	 * @throws MidiUnavailableException
	 * @throws InvalidMidiDataException
	 * @see Sequence
	 * @see Sequencer
	 * @since 0.0.1
	 */
	public static Sequencer getSequencer(final Sequence sequence) throws MidiUnavailableException, InvalidMidiDataException { //$JUnit$
		if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(sequence));
		if (null == sequence) {
			throw new RuntimeExceptionIsNull("sequence"); //$NON-NLS-1$
		}

		final Sequencer result = MidiSystem.getSequencer();  // Used to play sequences
		result.open(); // Turn it on.

		// Get a Synthesizer for the Sequencer to send notes to
//		try (Synthesizer synth = MidiSystem.getSynthesizer()) {
			final Synthesizer synth = MidiSystem.getSynthesizer();
			synth.open();  // acquire whatever resources it needs
	
			// The Sequencer obtained above may be connected to a Synthesizer
			// by default, or it may not.  Therefore, we explicitly connect it.
//			try (Transmitter transmitter = result.getTransmitter()) {
				final Transmitter transmitter = result.getTransmitter();
				transmitter.setReceiver(synth.getReceiver());
//			}
//		}
		// Read the sequence from the file and tell the sequencer about it
		result.setSequence(sequence);

		if (log.isDebugEnabled()) log.debug(HelperLog.methodExit(result));
		return result;
	}
 
开发者ID:slaubenberger,项目名称:wichtel,代码行数:39,代码来源:HelperSound.java

示例14: SequencerMidiPlayer

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
public SequencerMidiPlayer(MidiRadio plugin) throws MidiUnavailableException {
	this.plugin = plugin;
	
	sequencer = MidiSystem.getSequencer();
	sequencer.open();
	
	if (plugin.getConfig().getBoolean("server-playback")) {
		sequencer.getTransmitter().setReceiver(this);
	} else { // Is the only way to stop this by hogging all transmitters? :/
		for (Transmitter t : sequencer.getTransmitters()) {
			t.setReceiver(this);
		}
	}
}
 
开发者ID:t7seven7t,项目名称:MidiRadio,代码行数:15,代码来源:SequencerMidiPlayer.java

示例15: testReceiveMidi

import javax.sound.midi.Transmitter; //导入方法依赖的package包/类
@Test
public void testReceiveMidi() throws MidiUnavailableException,
        InvalidMidiDataException, InterruptedException {

    int portCount = 0;
    final ArrayList<MidiMessage> list = new ArrayList<MidiMessage>();
    ShortMessage shortMessage = new ShortMessage();
    shortMessage.setMessage(ShortMessage.CONTROL_CHANGE, 0, 0);
    list.add(shortMessage);

    SysexMessage sysexMessage = new SysexMessage();
    byte[] buf =
            new byte[] {
                    (byte) 0xF0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x01, 0x33,
                    0x02, 0x0D, (byte) 0xF7 };
    sysexMessage.setMessage(buf, buf.length);
    list.add(sysexMessage);

    Info[] midiDeviceInfos = MidiSystem.getMidiDeviceInfo();
    for (Info info : midiDeviceInfos) {
        if (info instanceof CoreMidiDeviceInfo) {
            MidiDevice midiDevice = MidiSystem.getMidiDevice(info);
            if (midiDevice.getMaxTransmitters() == -1) {
                portCount++;
                assertEquals(CoreMidiSource.class, midiDevice.getClass());

                midiDevice.open();

                Transmitter transmitter = midiDevice.getTransmitter();
                transmitter.setReceiver(new Receiver() {
                    @Override
                    public void send(MidiMessage arg0, long arg1) {
                        try {
                            logger.info("Received midi message!");
                            MidiMessage msg = list.get(arrayIndex);
                            arrayIndex++;
                            assertEquals(msg.getClass(), arg0.getClass());
                            assertEquals(msg.getStatus(), arg0.getStatus());
                            assertEquals(msg.getLength(), arg0.getLength());
                        } catch (Exception e) {
                            failureMessage = e.getMessage();
                            logger.info(e.getMessage(), e);
                        }
                    }

                    @Override
                    public void close() {
                    }
                });

                sendMidiMessagesToPort(info.getName(), list);
                Thread.sleep(1000);
                midiDevice.close();

                assertEquals(list.size(), arrayIndex);
                assertNull(failureMessage);
                break;
            }
        }
    }
}
 
开发者ID:locurasoft,项目名称:osxmidi4j,代码行数:62,代码来源:SendMidiMacOsXTest.java


注:本文中的javax.sound.midi.Transmitter.setReceiver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。