oshkoshbagoshh icon

LPX-Scripter-in-scale

oshkoshbagoshh | PRO | 07/29/23 04:37:13 PM UTC | 0 ⭐ | 1328 👁️ | Never ⏰ | [JavaScript, scripter, midi, Logic Pro X]
JavaScript |

2.3 KB

|

Music

|

0 👍

/

0 👎

/*
With Scripter, you can use JavaScript to create your own custom MIDI processing 
effects, including slider controls for real-time interaction.
 
For detailed information about using Scripter, including code samples, 
see the MIDI plug-ins chapter of the Logic Pro X Effects or 
MainStage 3 Effects manual.
*/
 
 
/*
 * @Author: AJ Javadi 
 * @Email: [email protected]
 * @Date: 2023-07-29 11:33:21 
 * @Last Modified by:   
 * @Last Modified time: 2023-07-29 11:33:21
 * @Description: In-scale-script
 *
 
// example: simple pass through and MIDI monitor
 
// map out the scale degreess for major and minor scales
 
Major Scale Relationship:
(W-W-H-W-W-W-H)
 
// major scale
// 0 2 4 5 7 9 11
 
 
Minor Scale Relationship:
(W-H-W-W-H-W-W)
// minor scale
// 0 2 3 5 7 8 10
 
 
// 0 = C
// 1 = C#
// 2 = D
// 3 = D#
// 4 = E
// 5 = F
// 6 = F#
// 7 = G
// 8 = G#
// 9 = A
// 10 = A#
// 11 = B
//12 = H    // H# is the same as C but one octave higher
 
*/
 
function HandleMIDI(event)
{
    event.trace();
    event.send();
}
const majorMinorMap = [
    [0, 0, 2, 2, 4, 5, 5, 7, 7, 9, 9, 11],
    [0, 0, 2, 2, 3, 5, 5, 7, 7, 8, 8, 10],
];
var PluginParameters = [
    {
        name: "Root Note",
        type: "menu",
        valueStrings: ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "H", "H#"],
        defaultValue: 0,
    },
    {
        name: "Octave Offset",
        type: "lin",
        minValue: -2,
        maxValue: 2,
        defaultValue: 0,
        numberOfSteps: 4,
    },
    {
        name: "Scale Type",
        type: "menu",
        valueStrings: ["Major", "Minor"],
        defaultValue: 0,
    },
    {
        name: "Fixed Velocity",
        type: "lin",
        minValue: 0,
        maxValue: 127,
        defaultValue: 0,
        numberOfSteps: 127,
    },
    {
        name: "MIDI Channel",
        type: "lin",
        minValue: 1,
        maxValue: 16,
        defaultValue: 3,
        numberOfSteps: 15,
    },
];
 
function HandleMIDI(event) {
    if (event.channel === GetParameter("MIDI Channel") && typeof event.pitch === "number") {
        const octave = Math.floor(event.pitch / 12);
        const mappedNote = majorMinorMap[GetParameter("Scale Type")][event.pitch % 12];
        event.pitch = mappedNote + (GetParameter("Octave Offset") + octave) * 12 + GetParameter("Root Note");
        event.channel = 1;
        if (GetParameter("Fixed Velocity") > 0) {
            event.velocity = GetParameter("Fixed Velocity");
        }
    }
    event.send();
}
 

Comments