Jump to content

Scripter lets notes play for a while and then stops working


Tiago Rocha

Recommended Posts

Hi Tiago,

There's nothing necessarily wrong with the script, except for the fact that you're only handling Note On events (and ignoring their corresponding Note Offs). If you are triggering an instrument with all those Note Ons and no Note Offs, maybe you're "choking it". 

Try changing your script to check for instances of Note events so that both Note Ons and Note Offs are handled?

J.

Link to comment
Share on other sites

6 hours ago, Jordi Torres said:

Hi Tiago,

There's nothing necessarily wrong with the script, except for the fact that you're only handling Note On events (and ignoring their corresponding Note Offs). If you are triggering an instrument with all those Note Ons and no Note Offs, maybe you're "choking it". 

Try changing your script to check for instances of Note events so that both Note Ons and Note Offs are handled?

J.

What's weird is that I have this other script that doesn't deal with Note Off, and it works without stopping:

 

var NOTES = MIDI._noteNames;

function HandleMIDI(event)
{
	if (event instanceof NoteOn && event.pitch != GetParameter('Note')) {
		return undefined;  // don't send if it's not the pitch defined by the menu
	}

	else {
		event.send();
	}
}

var PluginParameters = [
	{	name:'Note',
		type:'menu',
		valueStrings:NOTES,
		numberOfSteps:127,
		defaultValue:30}
];

By the way, I don't know if this makes any difference, but these are drum hits, not sustain notes, so there's fewer changes of it "choking", right?

Anyway, I'm not an expert when it comes to the Scripter. Do you mind sharing an example of what you mean by "Try changing your script to check for instances of Note events so that both Note Ons and Note Offs are handled"?

Link to comment
Share on other sites

Hi Tiago,

43 minutes ago, Tiago Rocha said:

By the way, I don't know if this makes any difference, but these are drum hits, not sustain notes, so there's fewer changes of it "choking", right?

I guess it would depend on the instrument, personally I would send both Note Ons and Note Offs by default if an instrument that's meant to play some sounds is on the receiving end. Exactly what instrument is producing the drum hits?

43 minutes ago, Tiago Rocha said:

What's weird is that I have this other script that doesn't deal with Note Off, and it works without stopping

Well, in that script you're actually allowing all events to be sent, except Note Ons that don't match the note in the menu. So that means the Note Off that corresponds to the note in the menu is being sent (and also Note Offs of other notes, and CCs, Pitch Bend, etc).

43 minutes ago, Tiago Rocha said:

Anyway, I'm not an expert when it comes to the Scripter. Do you mind sharing an example of what you mean by "Try changing your script to check for instances of Note events so that both Note Ons and Note Offs are handled"?

Here you go, it's a very minor modification to yours:

function HandleMIDI(event) {
  if (event instanceof Note && event.pitch === 38) {
    event.send();
    event.trace();
  }	
}

J.

Edited by Jordi Torres
  • Like 1
Link to comment
Share on other sites

9 minutes ago, Jordi Torres said:

Exactly what instrument is producing the drum hits

Alesis Surge Drum Kit

 

11 minutes ago, Jordi Torres said:

Well, in that script you're actually allowing all events to be sent, except Note Ons that don't match the note in the menu. So that means the Note Off that corresponds to the note in the menu is being sent (and also Note Offs of other notes, and CCs, Pitch Bend, etc).

Ok I see what you mean.

And thanks for the script. I understand what you meant the first time now. I was being specific by using NoteOn and now by using just Note, it includes both. I will try it tomorrow again and see if it works. Appreciate it!

  • Like 1
Link to comment
Share on other sites

On 12/30/2023 at 5:08 PM, Jordi Torres said:

Here you go, it's a very minor modification to yours:

function HandleMIDI(event) {
  if (event instanceof Note && event.pitch === 38) {
    event.send();
    event.trace();
  }	
}

J.

I noticed in your script you typed 3 equals symbols (...pitch === 38) instead of 2 (...pitch == 38). Is there a reason for same or just a typo?

Link to comment
Share on other sites

Hi Atlas,

6 hours ago, Atlas007 said:

I noticed in your script you typed 3 equals symbols (...pitch === 38) instead of 2 (...pitch == 38). Is there a reason for same or just a typo?

No, that's definitely not a typo. That's a strict equality operator. The difference between it and the the "plain" (or "loose") equality operator ("==") is that with the strict one, both the value and the type of the operands need to be equal otherwise you get false. On the other hand, the "==" will try to convert types and then do the comparison, which in some situations may not give you the expected result. See here for more insight on the topic (I really like the Douglas Crockford quote there from JavaScript: The Good Parts).

In the context of Scripter, comparing a Note event's pitch with a number with either operator will not be a problem, you'll get the same result with both "==" and "===". But personally I always go for "===" even in Scripter as it is a good practice that I adopted through Web development.

BTW, there's also the corresponding strict inequality ("!==") and loose inequality ("!=") operators.

J.

  • Like 2
Link to comment
Share on other sites

32 minutes ago, Jordi Torres said:

Hi Atlas,

No, that's definitely not a typo. That's a strict equality operator. The difference between it and the the "plain" (or "loose") equality operator ("==") is that with the strict one, both the value and the type of the operands need to be equal otherwise you get false. On the other hand, the "==" will try to convert types and then do the comparison, which in some situations may not give you the expected result. See here for more insight on the topic (I really like the Douglas Crockford quote there from JavaScript: The Good Parts).

In the context of Scripter, comparing a Note event's pitch with a number with either operator will not be a problem, you'll get the same result with both "==" and "===". But personally I always go for "===" even in Scripter as it is a good practice that I adopted through Web development.

BTW, there's also the corresponding strict inequality ("!==") and loose inequality ("!=") operators.

J.

Hi Jordi,

Thanx for your response and very informative answer!

I realize that my knowledge in Scripter and JS is pretty limited. And despite reading the references you provided, I confess not grasping too well the nuances demonstrated.

Anyhow, I learned (although superficially) something new today and really appreciate your contribution so same and the time you took to reply to my query.

Best wishes for 2024!

 

Edited by Atlas007
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...