-
Notifications
You must be signed in to change notification settings - Fork 1
usine event class
#sdk #reference #class #events #audio #midi #data #color
UsineEventClass is the main data container class in the Usine SDK. It wraps a UsineEventPtr and provides methods for manipulating audio, data, MIDI, color, and text values.
Defined in: sdk/UsineEventClass.h
Events are the universal data type in Usine. Every parameter is backed by an event, and all data flows through events. An event is essentially a dynamically-sized array of float (TPrecision) values with specialized accessors for different data interpretations.
UsineEventClass(); // Default constructor (null event)
explicit UsineEventClass(UsineEventPtr e); // Wrap existing event pointerNote:
UsineEventClassis non-copyable (copy assignment is deleted). Events are typically bound to parameters viaTParamInfo::setEventClass()and managed by Usine.
void createEvent(int size); // Allocate a new event with given size
void destroyEvent(); // Destroy the event and set to nullptrUse createEvent/destroyEvent for temporary events (e.g., intermediate buffers in audio processing). Events bound to parameters are managed automatically.
UsineEventPtr& event(); // Get raw event pointer
operator UsineEventPtr(); // Implicit cast to UsineEventPtr
explicit operator UsineEventPtr*(); // Explicit cast to pointer-to-pointervoid setSize(int size); // Set number of elements
int getSize(); // Get number of elements
void setMaxSize(int size); // Set maximum capacity (pre-allocate)void setData(TPrecision value); // Set the first element
TPrecision getData(); // Get the first element
void setColor(TUsineColor color); // Set as color value
TUsineColor getColor(); // Get as color value
void setPChar(AnsiCharPtr s); // Set text value
AnsiCharPtr getPChar(); // Get text valuevoid setArrayData(int index, TPrecision value); // Set element at index
TPrecision getArrayData(int index); // Get element at index
void pushArrayData(TPrecision value); // Append value (auto-resizes by PUSH_GRANULARITY=128)
void setArrayColor(int index, TUsineColor color); // Set color at index
TUsineColor getArrayColor(int index); // Get color at index
void setArrayMidi(int index, TUsineMidiCode midi); // Set MIDI code at index
TUsineMidiCode getArrayMidi(int index); // Get MIDI code at index
T3DPointF get3DPoint(int pointIndex); // Get 3D point (event size must be multiple of 3)
TPrecision* getDataAddr(); // Get raw pointer to first elementFor ptPointer type parameters:
void* getPointerData(); // Get raw pointer data
int getPointerDataSize(); // Get pointer data size in bytes
void setPointerDataSize(int size); // Set pointer data size in bytes
int getPointerDataType(); // Get pointer data type
void setPointerDataChanged(); // Notify Usine that pointer data changedLongBool compare(UsineEventClass& e); // Compare two events for equality
void copyfrom(UsineEventClass& src); // Copy data from source
void copyto(UsineEventClass& dest); // Copy data to destination
void concat(UsineEventClass& e); // Append another event's data
void shift(int n); // Shift values right (n>0) or left (n<0)void add(UsineEventClass& e); // Element-wise addition
void sub(UsineEventClass& e); // Element-wise subtraction
void mult(TPrecision factor); // Multiply all elements by scalar
void mult(UsineEventClass& e); // Element-wise multiplication
void div(UsineEventClass& e); // Element-wise division
void mod(UsineEventClass& e); // Element-wise modulo
void power(UsineEventClass& e); // Element-wise powervoid exp(); // Exponential of all elements (in-place)
void sqrt(); // Square root of all elements (in-place)
TPrecision max(); // Get maximum value
TPrecision min(); // Get minimum value
void tresh(TPrecision min, TPrecision max); // Clamp values to rangevoid multAudio(UsineEventClass& e); // Multiply audio events (optimized)
void fadeIn(); // Apply fade-in envelope
void fadeOut(); // Apply fade-out envelope
void clearAudio(); // Zero audio with denormalization
void denormalizeAudio(); // Add tiny value to prevent denormalsvoid mixMidi(UsineEventClass& e); // Mix MIDI events togethervoid smooth(TPrecision& oldValue, TPrecision factor);
// Smooth a single value: oldValue += (getData() - oldValue) * factor
void smooth(TPrecision& oldValue, TPrecision target, TPrecision factor);
// Smooth towards target: oldValue += (target - oldValue) * factor| Constant | Value | Description |
|---|---|---|
SMOOTH_VERY_VERY_SLOW |
0.00001f |
Extremely slow smoothing |
SMOOTH_VERY_SLOW |
0.0001f |
Very slow smoothing |
SMOOTH_SLOW |
0.001f |
Slow smoothing |
SMOOTH_NORMAL |
0.005f |
Normal smoothing |
SMOOTH_FAST |
0.01f |
Fast smoothing |
SMOOTH_VERY_FAST |
0.05f |
Very fast smoothing |
SMOOTH_VERY_VERY_FAST |
0.1f |
Extremely fast smoothing |
SMOOTH_NO_SMOOTH |
1.0f |
No smoothing (instant) |
See DataMultiply for a complete example.
UsineEventClass input, output;
// In onProcess:
float value = input.getData();
output.setData(value * 2.0f);See AudioVolume for a complete example.
UsineEventClass audioIn, audioOut, gain;
// In onProcess:
audioOut.copyfrom(audioIn);
audioOut.multAudio(gain);UsineEventClass arrayEvt;
arrayEvt.createEvent(10);
for (int i = 0; i < 10; i++)
arrayEvt.setArrayData(i, (float)i);
float val = arrayEvt.getArrayData(5); // 5.0
arrayEvt.pushArrayData(99.0f); // appends, now size=11See MidiTranspose for a complete example.
UsineEventClass midiIn, midiOut;
// In onProcess:
int size = midiIn.getSize();
midiOut.copyfrom(midiIn);
for (int i = 0; i < size; i++)
{
TUsineMidiCode code = midiOut.getArrayMidi(i);
if (code.Msg == MIDI_NOTEON)
code.Data1 += 12; // transpose up one octave
midiOut.setArrayMidi(i, code);
}-
Data Types & Constants —
TPrecision,TUsineColor,TUsineMidiCode, etc. - Module Architecture — How events flow through modules
- UserModuleBase Class — Module base class and callbacks
- SDK Functions — Global utility functions