Skip to content

Code guidelines

relt-1 edited this page Jan 20, 2023 · 5 revisions

Variable names

  • windowObject : Variable, Argument : Always the one and only Window object.
  • frame : Argument : The time expressed in project frames since the keyframe start.
  • params : Argument : Expected Params object.

  1. If a function needs to access the Window object, pass in the windowObject parameter
def somefunction(windowObject):
    windowObject.timeline.scene.addItem(...)

  1. If a function takes a Param object instead of arguments, always put a comment what the function will expect in the Param object.
"""
Expected params:
{
  "path":StringProperty(""),
  "speed":IntProperty(1)
}
"""
def source(params:Params):
    ...

  1. Conform to a standard. The program expects a function to behave a certain way and that expectation should not be disregarded.

All ASE objects must have:

  • A name variable.
  • A default params object which the functions inside the object will expect.
class SomeSource:
    name = "Some Source"
    params = Params({
        "path":StringProperty(""),
        "speed":IntProperty(1)
    })

Functions for each type of object, note that each one is optional and doesn't need to exist

Source

  • image(params:Params,keyframe:Keyframe,frame:int) Takes the expected params, the keyframe which contains the object, and frame. Returns a numpy array with shape (image_height,image_width,4)

  • sound(params:Params,keyframe:Keyframe,sample:int) Two first arguments are the same, and sample is the start sound sample. Returns a numpy array with shape (1024,2) and samples are in project sample rate.

  • timelineGizmos(params:Params,keyframe:Keyframe,windowObject) Returns a list of timeline gizmos, initalized with the same arguments.

  • seek(params:Params,frame:int) Returns nothing, gets called in a thread. Intended for pre-seeking streams and other slow-to-seek objects.

  • viewportGizmos(params:Params,windowObject) Returns a list of viewport gizmos, initialized with the same arguments.

Action

  • Has the same functions as Source but without image and sound. Instead, it has action(params:Params,stateToModify:list,keyframe:Keyframe,frame:int) where stateToModify is a list of Keyframe objects. Returns a new Keyframe object list.

Effect

  • Same case as the Actions object. Has a imageEffect and soundEffect function.
  • imageEffect(params:Params,image,vertices,keyframe:Keyframe,frame:int) image is an ndarray returned by the Source.image function and vertices is a numpy array. Returns a tuple of new image and vertices. Also gets called inside an OpenGL context.
  • soundEffect(params:Params,sound,sample:int) sound is an numpy array returned by the Source.sound function. Sample is the same as in Source.sound. Returns a new numpy array of size of the original.

Clone this wiki locally