Implemented audio notes
authorEnrico Zini <enrico@enricozini.org>
Mon, 15 Jun 2009 15:57:33 +0000 (23:57 +0800)
committerEnrico Zini <enrico@enricozini.org>
Mon, 15 Jun 2009 15:57:33 +0000 (23:57 +0800)
plugins/50_audio_notes.py [new file with mode: 0644]
zavai/audio.py

diff --git a/plugins/50_audio_notes.py b/plugins/50_audio_notes.py
new file mode 100644 (file)
index 0000000..91f015e
--- /dev/null
@@ -0,0 +1,43 @@
+import os.path
+import time
+from gettext import gettext as _
+import gtk
+import zavai
+
+class AudioNotes(gtk.ToggleAction):
+    states = [_("Start recording audio"), _("Stop recording audio")]
+
+    def __init__(self, registry, **kw):
+        self.state = 0
+        super(AudioNotes, self).__init__("menu.main.notes.audio", self.states[self.state], None, None)
+
+        self.registry = registry
+        self.recorder = zavai.Recorder(registry)
+        self.set_active(False)
+
+        self.connect("toggled", self.on_toggle)
+
+    def shutdown(self):
+        self.recorder.stop()
+        super(AudioNotes, self).shutdown()
+
+    def on_toggle(self, *args):
+        self.state = (self.state + 1) % len(self.states)
+        self.set_property("label", self.states[self.state])
+        if self.get_active():
+            self.start()
+        else:
+            self.stop()
+
+    def start(self):
+        zavai.info("Audio note started")
+
+        name = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
+        os.path.join(self.registry.resource("conf").homedir, name + ".wav")
+        self.recorder.start(name)
+
+    def stop(self):
+        self.recorder.stop()
+
+def init(conf = None, registry = None, **kw):
+    registry.register(AudioNotes(registry))
index 8354be5c9d84d23ee3e54585ef58a43de897e040..d50c9b8f931c98288391a607b6f370d1d91a0047 100755 (executable)
 import zavai
 import struct
 import gobject
+import os.path
+import subprocess
 #import sys
 #import os
-#import os.path
 #import time
 #import signal
 #import optparse
 #import dbus
 #import dbus.mainloop.glib
-#import subprocess
 
 class Recorder(zavai.Resource):
     def __init__(self, registry):
@@ -62,7 +62,7 @@ class Recorder(zavai.Resource):
 #  - if plugged, redo headest mixer settings
 class Audio(zavai.Service):
     "Handle mixer settings, audio recording and headset button presses"
-    def __init__(self, registry):
+    def __init__(self, registry, name):
         super(Audio, self).__init__(["audio", "button", "jack"])
 
         conf = registry.resource("conf")