Advertisement
retrokits

RK002 Note remapper example

Jun 15th, 2022 (edited)
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* DUY Code: note remapper */
  2.  
  3. /*
  4.  * Parameters:
  5.  * CHANNEL = channel to listen to 1-16 (1, default, 0 = on all channels (=omni))
  6.  */
  7.  
  8. RK002_DECLARE_PARAM(CHANNEL,1,0,16,1)
  9. RK002_DECLARE_PARAM(REMAPNOTE,1,0,127,65)
  10.  
  11. // DECLARE_PARAM parameters can be stored in the cable and are accessible from the portal without the need to recompile
  12. // you can adjust them via the DUY 'details' button and a MIDI SysEx code can be used to set it as well:
  13. // parameter 0 = F0 00 21 23 00 02 48 00 [paramnr] 00 [val] 00 F7
  14.  
  15. byte dChannel=0; // holds internal midi channel = 0-15
  16. // declare a list of notes to check:
  17. byte noteList[6]={65,67,69,71,72,74};
  18.  
  19. bool RK002_onNoteOn(byte ch,byte key,byte velo){
  20.   bool retval=true; // default = thru notes
  21.   if((ch==16) || (ch==dChannel)){
  22.     for(byte i=0;i<sizeof(noteList);i++){
  23.       if(noteList[i]==key){
  24.         retval=false; // don't send original note
  25.         RK002_sendNoteOn(((8+i) % 15),RK002_paramGet(REMAPNOTE),velo); // send note to ch 9+foundnote in list
  26.         // I added the % 15 in case you make a too-long notelist, this will wrap the midi channel to 0-15 range
  27.         break; // exit loop key search
  28.       }
  29.     }
  30.   }
  31.   return retval;
  32. }
  33.  
  34. // as in note on, but now for note off
  35. bool RK002_onNoteOff(byte ch,byte key,byte velo){
  36.   bool retval=true; // default = thru notes
  37.   if((ch==16) || (ch==dChannel)){
  38.     for(byte i=0;i<sizeof(noteList);i++){
  39.       if(noteList[i]==key){
  40.         retval=false;
  41.         RK002_sendNoteOff(((8+i) % 15),RK002_paramGet(REMAPNOTE),velo);
  42.         break;
  43.       }
  44.     }
  45.   }
  46.   return retval;
  47. }
  48. // called on start and on param change from exchange portal
  49. void updateParams(){
  50.   // need to decrement the parameter for readable - programming conversion; ch 0-15 = 1-16 un human read
  51.   dChannel = (RK002_paramGet(CHANNEL)>0) ? RK002_paramGet(CHANNEL)-1 : 16;
  52. }
  53. void RK002_onParamSet(unsigned param_nr, int val){
  54.   updateParams();
  55. }
  56.  // initialize
  57. void setup()
  58. {  
  59.   updateParams();
  60. }
  61.  
  62. // the main loop
  63. void loop()
  64. {
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement