Example usage for javax.sound.midi Synthesizer getChannels

List of usage examples for javax.sound.midi Synthesizer getChannels

Introduction

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

Prototype

MidiChannel[] getChannels();

Source Link

Document

Obtains the set of MIDI channels controlled by this synthesizer.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Sequencer sequencer = MidiSystem.getSequencer();
    sequencer.open();//from w w  w  . j a v  a2  s  . c om
    if (sequencer instanceof Synthesizer) {
        Synthesizer synthesizer = (Synthesizer) sequencer;
        MidiChannel[] channels = synthesizer.getChannels();

        // gain is a value between 0 and 1 (loudest)
        double gain = 0.9D;
        for (int i = 0; i < channels.length; i++) {
            channels[i].controlChange(7, (int) (gain * 127.0));
        }
    }
}

From source file:Drums.java

public Drums(Synthesizer synth) {
    super("Drums");

    // Channel 10 is the GeneralMidi percussion channel. In Java code, we
    // number channels from 0 and use channel 9 instead.
    channel = synth.getChannels()[9];

    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            int key = e.getKeyCode();
            if (key >= 35 && key <= 81) {
                channel.noteOn(key, velocity);
            }/*from ww  w  . j a  v  a 2  s  .  c o m*/
        }

        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
            if (key >= 35 && key <= 81)
                channel.noteOff(key);
        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseMoved(MouseEvent e) {
            velocity = e.getX();
        }
    });
}

From source file:Main.java

public Main(Synthesizer synth) {
    super("Drums");

    // Channel 10 is the GeneralMidi percussion channel. In Java code, we
    // number channels from 0 and use channel 9 instead.
    channel = synth.getChannels()[9];

    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            int key = e.getKeyCode();
            if (key >= 35 && key <= 81) {
                channel.noteOn(key, velocity);
            }/*  www.jav  a  2 s.c  om*/
        }

        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
            if (key >= 35 && key <= 81)
                channel.noteOff(key);
        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseMoved(MouseEvent e) {
            velocity = e.getX();
        }
    });
}