1/*
2 * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24import javax.sound.midi.MidiDevice;
25import javax.sound.midi.MidiSystem;
26import javax.sound.midi.MidiUnavailableException;
27
28/**
29 * @test
30 * @bug 4356787
31 * @summary MIDI device I/O is not working
32 */
33public class MidiIO {
34
35    public static void main(String[] args) throws Exception {
36        out("4356787: MIDI device I/O is not working (windows)");
37
38        if (System.getProperty("os.name").startsWith("Windows")) {
39            boolean forInput=true;
40            boolean forOutput=true;
41            int outOnlyCount=0;
42            int inOnlyCount=0;
43            out("  available MIDI devices:");
44            MidiDevice.Info[] aInfos = MidiSystem.getMidiDeviceInfo();
45            for (int i = 0; i < aInfos.length; i++) {
46                try {
47                    MidiDevice      device = MidiSystem.getMidiDevice(aInfos[i]);
48                    boolean         bAllowsInput = (device.getMaxTransmitters() != 0);
49                    boolean         bAllowsOutput = (device.getMaxReceivers() != 0);
50                    if (bAllowsInput && !bAllowsOutput) {
51                        inOnlyCount++;
52                    }
53                    if (!bAllowsInput && bAllowsOutput) {
54                        outOnlyCount++;
55                    }
56                    if ((bAllowsInput && forInput) || (bAllowsOutput && forOutput)) {
57                        out(""+i+"  "
58                                +(bAllowsInput?"IN ":"   ")
59                                +(bAllowsOutput?"OUT ":"    ")
60                                +aInfos[i].getName()+", "
61                                +aInfos[i].getVendor()+", "
62                                +aInfos[i].getVersion()+", "
63                                +aInfos[i].getDescription());
64                    }
65                }
66                catch (MidiUnavailableException e) {
67                    // device is obviously not available...
68                }
69            }
70            if (aInfos.length == 0) {
71                out("No devices available. Test should be run on systems with MIDI drivers installed.");
72            } else {
73                if (outOnlyCount>1) {
74                    if (inOnlyCount==0) {
75                        //throw new Exception("No input devices! test fails.");
76                        out("System provides out devices, but no input devices. This means either");
77                        out("a bug in Java Sound, or the drivers are not set up correctly.");
78                    }
79                    out("Test passed.");
80                } else {
81                    out("no MIDI I/O installed. Test should be run on systems with MIDI drivers installed.");
82                }
83            }
84        } else {
85            out("  -- not on Windows. Test doesn't apply.");
86        }
87    }
88
89    static void out(String s) {
90        System.out.println(s); System.out.flush();
91    }
92}
93