Example usage for javax.sound.midi MetaMessage MetaMessage

List of usage examples for javax.sound.midi MetaMessage MetaMessage

Introduction

In this page you can find the example usage for javax.sound.midi MetaMessage MetaMessage.

Prototype

public MetaMessage() 

Source Link

Document

Constructs a new MetaMessage .

Usage

From source file:com.rockhoppertech.music.midi.js.MIDIEvent.java

/**
 * Create a JavaSound MidiMessage from this instance.
 * /*w  w  w  .j  a  va2  s.  co  m*/
 * @param mm
 * @return
 */
private MidiMessage createMidiMessage() {
    MidiMessage mm = null;
    if (MIDIUtils.isChannelMessage(status)) {
        logger.debug("isChannelMessage for " + Integer.toHexString(status));
        mm = MIDIUtils.createShortMessage(status, bytes);

    } else if (MIDIUtils.isMetaMessage(status)) {
        logger.debug("MetaMessage: " + Integer.toHexString(status));
        MetaMessage meta = new MetaMessage();
        try {
            meta.setMessage(metaMessageType, bytes, bytes.length);
        } catch (InvalidMidiDataException e) {
            e.printStackTrace();
        }
        mm = meta;

    } else if (MIDIUtils.isSysexMessage(status)) {
        logger.debug("Sysex message: " + Integer.toHexString(status));
        SysexMessage sex = new SysexMessage();
        try {
            sex.setMessage(bytes, bytes.length);
        } catch (InvalidMidiDataException e) {
            e.printStackTrace();
        }
        mm = sex;
    } else {
        logger.debug("Unknown status " + Integer.toHexString(status));
    }
    return mm;
}

From source file:at.ofai.music.util.WormFileParseException.java

public Sequence toMIDI(EventList pedal) throws InvalidMidiDataException {
    final int midiTempo = 1000000;
    Sequence s = new Sequence(Sequence.PPQ, 1000);
    Track[] tr = new Track[16];
    tr[0] = s.createTrack();/*w  w  w .j av a 2s .  c o m*/
    MetaMessage mm = new MetaMessage();
    byte[] b = new byte[3];
    b[0] = (byte) ((midiTempo >> 16) & 0xFF);
    b[1] = (byte) ((midiTempo >> 8) & 0xFF);
    b[2] = (byte) (midiTempo & 0xFF);
    mm.setMessage(0x51, b, 3);
    tr[0].add(new MidiEvent(mm, 0L));
    for (Event e : l) { // from match or beatTrack file
        if (e.midiCommand == 0) // skip beatTrack file
            break;
        if (tr[e.midiTrack] == null)
            tr[e.midiTrack] = s.createTrack();
        //switch (e.midiCommand) 
        //case ShortMessage.NOTE_ON:
        //case ShortMessage.POLY_PRESSURE:
        //case ShortMessage.CONTROL_CHANGE:
        //case ShortMessage.PROGRAM_CHANGE:
        //case ShortMessage.CHANNEL_PRESSURE:
        //case ShortMessage.PITCH_BEND:
        ShortMessage sm = new ShortMessage();
        sm.setMessage(e.midiCommand, e.midiChannel, e.midiPitch, e.midiVelocity);
        tr[e.midiTrack].add(new MidiEvent(sm, (long) Math.round(1000 * e.keyDown)));
        if (e.midiCommand == ShortMessage.NOTE_ON) {
            sm = new ShortMessage();
            sm.setMessage(ShortMessage.NOTE_OFF, e.midiChannel, e.midiPitch, 0);
            tr[e.midiTrack].add(new MidiEvent(sm, (long) Math.round(1000 * e.keyUp)));
        }
    }
    if (pedal != null) { // from MIDI file
        //      if (t.size() > 0)   // otherwise beatTrack files leave an empty trk
        //         t = s.createTrack();
        for (Event e : pedal.l) {
            if (tr[e.midiTrack] == null)
                tr[e.midiTrack] = s.createTrack();
            ShortMessage sm = new ShortMessage();
            sm.setMessage(e.midiCommand, e.midiChannel, e.midiPitch, e.midiVelocity);
            tr[e.midiTrack].add(new MidiEvent(sm, (long) Math.round(1000 * e.keyDown)));
            if (e.midiCommand == ShortMessage.NOTE_ON) {
                sm = new ShortMessage();
                sm.setMessage(ShortMessage.NOTE_OFF, e.midiChannel, e.midiPitch, e.midiVelocity);
                tr[e.midiTrack].add(new MidiEvent(sm, (long) Math.round(1000 * e.keyUp)));
            }
            //catch (InvalidMidiDataException exception) {}
        }
    }
    return s;
}