Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GinSing.h>
- GinSing GS;
- #define rcvPin 4
- #define sndPin 3
- #define ovfPin 2
- #define boomPin 8
- #define chuckPin 9
- #define melodyPin 10
- #define stagePin 11
- GinSingPoly * poly = 0x0;
- GSNote pitchLookup[85] = { C_1, CS_1, D_1, DS_1, E_1, F_1, FS_1, G_1, GS_1, A_1, AS_1, B_1,
- C_2, CS_2, D_2, DS_2, E_2, F_2, FS_2, G_2, GS_2, A_2, AS_2, B_2,
- C_3, CS_3, D_3, DS_3, E_3, F_3, FS_3, G_3, GS_3, A_3, AS_3, B_3,
- C_4, CS_4, D_4, DS_4, E_4, F_4, FS_4, G_4, GS_4, A_4, AS_4, B_4,
- C_5, CS_5, D_5, DS_5, E_5, F_5, FS_5, G_5, GS_5, A_5, AS_5, B_5,
- C_6, CS_6, D_6, DS_6, E_6, F_6, FS_6, G_6, GS_6, A_6, AS_6, B_6,
- C_7, CS_7, D_7, DS_7, E_7, F_7, FS_7, G_7, GS_7, A_7, AS_7, B_7 };
- #define _NUMCHORDS 4
- #define _NUMNOTESINCHORD 5
- #define _NUMNOTESINSCALE 8
- int chords1[_NUMCHORDS][_NUMNOTESINCHORD] = { {-12, -17, 0, 3, 7},
- {-12, -17, 0, 4, 10},
- {-19, -13, 0, 5, 8},
- {-11, -17, -1, 5, 7} };
- int chords2[_NUMCHORDS][_NUMNOTESINCHORD] = { {-12, -17, 0, 4, 7},
- {-17, -10, -1, 2, 7},
- {-10, -15, -3, 0, 6},
- {-13, -6, -1, 3, 6} };
- int chords3[_NUMCHORDS][_NUMNOTESINCHORD] = { {-19, -13, 0, 5, 8},
- {-12, -17, 0, 4, 7},
- {-21, -14, -2, 3, 6},
- {-12, -19, -3, 0, 5} };
- int (*chords)[_NUMNOTESINCHORD];
- int scales1[_NUMCHORDS][_NUMNOTESINSCALE] = { {-5, 0, 3, 7, -4, -1, 2, 6},
- {-5, -2, 4, 7, -4, 0, 3, 6},
- {-4, 0, 5, 8, -5, -1, 3, 7},
- {-5, -1, 1, 5, -4, 0, 3, 7} };
- int scales2[_NUMCHORDS][_NUMNOTESINSCALE] = { {-5, 0, 4, 7, -3, -2, 3, 6},
- {-5, -1, 2, 7, -3, 0, 4, 5},
- {-3, 0, 2, 6, -2, -1, 3, 7},
- {-1, 3, 6, 9, 0, 4, 7, 11} };
- int scales3[_NUMCHORDS][_NUMNOTESINSCALE] = { {-4, 0, 5, 8, -1, 1, 4, 7},
- {-5, 0, 4, 7, -4, -1, 3, 5},
- {-6, -2, 3, 6, -3, -1, 2, 5},
- {-7, -2, 2, 5, -6, -3, 1, 3} };
- int (*scales)[_NUMNOTESINSCALE];
- #define _NUM_CHORDS_IN_SEQUENCE 12
- int chord_sequence1[_NUM_CHORDS_IN_SEQUENCE] = { 0, 0, 3, 0, 2, 0, 3, 1, 2, 0, 3, 0 };
- int chord_sequence2[_NUM_CHORDS_IN_SEQUENCE] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 };
- int chord_sequence3[_NUM_CHORDS_IN_SEQUENCE] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 };
- int (*chord_sequence);
- int key = 36;
- int prevValues[4] = {0,0,0,0};
- int curValues[4] = {0,0,0,0};
- int valuePins[4] = {boomPin, chuckPin, melodyPin, stagePin};
- float distortion = 0.;
- void setup()
- {
- GS.begin(rcvPin, sndPin, ovfPin);
- Serial.begin(9600);
- pinMode(7, INPUT);
- pinMode(8, INPUT);
- poly = GS.getPoly();
- poly->begin();
- poly->setEnvelope(0, AT_8MS, 1.f, DR_292MS, 1.f, DR_145MS, 0.0f);
- poly->setEnvelope(1, AT_8MS, .75f, DR_292MS, .4f, DR_292MS, 0.0f);
- poly->setEnvelope(2, AT_8MS, .75f, DR_292MS, .4f, DR_292MS, 0.0f);
- poly->setEnvelope(3, AT_8MS, .75f, DR_292MS, .4f, DR_292MS, 0.0f);
- poly->release(4);
- poly->setWaveform(0, TRIANGLE);
- advanceState();
- }
- int chord = -1;
- int boomchuck = -1;
- int beat = -1;
- int state = -1;
- int chord_counter = -1;
- int cue = -1;
- int prev_pick = -1;
- int boomWait = 1000;
- int chuckWait = 1000;
- int melodyWait = 1000;
- GSNote pitch;
- int nextMelodyNote = -1;
- int r;
- void loop()
- {
- int cue = waitForCue();
- if (cue == 0) {
- boomchuck = (boomchuck+1) % 2;
- boomWait = 0;
- if (boomchuck == 0) {
- chord_counter = (chord_counter + 1) % _NUM_CHORDS_IN_SEQUENCE;
- chord = chord_sequence[chord_counter];
- if (chord_counter % 4 == 0 && state == 2) {
- key = (key-2) % 12 + 36;
- distortion += 0.05;
- setDistortion(distortion);
- }
- }
- pitch = pitchLookup[getPitchNum(chord, boomchuck)];
- poly->setNote(0, pitch);
- poly->trigger(0);
- } else if (cue == 1) {
- for (int i=1; i<4; i++) {
- pitch = pitchLookup[getPitchNum(max(chord, 0), i+1)];
- poly->setNote(i, pitch);
- poly->trigger(i);
- chuckWait = 0;
- }
- } else if (cue == 2) {
- if (nextMelodyNote < 0) {
- r = prev_pick;
- while (r % 4 == prev_pick) {
- r = random(0, 4);
- int r2 = random(0, 3);
- if (r2 == 0) {
- // play appogiatura
- nextMelodyNote = r;
- r += 4;
- }
- }
- } else {
- r = nextMelodyNote;
- nextMelodyNote = -1;
- }
- prev_pick = r;
- if (state == 0) {
- poly->setPortamento(4, 1., 0.3);
- } else if (state == 2) {
- poly->setPortamento(4, 1., 0.2);
- } else {
- poly->setPortamento(4, 1., 1);
- }
- pitch = pitchLookup[getScaleNum(max(chord, 0), r)];
- poly->setNote(4, pitch);
- poly->trigger(4);
- melodyWait = 0;
- } else if (cue == 3) {
- advanceState();
- }
- if (boomWait == 250) {
- poly->release(0);
- }
- if (chuckWait == 50) {
- poly->release(1);
- poly->release(2);
- poly->release(3);
- }
- if (melodyWait == 500) {
- poly->release(4);
- }
- delay(10);
- boomWait += 10;
- chuckWait += 10;
- melodyWait += 10;
- }
- int waitForCue() {
- while (true) {
- for (int i=0; i<4; i++) {
- prevValues[i] = curValues[i];
- curValues[i] = digitalRead(valuePins[i]);
- if (curValues[i] == 1 && prevValues[i] == 0) {
- return i;
- }
- }
- return -1;
- }
- }
- void advanceState() {
- chord = -1;
- boomchuck = -1;
- beat = -1;
- chord_counter = -1;
- state = (state+1) % 3;
- if (state == 0) {
- distortion = 0.;
- setDistortion(distortion);
- key = 36;
- chords = chords1;
- scales = scales1;
- chord_sequence = chord_sequence1;
- } else if (state == 1) {
- distortion = 0.3;
- setDistortion(distortion);
- key += 6;
- chords = chords2;
- scales = scales2;
- chord_sequence = chord_sequence2;
- } else if (state == 2) {
- distortion = 0.;
- setDistortion(distortion);
- chords = chords3;
- scales = scales3;
- chord_sequence = chord_sequence3;
- }
- }
- int getPitchNum(int chordNum, int noteNum) {
- return chords[chordNum][noteNum % _NUMNOTESINCHORD] + key + floor(noteNum/_NUMNOTESINCHORD)*12;
- }
- int getScaleNum(int chordNum, int noteNum) {
- return scales[chordNum][noteNum % _NUMNOTESINSCALE] + key + 12 + floor(noteNum/_NUMNOTESINSCALE)*12;
- }
- void setDistortion(float amt) {
- for (int i=0; i<5; i++) {
- poly->setFreqDist(i, amt);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement