Permalink
Browse files

* cplay (1.46pre3)

	- LIRC support via control FIFO (Pugo)
  • Loading branch information...
1 parent 4d52220 commit e4760d33cc98983e46c02bd29d2e4db57887b806 Ulf Betlehem committed with Aug 28, 2002
Showing with 41 additions and 2 deletions.
  1. +5 −0 ChangeLog
  2. +36 −2 cplay
View
@@ -1,3 +1,8 @@
+2002-08-28 Ulf Betlehem <flu@iki.fi>
+
+ * cplay (1.46pre3)
+ - LIRC support via control FIFO (Pugo)
+
2002-08-21 Ulf Betlehem <flu@iki.fi>
* cplay (1.46pre2)
View
38 cplay
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- python -*-
-__version__ = "cplay 1.46pre2"
+__version__ = "cplay 1.46pre3"
"""
cplay - A curses front-end for various audio players
@@ -75,6 +75,8 @@ for DSP in ["/dev/sound/dsp", "/dev/dsp"]:
for MIXER in ["/dev/sound/mixer", "/dev/mixer"]:
if os.path.exists(MIXER): break
+CONTROL_FIFO = '/var/tmp/cplay_control'
+
# ------------------------------------------
def which(program):
for path in string.split(os.environ["PATH"], ":"):
@@ -1169,11 +1171,40 @@ class Timeout:
return len(self.dict) and 0.2 or None
# ------------------------------------------
+class FIFOControl:
+ def __init__(self, parent):
+ self.parent = parent
+ try: self.fd = open(CONTROL_FIFO, 'rb+', 0)
+ except: self.fd = None
+ self.commands = {'pause' : self.parent.toggle_pause,
+ 'next' : self.parent.next_song,
+ 'prev' : self.parent.prev_song,
+ 'forward' : self.forward,
+ 'backward' : self.backward,
+ 'play' : self.parent.toggle_stop,
+ 'stop' : self.parent.toggle_stop,
+ 'volup' : self.parent.inc_volume,
+ 'voldown' : self.parent.dec_volume,
+ 'quit' : self.parent.quit}
+
+ def handle_command(self):
+ command = string.strip(self.fd.readline())
+ if command in self.commands.keys():
+ self.commands[command]()
+
+ def forward(self):
+ self.parent.seek(1)
+
+ def backward(self):
+ self.parent.seek(-1)
+
+# ------------------------------------------
class Application:
def __init__(self):
self.keymapstack = KeymapStack()
self.mixer_read = SOUND_MIXER_READ_VOLUME
self.mixer_write = SOUND_MIXER_WRITE_VOLUME
+ self.control = FIFOControl(self)
def setup(self):
if tty:
@@ -1216,6 +1247,8 @@ class Application:
tty and tty.tcsetattr(sys.stdin.fileno(), tty.TCSADRAIN, self.tcattr)
def run(self):
+ R = [sys.stdin, self.player.stdout_r, self.player.stderr_r]
+ self.control.fd and R.append(self.control.fd)
while 1:
now = time.time()
timeout = self.timeout.check(now)
@@ -1226,7 +1259,6 @@ class Application:
pathname = self.win_playlist.next_song()
if pathname: self.play(pathname)
else: self.player.stopped = 1 # end of playlist hack
- R = [sys.stdin, self.player.stdout_r, self.player.stderr_r]
try: r, w, e = select.select(R, [], [], timeout)
except select.error: continue
## user input
@@ -1239,6 +1271,8 @@ class Application:
## player input
if self.player.stdout_r in r:
self.player.read_stdout()
+ if self.control.fd in r:
+ self.control.handle_command()
def play(self, pathname, offset = 0):
self.seek_tag = None

0 comments on commit e4760d3

Please sign in to comment.