当前位置: 首页>>代码示例>>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;未经允许,请勿转载。