Advertisement
retrokits

Kalimba scale example

May 14th, 2023 (edited)
1,216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.82 KB | Music | 0 0
  1. /*
  2.   Sawyer Monk Kalimba Style Example
  3.   I defined two scales to compare, one the regular scale, and one for the kalimba
  4.   with CC1 (modwheel) you can switch through the scales, off = chromatic, full = kalimba
  5.  
  6.   scale array explanation:
  7.  
  8.   0 - 11 are as follows:
  9.   0  1  2  3  4  5  6  7  8  9  10  11
  10.   C  C# D  D# E  F  F# G  G# A  A#  B
  11.  
  12.   to remap whites:
  13.   C     E     G  B     D     F     A
  14.   written in numbers:
  15.   0     2     7  11    2     5     9
  16.   blacks:
  17.      D     F        C     E     G
  18.   =  2     5        1     4     7
  19.   total array entry:
  20.   0, 2, 2,  5, 7,11, 1, 2, 4,5, 7, 9
  21.  
  22.   now let's duy it!:
  23. */
  24. const byte scales[2][12] = {
  25. {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, // 0 'Chromatic'
  26. {0, 2 ,2, 5, 7, 11,1, 2, 4, 5, 7, 9}, // 1 β€˜Kalimba’  
  27. };
  28.  
  29. byte scale=0;
  30.  
  31. // calculate key octave:
  32. byte octavebyKey(byte key)
  33. {
  34.   if (key == 0)
  35.     return 0;
  36.  
  37.   return (key / 12);
  38. }
  39.  
  40. // calculate scaled key:
  41. byte scaledKey(byte key)
  42. {
  43.   return scales[scale][(key % 12)] + (octavebyKey(key) * 12);
  44. }
  45.  
  46. // check if modwheel is changed:
  47. bool RK002_onControlChange(byte chn, byte nr, byte val)
  48. {
  49.   if (nr == 1) {
  50.     scale=val/126; // low values will give scale value 0, high values will give value 1
  51.     // Send "all notes off" to disable notes being sustained during controller change
  52.     RK002_sendControlChange(chn, 123, 0);
  53.   }
  54.   return true;
  55. }
  56.  
  57. // process note on messages:
  58. bool RK002_onNoteOn(byte chn, byte key, byte vel)
  59. {
  60.   RK002_sendNoteOn(chn, scaledKey(key), vel);
  61.   return false;
  62. }
  63.  
  64. // process note of messages:
  65. bool RK002_onNoteOff(byte chn, byte key, byte vel)
  66. {
  67.   RK002_sendNoteOff(chn, scaledKey(key), vel);
  68.   return false;
  69. }
  70. // .. no other processed needed, next is the compulsory routines
  71. // but these can be empty
  72.  
  73. void setup()
  74. {
  75. }
  76.  
  77. void loop()
  78. {
  79. }
  80.  
Tags: rk002
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement