Question about storing numbers in custom properties

This forum is for developers of Rack Extensions to discuss the RE SDK, share code, and offer tips to other developers.
Post Reply
wendallsan
Posts: 45
Joined: 10 Dec 2017

15 Jun 2021

I'm trying to store a number in the MOM so I can inspect it in the Recon Tools > Inspect Properties panel. The number is the velocity of the 1st note detected in a HandleNotePressed method, lifted from the Hello World tutorial. So far, I've only been storing booleans this way and I've not been able to find an example that I can make sense of. Here is what I currently have:

In my motherboard_def.lua I have:

Code: Select all

custom_properties = jbox.property_set{
	rt_owner = {
		properties = {
			noteVelocity = jbox.number{
				default = 0,
				ui_name = jbox.ui_text( "text_noteVelocity" ),
				ui_type = jbox.ui_linear( { min = 0, max = 127, units= {{decimals=0}} } ),
			}
		}
	}
	...	
In my .cpp I have this method, which gets called in RenderBatch:

Code: Select all

void CTriggerHappy::HandleNotePressed( const TJBox_PropertyDiff iPropertyDiffs[], TJBox_UInt32 iDiffCount ){
	for( TJBox_UInt32 i = 0; i < iDiffCount; ++i ){
        if( iPropertyDiffs[ i ].fPropertyRef.fObject == fNoteStates ){
			TJBox_Float64 velocity = JBox_GetNumber( iPropertyDiffs[ i ].fCurrentValue );
			JBox_StoreMOMPropertyAsNumber( fNoteVelocityPropertyRef, JBox_MakeNumber( velocity ) );
			
		}
	}
}
When I test this in Recon, I get an error as soon as I play a note into the device. When I review the logs, I see:

Code: Select all

0000000000000000 20210615-175031.612 Device instance failed: An error has occurred in device 'thappy 1' (Trigger Happy)
ModFunc: RenderRealtime
HostFunc: JBox_StoreMOMProperty
Message: Could not store property: Value out of range (Object: 0, Property Name: 'noteVelocity')  
Can anyone identify why trying to store this number is crashing things? Thanks for any help!

User avatar
thefixr
Posts: 113
Joined: 30 Jan 2015

15 Jun 2021

This may be a dumb question, but can a note velocity really be 0?
YouTube.com/iamthefixr

wendallsan
Posts: 45
Joined: 10 Dec 2017

16 Jun 2021

thefixr wrote:
15 Jun 2021
This may be a dumb question, but can a note velocity really be 0?
I THINK that might be the equivalent of a note off event(?) In MIDI, a Velocity 0 event is a note off.

User avatar
orthodox
RE Developer
Posts: 2286
Joined: 22 Jan 2015
Location: 55°09'24.5"N 37°27'41.4"E

16 Jun 2021

wendallsan wrote:
15 Jun 2021
Can anyone identify why trying to store this number is crashing things? Thanks for any help!
Is the value in the range 0<=val<=1 ?

See Number properties:
SDK4.2 wrote: Number properties contain single precision floating point values. The values can be continuous or discrete (stepped). Continuous number properties must be in the range [0.0, 1.0]. Discrete number properties are integer valued floating point numbers in the range [0.0, 1.0, …​ , (steps - 1.0)] where steps is the number of steps.
Either you do (linear) conversion or add "steps = " to your declaration. Both ways have their pros and cons.

wendallsan
Posts: 45
Joined: 10 Dec 2017

16 Jun 2021

Thanks again, that is what I needed! I've added a steps = 128 property in the declaration in my motherboard_ref.lua file and things are working great now.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest