Old 04-07-2022, 02:13 AM   #1
andrewbruhelius
Human being with feelings
 
Join Date: Jul 2019
Posts: 7
Default Merging Midi CC data from multiple sources

Dear community...
I have a specific application in mind where I would like to control an LFO using midi CC1. Then I'd like to use aftertouch (converted to, for example, midi CC21) to add some extra contribution to CC1. The total sum should be capped at 127 for 7-bit raw midi. Is there an easy way to do this using JSFX?
My plan is to remap the CC21 to not contribute more than 47 (out of 127), since the values of midi CC1 would be capped at 80 (for aesthetic reasons to not have too much LFO intensity). But for certain applications I want to use the AT to "lean into" the notes more and trigger values of CC1 to exceed 80.

Here is how I want to merge the two (pseudocode):

CC1_val = "retrieve current CC value for CC1"
CC1_val = CC1_val + CC21_val;

if CC1_val > 127:
CC1_val = 127
end
"print CC1_val to output CC1 to overwrite old value with merged one"

That's it basically.
Thanks!
andrewbruhelius is offline   Reply With Quote
Old 04-07-2022, 03:16 AM   #2
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,681
Default

Yes, it certainly could be done. Which Aftertouch? Poly Aftertouch or Channel Pressure?

The key statement will be something like:
out_CC_value = min(CC1_value, 80) + floor(AT_value/127 *47);
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Old 04-07-2022, 03:31 AM   #3
andrewbruhelius
Human being with feelings
 
Join Date: Jul 2019
Posts: 7
Default

Thanks for your message @DarkStar. In this case it would be Channel Pressure.
andrewbruhelius is offline   Reply With Quote
Old 04-08-2022, 02:01 AM   #4
andrewbruhelius
Human being with feelings
 
Join Date: Jul 2019
Posts: 7
Default

Quote:
Originally Posted by DarkStar View Post
Yes, it certainly could be done. Which Aftertouch? Poly Aftertouch or Channel Pressure?

The key statement will be something like:
out_CC_value = min(CC1_value, 80) + floor(AT_value/127 *47);
Is this code here going to work (first time ever that I write something in JSFX) ?

Code:
desc: add another midi CC's value to examined one
// version 0.1

slider1:19<0,127,1>CC number to examine, default CC19
slider2:99<0,127,1>CC number to add to existing one, CC99
slider3:19<0,127,1>CC number to output, default is overwrite CC19

@init

@slider
ccGet = slider1;  // first CC number
ccAdd = slider2;  // CC that will add on top of first one
ccOut = slider3;  // output/target CC number...default value is same as ccGet

@block

ccAddval = 0; // set a buffer-variable to zero to start with

while (midirecv(offset,msg1,msg2,msg3))  (
	
	channel = msg1 & $x0F; // identify which channel the signal is on
	
	msg1 == $xB0  && msg2 == ccAdd ? (    // check if the event is the correct CC number
	
		ccAddval = msg3; // fill the buffer-variable with the input from the examined CC number
	
	);
);

ccAddval != 0 ? (     // if the buffer is filled, proceed to read out more midi data, this time, look for the target CC 
	while (midirecv(offset,msg1,msg2,msg3))  (
		
		channel2 = msg1 & $x0F;  // identify which channel the signal is on
		
		channel2 == channel && msg1 == $xB0  && msg2 == ccGet ? (  // if same channel before and the CC number is correct
		
			ccNewval = min(msg3, 80) + floor(ccAddval/127 *47); 
		
		);

	);
	midisend(offset, $xB0+channel, ccOut, ccNewval)
);

Last edited by andrewbruhelius; 04-10-2022 at 05:52 PM.
andrewbruhelius is offline   Reply With Quote
Old 04-12-2022, 09:20 PM   #5
andrewbruhelius
Human being with feelings
 
Join Date: Jul 2019
Posts: 7
Default

It seems that the code is not doing what it is intended to do. There doesn't seem to be a readout of "ccNewval" in the second while loop. Perhaps the conditions are not correctly set up, or the usage of @block is not suitable?

Any thoughts?
andrewbruhelius is offline   Reply With Quote
Old 04-13-2022, 04:34 AM   #6
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,681
Default

Well, I have had a look but cannot see the problem (yet )
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Old 04-13-2022, 06:17 AM   #7
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,681
Default

Try this:

Code:
desc: add another midi CC's value to examined one
// version 0.2

slider1:19<0,127,1>CC number to examine, default CC19
slider2:99<0,127,1>CC number to add to existing one, CC99
slider3:19<0,127,1>CC number to output, default is overwrite CC19

@init

@slider
ccGet = slider1;  // first CC number
ccAdd = slider2;  // CC that will add on top of first one
ccOut = slider3;  // output/target CC number...default value is same as ccGet

@block

while (midirecv(offset,msg1,msg2,msg3))  ( 
	
    type = msg1 >> 4;
    channel = msg1 & $x0F; // identify which channel the signal is on
    type == $x0B  && msg2 == ccAdd ? (    // check if the event is the correct CC number
        ccAddval = msg3; // fill the buffer-variable with the input from the examined CC number
    );

    ccAddval != 0 ? (     // if the buffer is filled, proceed to read out more midi data, this time, look for the target CC 
	type2 = msg1 >> 4;
	channel2 = msg1 & $x0F;  // identify which channel the signal is on
	channel2 == channel && type2 == $x0B  && msg2 == ccGet ? (  // if same channel before and the CC number is correct
	    ccNewval = min(msg3, 80) + floor(ccAddval/127 *47 +0.5);
	    midisend(offset, $xB0+channel, ccOut, ccNewval);
	);
    );

);  // end of the while loop
Quote:
/*
-- removed the initialisation at the start of each block
-- put both tests in the same while ( ... ) loop
-- extracted the message type, so that MIDI channels other then 1 are handled
-- send the MIDI only when there is a ccGet message received
-- rounded the added value to the nearest integer, in the range 0 ... 47
*/
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Old 04-15-2022, 10:02 AM   #8
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,681
Default

... any news?
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Old 04-17-2022, 07:25 PM   #9
andrewbruhelius
Human being with feelings
 
Join Date: Jul 2019
Posts: 7
Default

Awesome, just saw the updates. I will have a look later and post here the results/feedback. Hoping that this can be of use for others users as well.
andrewbruhelius is offline   Reply With Quote
Old 04-18-2022, 05:27 AM   #10
andrewbruhelius
Human being with feelings
 
Join Date: Jul 2019
Posts: 7
Default

I think it is working as intended, except for the pass-thru functionality...that is CC19 values should pass through if there is no CC99 messages coming in. I suppose this is easy enough for me to fix though. Also, I will include another slider with the thresholds, so the scaling of CC99 can be more generally defined upfront.
andrewbruhelius is offline   Reply With Quote
Old 04-18-2022, 05:41 AM   #11
andrewbruhelius
Human being with feelings
 
Join Date: Jul 2019
Posts: 7
Default

Looks like I was wrong about this:

Quote:
Originally Posted by andrewbruhelius View Post
I think it is working as intended, except for the pass-thru functionality...that is CC19 values should pass through if there is no CC99 messages coming in. I suppose this is easy enough for me to fix though. Also, I will include another slider with the thresholds, so the scaling of CC99 can be more generally defined upfront.
The following code works as intended (same as version 0.2 with small changes to generalize it)...

Code:
desc: CC mixer 
//add another midi CC's value to examined one
// version 0.3

slider1:19<0,127,1>CC number to examine, default CC19
slider2:99<0,127,1>CC number to add to existing one, CC99
slider3:19<0,127,1>CC number to output, default is overwrite CC19
slider4:80<0,127,1>CC value where examined CC cuts off normally

@init

@slider
ccGet = slider1;  // first CC number
ccAdd = slider2;  // CC that will add on top of first one
ccOut = slider3;  // output/target CC number...default value is same as ccGet
ccValcut = slider4;

@block

while (midirecv(offset,msg1,msg2,msg3))  ( 
  
    type = msg1 >> 4;
    channel = msg1 & $x0F; // identify which channel the signal is on
    //ccAddval = 0;
    type == $x0B  && msg2 == ccAdd ? (    // check if the event is the correct CC number
        ccAddval = msg3; // fill the buffer-variable with the input from the examined CC number
    );

    ccAddval != 0 ? (     // if the buffer is filled, proceed to read out more midi data, this time, look for the target CC 
      type2 = msg1 >> 4;
      channel2 = msg1 & $x0F;  // identify which channel the signal is on
      channel2 == channel && type2 == $x0B  && msg2 == ccGet ? (  // if same channel before and the CC number is correct
          ccNewval = min(msg3, ccValcut) + floor(ccAddval/127 *(127-ccValcut) + 0.5);
          midisend(offset, $xB0+channel, ccOut, ccNewval);
      ); 
    );
);  // end of the while loop
andrewbruhelius 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 03:53 AM.


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