jdk/src/java.desktop/share/classes/com/sun/media/sound/MidiDeviceReceiverEnvelope.java
author serb
Thu, 14 Jan 2016 23:14:01 +0300
changeset 35687 78e8e8fea09b
parent 25859 3317bb8137f4
child 40444 afabcfc2f3ef
permissions -rw-r--r--
8147407: Provide support of WaveExtensible sound format Reviewed-by: prr, amenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6508
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
     1
/*
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6508
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
6508
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
     4
 *
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    10
 *
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    15
 * accompanied this code).
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    16
 *
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    20
 *
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    23
 * questions.
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    24
 */
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    25
package com.sun.media.sound;
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    26
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    27
import javax.sound.midi.*;
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    28
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    29
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    30
/**
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    31
 * Helper class which allows to convert {@code Receiver}
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    32
 * to {@code MidiDeviceReceiver}.
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    33
 *
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    34
 * @author Alex Menkov
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    35
 */
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 6508
diff changeset
    36
public final class MidiDeviceReceiverEnvelope implements MidiDeviceReceiver {
6508
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    37
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    38
    private final MidiDevice device;
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    39
    private final Receiver receiver;
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    40
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    41
    /**
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    42
     * Creates a new {@code MidiDeviceReceiverEnvelope} object which
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    43
     * envelops the specified {@code Receiver}
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    44
     * and is owned by the specified {@code MidiDevice}.
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    45
     *
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    46
     * @param device the owner {@code MidiDevice}
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    47
     * @param receiver the {@code Receiver} to be enveloped
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    48
     */
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    49
    public MidiDeviceReceiverEnvelope(MidiDevice device, Receiver receiver) {
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    50
        if (device == null || receiver == null) {
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    51
            throw new NullPointerException();
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    52
        }
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    53
        this.device = device;
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    54
        this.receiver = receiver;
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    55
    }
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    56
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    57
    // Receiver implementation
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    58
    public void close() {
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    59
        receiver.close();
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    60
    }
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    61
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    62
    public void send(MidiMessage message, long timeStamp) {
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    63
        receiver.send(message, timeStamp);
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    64
    }
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    65
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    66
    // MidiDeviceReceiver implementation
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    67
    public MidiDevice getMidiDevice() {
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    68
        return device;
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    69
    }
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    70
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    71
    /**
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    72
     * Obtains the receiver enveloped
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    73
     * by this {@code MidiDeviceReceiverEnvelope} object.
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    74
     *
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    75
     * @return the enveloped receiver
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    76
     */
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    77
    public Receiver getReceiver() {
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    78
        return receiver;
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    79
    }
6c00b4789626 4933700: RFE: Add way to get device from Receiver and Transmitter
amenkov
parents:
diff changeset
    80
}