|
|
|
04-07-2022, 02:13 AM
|
#1
|
Human being with feelings
Join Date: Jul 2019
Posts: 7
|
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!
|
|
|
04-07-2022, 03:16 AM
|
#2
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,681
|
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 ...
|
|
|
04-07-2022, 03:31 AM
|
#3
|
Human being with feelings
Join Date: Jul 2019
Posts: 7
|
Thanks for your message @DarkStar. In this case it would be Channel Pressure.
|
|
|
04-08-2022, 02:01 AM
|
#4
|
Human being with feelings
Join Date: Jul 2019
Posts: 7
|
Quote:
Originally Posted by DarkStar
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.
|
|
|
04-12-2022, 09:20 PM
|
#5
|
Human being with feelings
Join Date: Jul 2019
Posts: 7
|
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?
|
|
|
04-13-2022, 04:34 AM
|
#6
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,681
|
Well, I have had a look but cannot see the problem (yet )
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
|
|
|
04-13-2022, 06:17 AM
|
#7
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,681
|
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 ...
|
|
|
04-15-2022, 10:02 AM
|
#8
|
Human being with feelings
Join Date: May 2006
Location: Surrey, UK
Posts: 19,681
|
... any news?
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
|
|
|
04-17-2022, 07:25 PM
|
#9
|
Human being with feelings
Join Date: Jul 2019
Posts: 7
|
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.
|
|
|
04-18-2022, 05:27 AM
|
#10
|
Human being with feelings
Join Date: Jul 2019
Posts: 7
|
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.
|
|
|
04-18-2022, 05:41 AM
|
#11
|
Human being with feelings
Join Date: Jul 2019
Posts: 7
|
Looks like I was wrong about this:
Quote:
Originally Posted by andrewbruhelius
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
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 03:53 AM.
|