Path: blob/master/test/jdk/javax/sound/midi/Devices/MidiIO.java
41152 views
/*1* Copyright (c) 2002, 2016, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.sound.midi.MidiDevice;24import javax.sound.midi.MidiSystem;25import javax.sound.midi.MidiUnavailableException;2627/**28* @test29* @bug 435678730* @summary MIDI device I/O is not working31*/32public class MidiIO {3334public static void main(String[] args) throws Exception {35out("4356787: MIDI device I/O is not working (windows)");3637if (System.getProperty("os.name").startsWith("Windows")) {38boolean forInput=true;39boolean forOutput=true;40int outOnlyCount=0;41int inOnlyCount=0;42out(" available MIDI devices:");43MidiDevice.Info[] aInfos = MidiSystem.getMidiDeviceInfo();44for (int i = 0; i < aInfos.length; i++) {45try {46MidiDevice device = MidiSystem.getMidiDevice(aInfos[i]);47boolean bAllowsInput = (device.getMaxTransmitters() != 0);48boolean bAllowsOutput = (device.getMaxReceivers() != 0);49if (bAllowsInput && !bAllowsOutput) {50inOnlyCount++;51}52if (!bAllowsInput && bAllowsOutput) {53outOnlyCount++;54}55if ((bAllowsInput && forInput) || (bAllowsOutput && forOutput)) {56out(""+i+" "57+(bAllowsInput?"IN ":" ")58+(bAllowsOutput?"OUT ":" ")59+aInfos[i].getName()+", "60+aInfos[i].getVendor()+", "61+aInfos[i].getVersion()+", "62+aInfos[i].getDescription());63}64}65catch (MidiUnavailableException e) {66// device is obviously not available...67}68}69if (aInfos.length == 0) {70out("No devices available. Test should be run on systems with MIDI drivers installed.");71} else {72if (outOnlyCount>1) {73if (inOnlyCount==0) {74//throw new Exception("No input devices! test fails.");75out("System provides out devices, but no input devices. This means either");76out("a bug in Java Sound, or the drivers are not set up correctly.");77}78out("Test passed.");79} else {80out("no MIDI I/O installed. Test should be run on systems with MIDI drivers installed.");81}82}83} else {84out(" -- not on Windows. Test doesn't apply.");85}86}8788static void out(String s) {89System.out.println(s); System.out.flush();90}91}929394