helgoboss / reaper-rs

Rust bindings for the REAPER C++ API
MIT License
82 stars 8 forks source link

Possible to access gmem? #76

Closed ryanorendorff closed 1 year ago

ryanorendorff commented 1 year ago

I have a few effects that write to gmem. At the moment I would like to not modify them and just read their output.

Is it possible to read global memory? I have not found documentation about it outside of Lua/JSFX but I figured I'd ask.

ryanorendorff commented 1 year ago

For those curious, you can write to sliders using the following effect and then read from them using TrackFX_GetParam. You can write to the sliders far faster than they update in a @sample block, so if you add some logic to make sure the memory is ready to read, you can read 30 doubles at a rate of 85Hz with one effect (or 20 kpbs). If one needs faster rates for reading/writing then multiple effects could be spawned.

desc:Read Global Memory

options:gmem=namespace
options:no_meter

// doubles up to 2^53 + 1 can represent exact integers, which represents 2.85
// million years at a 100 Hz sample rate for a monotonically increasing nonce.
// So we should be ok.
slider1:nonce=0<0,9007199254740992,1>nonce
slider2:latch=0<0, 1, 1{off, on}>latch
slider3:last_latch=0<0, 1, 1{off, on}>-last latch
slider4:ready_to_read=0<0, 1, 1{off, on}>read ready status

// According to reaper, you can address up to 2^23 global memory addresses as an
// upper bound, although the default is 2^20.
slider5:memory_address_0=0<0,8388607,1>-memory address 0
slider6:memory_address_1=0<0,8388607,1>-memory address 1
slider7:memory_address_2=0<0,8388607,1>-memory address 2
slider8:memory_address_3=0<0,8388607,1>-memory address 3
slider9:memory_address_4=0<0,8388607,1>-memory address 4
slider10:memory_address_5=0<0,8388607,1>-memory address 5
slider11:memory_address_6=0<0,8388607,1>-memory address 6
slider12:memory_address_7=0<0,8388607,1>-memory address 7
slider13:memory_address_8=0<0,8388607,1>-memory address 8
slider14:memory_address_9=0<0,8388607,1>-memory address 9
slider15:memory_address_10=0<0,8388607,1>-memory address 10
slider16:memory_address_11=0<0,8388607,1>-memory address 11
slider17:memory_address_12=0<0,8388607,1>-memory address 12
slider18:memory_address_13=0<0,8388607,1>-memory address 13
slider19:memory_address_14=0<0,8388607,1>-memory address 14
slider20:memory_address_15=0<0,8388607,1>-memory address 15
slider21:memory_address_16=0<0,8388607,1>-memory address 16
slider22:memory_address_17=0<0,8388607,1>-memory address 17
slider23:memory_address_18=0<0,8388607,1>-memory address 18
slider24:memory_address_19=0<0,8388607,1>-memory address 19
slider25:memory_address_20=0<0,8388607,1>-memory address 20
slider26:memory_address_21=0<0,8388607,1>-memory address 21
slider27:memory_address_22=0<0,8388607,1>-memory address 22
slider28:memory_address_23=0<0,8388607,1>-memory address 23
slider29:memory_address_24=0<0,8388607,1>-memory address 24
slider30:memory_address_25=0<0,8388607,1>-memory address 25
slider31:memory_address_26=0<0,8388607,1>-memory address 26
slider32:memory_address_27=0<0,8388607,1>-memory address 27
slider33:memory_address_28=0<0,8388607,1>-memory address 28
slider34:memory_address_29=0<0,8388607,1>-memory address 29
slider35:memory_value_0=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 0
slider36:memory_value_1=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 1
slider37:memory_value_2=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 2
slider38:memory_value_3=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 3
slider39:memory_value_4=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 4
slider40:memory_value_5=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 5
slider41:memory_value_6=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 6
slider42:memory_value_7=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 7
slider43:memory_value_8=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 8
slider44:memory_value_9=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 9
slider45:memory_value_10=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 10
slider46:memory_value_11=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 11
slider47:memory_value_12=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 12
slider48:memory_value_13=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 13
slider49:memory_value_14=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 14
slider50:memory_value_15=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 15
slider51:memory_value_16=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 16
slider52:memory_value_17=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 17
slider53:memory_value_18=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 18
slider54:memory_value_19=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 19
slider55:memory_value_20=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 20
slider56:memory_value_21=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 21
slider57:memory_value_22=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 22
slider58:memory_value_23=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 23
slider59:memory_value_24=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 24
slider60:memory_value_25=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 25
slider61:memory_value_26=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 26
slider62:memory_value_27=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 27
slider63:memory_value_28=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 28
slider64:memory_value_29=0<-300000000000000000000000000000000, 300000000000000000000000000000000, 0.000000000000000001>-value 29

@init
ext_noinit = 1;
nonce = 0;
latch = 0;
last_latch = 0;
ready_to_read = 0;
memory_address_0 = 0;
memory_address_1 = 1;
memory_address_2 = 2;
memory_address_3 = 3;
memory_address_4 = 4;
memory_address_5 = 5;
memory_address_6 = 6;
memory_address_7 = 7;
memory_address_8 = 8;
memory_address_9 = 9;
memory_address_10 = 10;
memory_address_11 = 11;
memory_address_12 = 12;
memory_address_13 = 13;
memory_address_14 = 14;
memory_address_15 = 15;
memory_address_16 = 16;
memory_address_17 = 17;
memory_address_18 = 18;
memory_address_19 = 19;
memory_address_20 = 20;
memory_address_21 = 21;
memory_address_22 = 22;
memory_address_23 = 23;
memory_address_24 = 24;
memory_address_25 = 25;
memory_address_26 = 26;
memory_address_27 = 27;
memory_address_28 = 28;
memory_address_29 = 29;
memory_value_0 = 0;
memory_value_1 = 0;
memory_value_2 = 0;
memory_value_3 = 0;
memory_value_4 = 0;
memory_value_5 = 0;
memory_value_6 = 0;
memory_value_7 = 0;
memory_value_8 = 0;
memory_value_9 = 0;
memory_value_10 = 0;
memory_value_11 = 0;
memory_value_12 = 0;
memory_value_13 = 0;
memory_value_14 = 0;
memory_value_15 = 0;
memory_value_16 = 0;
memory_value_17 = 0;
memory_value_18 = 0;
memory_value_19 = 0;
memory_value_20 = 0;
memory_value_21 = 0;
memory_value_22 = 0;
memory_value_23 = 0;
memory_value_24 = 0;
memory_value_25 = 0;
memory_value_26 = 0;
memory_value_27 = 0;
memory_value_28 = 0;
memory_value_29 = 0;

@sample
switched_on = ((latch - last_latch) == 1);
switched_off = ((last_latch - latch) == 1);

last_latch = latch;

switched_on ? (
    ready_to_read = 0;
);

(latch & !ready_to_read) ? (
    memory_value_0 = gmem[memory_address_0];
    memory_value_1 = gmem[memory_address_1];
    memory_value_2 = gmem[memory_address_2];
    memory_value_3 = gmem[memory_address_3];
    memory_value_4 = gmem[memory_address_4];
    memory_value_5 = gmem[memory_address_5];
    memory_value_6 = gmem[memory_address_6];
    memory_value_7 = gmem[memory_address_7];
    memory_value_8 = gmem[memory_address_8];
    memory_value_9 = gmem[memory_address_9];
    memory_value_10 = gmem[memory_address_10];
    memory_value_11 = gmem[memory_address_11];
    memory_value_12 = gmem[memory_address_12];
    memory_value_13 = gmem[memory_address_13];
    memory_value_14 = gmem[memory_address_14];
    memory_value_15 = gmem[memory_address_15];
    memory_value_16 = gmem[memory_address_16];
    memory_value_17 = gmem[memory_address_17];
    memory_value_18 = gmem[memory_address_18];
    memory_value_19 = gmem[memory_address_19];
    memory_value_20 = gmem[memory_address_20];
    memory_value_21 = gmem[memory_address_21];
    memory_value_22 = gmem[memory_address_22];
    memory_value_23 = gmem[memory_address_23];
    memory_value_24 = gmem[memory_address_24];
    memory_value_25 = gmem[memory_address_25];
    memory_value_26 = gmem[memory_address_26];
    memory_value_27 = gmem[memory_address_27];
    memory_value_28 = gmem[memory_address_28];
    memory_value_29 = gmem[memory_address_29];

    nonce = nonce+1;
    ready_to_read = 1;
    latch = 0;
);
helgoboss commented 1 year ago

Hi Ryan! I think you might be in the wrong place here. This is not the REAPER forum. It's the issue section of a 3rd-party library that allows programming REAPER extensions in Rust. The REAPER forum is at reaper.fm

ryanorendorff commented 1 year ago

I am familiar with the reaper form, I figured I would just add a solution while I was here anyway. I had not found a ton on the reaper form related to this; it seems like a requested feature but no one had a real way to access gmem. So I was kinda hoping that someone here had found more to the API than that Reaper themselves had listed.

helgoboss commented 1 year ago

If you are looking for a way to access gmem from native extensions, this might help. Haven't tried it yet.