Example usage for javax.sound.midi InvalidMidiDataException printStackTrace

List of usage examples for javax.sound.midi InvalidMidiDataException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:MidiTest.java

/**
 * Plays a sequence, optionally looping. This method returns immediately.
 * The sequence is not played if it is invalid.
 *///w ww  .  jav a  2  s .c  om
public void play(Sequence sequence, boolean loop) {
    if (sequencer != null && sequence != null && sequencer.isOpen()) {
        try {
            sequencer.setSequence(sequence);
            sequencer.start();
            this.loop = loop;
        } catch (InvalidMidiDataException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:MidiTest.java

/**
 * Loads a sequence from an input stream. Returns null if an error occurs.
 */// w w  w  . ja  v a  2 s.c  o m
public Sequence getSequence(InputStream is) {
    try {
        if (!is.markSupported()) {
            is = new BufferedInputStream(is);
        }
        Sequence s = MidiSystem.getSequence(is);
        is.close();
        return s;
    } catch (InvalidMidiDataException ex) {
        ex.printStackTrace();
        return null;
    } catch (IOException ex) {
        ex.printStackTrace();
        return null;
    }
}

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

/**
 * Create a JavaSound MidiMessage from this instance.
 * //from   w w  w  .  j a  v  a 2s  .  c om
 * @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:org.monome.pages.MIDIKeyboardJulienBPage.java

private void stopNotes() {
    ShortMessage note_out = new ShortMessage();
    for (int chan = 0; chan < 16; chan++) {
        for (int i = 0; i < 128; i++) {
            if (this.notesOn[chan][i] == 1) {
                try {
                    note_out.setMessage(ShortMessage.NOTE_OFF, chan, i, 0);
                    for (int j = 0; j < midiReceivers.size(); j++) {
                        midiReceivers.get(j).send(note_out, -1);
                    }/*from  ww  w . ja  va  2  s . c om*/
                } catch (InvalidMidiDataException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

From source file:org.monome.pages.MIDIKeyboardJulienBPage.java

/**
 * Plays a MIDI note.  0 velocity will send a note off, and > 0 velocity will send a note on.
 * //  w w  w  . jav a  2  s . co  m
 * @param note_num
 * @param velocity
 * @param channel
 */
public void playNote(int note_num, int velocity, int channel) {
    ShortMessage note_out = new ShortMessage();
    try {
        if (velocity == 0) {
            note_out.setMessage(ShortMessage.NOTE_OFF, channel, note_num, velocity);
        } else {
            note_out.setMessage(ShortMessage.NOTE_ON, channel, note_num, velocity);
        }
        for (int i = 0; i < midiReceivers.size(); i++) {
            midiReceivers.get(i).send(note_out, -1);
        }
    } catch (InvalidMidiDataException e) {
        e.printStackTrace();
    }
}

From source file:org.monome.pages.MIDIKeyboardPage.java

private void stopNotes() {
    ShortMessage note_out = new ShortMessage();
    for (int chan = 0; chan < 16; chan++) {
        for (int i = 0; i < 128; i++) {
            if (this.notesOn[chan][i] == 1) {
                try {
                    note_out.setMessage(ShortMessage.NOTE_OFF, chan, i, 0);
                    recv.send(note_out, -1);
                } catch (InvalidMidiDataException e) {
                    e.printStackTrace();
                }//from w  w w  .j a  va 2 s.  com
            }
        }
    }
}

From source file:org.monome.pages.MIDIKeyboardPage.java

/**
 * Plays a MIDI note.  0 velocity will send a note off, and > 0 velocity will send a note on.
 * //from  w  w  w  .j a v a 2 s  .c  o m
 * @param note_num
 * @param velocity
 * @param channel
 */
public void playNote(int note_num, int velocity, int channel) {
    ShortMessage note_out = new ShortMessage();
    if (this.recv == null) {
        return;
    }
    try {
        if (velocity == 0) {
            note_out.setMessage(ShortMessage.NOTE_OFF, channel, note_num, velocity);
        } else {
            note_out.setMessage(ShortMessage.NOTE_ON, channel, note_num, velocity);
        }
        recv.send(note_out, -1);

    } catch (InvalidMidiDataException e) {
        e.printStackTrace();
    }
}

From source file:org.monome.pages.MIDIKeyboardPage.java

/**
 * Sends CC64 (sustain).  0 velocity will send a note off, and > 0 velocity will send a note on.
 *
 *//*from  www.  j a  v a  2 s . com*/
public void doSustain() {
    ShortMessage sustain_out = new ShortMessage();
    if (this.recv == null) {
        return;
    }
    try {
        if (this.sustain == 1) {
            sustain_out.setMessage(ShortMessage.CONTROL_CHANGE, this.midiChannel, 64, 127);
        } else {
            sustain_out.setMessage(ShortMessage.CONTROL_CHANGE, this.midiChannel, 64, 0);
        }
        recv.send(sustain_out, -1);

    } catch (InvalidMidiDataException e) {
        e.printStackTrace();
    }
}

From source file:org.monome.pages.MIDISequencerPage.java

public void stopNotes() {
    ShortMessage note_out = new ShortMessage();
    for (int i = 0; i < 16; i++) {
        if (this.heldNotes[i] == 1) {
            this.heldNotes[i] = 0;
            int note_num = this.getNoteNumber(i);
            try {
                note_out.setMessage(ShortMessage.NOTE_OFF, 0, note_num, 0);
                this.recv.send(note_out, -1);
            } catch (InvalidMidiDataException e) {
                e.printStackTrace();
            }//w  ww. ja va  2  s  .  c o  m
        }
    }
}

From source file:org.monome.pages.MIDISequencerPage.java

/**
 * Send MIDI note messages based on the sequence position.  If on = 0, note off will be sent.
 * /*from   w w  w  . j a  v a2s .  c o m*/
 * @param seq_pos The sequence position to play notes for
 * @param on Whether to turn notes on or off, a value of 1 means play notes
 */
public void playNotes(int seq_pos, int on) {
    ShortMessage note_out = new ShortMessage();
    int note_num;
    int velocity;
    int midiChannel = Integer.parseInt(this.midiChannel) - 1;
    for (int y = 0; y < 16; y++) {
        // hold mode
        if (this.getHoldModeCB().isSelected()) {
            if (on == 0) {
                return;
            }
            if (sequence[this.bank][seq_pos][y] > 0) {
                velocity = (this.sequence[this.bank][seq_pos][y] * 64) - 1;
            } else {
                velocity = 0;
            }
            note_num = this.getNoteNumber(y);
            try {
                if (velocity == 0 && this.heldNotes[y] == 1) {
                    this.heldNotes[y] = 0;
                    note_out.setMessage(ShortMessage.NOTE_OFF, midiChannel, note_num, velocity);
                    this.recv.send(note_out, -1);
                } else if (velocity > 0 && this.heldNotes[y] == 0) {
                    this.heldNotes[y] = 1;
                    note_out.setMessage(ShortMessage.NOTE_ON, midiChannel, note_num, velocity);
                    this.recv.send(note_out, -1);
                }
            } catch (InvalidMidiDataException e) {
                e.printStackTrace();
            }
            // normal mode 
        } else {
            if (sequence[this.bank][seq_pos][y] > 0) {
                if (on > 0) {
                    velocity = (this.sequence[this.bank][seq_pos][y] * 64) - 1;
                } else {
                    velocity = 0;
                }
                note_num = this.getNoteNumber(y);
                try {
                    if (velocity == 0) {
                        note_out.setMessage(ShortMessage.NOTE_OFF, midiChannel, note_num, velocity);
                        this.heldNotes[y] = 0;
                    } else {
                        note_out.setMessage(ShortMessage.NOTE_ON, midiChannel, note_num, velocity);
                        this.heldNotes[y] = 1;
                    }
                    this.recv.send(note_out, -1);
                } catch (InvalidMidiDataException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}