Truck Enthusiasts Forum

Truck Enthusiasts Forum



SearchSearch   Users   Registration   Entrance
Today: 27.01.2026 - 10:18:05
Pages:  1  

JSFX Programming - midirecv

AuthorMessage

StormshadO

King of memes


Statistics:
Messages: 244
Registration: 02.19.2003
Rating:
🔥🔥🔥🔥🔥
🔥🔥🔥🔥🔥

Hello fellow JSFX Programmers, I am venturing into my first JSFX program. Kept it as simple as possible. The intension was a simple audio envelope modulation via sin wave where the user can change the modulation frequency -- all OK up here, this works as expected. Next I wanted to add an exponential decay, where the decay process starts at time=0 when a midi note is pressed -- this is where things did not work. I used the midirecv function within the @block part of the code and poll until it returns a non-zero value (accord to the user manual), but this never gets executed. The code is listed below: desc:new effect //Simple audio envelope modulation with exponential decay trigered from midi noteOn event slider1:1<0.1,10,0.001>Modulation Frequency, Hz slider2:0<-6.283,6.283,0.1>Phase of signal 1 slider3:0<-6.283,6.283,0.1>Phase of signal 2 slider4:0.001<0.001,100,.001>expo time constant @init t_=0; // time, intent is to start counting from zero from a noteOn event tmax_=100 ; // maximum for t_ allowed after thich it resets to zero dt_=1/srate; //Time step noteOn=$x90; //Mask for noteOn midi message noteOff=$x00; //have not fount this correctly yet trg=0; //Debug: count number of noteOn events miditrg=0; //Debug: count number of times midirecv returned non-zero value blktrg=0; //Debug: count number of times @block was entered @slider //Save slider values to local variables myparm1=slider1; myparm2=slider2; myparm3=slider3; myparm4=slider4; @block //Block processing here is intended to see when a noteOn event happened, and if it did reset time t_ to zero. blktrg+=1; //debugging, count number of times block entered loops_=samplesblock; //Samples per block, assume sets max offset-1 for midirecv function offset=-1; loop(loops_, //Loop through offset for midirecv function offset+=1; //Increment offset while (ret_=midirecv(offset,msg1,msg2,msg3)) //See if midirecv returned non-zero ( miditrg+=1; //Debug: see how many times midirecv returned non-zero value --> never reached, why? <-- msg1==noteOn && msg3!=0 ? //For the noteOn events ( t_=0; //Reset time to zero, when a noteOn event happend --> never reached, why? <-- trg+=1; //Debug: see how many times this was triggered loops_=-1; //Once triggered do not process remainder of buffer ); ); ); t_ > tmax_ ? (t_=0;); //Set upper limit for time, reset to zero when exceeded @sample t_+=dt_; // increment time by time step expo_=exp(-t_/myparm4); // calculate exponential decay envelope spl0=spl0*(sin(2*3.145*myparm1*t_+myparm2))*expo_; // Apply both a sin modulation envelope and an exponential decay envelop spl1=spl1*(sin(2*3.145*myparm1*t_+myparm3))*expo_; // to the two audio signals. A phase offset is also applied. Any ideas? Ignore the smiley face. Thanks, Norman.



Message # 1 24.03.23 - 01:19:19
RE: JSFX Programming - midirecv

StealthM2O

King of memes


Statistics:
Messages: 501
Registration: 12.02.2002
Rating:
🔥🔥🔥🔥🔥
🔥🔥🔥🔥🔥

Welcome to JSFX programming !! You'll get more attention to this in the "scripting" subforum ! And for readability you should include the code in a [code] section ! see you there... A usual problem is understanding the two kinds of while statements eel features. For example code, you can take a look at many MIDI filter JSFX plugins that come with Reaper, or at mine that are available via ReaPack. In ReaPack you'll also find a great modular synth done in JSFXes that already might provide something that comes close to your needs. -Michael


---------------------------------------
The only TRUE engineering .... IS GERMAN ENGINEERING!!
Message # 2 24.03.23 - 01:28:36
RE: JSFX Programming - midirecv

thrlls

King of memes


Statistics:
Messages: 6,023
Registration: 01.01.2003
Rating:
🔥🔥🔥🔥🔥
🔥🔥🔥🔥🔥

and here I thought I was missing something ... The first FX for the track is a VSTi (Full Bucket's FB-3300 synth.), which receives the midi messages and acts on them correctly. Any audio FXs after this also get processed as expected. What I did not expect was that the VSTi would not pass through the midi events ready for the next FX to process. So do not know if this is a bug in Reaper or a "feature" of this VSTi. So that is why my FX program did not detect the noteOn events as the synth VSTi was consuming them. This was confirmed by putting a VST:ReaControlMIDI(Cockos) in-front of the synth and right after it and turn on the midi log, pre synth midi log shows data, post synth midi log shows no data.



Message # 3 24.03.23 - 01:39:40
RE: JSFX Programming - midirecv

TBM311

King of memes


Statistics:
Messages: 71
Registration: 09.04.2002
Rating:
🔥🔥🔥🔥🔥
🔥🔥🔥🔥🔥

The way that I understand the while(midireceive... loop is that it will listen for midi messages for the duration of the block, so you only need to call it once. What I often do now is save the result of any MIDI message received in indexed memory (indexed by the offset). If I want to process those results @sample, I use a counter, which is reset at the start of each block to access the result from memory. Edit, as preferred.nomenclature says, you may need to use flags. I usually use memset to set the relevant block of memory to -1 at the start of each block. Code:



Message # 4 24.03.23 - 01:45:29
RE: JSFX Programming - midirecv

orangechicken

King of memes


Statistics:
Messages: 185
Registration: 05.22.2001
Rating:
🔥🔥🔥🔥🔥
🔥🔥🔥🔥🔥

TimeWaster, I believe in your example when you use the offset of the received message as the index into memory you store it at, you will end up ignoring all but the last message received with that offset. (I have tested to confirm that it is possible to receive multiple messages wih the same offset).


---------------------------------------
How do you delete your signature?
Message # 5 24.03.23 - 01:50:17
RE: JSFX Programming - midirecv

Hornswoggler

King of memes


Statistics:
Messages: 2,422
Registration: 01.19.2003
Rating:
🔥🔥🔥🔥🔥
🔥🔥🔥🔥🔥

That's true. In my case I'm usually looking for a specific message, and I only want to process one per sample, so the last one only is fine. You can store different types of message received at the same offset by using another array: offset[mempos1]; offset[mempos2] etc. and perhaps use a loop to store multiples of the same message received at the same offset, something like: Code:



Message # 6 24.03.23 - 01:59:45
RE: JSFX Programming - midirecv
Pages:  1  

The administrator has prohibited guests from replying to messages! To register, follow the link: register


Participants

Powered: XenForo™ 5.0.6