I have a gate input that is currently working well and is flashing a lamp on the front of the device for 0.3 seconds when a gate signal is received (all thanks to the Hello World tutorial). I want to have the gate out on the back panel go 'high' when this lamp is on. How do I make a gate out go 'high'?
I've dropped in relevant bits of code below of what I have so far, in case that is helpful. Thanks for any assistance you can provide!
device_2d.lua:
Code: Select all
...
back = {
Bg = {
{ path = "Panel_Back_1U" },
},
TapeBack = {
offset = { 200, 50 },
{ path = "Tape_Horizontal_1frames" },
},
Placeholder = {
offset = { 100, 120 },
{path = "Placeholder"}
},
S_cv_input_socket_gate_cv = {
offset = { 1555, 55 },
{path="SharedCVJack", frames = 3},
},
S_cv_output_socket_gate_cv = {
offset = { 1555, 155 },
{ path="SharedCVJack", frames = 3 }
}
}
...
Code: Select all
...
back = jbox.panel{
...
jbox.cv_output_socket{
graphics = { node = "S_cv_output_socket_gate_cv" },
socket = "/cv_outputs/trigger_out",
}
...
}
...
Code: Select all
...
cv_outputs = {
trigger_out = jbox.cv_output{
ui_name = jbox.ui_text( "text_triggerOutIsOn" )
}
}
custom_properties = jbox.property_set{
rt_owner = {
properties = {
lampIsOn = jbox.boolean{
default = false,
ui_name = jbox.ui_text( "text_lampIsOn" ),
ui_type = jbox.ui_linear( { min = 0, max = 1, units= {{decimals=0}} } ),
},
triggerOutIsOn = jbox.boolean{
default = false,
ui_name = jbox.ui_text( "text_triggerOutIsOn" ),
ui_type = jbox.ui_linear( { min = 0, max = 1, units= {{decimals=0}} } ),
}
}
},
...
}
...
Code: Select all
...
private: TJBox_PropertyRef fTriggerOutIsOnPropertyRef;
private: TJBox_ObjectRef fTriggerCVRef;
...
Code: Select all
// CONSTRUCTOR
MyExtension::MyExtension( TJBox_Float32 iSampleRate ) :
...
fTriggerOutIsOnPropertyRef( JBox_MakePropertyRef( fCustomProps, "triggerOutIsOn" ) ),
fTriggerCVRef( JBox_GetMotherboardObjectRef( "/cv_outputs/trigger_out" ) )
{}
// RENDERBATCH
void MyExtension::RenderBatch( const TJBox_PropertyDiff iPropertyDiffs[], TJBox_UInt32 iDiffCount ){
HandleCVInputChanges();
HandleLampTurnOff();
HandleTriggerOutTurnOff();
}
void MyExtension::HandleCVInputChanges(){
...
TJBox_Value gateCVValue = JBox_LoadMOMProperty( fGateCVInputRef );
TJBox_Tag gateCV = clamp( JBox_GetNumber( gateCVValue ) * 127.f, 0, 127 );
if( gateCV != fLastGateCV ){
if( gateCV > 0 ) {
SetLampState( true );
SetTriggerOut( true );
}
fLastGateCV = gateCV;
}
}
void CMyExtension::SetLampState( bool bLampState ){
JBox_StoreMOMProperty( fLampIsOnPropertyRef, JBox_MakeBoolean( bLampState ) );
if( bLampState ){
fSecondsUntilLampTurnOff = 0.3f;
}
}
void CMyExtension::SetTriggerOut( bool bTriggerOutState ){
JBox_StoreMOMProperty( fTriggerOutIsOnPropertyRef, JBox_MakeBoolean( bTriggerOutState ) );
JBox_StoreMOMPropertyAsNumber( fTriggerCVRef, kJBox_CVOutputValue, 1.f );
if( bTriggerOutState ){
fSecondsUntilTriggerOutTurnOff = 0.3f;
}
}
void CMyExtension::HandleLampTurnOff() {
if( fSecondsUntilLampTurnOff > 0.f ){
fSecondsUntilLampTurnOff -= kBatchSize / fSampleRate;
} else if( fSecondsUntilLampTurnOff > -1.f ){
SetLampState( false );
JBOX_TRACE( "Lamp turn off" );
}
}
void CMyExtension::HandleTriggerOutTurnOff(){
if( fSecondsUntilTriggerOutTurnOff > 0.f ){
fSecondsUntilTriggerOutTurnOff -= kBatchSize / fSampleRate;
} else if( fSecondsUntilTriggerOutTurnOff > -1.f ){
SetTriggerOut( false );
}
}