Danny Wyatt Posted December 10, 2023 Share Posted December 10, 2023 (edited) I have these 4 Scripters in series to control my Alesis drum kit. They work together, but once I merge them as 1 Scripter, it stops working. A while ago I was learning a bit of Javascript and I can still understand a few things, but it's one of those things that if you don't use it on a regular basis, you tend to forget a few details. This is the 4 Scripters together (I just copied each script one after there other). There's 4 comments (First Scripter, Second Scripter, Third Scripter, Forth Scripter) so it's easy to see where it starts and ends. //FIRST SCRIPTER // Velocity Range Convertion function HandleMIDI(event) { if (event instanceof Note && event.pitch == 38) { event.velocity = (event.velocity-29) * 1.2959 } event.trace(); event.send(); } //SECOND SCRIPTER // Crash choke function HandleMIDI(event) { if (event instanceof PolyPressure) { if (event.pitch == 49 && event.value == 127) { // The number 49 might be different on different drum modules. If so, use one of the two pitches when you choke your crash. It is of the type of PolyPressure. var event = new NoteOn; event.channel = 10; event.pitch = 28; event.velocity = 1; event.trace(); event.send(); var of = new NoteOff(event); of.trace(); of.send(); } else if (event.pitch == 57 && event.value == 127) { var event = new NoteOn; event.channel = 10; event.pitch = 29; event.velocity = 1; event.trace(); event.send(); var of = new NoteOff(event); of.trace(); of.send(); } } else { event.send(); } } //THIRD SCRIPTER // Note based on velocity - Ride Bell variables var ridePitch1 = MIDI.noteNumber("D#2"); var ridePitch2 = MIDI.noteNumber("F2"); var lastRidePitch = ridePitch1; // Note based on velocity - Snare rimshot variables var snareHead = MIDI.noteNumber("D1"); var rimshot = MIDI.noteNumber("E1"); var lastSnarePitch = snareHead; // HiHat Articulation Variables var ModWheelHiHatArticulation = new ControlChange; ModWheelHiHatArticulation.number = 1; function HandleMIDI(event) { // Note based on velocity - Ride Bell if (event instanceof NoteOn && event.pitch == ridePitch1) { if(event.velocity > 100) { event.pitch = ridePitch2; lastRidePitch = ridePitch2; } else { lastRidePitch = ridePitch1; } } else if (event instanceof NoteOff && event.pitch == ridePitch1) { event.pitch = lastRidePitch; } event.trace(); // Note based on velocity - Snare rimshot if(event instanceof NoteOn && event.pitch == snareHead) { if(event.velocity > 120) { event.pitch = rimshot; lastSnarePitch = rimshot; } else { lastSnarePitch = snareHead; } } else if (event instanceof NoteOff && event.pitch == snareHead) { event.pitch = lastSnarePitch; } event.trace(); // Compression on sidestick if (event instanceof Note && event.pitch == 37) { event.velocity = event.velocity * (GetParameter (1) - GetParameter (0)) / 127 + GetParameter (0); } event.trace(); //HiHat Articulation ModWheelHiHatArticulation.channel = event.channel; //HiHat Articulation - Closed HiHat if (event instanceof Note && event.pitch == 42 && event.velocity <=110) { ModWheelHiHatArticulation.value = 1; } else if (event instanceof Note && event.pitch == 42 && event.velocity >=111) { ModWheelHiHatArticulation.value = 50; } //HiHat Articulation - Open HiHat if (event instanceof Note && event.pitch == 46) { ModWheelHiHatArticulation.value = 127; } //Foot Pedal Swap if (event instanceof Note && event.pitch == 44) { event.pitch = 33; } ModWheelHiHatArticulation.send(); ModWheelHiHatArticulation.trace(); event.send(); } var PluginParameters = [ { name:"Sidestick Min Velocity", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:0, }, { name:"Sidestick Max Velocity", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:26, } ] //FORTH SCRIPTER // Rimshot Round Robin var toggleRimshot = false; var snareRimshot1 = MIDI.noteNumber("E1"); var snareRimshot2 = MIDI.noteNumber("G#0"); function HandleMIDI(event) { if(event instanceof NoteOn && event.pitch == snareRimshot1) { event.pitch = getPitch(event); } else if (event instanceof NoteOff && event.pitch == snareRimshot1) { event.send(); event.pitch = snareRimshot2; } event.send(); event.trace(); } function getPitch(event) { if(toggleRimshot == true) { toggleRimshot = false; return snareRimshot2; } else { toggleRimshot = true; return snareRimshot1; } event.trace(); } If you can help me with some tips, that would be great! When I was trying to merge them I did the following, but some stuff stopped working anyway, while some was still working: 1 - I put all variables at the top, just to make it easier to see what they are. I'm not sure if that makes a difference? 2 - Since there are multiple "function HandleMIDI(event)" I grabbed all code that was inside those multiple "function HandleMIDI(event)" instances and put them all inside a single "function HandleMIDI(event)" (hope it's making sense...). I did this, because I assumed I can't have more than one of those inside a single script? Maybe I'm wrong about that. Or maybe I can use more than 1, as long as I call the first one "event", then the second one "event2", etc? 3 - Then there are 2 separate sections that I put at the bottom, but again, it doesn't work 100%. These sections are var PluginParameters = [ { name:"Sidestick Min Velocity", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:0, }, { name:"Sidestick Max Velocity", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:26, } ] And function getPitch(event) { if(toggleRimshot == true) { toggleRimshot = false; return snareRimshot2; } else { toggleRimshot = true; return snareRimshot1; } event.trace(); } So I ended up with this: //All Variables // Note based on velocity - Ride Bell variables var ridePitch1 = MIDI.noteNumber("D#2"); var ridePitch2 = MIDI.noteNumber("F2"); var lastRidePitch = ridePitch1; // Note based on velocity - Snare rimshot variables var snareHead = MIDI.noteNumber("D1"); var rimshot = MIDI.noteNumber("E1"); var lastSnarePitch = snareHead; // HiHat Articulation variables var ModWheelHiHatArticulation = new ControlChange; ModWheelHiHatArticulation.number = 1; // Rimshot Round Robin variables var toggleRimshot = false; var snareRimshot1 = MIDI.noteNumber("E1"); var snareRimshot2 = MIDI.noteNumber("G#0"); function HandleMIDI(event) { // Velocity Range Convertion if (event instanceof Note && event.pitch == 38) { event.velocity = (event.velocity-29) * 1.2959 } event.trace(); event.send(); // Crash choke if (event instanceof PolyPressure) { if (event.pitch == 49 && event.value == 127) { // The number 49 might be different on different drum modules. If so, use one of the two pitches when you choke your crash. It is of the type of PolyPressure. var event = new NoteOn; event.channel = 10; event.pitch = 28; event.velocity = 1; event.trace(); event.send(); var of = new NoteOff(event); of.trace(); of.send(); } else if (event.pitch == 57 && event.value == 127) { var event = new NoteOn; event.channel = 10; event.pitch = 29; event.velocity = 1; event.trace(); event.send(); var of = new NoteOff(event); of.trace(); of.send(); } } else { event.send(); } // Note based on velocity - Ride Bell if (event instanceof NoteOn && event.pitch == ridePitch1) { if(event.velocity > 100) { event.pitch = ridePitch2; lastRidePitch = ridePitch2; } else { lastRidePitch = ridePitch1; } } else if (event instanceof NoteOff && event.pitch == ridePitch1) { event.pitch = lastRidePitch; } event.trace(); // Note based on velocity - Snare rimshot if(event instanceof NoteOn && event.pitch == snareHead) { if(event.velocity > 120) { event.pitch = rimshot; lastSnarePitch = rimshot; } else { lastSnarePitch = snareHead; } } else if (event instanceof NoteOff && event.pitch == snareHead) { event.pitch = lastSnarePitch; } event.trace(); // Compression on sidestick if (event instanceof Note && event.pitch == 37) { event.velocity = event.velocity * (GetParameter (1) - GetParameter (0)) / 127 + GetParameter (0); } event.trace(); //HiHat Articulation ModWheelHiHatArticulation.channel = event.channel; //HiHat Articulation - Closed HiHat if (event instanceof Note && event.pitch == 42 && event.velocity <=110) { ModWheelHiHatArticulation.value = 1; } else if (event instanceof Note && event.pitch == 42 && event.velocity >=111) { ModWheelHiHatArticulation.value = 50; } //HiHat Articulation - Open HiHat if (event instanceof Note && event.pitch == 46) { ModWheelHiHatArticulation.value = 127; } //Foot Pedal Swap if (event instanceof Note && event.pitch == 44) { event.pitch = 33; } ModWheelHiHatArticulation.send(); ModWheelHiHatArticulation.trace(); event.send(); // Rimshot Round Robin if(event instanceof NoteOn && event.pitch == snareRimshot1) { event.pitch = getPitch(event); } else if (event instanceof NoteOff && event.pitch == snareRimshot1) { event.send(); event.pitch = snareRimshot2; } event.send(); event.trace(); } // Rimshot Round Robin function getPitch(event) { if(toggleRimshot == true) { toggleRimshot = false; return snareRimshot2; } else { toggleRimshot = true; return snareRimshot1; } event.trace(); } //Sidestick sliders var PluginParameters = [ { name:"Sidestick Min Velocity", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:0, }, { name:"Sidestick Max Velocity", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:26, } ] Again, some things are working, but not all. For example the HiHat is acting weird and I'm not 100% sure that the rimshot section is being triggered (round robin). I just wanted to have everything in 1 place to avoid having 4 Scripters, especially because I want to add a few more things, and it's a pain to open each and try to track what I'm doing. After a while, it's a big mess. Any help would be greatly appreciated. Edited December 10, 2023 by Danny Wyatt Quote Link to comment Share on other sites More sharing options...
Danny Wyatt Posted December 10, 2023 Author Share Posted December 10, 2023 UPDATE After a lot of trial and error I was able to make it work with just 2 Scripter instances, which is already a good thing. Now I can't merge them, because the snare's round robin, won't work. So scripter 1: //VARIABLES // Note based on velocity - Ride Bell variables var ridePitch1 = MIDI.noteNumber("D#2"); var ridePitch2 = MIDI.noteNumber("F2"); var lastRidePitch = ridePitch1; // HiHat Articulation variables var ModWheelHiHatArticulation = new ControlChange; ModWheelHiHatArticulation.number = 1; function HandleMIDI(event) { // Snare Velocity Range Conversion if (event instanceof Note && event.pitch == 38) { event.velocity = (event.velocity-29) * 1.2959 } // Crash 1 Choke if (event instanceof PolyPressure) { if (event.pitch == 49 && event.value == 127) { // The number 49 might be different on different drum modules. If so, use one of the two pitches when you choke your crash. It is of the type of PolyPressure. var event = new NoteOn; event.channel = 10; event.pitch = 28; event.velocity = 1; event.trace(); event.send(); var of = new NoteOff(event); of.trace(); of.send(); } else if (event.pitch == 57 && event.value == 127) { var event = new NoteOn; event.channel = 10; event.pitch = 29; event.velocity = 1; event.trace(); event.send(); var of = new NoteOff(event); of.trace(); of.send(); } } else { //event.send(); event.trace(); } // Note based on velocity - Ride Bell if (event instanceof NoteOn && event.pitch == ridePitch1) { if(event.velocity > 100) { event.pitch = ridePitch2; lastRidePitch = ridePitch2; } else { lastRidePitch = ridePitch1; } } else if (event instanceof NoteOff && event.pitch == ridePitch1) { event.pitch = lastRidePitch; } event.trace(); // Compression on sidestick if (event instanceof Note && event.pitch == 37) { event.velocity = event.velocity * (GetParameter (1) - GetParameter (0)) / 127 + GetParameter (0); } event.trace(); //HiHat Articulation ModWheelHiHatArticulation.channel = event.channel; //HiHat Articulation - Closed HiHat if (event instanceof Note && event.pitch == 42 && event.velocity <=110) { ModWheelHiHatArticulation.value = 1; } else if (event instanceof Note && event.pitch == 42 && event.velocity >=111) { ModWheelHiHatArticulation.value = 50; } //HiHat Articulation - Open HiHat if (event instanceof Note && event.pitch == 46) { ModWheelHiHatArticulation.value = 127; } //Foot Pedal Swap if (event instanceof Note && event.pitch == 44) { event.pitch = 33; } ModWheelHiHatArticulation.send(); ModWheelHiHatArticulation.trace(); event.send(); } var PluginParameters = [ { name:"Sidestick Min Velocity", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:0, }, { name:"Sidestick Max Velocity", type:"lin", minValue:0, maxValue:127, numberOfSteps:127, defaultValue:26, } ] Then after that, Scripter 2: // Note based on velocity - Snare rimshot variables var snareHead = MIDI.noteNumber("D1"); var rimshot = MIDI.noteNumber("E1"); var lastSnarePitch = snareHead; // Rimshot Round Robin var toggleRimshot = false; var snareRimshot1 = MIDI.noteNumber("E1"); var snareRimshot2 = MIDI.noteNumber("G#0"); function HandleMIDI(event) { // Note based on velocity - Snare rimshot if(event instanceof NoteOn && event.pitch == snareHead) { if(event.velocity > 120) { event.pitch = rimshot; lastSnarePitch = rimshot; } else { lastSnarePitch = snareHead; } } else if (event instanceof NoteOff && event.pitch == snareHead) { event.pitch = lastSnarePitch; } event.trace(); if(event instanceof NoteOn && event.pitch == snareRimshot1) { event.pitch = getPitch(event); } else if (event instanceof NoteOff && event.pitch == snareRimshot1) { event.send(); event.pitch = snareRimshot2; } event.send(); event.trace(); } function getPitch(event) { if(toggleRimshot == true) { toggleRimshot = false; return snareRimshot2; } else { toggleRimshot = true; return snareRimshot1; } event.trace(); } Any idea how to merge these 2? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.