Monkeymonkey35 Posted April 3, 2018 Share Posted April 3, 2018 This is directly from Tutorial Script 8. It does convert every note to C3, however it leaves hanging notes instead of sending the Noteoff. What am I missing? //Replace every MIDI event received with a C3 notes on/off //Tip: you can use the JavaScript "new" keyboard to generate a new instance of an //Event object of any type. var NeedsTimingInfo = true; //needed for .sendAfterBeats() to work function HandleMIDI(event) { var on = new NoteOn; //make a new note on on.pitch = 60; //set it's pitch to C3 on.send(); //send the note var off = new NoteOff(on); //make a note off using the note on to initialize //it's pitch value (to C3) off.sendAfterBeats(1); //send a note off one beat later } Quote Link to comment Share on other sites More sharing options...
Eric Cardenas Posted April 3, 2018 Share Posted April 3, 2018 Looks broken here too. Try this instead: //Replace every MIDI event received with a C3 notes on/off //Tip: you can use the JavaScript "new" keyboard to generate a new instance of an //Event object of any type. var NeedsTimingInfo = true; //needed for .sendAfterBeats() to work function HandleMIDI(event) { var pos = event.beatPos; //keep track of current position var on = new NoteOn; //make a new note on on.pitch = 60; //set it's pitch to C3 on.send(); //send the note var off = new NoteOff(on); //make a note off using the note on to initialize //it's pitch value (to C3) off.sendAfterBeats(1 + pos); //send a note off one beat later } Quote Link to comment Share on other sites More sharing options...
Monkeymonkey35 Posted April 3, 2018 Author Share Posted April 3, 2018 Hmm, that adds a very quick delay (or tremolo reattack if you hold the note), but doesn't delay the note. Even very high values in off.sendAfterBeats(1 + pos); don't seem to change anything. Quote Link to comment Share on other sites More sharing options...
Eric Cardenas Posted April 3, 2018 Share Posted April 3, 2018 Did you copy everything or just that line? Quote Link to comment Share on other sites More sharing options...
Dewdman42 Posted April 4, 2018 Share Posted April 4, 2018 (edited) Here is my take: var NeedsTimingInfo = true; function HandleMIDI(event) { if(event instanceof NoteOn) { event.pitch = 60; event.send(); event.velocity = 0; event.sendAfterBeats(1); } else { event.send(); } } Edited April 4, 2018 by Dewdman42 Quote Link to comment Share on other sites More sharing options...
Monkeymonkey35 Posted April 4, 2018 Author Share Posted April 4, 2018 hmm! neither version seemed to work. (Eric - I tried the full script). Quote Link to comment Share on other sites More sharing options...
Dewdman42 Posted April 4, 2018 Share Posted April 4, 2018 see above more complete Quote Link to comment Share on other sites More sharing options...
Monkeymonkey35 Posted April 4, 2018 Author Share Posted April 4, 2018 Hmm, yup, still nothing. Just in case, I tried on an old computer with 10.3.3, in addition to 10.4.1. Quote Link to comment Share on other sites More sharing options...
Eric Cardenas Posted April 4, 2018 Share Posted April 4, 2018 That's strange it works fine here: Thanks to Dewdman I understand why it was not working in the first place. Looks broken here too. I have modified the script to reflect the change. I only added this line, otherwise the beatPos property would always be at 0: off.beatPos = event.beatPos; Here's a new script to try out: var NeedsTimingInfo = true; function HandleMIDI(event) { let on = new NoteOn; on.pitch = 60; on.send(); let off = new NoteOff(on); off.beatPos = event.beatPos; off.sendAfterBeats(1); } This should now work with any event you throw at it. Whether it is Notes or CC's. Quote Link to comment Share on other sites More sharing options...
Dewdman42 Posted April 4, 2018 Share Posted April 4, 2018 yes if you want all midi events converted to c3 note on that’s the way to go. You can make the script a tiny bit more efficient by avoiding creating a new noteoff event. Just reuse the “on” object, set the velocity to zero and send it again after one beat. Quote Link to comment Share on other sites More sharing options...
Eric Cardenas Posted April 4, 2018 Share Posted April 4, 2018 Yes. I saw that on your script. Very smart. Thanks D! Quote Link to comment Share on other sites More sharing options...
Monkeymonkey35 Posted April 4, 2018 Author Share Posted April 4, 2018 Thanks guys for hanging in there with me. It looks like this script is behaving differently on our respective computers. (something wrong with my JS library maybe?) The NoteOff segment works just fine, I can adjust that without issues. The NoteOn always sends two events. (GIF below) The following delays those two NoteOns (they still occur the same distance from each other): let on = new NoteOn; on.pitch = 60; on.beatPos = event.beatPos; on.sendAfterBeats(4); Quote Link to comment Share on other sites More sharing options...
Eric Cardenas Posted April 4, 2018 Share Posted April 4, 2018 That’s because the script is creating 1 on and one off event for every event. In your case you have a note that is sending a note on and off message by itself. The note on message triggers a new on and a new off (a beat delayed), then the off message creates an additional on and off(a beat delayed) message. Hope that makes sense. Quote Link to comment Share on other sites More sharing options...
Monkeymonkey35 Posted April 4, 2018 Author Share Posted April 4, 2018 Eric, yes, crystal clear. My misunderstanding, I expected a single note x beats later. let on = event; //accomplishes that. Thanks again 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.