Commits

Adam Lindsay  committed efa518a

starting to work

  • Participants
  • Parent commits 6c95605

Comments (0)

Files changed (1)

 import os.path
 import subprocess
 import tempfile
+import glob
 
 from echonest import audio
 from echonest.selection import *
     renderable = None
     renderablename = ""
     
-    def do_greet(self, line):
-        print "hello"
-    
     def do_EOF(self, line):
         return True
     
         print
     
     def precmd(self, line):
-        print line
+        # print line
+        self.cwd  = os.getcwd()
         return line
     
     def default(self, line):
+        """execute a command"""
         if os.path.exists(os.path.join(self.cwd, line)):
             self.load(os.path.join(self.cwd, line))
         else:
             self.execute(line)
     
     def do_play(self, line):
+        """plays the current buffer or a given filename"""
         if not line:
             if self.renderable and not self.renderablename:
-                line = tempfile.NamedTemporaryFile(suffix='.wav')
+                foo, line = tempfile.mkstemp(".wav")
                 self.renderablename = line
-                self.renderable.encode(line)
+                self.renderable.encode(self.renderablename)
             elif self.renderablename:
                 line = self.renderablename
+        if not line:
+            print "nothing to play"
+            return
         CMD = ["qlmanage", '-p', line]
         pid=subprocess.Popen(CMD, stderr=subprocess.PIPE).pid
         
-    def load(self, path):
+    def do_load(self, path):
         if os.path.isdir(path):
             self.cwd = os.path.abspath(path)
+            os.chdir(self.cwd)
         else:
             try:
                 a = audio.LocalAudioFile(path)
                 return
             self.currfilename = os.path.abspath(path)
             self.prompt = "%s > " % os.path.basename(self.currfilename)
-            self.env['segments'] = a.analysis.segments
             self.renderable = a
             self.renderablename = self.currfilename
+            self.env['segments'] = a.analysis.segments
+            self.env['sections'] = a.analysis.sections
+            self.env['beats'] = a.analysis.beats
+            self.env['bars'] = a.analysis.bars
+            self.env['tatums'] = a.analysis.tatums
+            self.env['_'] = None
+    
+    
+    
+    def complete_load(self, text, line, begidx, endidx):
+        wav = glob.glob("%s*.wav" % text)
+        mp3 = glob.glob("%s*.mp3" % text)
+        dirs = [d for d in glob.glob("%s*" % text) if os.path.isdir(d)]
+        return mp3 + wav # + dirs
     
     def execute(self, rawcmd):
-        self.renderable = eval(rawcmd, self.env)
+        try:
+            self.renderable = eval(rawcmd, globals(), self.env)
+        except:
+            print "syntax error or file not found"
+        self.renderablename = ""
+        if not isinstance(self.renderable, audio.AudioRenderable):
+            self.renderable = audio.AudioQuantumList(self.renderable)
+        self.env['_'] = self.renderable