Package javax.sound.midi

Examples of javax.sound.midi.Patch


     */
    public void test_getName() {
        Instrument1 inst = new Instrument1(null, null, null, null);
        assertNull(inst.getName());

        Instrument1 inst2 = new Instrument1(null, new Patch(10, 20), "Test", null);
        assertEquals("Test",inst2.getName());
    }
View Full Code Here


     * test constructor of class Patch
     *
     */
    public void test_constructor()
    {
        Patch patch = new Patch( 34, 68 );
        assertEquals(34, patch.getBank());
        assertEquals(68, patch.getProgram());
       
        Patch patch2 = new Patch( -4, 567 );
        assertEquals(-4, patch2.getBank());
        assertEquals(567, patch2.getProgram());
    }
View Full Code Here

     * test method getBank() of class Patch
     *
     */
    public void test_getBank()
    {
        Patch patch = new Patch( 45, 78 );
        assertEquals(45, patch.getBank());
       
        Patch patch1 = new Patch( -78, 78 );
        assertEquals(-78, patch1.getBank());
       
        Patch patch2 = new Patch( 16400, 78 );
        assertEquals(16400, patch2.getBank());
       
    }
View Full Code Here

        int bank = patch.getBank();
        boolean percussion = false;
        if (patch instanceof ModelPatch)
            percussion = ((ModelPatch)patch).isPercussion();
        for (Instrument instrument : instruments) {
            Patch patch2 = instrument.getPatch();
            int program2 = patch2.getProgram();
            int bank2 = patch2.getBank();
            if (program == program2 && bank == bank2) {
                boolean percussion2 = false;
                if (patch2 instanceof ModelPatch)
                    percussion2 = ((ModelPatch) patch2).isPercussion();
                if (percussion == percussion2)
View Full Code Here

                        subid2 = data[4] & 0xFF;
                        switch (subid2) {
                        case 0x01// BULK TUNING DUMP
                        {
                            // http://www.midi.org/about-midi/tuning.shtml
                            SoftTuning tuning = synth.getTuning(new Patch(0,
                                    data[5] & 0xFF));
                            tuning.load(data);
                            break;
                        }
                        case 0x04// KEY-BASED TUNING DUMP
                        case 0x05// SCALE/OCTAVE TUNING DUMP, 1 byte format
                        case 0x06// SCALE/OCTAVE TUNING DUMP, 2 byte format
                        case 0x07// SINGLE NOTE TUNING CHANGE (NON REAL-TIME)
                                    // (BANK)
                        {
                            // http://www.midi.org/about-midi/tuning_extens.shtml
                            SoftTuning tuning = synth.getTuning(new Patch(
                                    data[5] & 0xFF, data[6] & 0xFF));
                            tuning.load(data);
                            break;
                        }
                        case 0x08// scale/octave tuning 1-byte form (Non
                                    // Real-Time)
                        case 0x09// scale/octave tuning 2-byte form (Non
                                    // Real-Time)
                        {
                            // http://www.midi.org/about-midi/tuning-scale.shtml
                            SoftTuning tuning = new SoftTuning(data);
                            int channelmask = (data[5] & 0xFF) * 16384
                                    + (data[6] & 0xFF) * 128 + (data[7] & 0xFF);
                            SoftChannel[] channels = synth.channels;
                            for (int i = 0; i < channels.length; i++)
                                if ((channelmask & (1 << i)) != 0)
                                    channels[i].tuning = tuning;
                            break;
                        }
                        default:
                            break;
                        }
                        break;
                    case 0x09// General Midi Message
                        subid2 = data[4] & 0xFF;
                        switch (subid2) {
                        case 0x01// General Midi 1 On
                            synth.setGeneralMidiMode(1);
                            reset();
                            break;
                        case 0x02// General Midi Off
                            synth.setGeneralMidiMode(0);
                            reset();
                            break;
                        case 0x03// General MidI Level 2 On
                            synth.setGeneralMidiMode(2);
                            reset();
                            break;
                        default:
                            break;
                        }
                        break;
                    case 0x0A: // DLS Message
                        subid2 = data[4] & 0xFF;
                        switch (subid2) {
                        case 0x01// DLS On
                            if (synth.getGeneralMidiMode() == 0)
                                synth.setGeneralMidiMode(1);
                            synth.voice_allocation_mode = 1;
                            reset();
                            break;
                        case 0x02// DLS Off
                            synth.setGeneralMidiMode(0);
                            synth.voice_allocation_mode = 0;
                            reset();
                            break;
                        case 0x03// DLS Static Voice Allocation Off
                            synth.voice_allocation_mode = 0;
                            break;
                        case 0x04// DLS Static Voice Allocation On
                            synth.voice_allocation_mode = 1;
                            break;
                        default:
                            break;
                        }
                        break;

                    default:
                        break;
                    }
                }
            }

            // Universal Real-Time SysEx
            if ((data[1] & 0xFF) == 0x7F) {
                int deviceID = data[2] & 0xFF;
                if (deviceID == 0x7F || deviceID == synth.getDeviceID()) {
                    int subid1 = data[3] & 0xFF;
                    int subid2;
                    switch (subid1) {
                    case 0x04: // Device Control

                        subid2 = data[4] & 0xFF;
                        switch (subid2) {
                        case 0x01: // Master Volume
                        case 0x02: // Master Balane
                        case 0x03: // Master fine tuning
                        case 0x04: // Master coarse tuning
                            int val = (data[5] & 0x7F)
                                    + ((data[6] & 0x7F) * 128);
                            if (subid2 == 0x01)
                                setVolume(val);
                            else if (subid2 == 0x02)
                                setBalance(val);
                            else if (subid2 == 0x03)
                                setFineTuning(val);
                            else if (subid2 == 0x04)
                                setCoarseTuning(val);
                            break;
                        case 0x05: // Global Parameter Control
                            int ix = 5;
                            int slotPathLen = (data[ix++] & 0xFF);
                            int paramWidth = (data[ix++] & 0xFF);
                            int valueWidth = (data[ix++] & 0xFF);
                            int[] slotPath = new int[slotPathLen];
                            for (int i = 0; i < slotPathLen; i++) {
                                int msb = (data[ix++] & 0xFF);
                                int lsb = (data[ix++] & 0xFF);
                                slotPath[i] = msb * 128 + lsb;
                            }
                            int paramCount = (data.length - 1 - ix)
                                    / (paramWidth + valueWidth);
                            long[] params = new long[paramCount];
                            long[] values = new long[paramCount];
                            for (int i = 0; i < paramCount; i++) {
                                values[i] = 0;
                                for (int j = 0; j < paramWidth; j++)
                                    params[i] = params[i] * 128
                                            + (data[ix++] & 0xFF);
                                for (int j = 0; j < valueWidth; j++)
                                    values[i] = values[i] * 128
                                            + (data[ix++] & 0xFF);

                            }
                            globalParameterControlChange(slotPath, params, values);
                            break;
                        default:
                            break;
                        }
                        break;

                    case 0x08// MIDI Tuning Standard
                        subid2 = data[4] & 0xFF;
                        switch (subid2) {
                        case 0x02// SINGLE NOTE TUNING CHANGE (REAL-TIME)
                        {
                            // http://www.midi.org/about-midi/tuning.shtml
                            SoftTuning tuning = synth.getTuning(new Patch(0,
                                    data[5] & 0xFF));
                            tuning.load(data);
                            SoftVoice[] voices = synth.getVoices();
                            for (int i = 0; i < voices.length; i++)
                                if (voices[i].active)
                                    if (voices[i].tuning == tuning)
                                        voices[i].updateTuning(tuning);
                            break;
                        }
                        case 0x07// SINGLE NOTE TUNING CHANGE (REAL-TIME)
                                    // (BANK)
                        {
                            // http://www.midi.org/about-midi/tuning_extens.shtml
                            SoftTuning tuning = synth.getTuning(new Patch(
                                    data[5] & 0xFF, data[6] & 0xFF));
                            tuning.load(data);
                            SoftVoice[] voices = synth.getVoices();
                            for (int i = 0; i < voices.length; i++)
                                if (voices[i].active)
View Full Code Here

        SF2Layer clarinet = new_clarinet(sf2);
        SF2Layer reverse_cymbal = new_reverse_cymbal(sf2);

        SF2Layer defaultsound = piano1;

        newInstrument(sf2, "Piano", new Patch(0, 0), gpiano, gpiano_hammer);
        newInstrument(sf2, "Piano", new Patch(0, 1), gpiano2, gpiano_hammer);
        newInstrument(sf2, "Piano", new Patch(0, 2), piano1);
        {
            SF2Instrument ins = newInstrument(sf2, "Honky-tonk Piano",
                    new Patch(0, 3), piano1, piano1);
            SF2InstrumentRegion region = ins.getRegions().get(0);
            region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 80);
            region.putInteger(SF2Region.GENERATOR_FINETUNE, 30);
            region = ins.getRegions().get(1);
            region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 30);
        }
        newInstrument(sf2, "Rhodes", new Patch(0, 4), epiano2);
        newInstrument(sf2, "Rhodes", new Patch(0, 5), epiano2);
        newInstrument(sf2, "Clavinet", new Patch(0, 6), epiano1);
        newInstrument(sf2, "Clavinet", new Patch(0, 7), epiano1);
        newInstrument(sf2, "Rhodes", new Patch(0, 8), epiano2);
        newInstrument(sf2, "Bell", new Patch(0, 9), bell);
        newInstrument(sf2, "Bell", new Patch(0, 10), bell);
        newInstrument(sf2, "Vibraphone", new Patch(0, 11), bell);
        newInstrument(sf2, "Marimba", new Patch(0, 12), bell);
        newInstrument(sf2, "Marimba", new Patch(0, 13), bell);
        newInstrument(sf2, "Bell", new Patch(0, 14), bell);
        newInstrument(sf2, "Rock Organ", new Patch(0, 15), organ);
        newInstrument(sf2, "Rock Organ", new Patch(0, 16), organ);
        newInstrument(sf2, "Perc Organ", new Patch(0, 17), organ);
        newInstrument(sf2, "Rock Organ", new Patch(0, 18), organ);
        newInstrument(sf2, "Church Organ", new Patch(0, 19), ch_organ);
        newInstrument(sf2, "Accordion", new Patch(0, 20), organ);
        newInstrument(sf2, "Accordion", new Patch(0, 21), organ);
        newInstrument(sf2, "Accordion", new Patch(0, 22), organ);
        newInstrument(sf2, "Accordion", new Patch(0, 23), organ);
        newInstrument(sf2, "Guitar", new Patch(0, 24), guitar, guitar_pick);
        newInstrument(sf2, "Guitar", new Patch(0, 25), guitar, guitar_pick);
        newInstrument(sf2, "Guitar", new Patch(0, 26), guitar, guitar_pick);
        newInstrument(sf2, "Guitar", new Patch(0, 27), guitar, guitar_pick);
        newInstrument(sf2, "Guitar", new Patch(0, 28), guitar, guitar_pick);
        newInstrument(sf2, "Distorted Guitar", new Patch(0, 29), guitar_dist);
        newInstrument(sf2, "Distorted Guitar", new Patch(0, 30), guitar_dist);
        newInstrument(sf2, "Guitar", new Patch(0, 31), guitar, guitar_pick);
        newInstrument(sf2, "Finger Bass", new Patch(0, 32), bass1);
        newInstrument(sf2, "Finger Bass", new Patch(0, 33), bass1);
        newInstrument(sf2, "Finger Bass", new Patch(0, 34), bass1);
        newInstrument(sf2, "Frettless Bass", new Patch(0, 35), bass2);
        newInstrument(sf2, "Frettless Bass", new Patch(0, 36), bass2);
        newInstrument(sf2, "Frettless Bass", new Patch(0, 37), bass2);
        newInstrument(sf2, "Synth Bass1", new Patch(0, 38), synthbass);
        newInstrument(sf2, "Synth Bass2", new Patch(0, 39), synthbass);
        newInstrument(sf2, "Solo String", new Patch(0, 40), string2, solostring);
        newInstrument(sf2, "Solo String", new Patch(0, 41), string2, solostring);
        newInstrument(sf2, "Solo String", new Patch(0, 42), string2, solostring);
        newInstrument(sf2, "Solo String", new Patch(0, 43), string2, solostring);
        newInstrument(sf2, "Solo String", new Patch(0, 44), string2, solostring);
        newInstrument(sf2, "Def", new Patch(0, 45), defaultsound);
        newInstrument(sf2, "Harp", new Patch(0, 46), bell);
        newInstrument(sf2, "Timpani", new Patch(0, 47), timpani);
        newInstrument(sf2, "Strings", new Patch(0, 48), string2);
        SF2Instrument slow_strings =
                newInstrument(sf2, "Slow Strings", new Patch(0, 49), string2);
        SF2InstrumentRegion region = slow_strings.getRegions().get(0);
        region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, 2500);
        region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 2000);
        newInstrument(sf2, "Synth Strings", new Patch(0, 50), string2);
        newInstrument(sf2, "Synth Strings", new Patch(0, 51), string2);


        newInstrument(sf2, "Choir", new Patch(0, 52), choir);
        newInstrument(sf2, "Choir", new Patch(0, 53), choir);
        newInstrument(sf2, "Choir", new Patch(0, 54), choir);
        {
            SF2Instrument ins = newInstrument(sf2, "Orch Hit",
                    new Patch(0, 55), orchhit, orchhit, timpani);
            region = ins.getRegions().get(0);
            region.putInteger(SF2Region.GENERATOR_COARSETUNE, -12);
            region.putInteger(SF2Region.GENERATOR_INITIALATTENUATION, -100);
        }
        newInstrument(sf2, "Trumpet", new Patch(0, 56), trumpet);
        newInstrument(sf2, "Trombone", new Patch(0, 57), trombone);
        newInstrument(sf2, "Trombone", new Patch(0, 58), trombone);
        newInstrument(sf2, "Trumpet", new Patch(0, 59), trumpet);
        newInstrument(sf2, "Horn", new Patch(0, 60), horn);
        newInstrument(sf2, "Brass Section", new Patch(0, 61), brass_section);
        newInstrument(sf2, "Brass Section", new Patch(0, 62), brass_section);
        newInstrument(sf2, "Brass Section", new Patch(0, 63), brass_section);
        newInstrument(sf2, "Sax", new Patch(0, 64), sax);
        newInstrument(sf2, "Sax", new Patch(0, 65), sax);
        newInstrument(sf2, "Sax", new Patch(0, 66), sax);
        newInstrument(sf2, "Sax", new Patch(0, 67), sax);
        newInstrument(sf2, "Oboe", new Patch(0, 68), oboe);
        newInstrument(sf2, "Horn", new Patch(0, 69), horn);
        newInstrument(sf2, "Bassoon", new Patch(0, 70), bassoon);
        newInstrument(sf2, "Clarinet", new Patch(0, 71), clarinet);
        newInstrument(sf2, "Flute", new Patch(0, 72), flute);
        newInstrument(sf2, "Flute", new Patch(0, 73), flute);
        newInstrument(sf2, "Flute", new Patch(0, 74), flute);
        newInstrument(sf2, "Flute", new Patch(0, 75), flute);
        newInstrument(sf2, "Flute", new Patch(0, 76), flute);
        newInstrument(sf2, "Flute", new Patch(0, 77), flute);
        newInstrument(sf2, "Flute", new Patch(0, 78), flute);
        newInstrument(sf2, "Flute", new Patch(0, 79), flute);
        newInstrument(sf2, "Organ", new Patch(0, 80), organ);
        newInstrument(sf2, "Organ", new Patch(0, 81), organ);
        newInstrument(sf2, "Flute", new Patch(0, 82), flute);
        newInstrument(sf2, "Organ", new Patch(0, 83), organ);
        newInstrument(sf2, "Organ", new Patch(0, 84), organ);
        newInstrument(sf2, "Choir", new Patch(0, 85), choir);
        newInstrument(sf2, "Organ", new Patch(0, 86), organ);
        newInstrument(sf2, "Organ", new Patch(0, 87), organ);
        newInstrument(sf2, "Synth Strings", new Patch(0, 88), string2);
        newInstrument(sf2, "Organ", new Patch(0, 89), organ);
        newInstrument(sf2, "Def", new Patch(0, 90), defaultsound);
        newInstrument(sf2, "Choir", new Patch(0, 91), choir);
        newInstrument(sf2, "Organ", new Patch(0, 92), organ);
        newInstrument(sf2, "Organ", new Patch(0, 93), organ);
        newInstrument(sf2, "Organ", new Patch(0, 94), organ);
        newInstrument(sf2, "Organ", new Patch(0, 95), organ);
        newInstrument(sf2, "Organ", new Patch(0, 96), organ);
        newInstrument(sf2, "Organ", new Patch(0, 97), organ);
        newInstrument(sf2, "Bell", new Patch(0, 98), bell);
        newInstrument(sf2, "Organ", new Patch(0, 99), organ);
        newInstrument(sf2, "Organ", new Patch(0, 100), organ);
        newInstrument(sf2, "Organ", new Patch(0, 101), organ);
        newInstrument(sf2, "Def", new Patch(0, 102), defaultsound);
        newInstrument(sf2, "Synth Strings", new Patch(0, 103), string2);
        newInstrument(sf2, "Def", new Patch(0, 104), defaultsound);
        newInstrument(sf2, "Def", new Patch(0, 105), defaultsound);
        newInstrument(sf2, "Def", new Patch(0, 106), defaultsound);
        newInstrument(sf2, "Def", new Patch(0, 107), defaultsound);
        newInstrument(sf2, "Marimba", new Patch(0, 108), bell);
        newInstrument(sf2, "Sax", new Patch(0, 109), sax);
        newInstrument(sf2, "Solo String", new Patch(0, 110), string2, solostring);
        newInstrument(sf2, "Oboe", new Patch(0, 111), oboe);
        newInstrument(sf2, "Bell", new Patch(0, 112), bell);
        newInstrument(sf2, "Melodic Toms", new Patch(0, 113), melodic_toms);
        newInstrument(sf2, "Marimba", new Patch(0, 114), bell);
        newInstrument(sf2, "Melodic Toms", new Patch(0, 115), melodic_toms);
        newInstrument(sf2, "Melodic Toms", new Patch(0, 116), melodic_toms);
        newInstrument(sf2, "Melodic Toms", new Patch(0, 117), melodic_toms);
        newInstrument(sf2, "Reverse Cymbal", new Patch(0, 118), reverse_cymbal);
        newInstrument(sf2, "Reverse Cymbal", new Patch(0, 119), reverse_cymbal);
        newInstrument(sf2, "Guitar", new Patch(0, 120), guitar);
        newInstrument(sf2, "Def", new Patch(0, 121), defaultsound);
        {
            SF2Instrument ins = newInstrument(sf2, "Seashore/Reverse Cymbal",
                    new Patch(0, 122), reverse_cymbal);
            region = ins.getRegions().get(0);
            region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
            region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 18500);
            region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 4500);
            region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, -4500);
        }
        {
            SF2Instrument ins = newInstrument(sf2, "Bird/Flute",
                    new Patch(0, 123), flute);
            region = ins.getRegions().get(0);
            region.putInteger(SF2Region.GENERATOR_COARSETUNE, 24);
            region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, -3000);
            region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
        }
        newInstrument(sf2, "Def", new Patch(0, 124), side_stick);
        {
            SF2Instrument ins = newInstrument(sf2, "Seashore/Reverse Cymbal",
                    new Patch(0, 125), reverse_cymbal);
            region = ins.getRegions().get(0);
            region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
            region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 18500);
            region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 4500);
            region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, -4500);
        }
        newInstrument(sf2, "Applause/crash_cymbal",
                new Patch(0, 126), crash_cymbal);
        newInstrument(sf2, "Gunshot/side_stick", new Patch(0, 127), side_stick);

        for (SF2Instrument instrument : sf2.getInstruments()) {
            Patch patch = instrument.getPatch();
            if (patch instanceof ModelPatch) {
                if (((ModelPatch) patch).isPercussion())
                    continue;
            }
            instrument.setName(general_midi_instruments[patch.getProgram()]);
        }

        return sf2;

    }
View Full Code Here

        tuningChange(0, program);
    }

    public void tuningChange(int bank, int program) {
        synchronized (control_mutex) {
            tuning = synthesizer.getTuning(new Patch(bank, program));
        }
    }
View Full Code Here

    public String getName() {
        return getClass().getName();
    }

    public Patch getPatch() {
        return new Patch(0, 0);
    }
View Full Code Here

        return getName();
    }

    public Instrument getInstrument(Patch patch) {
        Instrument ins = getInstrument();
        Patch p = ins.getPatch();
        if (p.getBank() != patch.getBank())
            return null;
        if (p.getProgram() != patch.getProgram())
            return null;
        if (p instanceof ModelPatch && patch instanceof ModelPatch) {
            if (((ModelPatch)p).isPercussion()
                    != ((ModelPatch)patch).isPercussion()) {
                return null;
View Full Code Here

        int bank = patch.getBank();
        boolean percussion = false;
        if (patch instanceof ModelPatch)
            percussion = ((ModelPatch) patch).isPercussion();
        for (Instrument instrument : instruments) {
            Patch patch2 = instrument.getPatch();
            int program2 = patch2.getProgram();
            int bank2 = patch2.getBank();
            if (program == program2 && bank == bank2) {
                boolean percussion2 = false;
                if (patch2 instanceof ModelPatch)
                    percussion2 = ((ModelPatch) patch2).isPercussion();
                if (percussion == percussion2)
View Full Code Here

TOP

Related Classes of javax.sound.midi.Patch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.