Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* DUY Code: ARP Arpeggio example */
- /*
- * Example script of RK002 arpeggiator.
- * ENABLE GPIO ON CONFIG ---->
- *
- * PARAMETERS (accessible via DUY Portal or SysEx without compiling)
- * MIDICHN : working input MIDI channel (1..16)
- * MODE : 0=off, 1=UP, 2=DOWN, 3=ALTERNATE, 4=RANDOM, 5=AS_PLAYED
- * OCTAVE_MIN : range min 0-4
- * OCTAVE_MAX : range max 0-4
- * CLOCKLENGTH: ARP clock length 1-48
- * GATE : gate length: 1=1/4, 2=2/4, 3=3/4, 4=1, 5=5/4 etc.
- * TRANSPOSE : ARP transpose 0-36
- */
- #define BUTTON1 13 // black button
- #define BUTTON2 6 // red button
- #define WAITTIME 16
- byte heartbeattmr = 0;
- bool buttons[2] = {false,false} ; // state variables for button lock during debouncing
- RK002_DECLARE_PARAM(MIDICHN,1,1,16,1);
- RK002_DECLARE_PARAM(MODE,0,0,5,1);
- RK002_DECLARE_PARAM(OCTAVE_MIN,0,-4,0,0);
- RK002_DECLARE_PARAM(OCTAVE_MAX,0,0,4,0);
- RK002_DECLARE_PARAM(CLOCKLENGTH,0,1,48,2);
- RK002_DECLARE_PARAM(GATELENGTH,0,1,16,1);
- RK002_DECLARE_PARAM(GATE,0,1,16,2);
- RK002_DECLARE_PARAM(TRANSPOSE,0,0,36,0);
- RKArp arp;
- byte midichn = 0;
- byte octmax=1;
- byte octmin=1;
- byte clockdiv=1;
- byte gatelen=1;
- byte arpmode=1;
- byte holdmode=0;
- void updateParams()
- {
- midichn = RK002_paramGet(MIDICHN) - 1;
- arp.setMode(RK002_paramGet(MODE));
- /*
- ARPMODE_OFF,
- ARPMODE_UP,
- ARPMODE_DOWN,
- ARPMODE_ALTERNATE,
- ARPMODE_RANDOM,
- ARPMODE_AS_PLAYED,
- */
- arp.setOctaveMin(RK002_paramGet(OCTAVE_MIN));
- arp.setOctaveMax(RK002_paramGet(OCTAVE_MAX));
- arp.setClockLength(RK002_paramGet(CLOCKLENGTH));
- arp.setGateCode(RK002_paramGet(GATELENGTH));
- arp.setTranspose(RK002_paramGet(TRANSPOSE));
- }
- void RK002_onParamChange(unsigned param_nr, int param_val)
- {
- updateParams();
- }
- bool RK002_onNoteOff(byte chn, byte note, byte velocity)
- {
- bool thru = true;
- if (chn == midichn)
- {
- arp.inputNote(note,0); // velo 0 = note off
- thru=false;
- }
- return thru;
- }
- bool RK002_onNoteOn(byte chn, byte note, byte velocity)
- {
- bool thru = true;
- if (chn == midichn)
- {
- if(buttons[1]==true){
- thru=false;
- byte cmd=note % 12;
- if(cmd==0){
- octmin++;
- octmin=octmin%4;
- arp.setOctaveMin(-1*octmin);
- RK002_paramSet(OCTAVE_MIN,-1*octmin);
- }
- if(cmd==1){
- octmax++;
- octmax=octmax%4;
- arp.setOctaveMax(octmax);
- RK002_paramSet(OCTAVE_MAX,octmax);
- }
- if(cmd==2){
- clockdiv++;
- clockdiv=clockdiv%5;
- clockdiv++;
- arp.setClockLength(clockdiv);
- RK002_paramSet(CLOCKLENGTH,clockdiv);
- }
- if(cmd==3){
- arpmode++;
- arpmode=arpmode%5;
- arpmode++;
- arp.setMode(arpmode);
- RK002_paramSet(MODE,arpmode);
- }
- if(cmd==4){
- gatelen++;
- gatelen=gatelen%15;
- gatelen++;
- arp.setGateCode(gatelen);
- RK002_paramSet(GATELENGTH,gatelen);
- }
- if(cmd==5){
- holdmode++;
- holdmode=holdmode%2;
- arp.setHold(holdmode==1);
- }
- }else{
- arp.inputNote(note,velocity);
- thru=false;
- }
- }
- return thru;
- }
- bool RK002_onClock()
- {
- arp.inputClock();
- return true;
- }
- void onArpOutput(void *userarg, byte key, byte vel)
- {
- if(!vel){
- RK002_sendNoteOff(midichn,key,100);
- }else{
- RK002_sendNoteOn(midichn,key,vel);
- }
- }
- void RK002_onHeartBeat() // we use heartbeat for button scanning with debouncing
- {
- // is timer running (button scanned) ?
- if (heartbeattmr > 0)
- {
- heartbeattmr--;
- if (heartbeattmr == 0)
- {
- if(!digitalRead(BUTTON1)){
- arp.setMode(0);
- buttons[0]=true;
- }else{
- buttons[0]=false;
- }
- if(!digitalRead(BUTTON2)){
- arp.setMode(RK002_paramGet(MODE));
- buttons[1]=true;
- }else{
- buttons[1]=false;
- }
- heartbeattmr=WAITTIME;
- }
- //end hbtimertimeout
- }
- // end hbtimer
- }
- void setup()
- {
- RK002_clockSetMode(0);// 0=auto clock, 1=only internal, 2=only external
- updateParams();
- pinMode(BUTTON1,INPUT_PULLUP); // button 1 black input
- pinMode(BUTTON2,INPUT_PULLUP); // button 2 red input
- heartbeattmr=WAITTIME;
- arp.setOutputHandler(onArpOutput,0);
- }
- void loop()
- {
- }
Add Comment
Please, Sign In to add comment