Sunday, November 25, 2012

Pure Data Notes: A Simple Time Base


This article will cover some very basic things I have learned about working with Puredata. The first patch shown here is an external timing patch. This can be used for timing sequencers in another patch. Details on the operation and construction of this patch can be found here. The patch can be downloaded here.

Basics of Python Classes

Classes in Python can store many variables and methods (read: functions) in a similar way to importing modules. But unlike modules they can act as blueprints and have to be constructed by reading them into a variable. The data or attributes contained in a class can be called by assigning the referencing the object (variable you assigned the class to) they exist in.
class basicClass():
    var1 = "bacon"
    var2 = "sausage"
    var3 = "toast"

breakfast = basicClass()

print breakfast.var1
This will output:
"bacon"
The class is defined first with all the variables we want in it. We then use that class or blueprint to create an object, breakfast, and by referencing that object followed by a dot and the attribute (much like importing modules) we can access the data from the class.
Classes can inherit attributes from other classes.
class basicClass():
    var1 = "bacon"
    var2 = "sausage"
    var3 = "toast"

class subClass(basicClass):
    pass

breakfast = subClass()
print breakfast.var2
Will output:
"sausage"
The new "subclass" has inherited all attributes of the class that was passed in its parameters. This is why the subclass can contain no data and we are still able to call it and return values from variables.
On top of this when creating a class that will inherit from another, you can overwrite any attribute you need to at the time of creation.
class basicClass():
    var1 = "bacon"
    var2 = "sausage"
    var3 = "toast"

class subClass(basicClass):
    var2 = "hash browns"

breakfast = subClass()
print breakfast.var2
Will output:
"hash browns"
The value of var2 was overwritten by the child class.