[solved] Display a value in hex form

Hello!

Is it possible to send an integer value to a widget (for instance, a text widget),
but to display it in hex form?

Specifically, I have a matrix of faders, and 2 labels per strip

I’d like to display something like 128 / 0x7F when I receive 128.

Is it doable? Thx

I think I could do it using OSC{}, but in this case, how do I specifiy a preArg?

OSC listeners inherit the widget’s preArgs by default, you could set the widget’s value as follows:

JS{{
var intValue = OSC{int, 0}
var hex = intValue.toString(16)
return '0x' + (hex.length < 2 ? 0 + hex : hex)
}}

This way you’ll be able to send the interger value to /text/address/int [preArgs] (without the leading slash, the listener’s address is considered relative to the host widget’s).

Note that 128 is 0x80, if you need to display 0x7F you’ll have to decremenent intValue by 1.

Edit: you could replace (hex.length < 2 ? 0 + hex : hex) with hex.padStart(2, 0) but this function is not supported on iOS 9.3. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)

Nice!
OK, thank you, I didn’t know this about OSC{} listeners and preArgs.

For now I am using a matrix, so I can send /REG 1 127 or /REG 2 0 to update the faders.

Is it still possible to use OSC() in this case?

  • Yeah you’re right about 127 vs 128, I was tired :wink:

  • I think the new JS syntax will be really useful for formatting or quick calculations.
    And I have seen that the set() function is available here too, this will be really useful too.

  • I still not really understand when this code is triggered.
    In my case, sending OSC to the widget triggers it, but if I use for instance the value of another widget as input (like @{widget1}), will this code be triggered each time widget1 value changes?

Thx for your replies and your patience :wink:

For now I am using a matrix, so I can send /REG 1 127 or /REG 2 0 to update the faders.
Is it still possible to use OSC() in this case?

I guess yes, you'd have to try !

And I have seen that the set() function is available here too, this will be really useful too.

It is not available except in script widgets (script and send() function · Issue #355 · jean-emmanuel/open-stage-control · GitHub).

In my case, sending OSC to the widget triggers it, but if I use for instance the value of another widget as input (like @{widget1}), will this code be triggered each time widget1 value changes?

Yes

For now I am using a matrix, so I can send /REG 1 127 or /REG 2 0 to update the faders.
Is it still possible to use OSC() in this case?

Actually I think you'll probably have to use a clone matrix to be able to do that : Dynamic matrix size/labels · Issue #496 · jean-emmanuel/open-stage-control · GitHub

Oh, OK, because I have seen it used here:

and I didn't notice the JS{{}} was inside a script widget

Yes, it is what I use

Yes I'm going to try it, but if I use OSC{/REG, 0}, how do I handle the preArgs ?

Can I use OSC{,0} (ie with an empty relative address?)

Yes I’m going to try it, but if I use OSC{/REG, 0}, how do I handle the preArgs ?

They are inherited from the host widget.

Can I use OSC{,0} (ie with an empty relative address?)

Maybe, but it's a bad idea, you'll have a conflict between the listener and the host widget.