Old 06-22-2016, 12:59 PM   #1
DruMunkey
Human being with feelings
 
Join Date: Feb 2016
Posts: 232
Default Convert toggled notes to on/off?

Man, I'm just having a hard time wrapping my head around the JS stuff... It's the midirecv(offset,msg1,msg23) stuff. It seems so overly complex, no two scripts seem to trat converting these messages into notes, channels, etc. the same, so trying to take bits of one code and mix them is a pain... Any, rant off...

Here's what I'm trying to do now:

Some buttons on my controller are by default latched. So I press a button, it works like this:

(From ReaControlMIDI log)

Press:
288: 90 3A 7F [Note On] chan 1 note 58 vel 127

Press again:
289: 80 3A 7F [Note Off] chan 1 note 58 offvel 127

I need a simple JS that will, for a slider selected midi note, send noteon AND noteoff each time it gets _either_ a noteon or a noteoff. Then I can map these notes to LEARN's toggle mode.


I've ALMOST got it, but I can't figure out how to send note on.. Again, these msg things + the hex + the operators I'm not used to... Ugh...

This works, but it sends noteoff 2x the second time, not noteon then note off...

Here's the output if I have note 60 in slider and press middle "C":

68: 90 3C 42 [Note On] chan 1 note 60 vel 66
69: 80 3C 42 [Note Off] chan 1 note 60 offvel 66
70: 90 3C 00 [Note Off] chan 1 note 60 <---- why is it sending note off here? and why is there no velocity info in this second send that goes out on noteoff?
71: 80 3C 00 [Note Off] chan 1 note 60

What's the way to send a status message for noteon?

Code:
desc:note toggle converter

slider1:0<0,15,1{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}>Input Channel
slider2:0<0,127,1>Midi Note

@init

NoteOn = $x90;
NoteOff = $x80;
mod_note=slider2;


@slider
mod_note=slider2;
mod_channel=slider1;

@block
while
(
  midirecv(offset, msg1, msg23) ?
  (  
    // Extract message type and channel
    status = msg1 & $xF0;
    channel = msg1 & $x0F;
      
        // Extract note value
        note = msg23 & $x7F;
        note == mod_note && channel==mod_channel ? (
        midisend(offset,NoteOn, note);        
        midisend(offset,NoteOff, note);        
        ) : midisend(offset, msg1, msg23);
  );
);
DruMunkey is offline   Reply With Quote
Old 06-22-2016, 11:04 PM   #2
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,652
Default

Quote:
Originally Posted by DruMunkey View Post
What's the way to send a status message for noteon?
This:

Code:
midisend(offset,NoteOn, note | velocity << 8);
Where velocity is a value in the range 1..127.

Quote:
Originally Posted by DruMunkey View Post
70: 90 3C 00 [Note Off] chan 1 note 60 <---- why is it sending note off here? and why is there no velocity info in this second send that goes out on noteoff?
Because a Note On (0x9N) message with a velocity of 0 actually means Note Off (0x8N) with a velocity of 64.
Tale is offline   Reply With Quote
Old 06-23-2016, 10:45 AM   #3
DruMunkey
Human being with feelings
 
Join Date: Feb 2016
Posts: 232
Default

Quote:
Originally Posted by Tale View Post
This:

Code:
midisend(offset,NoteOn, note | velocity << 8);
Where velocity is a value in the range 1..127.

.
Thank you for your answer.

I read what the docs said about what << and I don't get it. Do you have a "For Dummies" version of what "converts both values to 32 bit integers, bitwise left shifts the first value by the second. Note that shifts by more than 32 or less than 0 produce undefined results." actually means?

Quote:
Because a Note On (0x9N) message with a velocity of 0 actually means Note Off (0x8N) with a velocity of 64
AHHHH that explains why with one controller this works, and one it doesn't. I think one is sending an explicit noteoff, one is doing the zero velocity thing.
DruMunkey is offline   Reply With Quote
Old 06-24-2016, 02:14 AM   #4
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,652
Default

Quote:
Originally Posted by DruMunkey View Post
I read what the docs said about what << and I don't get it. Do you have a "For Dummies" version of what "converts both values to 32 bit integers, bitwise left shifts the first value by the second. Note that shifts by more than 32 or less than 0 produce undefined results." actually means?
Convert to integer means rounding down, i.e. it cuts off any numbers after the decimal dot. So e.g. 1.01 becomes 1, and 2.99 becomes 2. A 32-bit integer has a range of 0..2^32-1, or 2^31-1 if 1 bit is used for the +/- sign.

A bit shift means that when you look at the number in binary (i.e. 0s and 1s) you shift them left or right, e.g.:

Code:
              8421 => 1*8 + 0*4 + 1*2 + 1*1 = 11
11 decimal == 1011 binary

1011 << 2 == 1100
1011 >> 2 == 0010
This example uses just 4 bits, but in reality we have 32 bits.

Note that a left shift of 1 is the same as multiplying by 2, and a right shift of 1 is the same as dividing by 2.
Tale is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:10 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.