Advertisement
oshkoshbagoshh

LPX-Scripter-in-scale

Jul 29th, 2023
960
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. With Scripter, you can use JavaScript to create your own custom MIDI processing
  3. effects, including slider controls for real-time interaction.
  4.  
  5. For detailed information about using Scripter, including code samples,
  6. see the MIDI plug-ins chapter of the Logic Pro X Effects or
  7. MainStage 3 Effects manual.
  8. */
  9.  
  10.  
  11. /*
  12.  * @Author: AJ Javadi
  13.  * @Email: amirjavadi25@gmail.com
  14.  * @Date: 2023-07-29 11:33:21
  15.  * @Last Modified by:  
  16.  * @Last Modified time: 2023-07-29 11:33:21
  17.  * @Description: In-scale-script
  18.  *
  19.  
  20. // example: simple pass through and MIDI monitor
  21.  
  22. // map out the scale degreess for major and minor scales
  23.  
  24. Major Scale Relationship:
  25. (W-W-H-W-W-W-H)
  26.  
  27. // major scale
  28. // 0 2 4 5 7 9 11
  29.  
  30.  
  31. Minor Scale Relationship:
  32. (W-H-W-W-H-W-W)
  33. // minor scale
  34. // 0 2 3 5 7 8 10
  35.  
  36.  
  37. // 0 = C
  38. // 1 = C#
  39. // 2 = D
  40. // 3 = D#
  41. // 4 = E
  42. // 5 = F
  43. // 6 = F#
  44. // 7 = G
  45. // 8 = G#
  46. // 9 = A
  47. // 10 = A#
  48. // 11 = B
  49. //12 = H    // H# is the same as C but one octave higher
  50.  
  51. */
  52.  
  53. function HandleMIDI(event)
  54. {
  55.     event.trace();
  56.     event.send();
  57. }
  58. const majorMinorMap = [
  59.     [0, 0, 2, 2, 4, 5, 5, 7, 7, 9, 9, 11],
  60.     [0, 0, 2, 2, 3, 5, 5, 7, 7, 8, 8, 10],
  61. ];
  62. var PluginParameters = [
  63.     {
  64.         name: "Root Note",
  65.         type: "menu",
  66.         valueStrings: ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "H", "H#"],
  67.         defaultValue: 0,
  68.     },
  69.     {
  70.         name: "Octave Offset",
  71.         type: "lin",
  72.         minValue: -2,
  73.         maxValue: 2,
  74.         defaultValue: 0,
  75.         numberOfSteps: 4,
  76.     },
  77.     {
  78.         name: "Scale Type",
  79.         type: "menu",
  80.         valueStrings: ["Major", "Minor"],
  81.         defaultValue: 0,
  82.     },
  83.     {
  84.         name: "Fixed Velocity",
  85.         type: "lin",
  86.         minValue: 0,
  87.         maxValue: 127,
  88.         defaultValue: 0,
  89.         numberOfSteps: 127,
  90.     },
  91.     {
  92.         name: "MIDI Channel",
  93.         type: "lin",
  94.         minValue: 1,
  95.         maxValue: 16,
  96.         defaultValue: 3,
  97.         numberOfSteps: 15,
  98.     },
  99. ];
  100.  
  101. function HandleMIDI(event) {
  102.     if (event.channel === GetParameter("MIDI Channel") && typeof event.pitch === "number") {
  103.         const octave = Math.floor(event.pitch / 12);
  104.         const mappedNote = majorMinorMap[GetParameter("Scale Type")][event.pitch % 12];
  105.         event.pitch = mappedNote + (GetParameter("Octave Offset") + octave) * 12 + GetParameter("Root Note");
  106.         event.channel = 1;
  107.         if (GetParameter("Fixed Velocity") > 0) {
  108.             event.velocity = GetParameter("Fixed Velocity");
  109.         }
  110.     }
  111.     event.send();
  112. }
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement