utils

blender.py

FCurvesFromObject(obj: bpy.types.Object) -> (obj: bpy.types.Object)

Gets FCurves (bpy.types.FCurve) from an object (bpy.types.Object).

Parameters

obj (bpy.types.Object) – the Blender object

Return List[bpy.types.FCurve]

a list of bpy.types.FCurve objects. If the object does not have FCurves, it will return an empty list.

cleanCollection(col: bpy.types.Collection, refObject: bpy.types.Object = None) -> (col: bpy.types.Collection, refObject: bpy.types.Object = None)

Cleans a collection of old objects (to be reanimated)

cleanKeyframes(obj: bpy.types.Object, channels: Set = {'all_channels'})

this will DELETE the keyframes on the specified object.

Parameters
  • obj (bpy.types.Object) – the Blender object to clean

  • channels (Set) – the channels to clean. If none are specified, it will delete all, defaults to {“all_channels”}

copyKeyframeProperties(obj: bpy.types.Object, keyframeToCopy: bpy.types.Keyframe, data_path: str = None, array_index: str = None)

Copies all properties of the last keyframe on the specified data path and array index EXCEPT for the frame and value.

Parameters
  • obj (bpy.types.Object) – the Blender object

  • keyframeToCopy (bpy.types.Keyframe) – the keyframe to copy the properties from

  • data_path (str) – the specific FCurve data path, defaults to None

  • array_index (str) – the specific FCurve array index, defaults to None

deleteMarkers(name: str)

deletes specific name markers on the scene

Parameters

name (str) – the makrer of the name

distanceFromVectors(point1: mathutils.Vector, point2: mathutils.Vector) -> (point1: mathutils.Vector, point2: mathutils.Vector)

Calculate distance between two points.

Parameters
  • point1 (Vector) – the first point

  • point2 (Vector) – the second point

Return float

the length between the two points

framesToSec(frames: float) -> (frames: float)

converts (using the Blender scene’s FPS) specified time (in frames) to seconds

Parameters

frames (float) – the time in frames

Return float

the time in seconds

getExactFps()

gets exact FPS (decimal place) of the Blender scene.

Return float

the exact FPS of the current Blender scene

objectsOverlap(obj1: bpy.types.Object, obj2: bpy.types.Object) -> (obj1: bpy.types.Object, obj2: bpy.types.Object)

finds out if two objects are overlapping

Parameters
  • obj1 (bpy.types.Object) – the first object

  • obj2 (bpy.types.Object) – the second object

Return bool

returns True if the object’s bounding boxes are overlapping, False otherwise

secToFrames(sec: float) -> (sec: float)

converts (using the Blender scene’s FPS) specified time (in seconds) to frames

Parameters

sec (float) – the time in seconds

Return float

the time in frames

setKeyframeHandleType(obj: bpy.types.Object, handleType: str, data_path=None, array_index=None)

sets the last keyframe’s on the object handle typw

Parameters
  • obj (bpy.types.Object) – the Blender object

  • handleType (str) – the handle type to set. Can be one of the following: ‘FREE’, ‘ALIGNED’, ‘VECTOR’, ‘AUTO’, ‘AUTO_CLAMPED’.

  • data_path (str) – the specific FCurve data path, defaults to None

  • array_index (str) – the specific FCurve array index, defaults to None

setKeyframeInterpolation(obj: bpy.types.Object, interpolation: str, data_path: str = None, array_index: str = None)

sets the last keyframe’s on the object interpolation

Parameters
  • obj (bpy.types.Object) – the Blender object

  • interpolation (str) – the interpolation to set. Can be one of the following: ‘CONSTANT’, ‘LINEAR’, ‘BEZIER’, ‘SINE’, ‘QUAD’, ‘CUBIC’, ‘QUART’, ‘QUINT’, ‘EXPO’, ‘CIRC’, ‘BACK’, ‘BOUNCE’, ‘ELASTIC’.

  • data_path (str) – the specific FCurve data path, defaults to None

  • array_index (str) – the specific FCurve array index, defaults to None

shapeKeyFCurvesFromObject(obj: bpy.types.Object) -> (obj: bpy.types.Object)

Gets shape key (bpy.types.ShapeKey) FCurves from a object (bpy.types.Object).

Parameters

obj (bpy.types.Object) – the Blender object

Return List[bpy.types.FCurve]

a list of bpy.types.FCurve objects. If the object does not have FCurves, it will return an empty list.

shapeKeysFromObject(obj: bpy.types.Object) -> (obj: bpy.types.Object)

gets shape keys from object

Parameters

object (bpy.types.Object) – the blender object

Return tuple

returns a tuple, first element being a list of the shape keys and second element being the reference key

showHideObj(obj: bpy.types.Object, hide: bool, frame: int)

adds keyframes to show/hide the object from the viewport and render

Parameters
  • obj (bpy.types.Object) – the Blender object to hide/unhide

  • hide (bool) – True to hide the object, False to unhide the object

  • frame (int) – the frame at which to hide/unhide the object

timeFromVectors(point1: mathutils.Vector, point2: mathutils.Vector, velocity: float) -> (point1: mathutils.Vector, point2: mathutils.Vector, velocity: float)

Calculats the time from 2 vectors given a velocity

Parameters
  • point1 (Vector) – the first point

  • point2 (Vector) – the second point

  • velocity (float) – the velocity

Return float

the amount of time between moving between these two points

validateFCurves(noteOnFCurves: typing.List[typing.Union[bpy.types.FCurve, ObjectShapeKey]], noteOffFCurves: typing.List[typing.Union[bpy.types.FCurve, ObjectShapeKey]], haveSorted: bool = False) -> (noteOnFCurves: typing.List[typing.Union[bpy.types.FCurve, ObjectShapeKey]], noteOffFCurves: typing.List[typing.Union[bpy.types.FCurve, ObjectShapeKey]], haveSorted: bool = False)

This function will ensure both lists of FCurves have the same data_paths and array_indexes.

Parameters
  • noteOnFCurves (List[Union[bpy.types.FCurve, ObjectShapeKey]]) – the list of Note On curves

  • noteOffFCurves (List[Union[bpy.types.FCurve, ObjectShapeKey]]) – the list of Note Off curves

  • haveSorted (bool) – this will sort the objects for you, defaults to False

Return bool

True if valid, False otherwise

velocityFromVectors(point1: mathutils.Vector, point2: mathutils.Vector, frames: float) -> (point1: mathutils.Vector, point2: mathutils.Vector, frames: float)

Calculates velocity from 2 vectors given a time

Parameters
  • point1 (Vector) – the first point

  • point2 (Vector) – the second point

  • frames (float) – the amount of time between moving between these two points

Return float

the velocity

worldBoundingBox(obj: bpy.types.Object)

gets the corners of the bounding box of an object in world coordinates

Parameters

obj (bpy.types.Object) – the Blender object

Returns

the corners of the bounding box

gmInstrumentMap.py

logger.py

class ColoredFormatter

Bases: logging.Formatter

COLORS = {'CRITICAL': '\x1b[1;31m', 'DEBUG': '\x1b[36m', 'ERROR': '\x1b[31m', 'INFO': '\x1b[32m', 'WARNING': '\x1b[33m'}
RESET = '\x1b[0m'
format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

Module contents

animateAlongTwoPoints(firstPoint: mathutils.Vector, secondPoint: mathutils.Vector, xComponent: float)
convertNoteNumbers(inputStr: str)

converts a note number string “c4” or “60” to a MIDI Note number (integer) Will work with more than 1 input if the values are seperated via commas

Parameters

inputStr (str) – the input note number string, e.g., “c3” or “60”

Raises

ValueError – if the string is invalid

Return int or Tuple[int]

a MIDI Note number (int)

gmProgramToName(pcNum: int) -> (pcNum: int)

Takes a General MIDI program change number from 0-127 and returns the GM instrument name.

Parameters

pcNum (int) – program change number

Return str

GM instrument name

mapRangeArcSin(value, inMin, inMax, outMin, outMax)

maps a range using an inverse sinusoidal curve. Useful when mapping one range of values to another.

taken from here: https://www.desmos.com/calculator/pw9tgtcq16

Parameters
  • value (float) – value to evaluate from

  • inMin (float) – in minimum

  • inMax (float) – in maximum

  • outMin (float) – out minimum

  • outMax (float) – out maximum

Return float

the resulting value mapped linearlly

mapRangeExp(value, inMin, inMax, outMin, outMax)

maps a range exponentially. Useful when mapping one range of values to another.

taken from here: https://www.desmos.com/calculator/pw9tgtcq16

Parameters
  • value (float) – value to evaluate from

  • inMin (float) – in minimum

  • inMax (float) – in maximum

  • outMin (float) – out minimum

  • outMax (float) – out maximum

Return float

the resulting value mapped linearlly

mapRangeLinear(value: float, inMin: float, inMax: float, outMin: float, outMax: float) -> (value: float, inMin: float, inMax: float, outMin: float, outMax: float)

maps a range linearly. Useful when mapping one range of values to another.

e.g., if I want to map the value 20 with the in range (0, 100) to the out range (0, 200), the return value will be 40 taken from here: https://www.desmos.com/calculator/pw9tgtcq16

Parameters
  • value (float) – value to evaluate from

  • inMin (float) – in minimum

  • inMax (float) – in maximum

  • outMin (float) – out minimum

  • outMax (float) – out maximum

Return float

the resulting value mapped linearlly

mapRangeLog(value, inMin, inMax, outMin, outMax)

maps a range logarithmically. Useful when mapping one range of values to another.

taken from here: https://www.desmos.com/calculator/pw9tgtcq16

Parameters
  • value (float) – value to evaluate from

  • inMin (float) – in minimum

  • inMax (float) – in maximum

  • outMin (float) – out minimum

  • outMax (float) – out maximum

Return float

the resulting value mapped linearlly

mapRangePara(value, inMin, inMax, outMin, outMax)

maps a range parabolically. Useful when mapping one range of values to another.

taken from here: https://www.desmos.com/calculator/pw9tgtcq16

Parameters
  • value (float) – value to evaluate from

  • inMin (float) – in minimum

  • inMax (float) – in maximum

  • outMin (float) – out minimum

  • outMax (float) – out maximum

Return float

the resulting value mapped linearlly

mapRangeRoot(value, inMin, inMax, outMin, outMax)

maps a range with a square root. Useful when mapping one range of values to another.

taken from here: https://www.desmos.com/calculator/pw9tgtcq16

Parameters
  • value (float) – value to evaluate from

  • inMin (float) – in minimum

  • inMax (float) – in maximum

  • outMin (float) – out minimum

  • outMax (float) – out maximum

Return float

the resulting value mapped linearlly

mapRangeSin(value, inMin, inMax, outMin, outMax)

maps a range sinusoidally. Useful when mapping one range of values to another.

taken from here: https://www.desmos.com/calculator/pw9tgtcq16

Parameters
  • value (float) – value to evaluate from

  • inMin (float) – in minimum

  • inMax (float) – in maximum

  • outMin (float) – out minimum

  • outMax (float) – out maximum

Return float

the resulting value mapped linearlly

nameToNote(nStr: str) -> (nStr: str)

Takes a name and returns the MIDI note number Example: nameToNote(“C3”) returns 60

Parameters

nStr (str) – the note name

Return int

the MIDI note number

noteToName(nVal: int) -> (nVal: int)

Takes a MIDI note number and returns the name Example: noteToName(60) returns “C3”

Parameters

nVal (int) – the MIDI note number

Return str

the note name

removeDuplicates(vals: list) -> (vals: list)

Removes duplicate items from a list. Useful for getting all used note numbers in a MIDI File.

Parameters

vals (list) – input list

Return list

duplicates removed

rotateAroundCircle(radius, angle)

Takes a radius (x) and an angle (y) and will return its X and Y.

Parameters
  • radius (float) – radius of the circle

  • angle (float) – angle of the circle

Return Tuple[int]

X and Y of the point

typeOfNoteNumber(inputStr: str)

Figures out if a string is a MIDI note number or a name of a note Will work with more than 1 input if the values are seperated via commas

Parameters

inputStr (str) – the input note number string, e.g., “c3” or “60”, or “c4, 60”

Raises

ValueError – if the string is invalid

Return str or Tuple[str]

returns “note” or “name” for the corresponding values, or a tuple if there are multiple values seperated by commas