Util¶
Stl.Util
Import¶
import "_IVLS/std-library/nodes/components/util.ksp"Node: Stl.Util¶
Uses: Init
Overview¶
Stl.Util
LIBRARY MODULE
General-purpose utility functions and macros for KSP array and value operations.
Provides array scanning (max, min, instance counting, value-count histograms), array manipulation (reverse, fill, copy, 2D copy, 2D resize, offset copy), variable swap helpers for integer, real, and string types, BPM calculation from DURATION_QUARTER, binary printing, a debug-conditional logging macro, and an async blocking helper. All state is held in the util family namespace.
This node is instantiated internally by lib.ICB() and must not be instantiated directly by user scripts.
API¶
Nodes¶
| Name | Description |
|---|---|
node Stl.Util |
--- |
Macros¶
| Name | Description |
|---|---|
util.array.copy(#arr_a#, #arr_b#) |
--- |
util.array.copy.2d(#arr_a#, #arr_b#) |
--- |
util.array.copy_n(#arr_a#, #arr_b#, #start_a#, #start_b#, #n#) |
--- |
util.array.fill(#arr#, #value#) |
--- |
util.array.print(#arr#, #from#, #to#) |
--- |
util.array.resize.2d(#array#, #old_size1#, #old_size2#, #new_size2#) |
--- |
util.async_block(#block#) |
--- |
util.f_swap(#a#, #b#) |
--- |
util.log(#text#) |
Prints a log message via message(). |
util.s_swap(#a#, #b#) |
--- |
util.swap(#a#, #b#) |
--- |
Functions¶
| Name | Description |
|---|---|
util.array.f_reverse(array) |
Reverses the values in the array of floats in place. |
util.array.fill_value_counts(count_array, value_array) |
Fills count_array with counts of each value found in value_array, where the inde... |
util.array.instances(array, value) -> return |
--- |
util.array.max(array) -> return |
--- |
util.array.max_idx(array) -> return |
--- |
util.array.min(array) -> return |
--- |
util.array.min_idx(array) -> return |
--- |
util.array.reverse(array) |
Reverses the values in the array of integers in place. |
util.get_bpm() -> return |
Returns the current host tempo in beats per minute as an integer. |
util.get_bpm_f() -> return |
Returns the current host tempo in beats per minute as a real number. |
util.print_as_binary(int_value) |
Prints int_value as a binary number, MSB first, via message(). |
Nodes¶
node Stl.Util¶
Callbacks: Init
(No description available.)
Preconditions: This is an internal call inside lib.ICB()
Macros¶
util.array.copy(#arr_a#, #arr_b#)¶
(No description available.)
| Parameter | Description |
|---|---|
#arr_a# |
source array |
#arr_b# |
destination array |
Post: Copies contents of array a into b.
util.array.copy.2d(#arr_a#, #arr_b#)¶
(No description available.)
| Parameter | Description |
|---|---|
#arr_a# |
source array |
#arr_b# |
destination array |
Post: Copies contents of 2D array a into b, as long as b's size is equal to or larger than a.
util.array.copy_n(#arr_a#, #arr_b#, #start_a#, #start_b#, #n#)¶
(No description available.)
| Parameter | Description |
|---|---|
#arr_a# |
source array |
#arr_b# |
destination array |
#start_a# |
starting value of a |
#start_b# |
starting value of b |
#n# |
number of elements (MUST be within bounds of both arrays) |
Post: copies n contents of array a into b, at given start points if start_a + n is less than start_b, this can be used to in-place copy within a single array by supplying the same name to both arr_a and arr_b
util.array.fill(#arr#, #value#)¶
(No description available.)
| Parameter | Description |
|---|---|
#arr# |
array to fill, type-agnostic |
#value# |
value to fill arr with, must match arr's value type |
Post: Fills arr with value.
util.array.print(#arr#, #from#, #to#)¶
(No description available.)
| Parameter | Description |
|---|---|
#arr# |
array to print, type-agnostic |
#from# |
array index from which printing starts |
#to# |
array index to which printing executes, inclusive |
util.array.resize.2d(#array#, #old_size1#, #old_size2#, #new_size2#)¶
(No description available.)
| Parameter | Description |
|---|---|
#array# |
the array we are operating on |
#old_size1# |
array first dimension OLD size |
#old_size2# |
array second dimension OLD size |
#new_size2# |
array second dimension NEW size |
Post: Resizes a 2D array, useful for converting from old snapshot versions.
util.async_block(#block#)¶
(No description available.)
| Parameter | Description |
|---|---|
#block# |
accessor for the blocking number (variable or array element) |
Post: will perform a wait() until the blocking number is less than 0
util.f_swap(#a#, #b#)¶
(No description available.)
| Parameter | Description |
|---|---|
#a# |
the first variable |
#b# |
the second variable |
Post: swaps contents of the two float variables
util.log(#text#)¶
Prints a log message via message(). Only active when SET_CONDITION(DEBUG) is set.
| Parameter | Description |
|---|---|
#text# |
log message to print |
util.s_swap(#a#, #b#)¶
(No description available.)
| Parameter | Description |
|---|---|
#a# |
the first variable |
#b# |
the second variable |
Post: swaps contents of the two string variables
util.swap(#a#, #b#)¶
(No description available.)
| Parameter | Description |
|---|---|
#a# |
the first variable |
#b# |
the second variable |
Post: swaps contents of the two integer variables
Functions¶
util.array.f_reverse(array)¶
Reverses the values in the array of floats in place.
| Parameter | Type | Description |
|---|---|---|
array |
float | source array |
util.array.fill_value_counts(count_array, value_array)¶
Fills count_array with counts of each value found in value_array, where the index equals the value being counted (e.g. index 0 holds the count of 0s).
Preconditions: count_array should have number of elements >= that of the max value of value array
| Parameter | Description |
|---|---|
count_array |
array indexed by the actual value to be counted, i.e. index 0 is the number of 0's found in the value_array |
value_array |
array of values to count |
util.array.instances(array, value) -> return¶
(No description available.)
| Parameter | Description |
|---|---|
array |
source array, type-agnostic |
value |
value for which the array will be scanned, has to be the same type as the array |
Returns: return
util.array.max(array) -> return¶
(No description available.)
| Parameter | Description |
|---|---|
array |
source array, type-agnostic |
Returns: return — maximum value found in the array (same type as the array)
util.array.max_idx(array) -> return¶
(No description available.)
| Parameter | Description |
|---|---|
array |
source array, type-agnostic |
Returns: return
util.array.min(array) -> return¶
(No description available.)
| Parameter | Description |
|---|---|
array |
source array, type-agnostic |
Returns: return — minimum value found in the array (same type as the array)
util.array.min_idx(array) -> return¶
(No description available.)
| Parameter | Description |
|---|---|
array |
source array, type-agnostic |
Returns: return — index of the minimum value in the array
util.array.reverse(array)¶
Reverses the values in the array of integers in place.
| Parameter | Type | Description |
|---|---|---|
array |
int | source array |
util.get_bpm() -> return¶
Returns the current host tempo in beats per minute as an integer.
Returns: return — current tempo in BPM, rounded to nearest integer
util.get_bpm_f() -> return¶
Returns the current host tempo in beats per minute as a real number.
Returns: return — current tempo in BPM
util.print_as_binary(int_value)¶
Prints int_value as a binary number, MSB first, via message().
| Parameter | Description |
|---|---|
int_value |
Example¶
// TODO: Add usage example