annotate DataTypes/dmx.py @ 0:45b12307c695

Initial revision
author drewp
date Wed, 03 Jul 2002 09:37:57 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
1
45b12307c695 Initial revision
drewp
parents:
diff changeset
2 class DMX(list):
45b12307c695 Initial revision
drewp
parents:
diff changeset
3 """the signal that goes on a real-life dmx wire. it's up to 512
45b12307c695 Initial revision
drewp
parents:
diff changeset
4 un-named channels each with a 8-bit value on each channel. this type
45b12307c695 Initial revision
drewp
parents:
diff changeset
5 is useful for a DMXOut node or DMXLevelDisplay node. the channels are
45b12307c695 Initial revision
drewp
parents:
diff changeset
6 stored in a python list where the first channel is at index 0. the
45b12307c695 Initial revision
drewp
parents:
diff changeset
7 first channel in dmx terminology would be called channel 1."""
45b12307c695 Initial revision
drewp
parents:
diff changeset
8
45b12307c695 Initial revision
drewp
parents:
diff changeset
9 def __init__(self,dmxlevels):
45b12307c695 Initial revision
drewp
parents:
diff changeset
10 if len(dmxlevels)>512:
45b12307c695 Initial revision
drewp
parents:
diff changeset
11 raise TypeError("DMX objects can't have more than 512 channels")
45b12307c695 Initial revision
drewp
parents:
diff changeset
12 list.extend(dmxlevels) # list.__init__ did't work right
45b12307c695 Initial revision
drewp
parents:
diff changeset
13
45b12307c695 Initial revision
drewp
parents:
diff changeset
14 def append(self,level):
45b12307c695 Initial revision
drewp
parents:
diff changeset
15 if len(self)==512:
45b12307c695 Initial revision
drewp
parents:
diff changeset
16 raise TypeError("DMX objects can't have more than 512 channels")
45b12307c695 Initial revision
drewp
parents:
diff changeset
17 list.append(self,level)
45b12307c695 Initial revision
drewp
parents:
diff changeset
18
45b12307c695 Initial revision
drewp
parents:
diff changeset
19 def extend(self,levels):
45b12307c695 Initial revision
drewp
parents:
diff changeset
20 if len(self)+len(levels)>512:
45b12307c695 Initial revision
drewp
parents:
diff changeset
21 raise TypeError("DMX objects can't have more than 512 channels")
45b12307c695 Initial revision
drewp
parents:
diff changeset
22 list.extend(self,levels)
45b12307c695 Initial revision
drewp
parents:
diff changeset
23
45b12307c695 Initial revision
drewp
parents:
diff changeset
24 def __setslice__(self,i,j,seq):
45b12307c695 Initial revision
drewp
parents:
diff changeset
25 newlength = len(self)-(max(0,j)-max(0,i))+len(seq)
45b12307c695 Initial revision
drewp
parents:
diff changeset
26 # we could check if newlength>512, but any length-changing slice is
45b12307c695 Initial revision
drewp
parents:
diff changeset
27 # probably wrong for this datatype
45b12307c695 Initial revision
drewp
parents:
diff changeset
28 if newlength!=len(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
29 raise NotImplementedError("Different-length setslice would disturb DMX channels")
45b12307c695 Initial revision
drewp
parents:
diff changeset
30 list.__setslice__(self,i,j,seq)
45b12307c695 Initial revision
drewp
parents:
diff changeset
31