Skip to content

Conditional Compilation

Conditional compilation includes or excludes code blocks at compile time based on flags. This enables debug builds, optional features, and configuration variants.

SET_CONDITION(FLAG)

Enables a compile-time flag that persists for the entire compilation. Flags must be set before they are checked.

SET_CONDITION(TCM_LARGE)
SET_CONDITION(IVLS_DEBUG)

on init
    SET_CONDITION(NO_SYS_SCRIPT_GROUP_START)
    SET_CONDITION(NO_SYS_SCRIPT_PEDAL)
    SET_CONDITION(NO_SYS_SCRIPT_RLS_TRIG)
end on

USE_CODE_IF(FLAG) ... END_USE_CODE

Includes enclosed code only when the flag has been set:

SET_CONDITION(IVLS_DEBUG)

function debug(str)
    USE_CODE_IF(IVLS_DEBUG)
        message(@debug.current_prefix & ": " & str)
    END_USE_CODE
end function

Wrap validation code that should be stripped from production:

SET_CONDITION(FIFO_CHECKS)

function FIFO.push(ref, data) -> entry
    USE_CODE_IF(FIFO_CHECKS)
        if check_ref(FIFO, ref)
    END_USE_CODE
            declare new := Entry.new()
            Entry[new].data := data
            entry := new
    USE_CODE_IF(FIFO_CHECKS)
        else
            message('No FIFO with ref ' & ref & " exists!")
        end if
    END_USE_CODE
end function

USE_CODE_IF_NOT(FLAG) ... END_USE_CODE

Includes enclosed code only when the flag has not been set. Use for features that should be enabled by default:

USE_CODE_IF_NOT(NO_PLAYBACK)
    on note
        disallow_group(ALL_GROUPS)
        ignore_event(EVENT_ID)
        // Note handling...
    end on
END_USE_CODE

To disable: SET_CONDITION(NO_PLAYBACK)


Common Compile-Time Flags

Flag Description
TCM_LARGE Large TCM mode (128 slots)
NO_PLAYBACK Disables note/release handlers
IVLS_DEBUG Enables debug output
DEBUG General debug flag for util.log()
FIFO_CHECKS Validation checks in FIFO operations
NO_SYS_SCRIPT_GROUP_START Disables system script group start
NO_SYS_SCRIPT_PEDAL Disables system script pedal handling
NO_SYS_SCRIPT_RLS_TRIG Disables system script release trigger
UI_NAME_FIRST Changes UI control parameter ordering

CONDITION.* Runtime Macros

While SET_CONDITION/USE_CODE_IF operate at compile time, CONDITION.* defines evaluate at runtime:

define CONDITION.IS_OUTSIDE_EVENT := get_event_par(EVENT_ID, EVENT_PAR_SOURCE) = -1
define CONDITION.IS_PEDAL_DOWN := CC[64] >= 64
define CONDITION.IS_PEDAL_UP := CC[64] < 64
define CONDITION.IS_BOOL(#i#) := in_range(#i#, 0, 2)
define CONDITION.ANY_MODIFIER(#control#) := (#control# -> key_alt = ON) or ...
                                            (#control# -> key_shift = ON) or ...
                                            (#control# -> key_ctrl = ON)
define CONDITION.IS_SIGNAL_TYPE(#type#) := (NI_SIGNAL_TYPE = #type#)
define CONDITION.IS_BITMASK_COMMON(A, B) := (A .and. B > 0)
on note
    if CONDITION.IS_OUTSIDE_EVENT
        Voice[vo].note := EVENT_NOTE
    end if
end on

Compile-Time vs Runtime

Feature Compile-Time Runtime
Syntax SET_CONDITION, USE_CODE_IF CONDITION.* defines
Evaluation During compilation During execution
Code inclusion Excluded code not compiled All code compiled, branch at runtime
Performance None for excluded code Branch evaluation cost
Use case Debug builds, feature toggles Event checks, state checks

See Also