music21.common.objects¶
EqualSlottedObjectMixin¶
-
class
music21.common.objects.EqualSlottedObjectMixin¶ Same as above, but __eq__ and __ne__ functions are defined based on the slots.
Slots are the only things compared, so do not mix with a __dict__ based object.
EqualSlottedObjectMixin bases
Iterator¶
-
class
music21.common.objects.Iterator(data)¶ A simple Iterator object used to handle iteration of Streams and other list-like objects.
>>> i = common.Iterator([2,3,4]) >>> for x in i: ... print(x) 2 3 4 >>> for y in i: ... print(y) 2 3 4
Iterator methods
-
Iterator.next()¶
SingletonCounter¶
-
class
music21.common.objects.SingletonCounter¶ A simple counter that can produce unique numbers (in ascending order) regardless of how many instances exist.
Instantiate and then call it.
>>> sc = common.SingletonCounter() >>> v0 = sc() >>> v1 = sc() >>> v1 > v0 True >>> sc2 = common.SingletonCounter() >>> v2 = sc2() >>> v2 > v1 True
SlottedObjectMixin¶
-
class
music21.common.objects.SlottedObjectMixin¶ Provides template for classes implementing slots allowing it to be pickled properly.
Only use SlottedObjectMixins for objects that we expect to make so many of that memory storage and speed become an issue. Thus, unless you are Xenakis, Glissdata is probably not the best example:
>>> import pickle >>> class Glissdata(common.SlottedObjectMixin): ... __slots__ = ('time', 'frequency') >>> s = Glissdata() >>> s.time = 0.125 >>> s.frequency = 440.0 >>> out = pickle.dumps(s) >>> t = pickle.loads(out) >>> t.time, t.frequency (0.125, 440.0)
Timer¶
-
class
music21.common.objects.Timer¶ An object for timing. Call it to get the current time since starting.
>>> t = common.Timer() >>> now = t() >>> nownow = t() >>> nownow > now True
Call stop to stop it. Calling start again will reset the number
>>> t.stop() >>> stopTime = t() >>> stopNow = t() >>> stopTime == stopNow True
All this had better take less than one second!
>>> stopTime < 1 True
Timer methods
-
Timer.clear()¶
-
Timer.start()¶ Explicit start method; will clear previous values.
Start always happens on initialization.
-
Timer.stop()¶