Java Code Examples for javax.sound.midi.ShortMessage#NOTE_ON

The following examples show how to use javax.sound.midi.ShortMessage#NOTE_ON . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MiPort.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void send(MidiMessage inMessage, long inTimeStamp)
{
if(inMessage instanceof ShortMessage)
	{
	ShortMessage	mm = (ShortMessage)inMessage;
	
	switch(mm.getCommand())
		{
		case ShortMessage.NOTE_ON:
		case ShortMessage.NOTE_OFF:
			MiProvider.instance().noteReceived(mm, inTimeStamp);
			break;

		case ShortMessage.CONTROL_CHANGE:
			//System.err.println("Control change");
			break;
		}
	}
}
 
Example 2
Source File: MidiWaveformSynthesizer.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public static final void addNotesToTrack(final Track track, final Track trk) throws InvalidMidiDataException {
    for (int ii = 0; ii < track.size(); ii++) {
        final MidiEvent me = track.get(ii);
        final MidiMessage mm = me.getMessage();
        if (mm instanceof ShortMessage) {
            final ShortMessage sm = (ShortMessage) mm;
            final int command = sm.getCommand();
            int com = -1;
            if (command == ShortMessage.NOTE_ON) {
                com = LOCAL_NOTE_ON;
            } else if (command == ShortMessage.NOTE_OFF) {
                com = LOCAL_NOTE_OFF;
            }
            if (com > 0) {
                final byte[] b = sm.getMessage();
                final int l = (b == null ? 0 : b.length);
                final MetaMessage metaMessage = new MetaMessage(com, b, l);
                final MidiEvent me2 = new MidiEvent(metaMessage, me.getTick());
                trk.add(me2);
            }
        }
    }
}
 
Example 3
Source File: MidiModule.java    From stagedisplayviewer with MIT License 6 votes vote down vote up
public void handleMessage(String message) {
	Matcher m = MIDI_COMMAND_REGEX.matcher(message);
    if (receiver !=null && m.find() && !message.equals(lastMessage)) {
        try {
            ShortMessage shortMessage = new ShortMessage(
        		ShortMessage.NOTE_ON, 
        		Integer.valueOf(m.group(1)), 
        		Integer.valueOf(m.group(2)), 
        		Integer.valueOf(m.group(3))
    		);
            receiver.send(shortMessage, -1);
            log.debug("Midi message sent: {}", message);
        } catch (InvalidMidiDataException e) {
            log.warn("Midi message failed: {} {}", message, e);
        }
    }
    lastMessage = message;
}
 
Example 4
Source File: SoftMainMixer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        if(delay_midievent != 0)
            softchannel.noteOn(data1, data2, delay_midievent);
        else
            softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}
 
Example 5
Source File: SoftMainMixer.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}
 
Example 6
Source File: MiProvider.java    From tuxguitar with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void	noteReceived(ShortMessage inMessage, long inTimeStamp)
{
byte	pitch		= (byte)inMessage.getData1(),
		velocity	= (byte)inMessage.getData2(),
		stringIndex = (byte)getString(inMessage.getChannel());

if(stringIndex != -1)
	{
	byte	fretIndex = (byte)getFret(pitch, stringIndex);

	if(fretIndex != -1)
		{
		switch(inMessage.getCommand())
			{
			case ShortMessage.NOTE_ON:
				{
				switch(f_Mode)
					{
					case MiConfig.MODE_FRETBOARD_ECHO:
						if(velocity == 0 || velocity > f_MinVelocity)	// questo VA MODIFICATO!!!
							echo(stringIndex, fretIndex, velocity > 0);
						break;

					case MiConfig.MODE_CHORDS_RECORDING:
						if(velocity == 0 || velocity > f_MinVelocity)	// questo VA MODIFICATO!!!
							echo(stringIndex, fretIndex, velocity > 0);

						chord_AddNote(stringIndex, fretIndex, pitch, velocity, inTimeStamp);
						break;

					case MiConfig.MODE_SCALES_RECOGNITION:
						if(velocity == 0 || velocity > f_MinVelocity)	// questo VA MODIFICATO!!!
							echo(stringIndex, fretIndex, velocity > 0);

						scale_AddNote(stringIndex, fretIndex, pitch, velocity, inTimeStamp);
						break;

					case MiConfig.MODE_SONG_RECORDING:
						if(velocity == 0 || velocity > f_MinVelocity)	// questo VA MODIFICATO!!!
							echo(stringIndex, fretIndex, velocity > 0);

						MiRecorder.instance().addNote(stringIndex, fretIndex, pitch, velocity, inTimeStamp);
						break;
					}
				}
				break;

			case ShortMessage.NOTE_OFF:
				switch(f_Mode)
					{
					case MiConfig.MODE_FRETBOARD_ECHO:
						echo(stringIndex, fretIndex, false);
						break;

					case MiConfig.MODE_CHORDS_RECORDING:
						echo(stringIndex, fretIndex, false);
						chord_AddNote(stringIndex, fretIndex, pitch, (byte)0, inTimeStamp);
						break;

					case MiConfig.MODE_SCALES_RECOGNITION:
						echo(stringIndex, fretIndex, false);
						scale_AddNote(stringIndex, fretIndex, pitch, (byte)0, inTimeStamp);
						break;

					case MiConfig.MODE_SONG_RECORDING:
						echo(stringIndex, fretIndex, false);
						MiRecorder.instance().addNote(stringIndex, fretIndex, pitch, (byte)0, inTimeStamp);
						break;
					}
				break;
			}
		}
	}
}
 
Example 7
Source File: SoftMainMixer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        if(delay_midievent != 0)
            softchannel.noteOn(data1, data2, delay_midievent);
        else
            softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}
 
Example 8
Source File: SoftMainMixer.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        if(delay_midievent != 0)
            softchannel.noteOn(data1, data2, delay_midievent);
        else
            softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}
 
Example 9
Source File: SoftMainMixer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        if(delay_midievent != 0)
            softchannel.noteOn(data1, data2, delay_midievent);
        else
            softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}
 
Example 10
Source File: SoftMainMixer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        if(delay_midievent != 0)
            softchannel.noteOn(data1, data2, delay_midievent);
        else
            softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}
 
Example 11
Source File: SoftMainMixer.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        if(delay_midievent != 0)
            softchannel.noteOn(data1, data2, delay_midievent);
        else
            softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}
 
Example 12
Source File: SoftMainMixer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        if(delay_midievent != 0)
            softchannel.noteOn(data1, data2, delay_midievent);
        else
            softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}
 
Example 13
Source File: SoftMainMixer.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        if(delay_midievent != 0)
            softchannel.noteOn(data1, data2, delay_midievent);
        else
            softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}
 
Example 14
Source File: SoftMainMixer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        if(delay_midievent != 0)
            softchannel.noteOn(data1, data2, delay_midievent);
        else
            softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}
 
Example 15
Source File: RealTimeSequencer.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * chase all events from beginning of Track
 * and send note off for those events that are active
 * in noteOnCache array.
 * It is possible, of course, to catch notes from other tracks,
 * but better than more complicated logic to detect
 * which notes are really from this track
 */
private void sendNoteOffIfOn(Track track, long endTick) {
    int size = track.size();
    int done = 0;
    try {
        for (int i = 0; i < size; i++) {
            MidiEvent event = track.get(i);
            if (event.getTick() > endTick) break;
            MidiMessage msg = event.getMessage();
            int status = msg.getStatus();
            int len = msg.getLength();
            if (len == 3 && ((status & 0xF0) == ShortMessage.NOTE_ON)) {
                int note = -1;
                if (msg instanceof ShortMessage) {
                    ShortMessage smsg = (ShortMessage) msg;
                    if (smsg.getData2() > 0) {
                        // only consider Note On with velocity > 0
                        note = smsg.getData1();
                    }
                } else {
                    byte[] data = msg.getMessage();
                    if ((data[2] & 0x7F) > 0) {
                        // only consider Note On with velocity > 0
                        note = data[1] & 0x7F;
                    }
                }
                if (note >= 0) {
                    int bit = 1<<(status & 0x0F);
                    if ((noteOnCache[note] & bit) != 0) {
                        // the bit is set. Send Note Off
                        getTransmitterList().sendMessage(status | (note<<8), -1);
                        // clear the bit
                        noteOnCache[note] &= (0xFFFF ^ bit);
                        done++;
                    }
                }
            }
        }
    } catch (ArrayIndexOutOfBoundsException aioobe) {
        // this happens when messages are removed
        // from the track while this method executes
    }
}
 
Example 16
Source File: SoftMainMixer.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        if(delay_midievent != 0)
            softchannel.noteOn(data1, data2, delay_midievent);
        else
            softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}
 
Example 17
Source File: SoftMainMixer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        if(delay_midievent != 0)
            softchannel.noteOn(data1, data2, delay_midievent);
        else
            softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}
 
Example 18
Source File: SoftMainMixer.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        if(delay_midievent != 0)
            softchannel.noteOn(data1, data2, delay_midievent);
        else
            softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}
 
Example 19
Source File: MidiWaveformSynthesizer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
public void decode(final float[] data, final int frameSize, final int updatePeriod, final int samplingRate,
        final int nBits) {
    if (frameSize <= 0) {
        throw new IllegalArgumentException("Frame size must be greater than zero");
    }
    final Track track = mergeShortMessageEvent(sequence.getTracks());
    final float length = 1e-6f * sequence.getMicrosecondLength();
    final float ts = 1.0f / samplingRate;
    final long trackTicks = track.ticks();
    final float tickLength = trackTicks <= 0 ? 0 : length / trackTicks;
    final int frameCount = data.length / frameSize;
    final float scale = 2 << Math.max(1, nBits + 1);

    final int fftSize = 2 * frameSize;
    final FloatFFT_1D fft = new FloatFFT_1D(fftSize);
    final float[] apodization = new float[fftSize];
    for (int i = 0; i < fftSize; i++) {
        apodization[i] = (float) Apodization.Hann.getIndex(i, apodization.length);
    }

    int frameCounter = 0;
    int tickIndex = 0;
    final float[] waveForm = new float[2 * frameSize];
    final int nUpdateDistance = (int) (updatePeriod / 1000.0 * samplingRate);
    for (int i = 0; frameCounter < frameCount; i++) {
        final float t = i * ts;
        final MidiEvent tickEvt = track.get(tickIndex);
        final float tickTimeStamp = tickEvt.getTick() * tickLength;

        // update waveform by one sample
        update(samplingRate, nBits);

        if ((t > tickTimeStamp) && (tickIndex < track.size() - 1)) {
            if ((tickEvt.getMessage() instanceof ShortMessage)) {
                final ShortMessage sm = (ShortMessage) tickEvt.getMessage();
                final int note = sm.getData1() & 0xFF;
                final int velocity = sm.getData2() & 0xFF;

                final int command = sm.getCommand();
                if ((command == ShortMessage.NOTE_ON) || (command == LOCAL_NOTE_ON)) {
                    noteAmplitude[note] = velocity;
                } else if ((command == ShortMessage.NOTE_OFF) || (command == LOCAL_NOTE_OFF)) {
                    noteAmplitude[note] = 0.0f;
                }
            }
            tickIndex++;
        }

        if (i > 0 && (i % nUpdateDistance == 0)) {
            for (int j = 0; j < waveForm.length; j++) {
                final float noise = (1e-3f * System.nanoTime() % 2); // adds some noise
                waveForm[j] = apodization[j] * getSample(j) + noise / scale;
            }
            decodeFrame(fft, waveForm, data, (frameCounter * frameSize) % data.length);
            frameCounter++;
        }
    }

    // return synthesizer to its original state
    for (int note = 0; note < N_NOTES; note++) {
        noteAmplitude[note] = 0.0f;
        synthesizerChannel.noteOff(note, 0);
    }
}
 
Example 20
Source File: SoftMainMixer.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void processMessage(int ch, int cmd, int data1, int data2) {
    synchronized (synth.control_mutex) {
        activity();
    }

    if (cmd == 0xF0) {
        int status = cmd | ch;
        switch (status) {
        case ShortMessage.ACTIVE_SENSING:
            synchronized (synth.control_mutex) {
                active_sensing_on = true;
            }
            break;
        default:
            break;
        }
        return;
    }

    SoftChannel[] channels = synth.channels;
    if (ch >= channels.length)
        return;
    SoftChannel softchannel = channels[ch];

    switch (cmd) {
    case ShortMessage.NOTE_ON:
        if(delay_midievent != 0)
            softchannel.noteOn(data1, data2, delay_midievent);
        else
            softchannel.noteOn(data1, data2);
        break;
    case ShortMessage.NOTE_OFF:
        softchannel.noteOff(data1, data2);
        break;
    case ShortMessage.POLY_PRESSURE:
        softchannel.setPolyPressure(data1, data2);
        break;
    case ShortMessage.CONTROL_CHANGE:
        softchannel.controlChange(data1, data2);
        break;
    case ShortMessage.PROGRAM_CHANGE:
        softchannel.programChange(data1);
        break;
    case ShortMessage.CHANNEL_PRESSURE:
        softchannel.setChannelPressure(data1);
        break;
    case ShortMessage.PITCH_BEND:
        softchannel.setPitchBend(data1 + data2 * 128);
        break;
    default:
        break;
    }

}