1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 from math import frexp
19 from flumotion.component import feedcomponent
20
21 __version__ = "$Rev$"
22
23
24 -class Volume(feedcomponent.Effect):
25 """
26 I am an effect that can be added to any component that has a level
27 element and a way of controlling volume.
28
29 My component should implement setVolume() and getVolume()
30 """
31 logCategory = "volume"
32
33 - def __init__(self, name, element, pipeline, allowIncrease=True,
34 allowVolumeSet=True):
35 """
36 @param element: the level element
37 @param pipeline: the pipeline
38 @param allowIncrease: whether the component allows > 1.0 volume level
39 @param allowVolumeSet: whether the component allows setting volume
40 """
41 feedcomponent.Effect.__init__(self, name)
42 self._element = element
43
44
45 element.set_property('interval', 200000000)
46 bus = pipeline.get_bus()
47 bus.add_signal_watch()
48 bus.connect('message::element', self._bus_message_received_cb)
49 self.firstVolumeValueReceived = False
50 self.allowIncrease = allowIncrease
51 self.allowVolumeSet = allowVolumeSet
52
61
63 """
64 @param bus: the message bus sending the message
65 @param message: the message received
66 """
67 if message.structure.get_name() == 'level':
68 s = message.structure
69 peak = list(s['peak'])
70 decay = list(s['decay'])
71 rms = list(s['rms'])
72 for l in peak, decay, rms:
73 for index, v in enumerate(l):
74 try:
75 v = frexp(v)
76 except (SystemError, OverflowError, ValueError):
77
78
79 l[index] = -100.0
80 if not self.uiState:
81 self.warning("effect %s doesn't have a uiState" %
82 self.name)
83 else:
84 for k, v in ('peak', peak), ('decay', decay), ('rms', rms):
85 self.uiState.set('volume-%s' % k, v)
86 if not self.firstVolumeValueReceived:
87 self.uiState.set('volume-volume', self.effect_getVolume())
88 self.firstVolumeValueReceived = True
89
91 """
92 Sets volume
93
94 @param value: what value to set volume to (float between 0.0 and 4.0)
95
96 Returns: the actual value it was set to
97 """
98 if self.allowVolumeSet:
99 self.component.setVolume(value)
100
101 self.uiState.set('volume-volume', value)
102 return value
103
105 """
106 Gets current volume setting.
107
108 @return: what value the volume is set to
109 @rtype: float (between 0.0 and 4.0)
110 """
111 if self.allowVolumeSet:
112 return self.component.getVolume()
113 else:
114 return 1.0
115