Instruments in SoundCipher

Instruments in SoundCipher

The SoundCipher library contains a large amount of instruments. This quick guide will show you how to take advantage of these different instruments. You can view the demo down below or at: https://www.ktbyte.com/projects/project/79781
The code down below shows how to create a SoundCipher entity and then change its instrument. Every different instrument in SoundCipher is assigned a different integer value. You can change the SoundCipher’s instrument by changing its instrument value to a different integer. In this scenario it uses a random instrument every time you click the screen. The code can be seen down below.
SoundCipher sc = new SoundCipher(this); //SoundCipher entity
//Different instrument values
int PIANO = 0,
    XYLOPHONE = 13,
    ELECTRIC_GUITAR = 27,
    ACOUSTIC_BASS = 32,
    STRINGS = 48,
    ORCHESTRA_HIT = 55,
    TRUMPET = 56,
    TUBA = 58,
    BRASS = 61,
    ALTO_SAX = 65,
    CLARINET = 71,
    FLUTE = 73,
    TAIKO = 116,
    SYNTH_DRUM = 118;

//Instruments stored in an array.
int[] instruments = {PIANO, XYLOPHONE, ELECTRIC_GUITAR, ACOUSTIC_BASS, STRINGS, ORCHESTRA_HIT, TRUMPET, TUBA, BRASS, ALTO_SAX, CLARINET, FLUTE, TAIKO, SYNTH_DRUM};

void setup() {
    size(480, 360);
}

void mousePressed() {
    sc.instrument = instruments[(int)random(instruments.length)]; //Plays random instrument from array
    sc.playNote(60, 50, 0.5);
    background(random(255), random(255), random(255)); //Changes background color every mouse press
}

Leave a Reply

Your email address will not be published. Required fields are marked *