jdk/test/javax/sound/midi/Synthesizer/Receiver/bug6186488.java
changeset 41905 e8e5df013c6e
equal deleted inserted replaced
41904:524d908e49ea 41905:e8e5df013c6e
       
     1 /*
       
     2  * Copyright (c) 2005, 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 
       
    24 import javax.sound.midi.MidiDevice;
       
    25 import javax.sound.midi.MidiMessage;
       
    26 import javax.sound.midi.MidiSystem;
       
    27 
       
    28 /**
       
    29  * @test
       
    30  * @bug 6186488
       
    31  * @summary Tests that software Java Syntesizer processed
       
    32  *          non-ShortMessage-derived messages
       
    33  * @run main/manual=yesno bug6186488
       
    34  */
       
    35 public class bug6186488 {
       
    36     public static void main(String[] args) throws Exception {
       
    37         MidiDevice/*Synthesizer*/ synth = null;
       
    38 
       
    39         try {
       
    40             synth = MidiSystem.getSynthesizer();
       
    41             //synth = MidiSystem.getMidiDevice(infos[0]);
       
    42 
       
    43             System.out.println("Synthesizer: " + synth.getDeviceInfo());
       
    44             synth.open();
       
    45             MidiMessage msg = new GenericMidiMessage(0x90, 0x3C, 0x40);
       
    46             //ShortMessage msg = new ShortMessage();
       
    47             //msg.setMessage(0x90, 0x3C, 0x40);
       
    48 
       
    49             synth.getReceiver().send(msg, 0);
       
    50             Thread.sleep(2000);
       
    51 
       
    52         } catch (Exception ex) {
       
    53             ex.printStackTrace();
       
    54             throw ex;
       
    55         } finally {
       
    56             if (synth != null && synth.isOpen())
       
    57                 synth.close();
       
    58         }
       
    59         System.out.print("Did you heard a note? (enter 'y' or 'n') ");
       
    60         int result = System.in.read();
       
    61         System.in.skip(1000);
       
    62         if (result == 'y' || result == 'Y')
       
    63         {
       
    64             System.out.println("Test passed sucessfully.");
       
    65         }
       
    66         else
       
    67         {
       
    68             System.out.println("Test FAILED.");
       
    69             throw new RuntimeException("Test failed.");
       
    70         }
       
    71     }
       
    72 
       
    73     private static class GenericMidiMessage extends MidiMessage {
       
    74         GenericMidiMessage(int... message) {
       
    75             super(new byte[message.length]);
       
    76             for (int i=0; i<data.length; i++) {
       
    77                 data[i] = (byte)(0xFF & message[i]);
       
    78             }
       
    79         }
       
    80 
       
    81         GenericMidiMessage(byte... message) {
       
    82             super(message);
       
    83         }
       
    84 
       
    85         public Object clone() {
       
    86             return new GenericMidiMessage((byte[])data.clone());
       
    87         }
       
    88     }
       
    89 }