Old 08-04-2020, 09:40 AM   #1
AlexBerty1
Human being with feelings
 
Join Date: Aug 2020
Posts: 8
Default JS Midi Plugin needed: change note number after CC values

Hello Reaper script experts,
I'm new to Reaper and I need a JS Midi Plugin. Unfortunately I don't have any scripting skills...

So my hope is that an expert here can help me out.

I need the following (for drum sampler hihat):

the two incoming midi notes 26 and 46 shall alter after CC4 values (+ note 26 shall be sent on a different channel).

Example:
incoming CC4 value range 127 - 111 --> note 26 stays note 26 + note 46 stays note 46
incoming CC4 value range 110 - 91 --> note 26 becomes note 25 + note 46 becomes note 70
incoming CC4 value range 90 - 81 --> note 26 becomes note 24 + note 46 becomes note 71
incoming CC4 value range 80 - 71 --> note 26 becomes note 23 + note 46 becomes note 72
incoming CC4 value range 70 - 61 --> note 26 becomes note 22 + note 46 becomes note 73
incoming CC4 value range 60 - 41 --> note 26 becomes note 21 + note 46 becomes note 74
incoming CC4 value range 40 - 0 --> note 26 becomes note 20 + note 46 becomes note 75


in addition:
I want to change the midi channel only for note number 26. The incoming midi is on channel 12 but I want to set note 26 to channel 10 (original incoming channel for note 26 is channel 12). (Again try to explain: Midi note 26 (channel 12) comes in and is remapped to new pitches depending on CC4. The new pitches shall be output on the original channel 12 except note 26 that has to be remapped to midi channel 10.)

---

And it is important that it works without adding latency (it is meant for real time drumming).

Is it possible for an expert to write such a script for me? If it works properly I will donate. Thanks in advance! AlexBerty1
AlexBerty1 is offline   Reply With Quote
Old 08-06-2020, 01:58 AM   #2
AlexBerty1
Human being with feelings
 
Join Date: Aug 2020
Posts: 8
Default

Any pro here who can handle it? I can pay for it.
AlexBerty1 is offline   Reply With Quote
Old 08-06-2020, 02:16 AM   #3
FeedTheCat
Human being with feelings
 
FeedTheCat's Avatar
 
Join Date: May 2019
Posts: 196
Default

Did you stumble upon this already? It probably is a good place to start
https://forum.cockos.com/showthread....703#post344703
FeedTheCat is offline   Reply With Quote
Old 08-06-2020, 08:13 AM   #4
AlexBerty1
Human being with feelings
 
Join Date: Aug 2020
Posts: 8
Default

Quote:
Originally Posted by FeedTheCat View Post
Did you stumble upon this already? It probably is a good place to start
https://forum.cockos.com/showthread....703#post344703
Thanks but unfortunately I'm not able to modify it...
AlexBerty1 is offline   Reply With Quote
Old 08-07-2020, 08:35 AM   #5
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,133
Default

Something like this you mean?

Code:
desc:Drum sampler hihat thingy

@block

while(midirecv(ofs, msg1, msg2, msg3)) (
  ch = msg1 & 0x0F;

  // MIDI channel 12
  ch == 11 ? (
    status = msg1 & 0xF0;
    
    // Control Change
    status == 0xB0 ? (

      // CC#4
      msg2 == 4 ? (
        msg3 >= 111 && msg3 <= 127 ? adj = 0 :
        msg3 >= 91  && msg3 <= 110 ? adj = 1 :
        msg3 >= 81  && msg3 <= 90  ? adj = 2 :
        msg3 >= 71  && msg3 <= 80  ? adj = 3 :
        msg3 >= 61  && msg3 <= 70  ? adj = 4 :
        msg3 >= 41  && msg3 <= 60  ? adj = 5 :
        msg3 >= 0   && msg3 <= 40  ? adj = 6;
      );
    ) :

    // Note On/Off
    status == 0x90 || status == 0x80 ? (

      // Note 26
      msg2 == 26 ? (
        // MIDI channel 10
        msg1 = status | 9;
        // Note 25..20
        msg2 -= adj;
      ) :

      // Note 46
      msg2 == 46 ? (
        // Note 70..75
        adj > 0 ? msg2 += adj + 23;
      );
    );
  );

  midisend(ofs, msg1, msg2, msg3)
);
Tale is offline   Reply With Quote
Old 08-08-2020, 07:51 AM   #6
AlexBerty1
Human being with feelings
 
Join Date: Aug 2020
Posts: 8
Default

Quote:
Originally Posted by Tale View Post
Something like this you mean?

Code:
desc:Drum sampler hihat thingy

@block

while(midirecv(ofs, msg1, msg2, msg3)) (
  ch = msg1 & 0x0F;

  // MIDI channel 12
  ch == 11 ? (
    status = msg1 & 0xF0;
    
    // Control Change
    status == 0xB0 ? (

      // CC#4
      msg2 == 4 ? (
        msg3 >= 111 && msg3 <= 127 ? adj = 0 :
        msg3 >= 91  && msg3 <= 110 ? adj = 1 :
        msg3 >= 81  && msg3 <= 90  ? adj = 2 :
        msg3 >= 71  && msg3 <= 80  ? adj = 3 :
        msg3 >= 61  && msg3 <= 70  ? adj = 4 :
        msg3 >= 41  && msg3 <= 60  ? adj = 5 :
        msg3 >= 0   && msg3 <= 40  ? adj = 6;
      );
    ) :

    // Note On/Off
    status == 0x90 || status == 0x80 ? (

      // Note 26
      msg2 == 26 ? (
        // MIDI channel 10
        msg1 = status | 9;
        // Note 25..20
        msg2 -= adj;
      ) :

      // Note 46
      msg2 == 46 ? (
        // Note 70..75
        adj > 0 ? msg2 += adj + 23;
      );
    );
  );

  midisend(ofs, msg1, msg2, msg3)
);
Thank you very much for trying to help.

Unfortunately I can't bring it to work: note 26 + 46 do not change at all... Did it work for you? Can you please send me the file?
AlexBerty1 is offline   Reply With Quote
Old 08-09-2020, 04:23 AM   #7
AlexBerty1
Human being with feelings
 
Join Date: Aug 2020
Posts: 8
Default

Hey Tale,

I'm sorry....

It works now (my Reaper version was too old: it did not work on that outdated version).

The only thing that still doesn't work: all notes resulting from note 26 are remapped to channel 10. I want only 26 to be on channel 10 and 25-20 on the orig. channel 12.

Can you fix it?

Thanks soooo much!

Best regards Alex
AlexBerty1 is offline   Reply With Quote
Old 08-09-2020, 05:22 AM   #8
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,133
Default

Well, I could probably rewrite it for older versions of REAPER, but that would make the code less readable...

Anyway, I think this should fix note 26 being rerouted when it shouldn't be:

Code:
desc:Drum sampler hihat thingy

@block

while(midirecv(ofs, msg1, msg2, msg3)) (
  ch = msg1 & 0x0F;

  // MIDI channel 12
  ch == 11 ? (
    status = msg1 & 0xF0;
    
    // Control Change
    status == 0xB0 ? (

      // CC#4
      msg2 == 4 ? (
        msg3 >= 111 && msg3 <= 127 ? adj = 0 :
        msg3 >= 91  && msg3 <= 110 ? adj = 1 :
        msg3 >= 81  && msg3 <= 90  ? adj = 2 :
        msg3 >= 71  && msg3 <= 80  ? adj = 3 :
        msg3 >= 61  && msg3 <= 70  ? adj = 4 :
        msg3 >= 41  && msg3 <= 60  ? adj = 5 :
        msg3 >= 0   && msg3 <= 40  ? adj = 6;
      );
    ) :

    // Note On/Off
    (status == 0x90 || status == 0x80) && adj > 0 ? (

      // Note 26
      msg2 == 26 ? (
        // MIDI channel 10
        msg1 = status | 9;
        // Note 25..20
        msg2 -= adj;
      ) :

      // Note 46
      msg2 == 46 ? (
        // Note 70..75
        msg2 += adj + 23;
      );
    );
  );

  midisend(ofs, msg1, msg2, msg3)
);
Note that there might be an issue when you send a Note On for note 26 or 46, and then change CC#4 before sending the Note Off. But this might not be a problem if e.g. the synth ignores Note Off anyway.
Tale is offline   Reply With Quote
Old 08-09-2020, 10:38 AM   #9
AlexBerty1
Human being with feelings
 
Join Date: Aug 2020
Posts: 8
Default

Quote:
Originally Posted by Tale View Post
Well, I could probably rewrite it for older versions of REAPER, but that would make the code less readable...
No, it's all right, you need not rewrite it.

Thanks so much! Great work!
AlexBerty1 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 05:57 PM.


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