Jump to content

off.sendAfterBeats(1) not sending?


Recommended Posts

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                       
} 

Link to comment
Share on other sites

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                       
} 

Link to comment
Share on other sites

That's strange it works fine here:

 

Notes.gif.54d4080c34bd1bdfc433df25eb422034.gif

 

 

 

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.

Link to comment
Share on other sites

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); 

ScreenFlow.thumb.gif.b957c32473c710b7dfe93c6a58ba780c.gif

Link to comment
Share on other sites

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.

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...