Tiago Rocha Posted December 30, 2023 Share Posted December 30, 2023 I have this simple script. I am able to play like 10 notes, then after that, no sound, even though I can see that the notes are being shown at the bottom: What's wrong with the script? Quote Link to comment Share on other sites More sharing options...
Jordi Torres Posted December 30, 2023 Share Posted December 30, 2023 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. Quote Link to comment Share on other sites More sharing options...
Tiago Rocha Posted December 30, 2023 Author Share Posted December 30, 2023 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"? Quote Link to comment Share on other sites More sharing options...
Jordi Torres Posted December 30, 2023 Share Posted December 30, 2023 (edited) 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 December 30, 2023 by Jordi Torres 1 Quote Link to comment Share on other sites More sharing options...
Tiago Rocha Posted December 30, 2023 Author Share Posted December 30, 2023 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! 1 Quote Link to comment Share on other sites More sharing options...
Atlas007 Posted January 3 Share Posted January 3 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? Quote Link to comment Share on other sites More sharing options...
Jordi Torres Posted January 3 Share Posted January 3 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. 2 Quote Link to comment Share on other sites More sharing options...
Atlas007 Posted January 3 Share Posted January 3 (edited) 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 January 3 by Atlas007 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.