Example usage for javax.sound.midi ShortMessage getChannel

List of usage examples for javax.sound.midi ShortMessage getChannel

Introduction

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

Prototype

public int getChannel() 

Source Link

Document

Obtains the MIDI channel associated with this event.

Usage

From source file:de.ailis.midi4js.MessageReceiver.java

/**
 * Processes a short message./*from w  ww .j  a v a  2s  .c o m*/
 *
 * @param message
 *            The message to process.
 * @param json
 *            The JSON stringer.
 * @throws JSONException
 *             When JSON output fails.
 */
private void processShortMessage(final ShortMessage message, final JSONStringer json) throws JSONException {
    json.key("class").value("ShortMessage");
    json.key("channel").value(message.getChannel());
    json.key("command").value(message.getCommand());
    json.key("data1").value(message.getData1());
    json.key("data2").value(message.getData2());
}

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

public void send(MidiMessage message, long timeStamp) {
    ShortMessage msg = (ShortMessage) message;
    int x = msg.getData1() - 12;
    int y = msg.getChannel();
    if (x >= 0 && x < this.monome.sizeX && y >= 0 && y < this.monome.sizeY) {
        int velocity = msg.getData2();
        if (velocity == 127) {
            this.toggleValues[x][y] = 1;
        } else {/*from www. j a  v a2 s .  c o m*/
            this.toggleValues[x][y] = 0;
        }
        this.redrawMonome();
    }
    return;
}

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

public void send(MidiMessage message, long timeStamp) {
    if (this.recv == null) {
        return;/*from  w  ww .  j  ava  2 s. c  om*/
    }

    // pass midi clock messages on to the machinedrum for tempo sync
    ShortMessage shortMessage;
    if (message instanceof ShortMessage) {
        shortMessage = (ShortMessage) message;
        switch (shortMessage.getCommand()) {
        case 0xF0:
            // midi clock message
            if (shortMessage.getChannel() == 0x08) {
                this.recv.send(message, timeStamp);
            }
            // midi start message
            if (shortMessage.getChannel() == 0x0A) {
                this.recv.send(message, timeStamp);
            }
            // midi stop message
            if (shortMessage.getChannel() == 0x0C) {
                this.recv.send(message, timeStamp);
            }
            break;
        default:
            this.recv.send(message, timeStamp);
            break;
        }
    }
}

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

public void send(MidiMessage message, long lTimeStamp) {
    ShortMessage shortMessage;
    // pass all messages along to all monomes (who pass to all pages)
    for (int i = 0; i < this.numMonomeConfigurations; i++) {
        this.monomeConfigurations.get(i).send(message, lTimeStamp);
    }/*from  www.j a v a 2  s  .  c  o  m*/

    // filter for midi clock ticks or midi reset messages
    if (message instanceof ShortMessage) {
        shortMessage = (ShortMessage) message;
        switch (shortMessage.getCommand()) {
        case 0xF0:
            if (shortMessage.getChannel() == 8) {
                for (int i = 0; i < this.numMonomeConfigurations; i++) {
                    this.monomeConfigurations.get(i).tick();
                }
            }
            if (shortMessage.getChannel() == 0x0C) {
                for (int i = 0; i < this.numMonomeConfigurations; i++) {
                    this.monomeConfigurations.get(i).reset();
                }
            }
            break;
        default:
            break;
        }
    }
}

From source file:org.monome.pages.configuration.MonomeConfiguration.java

/**
 * Called every time a MIDI message is received, the messages are passed along to each page.
 * /*from   www.ja  v a2  s  . com*/
 * @param message The MIDI message received
 * @param timeStamp The timestamp of the MIDI message
 */
public synchronized void send(MidiDevice device, MidiMessage message, long timeStamp) {
    if (this.useMIDIPageChanging) {
        if (message instanceof ShortMessage) {
            ShortMessage msg = (ShortMessage) message;
            int velocity = msg.getData1();
            if (msg.getCommand() == ShortMessage.NOTE_ON && velocity > 0) {
                int channel = msg.getChannel();
                int note = msg.getData1();

                for (int j = 0; j < this.pageChangeMidiInDevices.length; j++) {
                    if (this.pageChangeMidiInDevices[j] == null) {
                        continue;
                    }
                    if (this.pageChangeMidiInDevices[j].compareTo(device.getDeviceInfo().getName()) == 0) {
                        for (int i = 0; i < this.midiPageChangeRules.size(); i++) {
                            MIDIPageChangeRule mpcr = this.midiPageChangeRules.get(i);
                            if (mpcr.checkNoteRule(note, channel) == true) {
                                int switchToPageIndex = mpcr.getPageIndex();
                                Page page = this.pages.get(switchToPageIndex);
                                this.switchPage(page, switchToPageIndex, true);
                            }
                        }
                    }
                }
            }
            if (msg.getCommand() == ShortMessage.CONTROL_CHANGE) {
                int cc = msg.getData1();
                int ccVal = msg.getData2();
                int channel = msg.getChannel();
                for (int j = 0; j < this.pageChangeMidiInDevices.length; j++) {
                    if (this.pageChangeMidiInDevices[j] == null) {
                        continue;
                    }
                    if (this.pageChangeMidiInDevices[j].compareTo(device.getDeviceInfo().getName()) == 0) {
                        for (int i = 0; i < this.midiPageChangeRules.size(); i++) {
                            MIDIPageChangeRule mpcr = this.midiPageChangeRules.get(i);
                            if (mpcr.checkCCRule(cc, ccVal, channel) == true) {
                                int switchToPageIndex = mpcr.getPageIndex();
                                Page page = this.pages.get(switchToPageIndex);
                                this.switchPage(page, switchToPageIndex, true);
                            }
                        }
                    }
                }
            }
        }
    }
    for (int i = 0; i < this.numPages; i++) {
        for (int j = 0; j < this.midiInDevices[i].length; j++) {
            if (this.midiInDevices[i][j] == null) {
                continue;
            }
            if (this.midiInDevices[i][j].compareTo(device.getDeviceInfo().getName()) == 0) {
                this.pages.get(i).send(message, timeStamp);
            }
        }
    }
}

From source file:org.monome.pages.configuration.Configuration.java

/**
 * Called by MIDIInReceiver objects when a MIDI message is received.
 * //w ww  . j a  v  a2 s.  com
 * @param device The MidiDevice the message was received from
 * @param message The MidiMessage
 * @param lTimeStamp The time when the message was received
 */
public void send(MidiDevice device, MidiMessage message, long lTimeStamp) {
    ShortMessage shortMessage;
    // pass all messages along to all monomes (who pass to all pages)
    for (int i = 0; i < MonomeConfigurationFactory.getNumMonomeConfigurations(); i++) {
        MonomeConfiguration monomeConfig = MonomeConfigurationFactory.getMonomeConfiguration(i);
        if (monomeConfig != null) {
            monomeConfig.send(device, message, lTimeStamp);
        }
    }
    for (int i = 0; i < ArcConfigurationFactory.getNumArcConfigurations(); i++) {
        ArcConfiguration arcConfig = ArcConfigurationFactory.getArcConfiguration(i);
        if (arcConfig != null) {
            arcConfig.send(device, message, lTimeStamp);
        }
    }

    // filter for midi clock ticks or midi reset messages
    if (message instanceof ShortMessage) {
        shortMessage = (ShortMessage) message;
        switch (shortMessage.getCommand()) {
        case 0xF0:
            if (shortMessage.getChannel() == 8) {
                for (int i = 0; i < MonomeConfigurationFactory.getNumMonomeConfigurations(); i++) {
                    MonomeConfiguration monomeConfig = MonomeConfigurationFactory.getMonomeConfiguration(i);
                    if (monomeConfig != null) {
                        monomeConfig.tick(device);
                    }
                }
                for (int i = 0; i < ArcConfigurationFactory.getNumArcConfigurations(); i++) {
                    ArcConfiguration arcConfig = ArcConfigurationFactory.getArcConfiguration(i);
                    if (arcConfig != null) {
                        arcConfig.tick(device);
                    }
                }
            }
            if (shortMessage.getChannel() == 0x0C) {
                for (int i = 0; i < MonomeConfigurationFactory.getNumMonomeConfigurations(); i++) {
                    MonomeConfiguration monomeConfig = MonomeConfigurationFactory.getMonomeConfiguration(i);
                    if (monomeConfig != null) {
                        monomeConfig.reset(device);
                    }
                }
                for (int i = 0; i < ArcConfigurationFactory.getNumArcConfigurations(); i++) {
                    ArcConfiguration arcConfig = ArcConfigurationFactory.getArcConfiguration(i);
                    if (arcConfig != null) {
                        arcConfig.reset(device);
                    }
                }
            }
            break;
        default:
            break;
        }
    }
}