Old 05-17-2022, 03:24 AM   #1
souk21
Human being with feelings
 
souk21's Avatar
 
Join Date: Mar 2021
Posts: 482
Default JSFX using special variables in wrong context

JSFX docs mention that certain variables are meant to be used in certain contexts, but lots of JSFX don't follow those rules, even some official ones.

For example in super8, "tempo", "ts_num" and "play_state" are read from @gfx, but are supposed to only be allowed in @block and @sample.

Another example is sequencer_megababy setting "gfx_clear" in @init when docs say "These functions and variables must only be used from the @gfx section"

How strict are these restrictions ?
Are the docs incomplete or are these JSFX relying on UB ?

Thank you
souk21 is offline   Reply With Quote
Old 05-18-2022, 03:22 AM   #2
souk21
Human being with feelings
 
souk21's Avatar
 
Join Date: Mar 2021
Posts: 482
Default

Or is it just that those variables *might* not be correct outside of their context?
souk21 is offline   Reply With Quote
Old 05-18-2022, 04:22 AM   #3
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,823
Default

Variables that describe the state of audio processing are not guaranteed to be correct (or more specifically, the meaning of "correct" is not well defined) when read in another context. It's fine to look at the tempo and display it in the @gfx section, but the value that is displayed is not necessarily the value that is currently valid in the audio processing thread, because "currently" means different things in different threads.
schwa is offline   Reply With Quote
Old 05-19-2022, 07:54 AM   #4
whats_up
Human being with feelings
 
Join Date: Nov 2020
Posts: 186
Default

6
Quote:
Originally Posted by souk21 View Post
JSFX docs mention that certain variables are meant to be used in certain contexts, but lots of JSFX don't follow those rules, even some official ones.

For example in super8, "tempo", "ts_num" and "play_state" are read from @gfx, but are supposed to only be allowed in @block and @sample.

Another example is sequencer_megababy setting "gfx_clear" in @init when docs say "These functions and variables must only be used from the @gfx section"

How strict are these restrictions ?
Are the docs incomplete or are these JSFX relying on UB ?

Thank you
I think the base rule is that audio/midi variables should be used (read/write)
Only from block/sample sections
and functions that are called from.

All other can be used (read/write)
everywhere except block/sample sections

For reading ONLY there is no restriction
Every variable can be read everywhere
But its validation is guarantee
Only in its context

Functions can be called ONLY from their context

The reason for this is that
Block/sample sections run in the same thread sequentially
Separately from other sections thread
__________________
Easy EEL to VST Building system
https://forum.cockos.com/showthread.php?t=245285
github: https://github.com/VisualCodeBase/CodeBase

Last edited by whats_up; 05-20-2022 at 12:54 AM.
whats_up is offline   Reply With Quote
Old 05-21-2022, 01:34 AM   #5
souk21
Human being with feelings
 
souk21's Avatar
 
Join Date: Mar 2021
Posts: 482
Default

@schwa Thanks for the insights

@whats_up Thanks! Yes that's pretty much it, I did a couple tests:

Code:
pdc_* //Anywhere but @init

ext_noinit //Anywhere

gfx_* //Anywhere (no timing guarantees) except:
gfx_dest //Has a really strange behavior when using across sections
gfx_texth //Always 0 in @init

Anywhere but @init (* read below):
- tempo
- play_state
- play_position
- beat_position
- ts_num
- ts_denom
- gfx_w
- gfx_h
- mouse_x
- mouse_y
- mouse_wheel
- mouse_hwheel
(*)Unless a @serialize section exists. In that case these variables will have their correct value in @init. I guess @serialize runs before @init and changes how things are initialized ?

I didn't test functions yet, and all these tests are done in a jsfx without any imports. I guess having multiple @init could maybe change some of the behaviors. Need to do more tests
souk21 is offline   Reply With Quote
Old 05-21-2022, 04:54 AM   #6
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,793
Default

I have weird behavior even with user defined variables.

In some configurations they get zeroed when the Reaper window looses the scope and regains it.

(I posed a big report on that behalf)

-Michael
mschnell is online now   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:08 PM.


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