-
Notifications
You must be signed in to change notification settings - Fork 1
user module base
#sdk #reference #class #callbacks #parameters #audio #drawing #threading #persistence #settings
UserModuleBase is the base class that every Usine user module inherits from. It provides virtual callback methods that Usine calls at various points in the module's lifecycle.
Defined in: sdk/UserModule.h
Implemented in: sdk/UserModule.cpp
| Constant | Type | Description |
|---|---|---|
MODULE_NAME |
AnsiCharPtr |
Module display name |
MODULE_DESC |
AnsiCharPtr |
Module description |
MODULE_VERSION |
AnsiCharPtr |
Module version string |
These must be implemented by every module.
virtual void onGetModuleInfo(TMasterInfo* pMasterInfo, TModuleInfo* pModuleInfo) = 0;Fill in the TModuleInfo structure to describe your module's characteristics. Called once during module creation.
Key fields to set:
| Field | Type | Description |
|---|---|---|
Name |
AnsiCharPtr |
Module name shown in Usine |
Description |
AnsiCharPtr |
Module description |
ModuleType |
TModuleType |
mtSimple, mtControl, mtVideo, etc. |
BackColor |
TUsineColor |
Module background color |
NumberOfParams |
int |
Total number of parameters |
Version |
AnsiCharPtr |
Version string |
DontProcess |
LongBool |
TRUE to skip onProcess() calls |
CanRecord |
LongBool |
TRUE to enable automation recording |
CanBeRandomized |
LongBool |
TRUE to enable randomize feature |
CanBeReset |
LongBool |
TRUE to enable reset feature |
CanBeSavedInPreset |
LongBool |
TRUE to enable preset saving |
DefaultWidth |
int |
Default module width |
DefaultHeight |
int |
Default module height |
NumberOfVideoInputs |
int |
Number of video inputs (for mtVideo) |
NumberOfVideoOutputs |
int |
Number of video outputs (for mtVideo) |
Query system fields:
| Field | Description |
|---|---|
QueryListString |
Comma-separated query option labels |
QueryListValues |
Comma-separated query values |
QueryListDefaultIdx |
Default selected index |
QueryLabel1 / QueryLabel2
|
Labels for query inputs |
QueryDefaultValue1 / QueryDefaultValue2
|
Default query values |
QueryMaxValue1 / QueryMaxValue2
|
Max query values |
QueryMinValue1 / QueryMinValue2
|
Min query values |
virtual void onGetParamInfo(int ParamIndex, TParamInfo* pParamInfo) = 0;Fill in the TParamInfo structure for each parameter. Called once per parameter during setup.
Key TParamInfo fields:
| Field | Type | Description |
|---|---|---|
ParamType |
TParamType |
Parameter type (see Data Types) |
Caption |
AnsiCharPtr |
Parameter label |
IsInput |
LongBool |
TRUE for input parameter |
IsOutput |
LongBool |
TRUE for output parameter |
MinValue |
TPrecision |
Minimum value |
MaxValue |
TPrecision |
Maximum value |
DefaultValue |
TPrecision |
Default value |
Scale |
TScale |
scLinear, scLog, or scExp
|
Symbol |
AnsiCharPtr |
Unit symbol (e.g., "Hz", "dB") |
Format |
AnsiCharPtr |
Display format (e.g., "%.2f") |
Color |
TUsineColor |
Parameter color |
ReadOnly |
LongBool |
TRUE for output-only parameters |
CallBackType |
TFastCallBackType |
ctNormal, ctImmediate, ctAsynchronous, cttVideo, cbtRealTime, cbtGraphic, cbtNetwork, ctNone
|
CallBackId |
NativeInt |
ID passed in wParam during callback |
DontSave |
LongBool |
TRUE to exclude from save |
IsStoredInPreset |
LongBool |
TRUE to include in presets |
IsSeparator |
LongBool |
TRUE to display a section separator |
SeparatorCaption |
AnsiCharPtr |
Separator label text |
IsInvisible |
LongBool |
TRUE to hide the parameter |
DisplayOrder |
int |
Display order override |
ListBoxStrings |
AnsiCharPtr |
Comma-text for ptListBox
|
TextValue |
AnsiCharPtr |
Default text for ptText
|
Translate |
LongBool |
TRUE to translate caption |
FileNameFilter |
AnsiCharPtr |
Filter for ptFileName
|
PointerDataType |
int |
Type for ptPointer params |
PointerDataInitialSize |
int |
Initial size for pointer data |
AllowZeroLenAsInput |
LongBool |
Allow zero-length events |
Binding events: Call pParamInfo->setEventClass(myEvent) to bind a UsineEventClass to the parameter.
virtual void onCallBack(TUsineMessage* Message);Called when a parameter changes or a UI event occurs.
TUsineMessage fields:
| Field | Description |
|---|---|
message |
Always MSG_CHANGE
|
wParam |
The CallBackId of the parameter |
lParam |
Message type: MSG_CHANGE, MSG_CLICK, MSG_DBLCLICK, MSG_SETFOCUS, MSG_KILLFOCUS, MSG_COMMATEXT, MSG_RESET, MSG_RANDOMIZE, MSG_AFTERLOADING, MSG_CHUNK_DESTROYED, MSG_CHUNK_ITEM_LIST_CHANGED
|
virtual int onGetNumberOfParams(int queryResult1, int queryResult2);Return the number of parameters based on user query popup selection. Used for dynamic parameter counts (e.g., multi-channel audio modules).
virtual void onAfterQuery(TMasterInfo* pMasterInfo, TModuleInfo* pModuleInfo,
int queryResult1, int queryResult2);Called after the query popup closes. Store query results for later use.
virtual void onInitModule(TMasterInfo* pMasterInfo, TModuleInfo* pModuleInfo);Called after all parameters are set up. Initialize resources, create threads, allocate buffers here.
virtual void onProcess();Called on the audio thread at every block tick. This is where audio/data processing happens.
Critical rules:
- No memory allocation
- No blocking I/O
- No locks (unless absolutely necessary and very brief)
- Keep as fast as possible
virtual void onProcessVideo();Called by the video thread for mtVideo modules. Use sdkGetInputFrame() and sdkSetOutputFrame() here.
void startJob();Launches (or restarts) the background job thread. Call this to trigger async processing.
virtual void onJobBegin();Called on the job thread before processing begins. Set up job state here.
virtual void onJobProcess();Called on the job thread. Execute your long-running task here.
virtual void onJobEnd();Called on the main thread after the job thread finishes. Collect results and update outputs here.
Example: See BackgroundJob for a complete background job implementation.
virtual void onBlocSizeChange(int BlocSize);Called when the audio block size changes. Resize buffers as needed.
virtual void onSampleRateChange(double SampleRate);Called when the sample rate changes. Update timing calculations.
virtual int onGetChunkLen(LongBool Preset);Return the estimated byte size of your chunk data. Preset indicates if saving a preset vs. full save.
virtual void onGetChunk(void* chunk, LongBool Preset);Write your module state into the chunk buffer.
virtual void onSetChunk(const void* chunk, int sizeInBytes, LongBool Preset);Restore your module state from the chunk buffer.
virtual void onAfterLoading();Called after the module is fully loaded and all chunks are restored.
Examples: See DrawTrajectoryBox and UsineChunks for chunk system usage.
virtual void onCreateSettings();Add entries to the module's Settings Panel using sdkAddSettingLine* methods.
virtual void onSettingsHasChanged();Called when any setting value changes. React accordingly.
virtual void onResize(float contentWidth, float contentHeight);Called when the module canvas is resized.
virtual void onPaint();Draw the module canvas content. Use sdkDraw* and sdkFill* methods.
Example: See DataOscilloscope for a graphics canvas implementation.
virtual void onMouseMove(TShiftState Shift, float X, float Y);Mouse moved over canvas. Coordinates are normalized (0.0 to 1.0).
virtual void onMouseDown(TMouseButton Button, TShiftState Shift, float X, float Y);Mouse button pressed.
virtual void onMouseUp(TMouseButton Button, TShiftState Shift, float X, float Y);Mouse button released.
virtual void onMouseWheel(TShiftState Shift, int WheelDelta);Mouse wheel scrolled.
virtual void onMouseMoveMulti(TShiftState Shift, UsineEventClass& touchPosX,
UsineEventClass& touchPosY, UsineEventClass& mouseBtn);
virtual void onMouseDownMulti(TShiftState Shift, UsineEventClass& touchPosX,
UsineEventClass& touchPosY, UsineEventClass& mouseBtn);
virtual void onMouseUpMulti(TShiftState Shift, UsineEventClass& touchPosX,
UsineEventClass& touchPosY, UsineEventClass& mouseBtn);virtual void onCreateCommands();Add entries using sdkAddCommand() and sdkAddCommandSeparator().
virtual void onSetRecordedValue(TPrecision X, TPrecision Y, TPrecision Z);Called during playback of recorded automation curves.
virtual void onRandomize();Called when the user triggers randomize. Randomize your module state.
virtual void onReset();Called when the user triggers reset. Reset your module to default state.
virtual void onSetQuickColor(TUsineColor color);Called when the user changes the module's global quick color.
virtual void onOpenEditor();
virtual void onBringToFront();
virtual void onCloseEditor();
virtual void onResizeEditor(int width, int height);Manage external child windows created with sdkCreateDeskWindow().
virtual void onMidiSendOut(int DeviceID, TUsineMidiCode Code);virtual void onDMXSendOut(int deviceId, char* ByteArray, int len, int universeNum);virtual void onLaserSendOut(int DeviceID, TUsineILDAPoint** pointsArray,
int numOfPoints, int convergenceAngle);These non-virtual methods are available for use in onPaint():
| Method | Description |
|---|---|
sdkDrawPoint(pos, color, size, rounded) |
Draw a single point |
sdkDrawMultiPoints(points, colors, size, rounded, count) |
Draw multiple points |
sdkDrawLine(p1, p2, color, width) |
Draw a line |
sdkDrawPolyLine(points, count, color, width) |
Draw a polyline |
sdkFillPolyLine(points, count, color) |
Fill a polygon |
sdkFillRect(rect, color, borderWidth, borderColor, radius) |
Fill a rectangle |
sdkFillText(rect, text, color, fontSize, bold, wordwrap, hAlign, vAlign) |
Draw text |
sdkBitBlit(pixels, W, H, rect) |
Blit a pixel buffer |
| Method | Description |
|---|---|
sdkDrawPathStart() |
Begin a new path |
sdkDrawPathMoveTo(point) |
Move path cursor |
sdkDrawPathLineTo(point) |
Add line segment |
sdkDrawPathQuadCurveTo(control, end) |
Add quadratic bezier curve |
sdkDrawPathClose() |
Close the path |
sdkDrawPathDraw(color, width) |
Stroke the path |
sdkDrawPathFill(color) |
Fill the path |
| Method | Description |
|---|---|
sdkRepaintPanel() |
Request canvas repaint |
sdkSetListBoxCommaText(param, text) |
Update listbox options |
sdkSetParamCaption(param, caption) |
Update parameter label |
sdkSetParamVisible(param, visible) |
Show/hide parameter |
sdkRecreateParam(param, paramInfo) |
Recreate a parameter |
sdkSetParamValueText(param, text) |
Set parameter display text |
sdkRepaintParam(param) |
Repaint a specific parameter |
| Member | Type | Description |
|---|---|---|
panelWidth |
float |
Current canvas width |
panelHeight |
float |
Current canvas height |
m_moduleInfo |
TModuleInfo* |
Pointer to module info |
m_masterInfo |
static TMasterInfo* |
Pointer to master info (shared) |
- UsineEventClass — Event data manipulation
- Data Types & Constants — Type definitions and enumerations
- SDK Functions — Global utility functions
- Module Architecture — How modules are structured
- Utility Functions — Color, geometry, math helpers
- Getting Started — Getting started with the SDK