Path: blob/master/src/java.desktop/share/classes/com/sun/media/sound/MidiDeviceReceiverEnvelope.java
41161 views
/*1* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.media.sound;2627import javax.sound.midi.MidiDevice;28import javax.sound.midi.MidiDeviceReceiver;29import javax.sound.midi.MidiMessage;30import javax.sound.midi.Receiver;3132/**33* Helper class which allows to convert {@code Receiver}34* to {@code MidiDeviceReceiver}.35*36* @author Alex Menkov37*/38public final class MidiDeviceReceiverEnvelope implements MidiDeviceReceiver {3940private final MidiDevice device;41private final Receiver receiver;4243/**44* Creates a new {@code MidiDeviceReceiverEnvelope} object which45* envelops the specified {@code Receiver}46* and is owned by the specified {@code MidiDevice}.47*48* @param device the owner {@code MidiDevice}49* @param receiver the {@code Receiver} to be enveloped50*/51public MidiDeviceReceiverEnvelope(MidiDevice device, Receiver receiver) {52if (device == null || receiver == null) {53throw new NullPointerException();54}55this.device = device;56this.receiver = receiver;57}5859// Receiver implementation60@Override61public void close() {62receiver.close();63}6465@Override66public void send(MidiMessage message, long timeStamp) {67receiver.send(message, timeStamp);68}6970// MidiDeviceReceiver implementation71@Override72public MidiDevice getMidiDevice() {73return device;74}7576/**77* Obtains the receiver enveloped78* by this {@code MidiDeviceReceiverEnvelope} object.79*80* @return the enveloped receiver81*/82public Receiver getReceiver() {83return receiver;84}85}868788