Package flumotion :: Package component :: Package effects :: Package volume :: Module volume
[hide private]

Source Code for Module flumotion.component.effects.volume.volume

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  from math import frexp 
 23  from flumotion.component import feedcomponent 
 24   
 25  # FIXME: it's illogical to have to provide level, but not volume. 
 26   
27 -class Volume(feedcomponent.Effect):
28 """ 29 I am an effect that can be added to any component that has a level 30 element and a volume element. 31 32 My component should implement setVolume() and getVolume() 33 """ 34 logCategory = "volume" 35
36 - def __init__(self, name, element, pipeline):
37 """ 38 @param element: the level element 39 @param pipeline: the pipeline 40 """ 41 feedcomponent.Effect.__init__(self, name) 42 self._element = element 43 # FIXME: set notification to every 1/5th sec, but maybe make 44 # configurable ? 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
50 - def setUIState(self, state):
51 feedcomponent.Effect.setUIState(self, state) 52 if state: 53 for k in 'peak', 'decay', 'rms': 54 state.addKey('volume-%s' % k, [-100.0]) 55 state.addKey('volume-volume', self.effect_getVolume())
56
57 - def _bus_message_received_cb(self, bus, message):
58 """ 59 @param bus: the message bus sending the message 60 @param message: the message received 61 """ 62 if message.structure.get_name() == 'level': 63 s = message.structure 64 peak = list(s['peak']) 65 decay = list(s['decay']) 66 rms = list(s['rms']) 67 for l in peak, decay, rms: 68 for v in l: 69 try: 70 v = frexp(v) 71 except (SystemError, OverflowError, ValueError): 72 # something confused log10() on the C side, punt 73 v = -100.0 74 if not self.uiState: 75 self.warning("effect %s doesn't have a uiState" % 76 self.name) 77 else: 78 for k, v in ('peak', peak), ('decay', decay), ('rms', rms): 79 self.uiState.set('volume-%s' % k, v)
80 81
82 - def effect_setVolume(self, value):
83 """ 84 Sets volume 85 86 @param value: what value to set volume to (float between 0.0 and 4.0) 87 88 Returns: the actual value it was set to 89 """ 90 self.component.setVolume(value) 91 # notify admin clients 92 self.uiState.set('volume-volume', value) 93 94 return value
95
96 - def effect_getVolume(self):
97 """ 98 Gets current volume setting. 99 100 @return: what value the volume is set to 101 @rtype: float (between 0.0 and 4.0) 102 """ 103 return self.component.getVolume()
104