Java 8 ShortMessage - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ShortMessage class.

This code example shows how to use the following methods:setMessage
 
    public static void main(String[] args) throws Exception {
        AudioSynthesizer synth = new SoftSynthesizer();
        Receiver recv = synth.getReceiver();
        assertTrue(recv != null);
        ShortMessage sm = new ShortMessage();
        sm.setMessage(ShortMessage.NOTE_OFF, 0, 64, 64);
        synth.open(new DummySourceDataLine(), null);
        recv.send(sm, -1);
        synth.close();
        try 
        { 
            recv.send(sm, -1);
            throw new RuntimeException("Exception not thrown!");
        } 
        catch(Exception e)
        { 
            // Just checking if exception is thrown 
        } 
    } 
6
CodeRank
This code example shows how to use the following methods:setMessage
 
    public static void main(String[] args) throws Exception {
        AudioSynthesizer synth = new SoftSynthesizer();
        Receiver recv = synth.getReceiver();
        assertTrue(recv != null);
        ShortMessage sm = new ShortMessage();
        sm.setMessage(ShortMessage.NOTE_OFF, 0, 64, 64);
        synth.open(new DummySourceDataLine(), null);
        recv.send(sm, -1);
        synth.close();
        try 
        { 
            recv.send(sm, -1);
            throw new RuntimeException("Exception not thrown!");
        } 
        catch(Exception e)
        { 
            // Just checking if exception is thrown 
        } 
    } 
6
CodeRank
This code example shows how to use the following methods:getChannel, getCommand, getData1, getData2
     * @param message The message to parse 
     * @param timestamp the time at which the message was encountered in this track 
     */ 
    private void parseShortMessage(ShortMessage message, long timestamp)
    { 
        int track = message.getChannel();
         
        switch (message.getCommand())
        { 
            case ShortMessage.PROGRAM_CHANGE :                  // 0xC0, 192
                trace("Program change to ",message.getData1());
                Instrument instrument = new Instrument((byte)message.getData1());
                fireTimeEvent(new Time(timestamp));
                fireVoiceEvent(new Voice((byte)track));
                fireInstrumentEvent(instrument);
                break; 
                 
            case ShortMessage.CONTROL_CHANGE :                  // 0xB0, 176
                trace("Controller change to ",message.getData1(),", value = ",message.getData2());                                    
                Controller controller = new Controller((byte)message.getData1(), (byte)message.getData2());

6
CodeRank
This code example shows how to use the following methods:getStatus, getChannel, getCommand, getData1, getData2
    public int data2;
    public int command;
    public Long timeStamp = -1L;
 
    public MIDIMessage(ShortMessage sm, Long ts) {
        command = sm.getCommand();
        channel = sm.getChannel();
        data1 = sm.getData1();
        data2 = sm.getData2();
        status = sm.getStatus();
        timeStamp = ts;
        if(command == 144 && data2 == 0){
            status = 128 + channel;
            command = 128;
        } 
    } 
 
    public MIDIMessage(int command_, int channel_, int data1_, int data2_, Long ts) {
        command = command_;
        channel = channel_;
5
CodeRank
This code example shows how to use the following methods:getData1
    } 
 
    // converts midi events into Note objects 
    public static byte midiToNote(ShortMessage smsg) {
 
        int semitone = smsg.getData1();
 
        if (semitone < 54) return (byte) ((semitone - 6) % (18 - 6));
        else if (semitone > 78) return (byte) ((semitone - 6) % (18 - 6) + 12);
        else return (byte) (semitone - 54);
    } 
 
    // converts midi events into pitch 
    public static double midiToPitch(ShortMessage smsg) {
 
        return noteToPitch(midiToNote(smsg));
    } 
} 
3
CodeRank
See Code Examples for Java 8 ShortMessage Methods: