當前位置: 首頁>>代碼示例>>Java>>正文


Java Receiver類代碼示例

本文整理匯總了Java中javax.sound.midi.Receiver的典型用法代碼示例。如果您正苦於以下問題:Java Receiver類的具體用法?Java Receiver怎麽用?Java Receiver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Receiver類屬於javax.sound.midi包,在下文中一共展示了Receiver類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getMidiInput

import javax.sound.midi.Receiver; //導入依賴的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: getDefaultProvider

import javax.sound.midi.Receiver; //導入依賴的package包/類
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:31,代碼來源:JDK13Services.java

示例3: main

import javax.sound.midi.Receiver; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    AudioSynthesizer synth = new SoftSynthesizer();
    Receiver recv = synth.getReceiver();
    assertTrue(recv != null);
    ShortMessage sm = new ShortMessage();
    sm.setMessage(ShortMessage.NOTE_OFF, 0, 64, 64);
    synth.open(new DummySourceDataLine(), null);
    recv.send(sm, -1);
    synth.close();
    try
    {
        recv.send(sm, -1);
        throw new RuntimeException("Exception not thrown!");
    }
    catch(Exception e)
    {
        // Just checking if exception is thrown
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:GetReceiver2.java

示例4: getConnectedDevice

import javax.sound.midi.Receiver; //導入依賴的package包/類
static MidiDevice getConnectedDevice(Sequencer sequencer) {
    List<Transmitter> trans = sequencer.getTransmitters();
    log("  sequencer has " + trans.size() + " opened transmitters:");
    for (Transmitter tr: trans) {
        Receiver r = tr.getReceiver();
        log("    " + getClassStr(tr) + " connected to " + getClassStr(r));
        if (r instanceof MidiDeviceReceiver) {
            MidiDeviceReceiver recv = (MidiDeviceReceiver)r;
            MidiDevice dev = recv.getMidiDevice();
            log("      - receiver of " + getClassStr(dev));
            return dev;
        } else {
            log("      - does NOT implement MidiDeviceReceiver");
        }
    }
    return null;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:SequencerImplicitSynthOpen.java

示例5: receiverChanged

import javax.sound.midi.Receiver; //導入依賴的package包/類
private void receiverChanged(BasicTransmitter t,
                             Receiver oldR,
                             Receiver newR) {
    synchronized(transmitters) {
        // some optimization
        if (midiOutReceiver == oldR) {
            midiOutReceiver = null;
        }
        if (newR != null) {
            if ((newR instanceof MidiOutDevice.MidiOutReceiver)
                && (midiOutReceiver == null)) {
                midiOutReceiver = ((MidiOutDevice.MidiOutReceiver) newR);
            }
        }
        optimizedReceiverCount =
              ((midiOutReceiver!=null)?1:0);
    }
    // more potential for optimization here
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:AbstractMidiDevice.java

示例6: sendMessage

import javax.sound.midi.Receiver; //導入依賴的package包/類
void sendMessage(byte[] data, long timeStamp) {
    try {
        synchronized(transmitters) {
            int size = transmitters.size();
            if (TRACE_TRANSMITTER) Printer.println("Sending long message to "+size+" transmitter's receivers");
            for (int i = 0; i < size; i++) {
                Receiver receiver = transmitters.get(i).getReceiver();
                if (receiver != null) {
                    //$$fb 2002-04-02: SysexMessages are mutable, so
                    // an application could change the contents of this object,
                    // or try to use the object later. So we can't get around object creation
                    // But the array need not be unique for each FastSysexMessage object,
                    // because it cannot be modified.
                    receiver.send(new FastSysexMessage(data), timeStamp);
                }
            }
        }
    } catch (InvalidMidiDataException e) {
        // this happens when invalid data comes over the wire. Ignore it.
        return;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:AbstractMidiDevice.java

示例7: getDefaultProvider

import javax.sound.midi.Receiver; //導入依賴的package包/類
/** Obtain the value of a default provider property.
    @param typeClass The type of the default provider property. This
    should be one of Receiver.class, Transmitter.class, Sequencer.class,
    Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
    Clip.class or Port.class.
    @return The complete value of the property, if available.
    If the property is not set, null is returned.
 */
private static synchronized String getDefaultProvider(Class<?> typeClass) {
    if (!SourceDataLine.class.equals(typeClass)
            && !TargetDataLine.class.equals(typeClass)
            && !Clip.class.equals(typeClass)
            && !Port.class.equals(typeClass)
            && !Receiver.class.equals(typeClass)
            && !Transmitter.class.equals(typeClass)
            && !Synthesizer.class.equals(typeClass)
            && !Sequencer.class.equals(typeClass)) {
        return null;
    }
    String name = typeClass.getName();
    String value = AccessController.doPrivileged(
            (PrivilegedAction<String>) () -> System.getProperty(name));
    if (value == null) {
        value = getProperties().getProperty(name);
    }
    if ("".equals(value)) {
        value = null;
    }
    return value;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:31,代碼來源:JDK13Services.java

示例8: testReceiverSend

import javax.sound.midi.Receiver; //導入依賴的package包/類
/**
 * Execute Receiver.send() and expect that there is no exception.
 */
private static boolean testReceiverSend() {
    boolean result = true;

    Receiver receiver;
    ShortMessage shMsg = new ShortMessage();

    try {
        receiver = MidiSystem.getReceiver();
        shMsg.setMessage(ShortMessage.NOTE_ON, 0,60, 93);
        try {
            receiver.send( shMsg, -1 );
        } catch(IllegalStateException ilEx) {
            ilEx.printStackTrace(System.out);
            out("IllegalStateException was thrown incorrectly!");
            result = false;
        }
        receiver.close();
    } catch(MidiUnavailableException e) {
        out("Midi unavailable, cannot test.");
    } catch(InvalidMidiDataException ine) {
        out("InvalidMidiDataException, cannot test.");
    }
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:ClosedReceiver.java

示例9: captureMidiMessages

import javax.sound.midi.Receiver; //導入依賴的package包/類
@Override
protected void captureMidiMessages(final Receiver receiver) throws MidiUnavailableException {
	// Modify all MidiMessages so that they specify channel 10 (encoded as 9,
	// which I suppose means that 0 indicates midi channel 1)
	Receiver setChannelReceiver = new Receiver() {
		@Override
		public void send(MidiMessage message, long timeStamp) {
			if (message instanceof ShortMessage) {
				ShortMessage sm = (ShortMessage) message;
				byte[] data = sm.getMessage();
				byte orig = data[0];
				data[0] = (byte) ((orig | 9) & 0xff);
				message = Midi.createShortMessage(data);
			}
			receiver.send(message, timeStamp);
		}
		
		@Override
		public void close() {
			receiver.close();
		}
	};
	
	super.captureMidiMessages(setChannelReceiver);
}
 
開發者ID:daveho,項目名稱:Gervill4Beads,代碼行數:26,代碼來源:DemoPercussion.java

示例10: setReceiver

import javax.sound.midi.Receiver; //導入依賴的package包/類
@Override
public void setReceiver(Receiver receiver) {
    EventGroup currentGroup = null;
    lock.lock();
    try {
        if (this.receiver != null) {
            if (this.future.cancel(false)) {
                currentGroup = triggerTask.eventGroup;
            }
        } else {
            nextGroupTime = System.nanoTime();
        }
        this.receiver = receiver;
        scheduleIfRequired(receiver, currentGroup);
    } finally {
        lock.unlock();
    }
}
 
開發者ID:AXDOOMER,項目名稱:mochadoom,代碼行數:19,代碼來源:FinnwMusicModule.java

示例11: test

import javax.sound.midi.Receiver; //導入依賴的package包/類
public int test() throws MidiUnavailableException, IOException, InterruptedException {

        int result = -1;
        MidiDevice keyboard = MidiDeviceTools.findKeyboard();
        Receiver receiver = new CustomReceiver();
        // Just use default synthesizer.
        if (keyboard != null) {
            // If you forget to open them you will hear no sound.
            keyboard.open();
            // Put the receiver in the transmitter.
            // This gives fairly low latency playing.
            keyboard.getTransmitter().setReceiver(receiver);
            System.out.println("Play MIDI keyboard: " + keyboard.getDeviceInfo().getDescription());
            result = 0;
            Thread.sleep(4000);
            System.out.println("Close the keyboard. It may not work after this according to the docs!");
            keyboard.close();
        } else {
            System.out.println("Could not find a keyboard.");
        }
        return result;
    }
 
開發者ID:philburk,項目名稱:jsyn,代碼行數:23,代碼來源:TestMidiLoop.java

示例12: getReceiver

import javax.sound.midi.Receiver; //導入依賴的package包/類
/**
 *
 * @return The reciever associated with this lane
 */
public Receiver getReceiver() {
    MidiDevice dev = ftw.getMidiDevice();

    if (dev == null) {
        return null;
    }

    try {
        // Jens:
        // return getTrack().getMidiDevice().getReceiver();
        Receiver r = ftw.getMidiDevice().getReceiver();
        if (r != null) {
            return new MonitorReceiver(midiMessageListeners, r);
        } else {
            return null;
        }
    } catch (MidiUnavailableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }

}
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:28,代碼來源:MidiLane.java

示例13: interceptMessage

import javax.sound.midi.Receiver; //導入依賴的package包/類
public final void interceptMessage(MidiMessage msg, Receiver receiver)
{
    try
    {
        ShortMessage shm = (ShortMessage)msg;
        if(shm.getCommand() == ShortMessage.NOTE_ON)
        {
            if(shm.getData2()==0)
            {
                pendingNoteOffs.get(receiver).remove(shm.getChannel() << 8 | shm.getData1());
            }
            else
            {
                if(!pendingNoteOffs.containsKey(receiver))
                    pendingNoteOffs.put(receiver,new HashSet<Integer>());
             
                pendingNoteOffs.get(receiver).add(shm.getChannel() << 8 | shm.getData1());
            }
        }
    } catch(Exception e) {}
}
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:22,代碼來源:NoteOnCache.java

示例14: releasePendingNoteOffs

import javax.sound.midi.Receiver; //導入依賴的package包/類
/**
 * Send note-off to all pending notes
 *
 */
public final void releasePendingNoteOffs()
{
    for(Receiver recv : pendingNoteOffs.keySet())
    {
        for (int note : pendingNoteOffs.get(recv)) {
            ShortMessage shm = new ShortMessage();
            try {
                shm.setMessage(ShortMessage.NOTE_ON, (note >> 8) & 0xf,
                        note & 0xff, 0);
                
                    recv.send(shm, -1);
            } catch (InvalidMidiDataException e) {
                e.printStackTrace();
            }
        }
    }
    pendingNoteOffs.clear();
}
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:23,代碼來源:NoteOnCache.java

示例15: init

import javax.sound.midi.Receiver; //導入依賴的package包/類
void init() {
	MidiDevice dev=dm.getDefaultMidiDevice();
	Receiver recv=null;
	if (dev != null )
		try {
			recv= dev.getReceiver();
		} catch (MidiUnavailableException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	configOut.setReceiver(recv);
	
	
	
	
}
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:17,代碼來源:DrumMapperGUI.java


注:本文中的javax.sound.midi.Receiver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。