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