Utils
Module included in FL Studio Python lib folder.
Contains useful functions and classes for use when working with FL Studio's Python API.
Note
This code is taken from FL Studio's Python lib folder and included in this package in the hope that it will be useful for script developers. It is not the creation of the repository authors, and no credit is claimed for the code content. However, the documentation for the provided code is created by the authors of this repository.
WARNING
Many of the provided functions in the FL Studio installation have bugs that may result in unexpected behavior. These bugs have been left as-is in this file for your inspection and warnings have been added to the docstrings. Use any functions here with caution.
TRect
Represents a rectangle object
__init__
Create a TRect
object representing a rectangle
Args:
-
left (int): left position
-
top (int): top position
-
right (int): right position
-
bottom (int): bottom position
RectOverlapEqual
Returns whether two rectangles are overlapping or touching
Args:
-
R1 (TRect): rectangle 1
-
R2 (TRect): rectangle 2
Returns:
- bool: whether rectangles overlap or touch
RectOverlap
Returns whether two rectangles are overlapping
Args:
-
R1 (TRect): rectangle 1
-
R2 (TRect): rectangle 2
Returns:
- bool: whether rectangles overlap
Limited
Limit a value to within the range Min
- Max
Args:
-
Value (float): Current value
-
Min (float): Min value
-
Max (float): Max value
Returns:
- float: limited value
InterNoSwap
Returns whether A <= X <= B, ie. whether X lies between A and B
Args:
-
X (number): x
-
A (number): a
-
B (number): b
Returns:
- bool
DivModU
Return integer division and modulus
Args:
-
A (int): int 1
-
B (int): int 2
Returns:
-
int: integer division
-
int: modulus
SwapInt
Zeros
Zeros_Strict
Sign
Equivalent to SignOf()
Args:
- value (
float | int
): number
Returns:
int
: sign
SignOf
Return the sign of a numerical value
Args:
- value (
float | int
): number
Returns:
-
int
: sign:-
0
: zero -
1
: positive -
-1
: negative
-
OffsetRect
Offset a rectangle by dx
and dy
Args:
-
R (TRect): rectangle
-
dx (int): x offset
-
dy (int): y offset
NOTE: Rectangle is adjusted in-place
RGBToHSV
Convert an RGB color to a HSV color
WARNING: Make sure to convert
Args:
-
R (float): red (0.0 - 1.0)
-
G (float): green (0.0 - 1.0)
-
B (float): blue (0.0 - 1.0)
Returns:
-
H: hue (degrees: 0.0-360)
-
S: saturation (0.0-1.0)
-
V: value/luminosity (0.0/1.0)
RGBToHSVColor
Convert an RGB color to a HSV color
Args:
- Color (int): color as integer (
0x--BBGGRR
)
Returns:
-
H: hue
-
S: saturation
-
V: value (brightness)
HSVtoRGB
Convert an HSV color to an RGB color
WARNING: This function returns data in an unexpected format! Be sure to convert as required before usage.
Args:
-
H (float): hue (degrees: 0.0-360)
-
S (float): saturation (0-1.0)
-
V (float): value/luminosity (0-1.0)
Returns:
-
float: red (0.0-1.0)
-
float: green (0.0-1.0)
-
float: blue (0.0-1.0)
GetNoteName
Return the note name given a note number
Args:
- NoteNum (int): note number
Returns:
- str: note name
ColorToRGB
Convert an integer color to an RGB tuple that uses range 0-255.
Args:
- Color (int): color as integer
Returns:
-
int: red
-
int: green
-
int: blue
RGBToColor
convert an RGB set to an integer color. values must be 0-255
Args:
-
R (int): red
-
G (int): green
-
B (int): blue
Returns:
- int: color
FadeColor
Fade between two colors
Args:
-
StartColor (int): color integer
-
EndColor (int): color integer
-
Value (float): fade position (0-255)
Returns:
- int: faded color
WARNING
- Blue value is incorrect, using green start value
LightenColor
Lighten a color by a certain amount
Args:
-
Color (int): color integer
-
Value (float): amount to lighten by (0-255)
Returns:
- int: lightened color