Jump to content

Should I add this only once per script? [SOLVED]


Danny Wyatt

Recommended Posts

UPDATE: Answer is here: viewtopic.php?f=45&t=162734#p853966

---

 

I'm trying to merge 5 different scripts, and all of them start with

function HandleMIDI(event) {

 

When merging them all into 1 single script, should I add that line over and over again, or should that work as a container for the whole script?

Looking at some factory presets it seems that function HandleMIDI(event) only shows up once for each script...

Link to comment
Share on other sites

So I was able to merge 4 of the scripts and everything is working so far. Anyone willing to look into it and see if there's something I should write differently or something?

// 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("G#0");
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,
}
]

 

Now when I try to add the last script, for a crash choke, everything works, but the section on the original script dedicated to the ride having 2 sounds based on velocity, acts weird, meaning, I get the bell sound, but if I play another ride note, it stops the bell sound. Here the script for the crash choke if anyone can help me merge this as well:

// 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();
  }
}

Link to comment
Share on other sites

You got the first question right...there should be only one instance of HandleMIDI function in your script. let me explain what that function is. That is called a "callback function". Its called that because LogicPro calls it back at certain times decided by LogicPro. In this case, it is called back by Logic Pro for each midi event that comes through that instrument channel where Scripter is being hosted.

 

So you define this callback function once and put whatever code you to process each midi event in there, as you have done.

 

You can make your code a little more organized by still using seperate functions for different kinds of midi events, instead of one giant if statement with complex nested curly braces... Sometimes that can make it easier to keep track of each case a little easier...

 

Its hard for me to know what are all the things you are trying to accomplish in your script to know why it still "acts weird"....

 

I see you are using PolyPressure, is that true, your kit really does support PolyPressure?

Link to comment
Share on other sites

You got the first question right...there should be only one instance of HandleMIDI function in your script. let me explain what that function is. That is called a "callback function". Its called that because LogicPro calls it back at certain times decided by LogicPro. In this case, it is called back by Logic Pro for each midi event that comes through that instrument channel where Scripter is being hosted.

 

So you define this callback function once and put whatever code you to process each midi event in there, as you have done.

 

You can make your code a little more organized by still using seperate functions for different kinds of midi events, instead of one giant if statement with complex nested curly braces... Sometimes that can make it easier to keep track of each case a little easier...

 

Its hard for me to know what are all the things you are trying to accomplish in your script to know why it still "acts weird"....

 

I see you are using PolyPressure, is that true, your kit really does support PolyPressure?

 

Thanks for clarifying the HandleMIDI function ;)

 

Regarding the PolyPressure: yes, the code for the crash choke works when it's on a separate Scripter instance, meaning, right now I have 3 Scripter instances:

1 - That first, long one

2 - The crash choke

3 - That last script with the rimshot going back and forth E1 <> G#0 (I will try and see how to merge this into the first one.

 

So when I try to merge 1 and 2, it's when the ride's bell "chokes". So there's something in there that's causing that. I tried renaming "event" to something else, because maybe it was creating some kind of conflict with something else, but no luck.

That code was copied from another user here on the forum and it's a bit complex for me at the moment, so I can't really say what could be changed, but I will for now try to merge 1 and 3 first and if everything's working with only 2 instances of Scripter, it's already a good step. Then I will see if I can figure out the issue with the crash choke. If anything I will reach out to you, if you don't mind ;)

 

And thanks. The basic scripting is not that hard, specially because I've been working with HTML and CSS for like 20 years here and there and eventually some PHP would pop up as well (while using Wordpress) so a language like Javascript is not something 100% unfamiliar, but still a new language to learn ;)

I appreciate the support!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...