XJ music engine  1.9.6
In-game runtime engine for XJ music.
Static Public Member Functions | Static Public Attributes | List of all members
XJ::ValueUtils Class Reference

#include <ValueUtils.h>

Static Public Member Functions

static float eitherOr (float d1, float d2)
 
static std::string eitherOr (std::string s1, std::string s2)
 
static std::set< int > dividedBy (float divisor, const std::set< int > &originals)
 
static float ratio (float value, float limit)
 
static bool isInteger (const std::string &raw)
 
static float limitDecimalPrecision (float value)
 
static std::string k (int value)
 
static std::string randomFrom (std::vector< std::string > from)
 
static std::vector< std::string > randomFrom (std::vector< std::string > from, int num)
 
static long gcd (long a, long b)
 
static std::vector< int > factors (long target, std::vector< int > testFactors)
 
static int subDiv (int numerator, int denominator)
 
static int multipleFloor (int factor, float value)
 
static float interpolate (float floor, float ceiling, float position)
 
static void enforceMaxStereo (int value)
 
static std::optional< UUIDgetKeyOfHighestValue (const std::map< UUID, int > &map)
 
static int roundToNearest (int N, int value)
 
static std::vector< UUIDwithIdsRemoved (std::vector< UUID > fromIds, int count)
 
static std::string emptyZero (int value)
 
static std::vector< std::string > last (int num, std::vector< std::string > list)
 

Static Public Attributes

static long MILLIS_PER_SECOND = 1000
 
static long MICROS_PER_MILLI = 1000
 
static long NANOS_PER_MICRO = 1000
 
static long MICROS_PER_SECOND = MICROS_PER_MILLI * MILLIS_PER_SECOND
 
static float MICROS_PER_SECOND_FLOAT = static_cast<float>(MICROS_PER_SECOND)
 
static long NANOS_PER_SECOND = NANOS_PER_MICRO * MICROS_PER_SECOND
 
static long SECONDS_PER_MINUTE = 60
 
static long MICROS_PER_MINUTE = SECONDS_PER_MINUTE * MICROS_PER_SECOND
 
static float MICROS_PER_MINUTE_FLOAT = static_cast<float>(MICROS_PER_MINUTE)
 
static long MINUTES_PER_HOUR = 60
 
static long HOURS_PER_DAY = 24
 
static long SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR
 
static long SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY
 

Member Function Documentation

◆ dividedBy()

std::set< int > ValueUtils::dividedBy ( float  divisor,
const std::set< int > &  originals 
)
static

Divide a set of integers by a float and return the divided set

Parameters
divisorto divide by
originalsto divide
Returns
divided originals

◆ eitherOr() [1/2]

float ValueUtils::eitherOr ( float  d1,
float  d2 
)
static

Return the first value if it's non-null, else the second

Parameters
d1to check if non-null and return
d2to default to, if s1 is null
Returns
s1 if non-null, else s2

◆ eitherOr() [2/2]

std::string ValueUtils::eitherOr ( std::string  s1,
std::string  s2 
)
static

Return the first value if it's non-null, else the second

Parameters
s1to check if non-null and return
s2to default to, if s1 is null
Returns
s1 if non-null, else s2

◆ emptyZero()

std::string ValueUtils::emptyZero ( int  value)
static

Get string value of int, or empty if zero

Parameters
valueto translate
Returns
non-zero value, or empty

◆ enforceMaxStereo()

void ValueUtils::enforceMaxStereo ( int  value)
static

Enforce a maximum

Parameters
valueactual
Exceptions
runtime_errorif value greater than allowable

◆ factors()

std::vector< int > ValueUtils::factors ( long  target,
std::vector< int >  testFactors 
)
static

Get the values (filtered from the given set of test factors) which are factors of the target value

Parameters
targetwhich we'll test values against
testFactorsvalues to test
Returns
values that are indeed a factor of the target value

◆ gcd()

long ValueUtils::gcd ( long  a,
long  b 
)
static

Greatest common denominator of two numbers

Parameters
afrom which to compute
bfrom which to compute
Returns
greatest common denominator

◆ getKeyOfHighestValue()

std::optional< UUID > ValueUtils::getKeyOfHighestValue ( const std::map< UUID, int > &  map)
static

Get the key from a map, based on the highest value stored

Parameters
mapof key-value pairs
Returns
key of the highest value

◆ interpolate()

float ValueUtils::interpolate ( float  floor,
float  ceiling,
float  position 
)
static

Interpolate a value between the floor and ceiling

Parameters
floorbottom value
ceilingtop value
positionbetween 0 and 1 of value to interpolate between the floor and ceiling
Returns
interpolated value

◆ isInteger()

bool ValueUtils::isInteger ( const std::string &  raw)
static

True if input string is an integer

Parameters
rawtext to check if it's an integer
Returns
true if it's an integer

◆ k()

std::string ValueUtils::k ( int  value)
static

Get the "kilos" representation of an integer, as in 128k for 128000

Parameters
valuefor which to get kilos
Returns
kilos representation

◆ last()

std::vector< std::string > ValueUtils::last ( int  num,
std::vector< std::string >  list 
)
static

Get the last N values from a list

Parameters
numof entries
listof all entries
Returns
last N entries from the list

◆ limitDecimalPrecision()

float ValueUtils::limitDecimalPrecision ( float  value)
static

Round a value to N decimal places. Architect wants to limit the floating point precision of chord and event position, in order to limit obsession over the position of things. https://www.pivotaltracker.com/story/show/154976066

Parameters
valueto round
Returns
rounded position

◆ multipleFloor()

int ValueUtils::multipleFloor ( int  factor,
float  value 
)
static

Round down to a multiple of the given factor

Parameters
factorof which to get a multiple
valuesource
Returns
floor of value

◆ randomFrom() [1/2]

std::string ValueUtils::randomFrom ( std::vector< std::string >  from)
static

Get a random string from the collection

Parameters
fromwhich to get random string
Returns
random string from collection

◆ randomFrom() [2/2]

std::vector< std::string > ValueUtils::randomFrom ( std::vector< std::string >  from,
int  num 
)
static

Get N number of the member strings from the collection. Don't repeat a choice.

Parameters
fromwhich to get random strings
numnumber of strings to get
Returns
random strings from collection

◆ ratio()

float ValueUtils::ratio ( float  value,
float  limit 
)
static

Calculate ratio (of 0 to 1) within a zero-to-N limit

Parameters
valueto calculate radio of
limitN where ratio will be calculated based on zero-to-N
Returns
ratio between 0 and 1

◆ roundToNearest()

int ValueUtils::roundToNearest ( int  N,
int  value 
)
static

Round value to the nearest positive multiple of N

◆ subDiv()

int ValueUtils::subDiv ( int  numerator,
int  denominator 
)
static

Get the smallest subdivision within the total, e.g. — [12,3] = 4 — [12,4] = 3 — [16,4] = 4 — [24,3] = 4 — [24,4] = 3 — [48,3] = 4 — [48,4] = 3 — [64,4] = 4

Parameters
numeratorfrom which to compute
denominatorfrom which to compute

◆ withIdsRemoved()

std::vector< UUID > ValueUtils::withIdsRemoved ( std::vector< UUID fromIds,
int  count 
)
static

Remove some number of ids from the list

Parameters
fromIdsto begin with
countnumber of ids to add
Returns
list including added ids

Member Data Documentation

◆ HOURS_PER_DAY

long ValueUtils::HOURS_PER_DAY = 24
static

◆ MICROS_PER_MILLI

long ValueUtils::MICROS_PER_MILLI = 1000
static

◆ MICROS_PER_MINUTE

long ValueUtils::MICROS_PER_MINUTE = SECONDS_PER_MINUTE * MICROS_PER_SECOND
static

◆ MICROS_PER_MINUTE_FLOAT

float ValueUtils::MICROS_PER_MINUTE_FLOAT = static_cast<float>(MICROS_PER_MINUTE)
static

◆ MICROS_PER_SECOND

long ValueUtils::MICROS_PER_SECOND = MICROS_PER_MILLI * MILLIS_PER_SECOND
static

◆ MICROS_PER_SECOND_FLOAT

float ValueUtils::MICROS_PER_SECOND_FLOAT = static_cast<float>(MICROS_PER_SECOND)
static

◆ MILLIS_PER_SECOND

long ValueUtils::MILLIS_PER_SECOND = 1000
static

◆ MINUTES_PER_HOUR

long ValueUtils::MINUTES_PER_HOUR = 60
static

◆ NANOS_PER_MICRO

long ValueUtils::NANOS_PER_MICRO = 1000
static

◆ NANOS_PER_SECOND

long ValueUtils::NANOS_PER_SECOND = NANOS_PER_MICRO * MICROS_PER_SECOND
static

◆ SECONDS_PER_DAY

long ValueUtils::SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY
static

◆ SECONDS_PER_HOUR

long ValueUtils::SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR
static

◆ SECONDS_PER_MINUTE

long ValueUtils::SECONDS_PER_MINUTE = 60
static

The documentation for this class was generated from the following files: