data_structures

midi.py

class MIDIEvent

Bases: object

Takes a channel, value, time and creates a MIDIEvent object.

Parameters
  • channel (int) – MIDI channel of the note, 0-15.

  • velocity (float) – MIDI value of the event, 0-127.

  • time (float) – Time the event occurred, in seconds.

__init__(channel: int, value: float, time: float) -> (channel: int, value: float, time: float)
channel: int
time: float
value: float
class MIDIFile

Bases: object

__init__(midiFile: str)

open file and store it as data in lists tracks with channels and track names, timesOn and off information for each track, velocity and MIDI CC info for each track, etc

Parameters

midiFile (str) – MIDI file path

findTrack(name)

Finds the track with a specified name

raises ValueError if there is no track with that specified name

Parameters

name (str) – The name of the track to be returned

Return list

The track with the specified name

getMIDITracks()

returns a list of all MIDITrack objects in the MIDIFile

Return List[MIDITrack]

a list of all MIDITrack objects

listTrackNames()

gets a list of all MIDITrack names

Return List[str]

returns a list of MIDITrack names

mergeTracks(track1: midi.MIDITrack, track2: midi.MIDITrack, name: str = None) -> (track1: midi.MIDITrack, track2: midi.MIDITrack, name: str = None)

merges 2 tracks together. You can also use the + operator.

Parameters
  • track1 (MIDITrack) – the first MIDITrack to merge

  • track2 (MIDITrack) – the second MIDITrack to merge

  • name (str) – name of the new track, defaults to None

Return MIDITrack

the merged `MIDITrack`s.

class MIDINote

Bases: object

Takes a channel, noteNumber, velocity, timeOn and timeOff and creates a MIDINote object.

Parameters
  • channel (int) – MIDI channel of the note, 0-15.

  • noteNumber (int) – MIDI note number of the note, 0-127.

  • velocity (int) – MIDI velocity of the note, 0-127.

  • timeOn (float) – Time the note was turned on, in seconds.

  • timeOff (float) – Time the note was turned off, in seconds.

Returns

None

__init__(channel: int, noteNumber: int, velocity: int, timeOn: float, timeOff: float) -> (channel: int, noteNumber: int, velocity: int, timeOn: float, timeOff: float)
channel: int
noteNumber: int
timeOff: float
timeOn: float
velocity: int
class MIDITrack

Bases: object

__init__(name: str)

initialize a MIDITrack

Parameters

name (str) – name of track

addAftertouch(channel: int, value: float, time: float) -> (channel: int, value: float, time: float)

add a aftertouch event

Parameters
  • channel (int) – the MIDI channel number

  • value (float) – value of the aftertouch, TODO range

  • time (float) – time value (in seconds)

addControlChange(control_number: int, channel: int, value: int, time: float)

add a control change value automatically checks if number has been added

Parameters
  • control_number (int) – the control change number

  • channel (int) – MIDI channel number

  • value (int) – value of the control change

  • time (float) – time value (in seconds)

addNoteOff(channel: int, noteNumber: int, velocity: int, timeOff: float) -> (channel: int, noteNumber: int, velocity: int, timeOff: float)

adds a Note Off event

Parameters
  • channel (int) – MIDI channel

  • noteNumber (int) – the note number, TODO range

  • velocity (int) – the note velocity, TODO range

  • timeOff (float) – the note time off, in seconds

addNoteOn(channel: int, noteNumber: int, velocity: int, timeOn: float) -> (channel: int, noteNumber: int, velocity: int, timeOn: float)

adds a Note Event

Parameters
  • channel (int) – the MIDI Channel the note is on

  • noteNumber (int) – the note number, range from 0-127

  • velocity (int) – the note velocity, range 0-127

  • timeOn (float) – the note time on, in seconds

addPitchwheel(channel: int, value: float, time: float) -> (channel: int, value: float, time: float)

add a pitchwheel event

Parameters
  • channel (int) – the MIDI channel number

  • value (float) – value of the pitch wheel TODO range

  • time (float) – time value (in seconds)

aftertouch: List[MIDIAnimator.data_structures.midi.MIDIEvent]
allUsedNotes()
Return list

a list of all used notes in the MIDITrack

controlChange: Dict[int, List[MIDIAnimator.data_structures.midi.MIDIEvent]]
name: str
notes: List[MIDIAnimator.data_structures.midi.MIDINote]
pitchwheel: List[MIDIAnimator.data_structures.midi.MIDIEvent]

Module contents

class CacheInstance

Bases: object

CacheInstance handles caching objects by finding avaialbe frame times. If there are not any avaiable frame times, it will create a new object

__init__()
addObject(frameRange: FrameRange)

adds FrameRange to the cache.

findRange(frameRange: FrameRange)

finds a index for the given frameRange

Parameters

frameRange (FrameRange) – the FrameRange to insert

Return int

the index key at which the FrameRange will be inserted into self._cache

getCache()

gets the entire cache

Return Dict[int, List[FrameRange]]

the cache instance dictionary with all of the indicies and `FrameRange`s

getStartTime()

gets the first start time in the cache. If there isn’t any data yet, it will be 0.

Return float

the first start time

class DummyFCurve

Bases: object

DummyFCurve(keyframe_points: ‘Tuple[Keyframe]’, array_index: ‘int’, data_path: ‘str’)

__init__(keyframe_points: typing.Tuple[Keyframe], array_index: int, data_path: str) -> (keyframe_points: typing.Tuple[Keyframe], array_index: int, data_path: str)
array_index: int
data_path: str
evaluate(frame)
keyframe_points: Tuple[MIDIAnimator.data_structures.Keyframe]
static range()
class FrameRange

Bases: object

this stores an object that will be moving from startFrame to endFrame

__init__(startFrame: int, endFrame: int, wpr: ObjectWrapper) -> (startFrame: int, endFrame: int, wpr: ObjectWrapper)
endFrame: int
startFrame: int
wpr: MIDIAnimator.data_structures.ObjectWrapper
class Keyframe

Bases: object

A simple keyframe data structure. :param float frame: the frame value of the keyframe (x) :param float value: the value of the keyframe (y)

__init__(frame: float, value: float) -> (frame: float, value: float)
property co
frame: float
value: float
class KeyframeSeconds

Bases: object

A simple keyframe data structure for time in seconds. :param float seconds: the seconds value of the keyframe (x) :param float value: the value of the keyframe (y)

__init__(seconds: float, value: float) -> (seconds: float, value: float)
property co
seconds: float
value: float
class ObjectShapeKey

Bases: object

Wrapper for a bpy.types.Object’s Shape Key

Parameters
  • name (str) – name of the shape key

  • referenceCurve (bpy.types.FCurve) – the reference shape key (with the reference/animation curve)

  • targetKey (bpy.types.ShapeKey) – the target shape key, this will be keyframed

  • data_path (str) – data path for the shape key (needed for keyframing)

  • array_index (int) – array index for the shape key (needed for keyframing)

__init__(name: str = '', referenceCurve: bpy.types.FCurve = None, targetKey: bpy.types.ShapeKey = None, data_path: str = '', array_index: int = 0) -> (name: str = '', referenceCurve: bpy.types.FCurve = None, targetKey: bpy.types.ShapeKey = None, data_path: str = '', array_index: int = 0)
array_index: int = 0
data_path: str = ''
property keyframe_points
name: str = ''
range()

returns the range (total length) of the reference curve

Return Tuple[float, float]

start time and end time

referenceCurve: bpy.types.FCurve = None
targetKey: bpy.types.ShapeKey = None
class ObjectWrapper

Bases: object

ObjectWrapper(obj: ‘bpy.types.Object’, noteNumbers: ‘Tuple[int]’, noteOnCurves: ‘List[Union[bpy.types.FCurve, ObjectShapeKey]]’, noteOffCurves: ‘List[Union[bpy.types.FCurve, ObjectShapeKey]]’)

__init__(obj: bpy.types.Object, noteNumbers: Tuple[int], noteOnCurves: List[Union[bpy.types.FCurve, ObjectShapeKey]], noteOffCurves: List[Union[bpy.types.FCurve, ObjectShapeKey]])

object wrapper for bpy.types.Object objects. this allows us to store data with the blender objects (such as FCurve data, note numbers, MIDI information, etc)

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

  • noteNumbers (Tuple[int]) – a tuple of note numbers of type int.

  • noteOnCurves (List[Union[bpy.types.FCurve, ObjectShapeKey]]) – A list of NoteOn curves dervided from obj.

  • noteOffCurves (List[Union[bpy.types.FCurve, ObjectShapeKey]]) – A list of NoteOff curves dervided from obj.

endFrame: float
noteNumbers: Tuple[int]
noteOffCurves: List[Union[bpy.types.FCurve, MIDIAnimator.data_structures.ObjectShapeKey]]
noteOnCurves: List[Union[bpy.types.FCurve, MIDIAnimator.data_structures.ObjectShapeKey]]
obj: bpy.types.Object
startFrame: float