debianmacno-cups
Last change
on this file since 8781af2 was
86f0b5b,
checked in by Mats Erik Ahlgren <mats.ahlgren@…>, 14 years ago
|
off-by-one counting error in smooth-volume-fade code (which should be supplanted by mplayer -slave)
it was scrolling from 0/10,1/10,...9/10, resulting in fades from 18-21 that only set the volume to 20
|
-
Property mode set to
100755
|
File size:
1.2 KB
|
Line | |
---|
1 | #!/usr/bin/python |
---|
2 | |
---|
3 | from __future__ import division |
---|
4 | from subprocess import * |
---|
5 | import sys |
---|
6 | import math |
---|
7 | import time |
---|
8 | import os |
---|
9 | j = os.path.join |
---|
10 | |
---|
11 | arg = sys.argv[1] |
---|
12 | currentDir = os.path.split(__file__)[0] |
---|
13 | #sys.path[:0] = [currentDir] |
---|
14 | |
---|
15 | def 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 | |
---|
22 | def 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+1): |
---|
30 | frac = i/10 |
---|
31 | tempV = int(v + (newV-v)*frac) |
---|
32 | command = ['amixer', 'set', 'PCM', str(tempV)] |
---|
33 | #print tempV |
---|
34 | sys.stdout.flush() |
---|
35 | call(command, stdout=PIPE) |
---|
36 | time.sleep(0.3) |
---|
37 | |
---|
38 | v = getVolume() |
---|
39 | map = { |
---|
40 | '+': int(math.ceil( v*1.13 + .001 )), |
---|
41 | '-': int(math.floor( v/1.13 + .001 )) |
---|
42 | } |
---|
43 | |
---|
44 | newVolume = map[arg] |
---|
45 | |
---|
46 | # Alert user |
---|
47 | print 'Smoothly modifying over next 3 seconds, by ~3dB (from %i to %i)...' % (v, newVolume) |
---|
48 | sys.stdout.flush() |
---|
49 | |
---|
50 | # Adjust volume |
---|
51 | setVolume(newVolume) |
---|
52 | |
---|
53 | # Alert user |
---|
54 | print 'Volume adjust finished.' |
---|
55 | |
---|
56 | # Send zephyr |
---|
57 | call([j(currentDir,'volume-zephyr')]) |
---|
58 | |
---|
Note: See
TracBrowser
for help on using the repository browser.