source: remctl/lib/gutenbach/volume-helper.py @ bbede33

debianmacno-cups
Last change on this file since bbede33 was bbede33, checked in by Mats Erik Ahlgren <mats.ahlgren@…>, 14 years ago

[remctl v up] is now less verbose; requested by pquimby

  • Property mode set to 100755
File size: 1.1 KB
RevLine 
[3ee56cf]1#!/usr/bin/python
2
3from __future__ import division
4from subprocess import *
5import sys
6import math
7import time
8import os
9j = os.path.join
10
11arg = sys.argv[1]
12currentDir = os.path.split(__file__)[0]
13#sys.path[:0] = [currentDir]
14
15def getVolume():
16        """
17                Returns current PCM volume percentage as int
18        """
19        v = int(Popen(j(currentDir,'volume-get'), stdout=PIPE).communicate()[0].split()[0])
20        return v
21
22def setVolume(percent):
23        """
24                Over the course of 3 seconds, in steps of 0.3sec, linearly sets
25                volume between [current vol]-->[new vol]
26        """
27        v = getVolume()
28        newV = percent
29        for i in range(10):
30                frac = i/10
31                tempV = int(v + (newV-v)*frac)
32                command = ['amixer', 'set', 'PCM', str(tempV)]
[bbede33]33                #print tempV
[e01a3af]34                sys.stdout.flush()
[3ee56cf]35                call(command, stdout=PIPE)
36                time.sleep(0.3)
37
38v = getVolume()
39map = {
[e01a3af]40        '+': int(math.ceil( v*1.13 + .001 )),
41        '-': int(math.floor( v/1.13 + .001 ))
[3ee56cf]42}
43
44newVolume = map[arg]
[bbede33]45
46# Alert user
47print 'Smoothly modifying over next 3 seconds, by ~3dB (from %i to %i)...' % (v, newVolume)
[3ee56cf]48sys.stdout.flush()
[bbede33]49
50# Adjust volume
[3ee56cf]51setVolume(newVolume)
[bbede33]52
53# Alert user
[3ee56cf]54print 'Volume adjust finished.'
[bbede33]55
56# Send zephyr
[3ee56cf]57call([j(currentDir,'volume-zephyr')])
[bbede33]58
Note: See TracBrowser for help on using the repository browser.