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