Commits

Brendan Howell committed c6dcb40

hacks for faders and burroughs - piksel version

Comments (0)

Files changed (3)

 """
 
 import markov
-import burroughs
+import textwrap
 
 class Lexer:
     def __init__(self, dev):
             text = open(intext).read()
             self.words = text.split()
             self.markov = markov.Markov(text)
-            self.burroughs = burroughs.Burroughs(text)
+            self.burroughs = textwrap.wrap(text, 44)
             self.name = intext.split("/")[-1]
         else:
             pass
         if self.position == len(self.words):
             self.position = 0
         return out
+        
+    def get_burr(self, offset):
+        out = ""
+        line = self.burroughs[self.position]
+        words = line[offset:-1].split()
+        #print words
+        try:
+	        if offset == 0:
+	            return words[0] + " "
+	        if line[offset-1].isspace():
+	            return words[0] + " "
+	        else:
+	            return words[1] + " "
+        except:
+            self.position += self.velocity
+            if self.position == len(self.burroughs):
+                self.position = 0
+            return self.get_burr(0)
+
+        
         	
     
     #fetches next chunk chunk->fx or fx->chunk depending on fx type
Binary file modified.
 reverse = False
 bgcolor = ( 0, 0, 0 )
 monitor = "A"
+mixmode = "statmux"
 
 statusbar = ScreenText()
 
-#joy = pygame.joystick.Joystick(0)
+joy = pygame.joystick.Joystick(0)
 
 #TODO: deck loading in separate thread
 #TODO: burroughs slicer
-#TODO: WTF is up with colors and compositing!
+#TODO: WTF is up with colors and compositing! font.render???
 #TODO: color knob
-#TODO: trog mode!!
-#TODO: console out
-#TODO: text-monitor switch
 #TODO: fx
-#TODO: set to 72 Characters per Line
+#TODO: set to 72 Characters per Line?
 
 def handle_keydown(event):
-    global monitor, reverse, bgcolor, lexer_idx, deck_A, deck_B
-    print "got keydown: " + event.unicode
+    global monitor, reverse, bgcolor, lexer_idx, deck_A, deck_B, mixmode
+    #print "got keydown: " + event.unicode
     
     #reverse / rewind?
     if event.unicode == "r":
     elif event.unicode == "q":
     	if monitor == "A":
     	    deck_A = lexers[lexer_idx]
+    	    deck_A.algorithm = mixmode
     	else:
+    	    deck_B.algorithm = mixmode
     	    deck_B = lexers[lexer_idx]
     	
     	lexer_idx += 1
         
     #switch burroughs, normal, markov
     elif event.unicode == "b":
+        mixmode = "burroughs"
     	deck_A.algorithm = "burroughs"
     	deck_B.algorithm = "burroughs"
     elif event.unicode == "n":
+        mixmode = "statmux"
         deck_A.algorithm = "statmux"
         deck_B.algorthm = "statmux"
     elif event.unicode == "m":
+        mixmode = "markov"
         deck_A.algorithm = "markov"
         deck_B.algorithm = "markov"
     
     
 def handle_keyup(event):
-    print "got keyup: " + str(event.key)
+    global reverse, bgcolor
+	
+    #print "got keyup: " + str(event.key)
     if event.key == pygame.K_r:
-        global reverse
         reverse = False
+    elif event.key == pygame.K_t:
+    	bgcolor = (0,0,0)
+        for row in out_text:
+            row.setColor(255,255,255)
+    elif event.key == pygame.K_ESCAPE:
+        sys.exit()
 
 
 def setup():
     global deck_A, deck_B
 
-    pycessing.size(640, 480)
+    pygame.mouse.set_visible(0)
+    pycessing.size(640, 480, True)
     pycessing.framerate = framerate
     
     cursor.setFontFromFile(font, font_size)
     pycessing.onKeyDown = handle_keydown
     pycessing.onKeyUp = handle_keyup
 
-    #joy.init()
+    joy.init()
 	
 def draw():
     
     skip_frame = True
     # update tempo 
-    wordrate = 0.8 + 0.8 / ( (pycessing.getMouseY()+1) / float( pycessing.getHeight() ))
+    #wordrate = 0.8 + 0.8 / ( (pycessing.getMouseY()+1) / float( pycessing.getHeight() ))
+    wordrate = 0.8 + (0.8 / ( (joy.get_axis(5) +1.0000000001 ) /2) )
 
 
 #    for axis in range(joy.get_numaxes()):
     
     pycessing.screen.fill(bgcolor)
     # update x-fader
-    xfader = pycessing.getMouseX() / float(pycessing.getWidth())
+    #xfader = pycessing.getMouseX() / float(pycessing.getWidth())
+    xfader = (joy.get_axis(4) +1 )/2
     #print "xfader " + str(xfader)
     
     global wordcounter 
         wordcounter = 0
         skip_frame = False
     
-        # select deck and get next word  (TODO:skip for burroughs)
-        if random.random() < xfader:
-            cursor.text = deck_A.get_word(cursor.text)
-            cursor.setColor(255, 255 , 255)
+        if deck_A.algorithm == "burroughs":
+            offset = len(out_text[-1].text)
+            print offset
+            if out_text[-1].getWidth() < (xfader * pycessing.getWidth()):
+            	cursor.text = deck_A.get_burr(offset)
+            else:
+                cursor.text = deck_B.get_burr(offset)
         else:
-            cursor.text = deck_B.get_word(cursor.text)
-            cursor.setColor(255 , 255 , 255 )
-
-        #TODO: do burroughs here
-        
-
-            
+        # select deck and get next word (skip for burroughs)
+	        if random.random() < xfader:
+	            cursor.text = deck_A.get_word(cursor.text)
+	            cursor.setColor(255, 255 , 255)
+	        else:
+	            cursor.text = deck_B.get_word(cursor.text)
+	            cursor.setColor(255 , 255 , 255 )
+                    
         #if cursor row full - line feed
         if (len(out_text[-1].text) + len(cursor.text)) > ROW_WIDTH:
             idx = 0
     statusbar.text = deck_B.name.upper()
     statusbar.draw(10, 10)
     statusbar.text = deck_A.name.upper()
-    statusbar.draw(460, 10)
+    statusbar.draw(470, 10)
     statusbar.text = "VS"
     statusbar.draw(310, 10)
     statusbar.text = "MIX: " + deck_A.algorithm.upper()
     statusbar.draw(10, 35)
     statusbar.text = "MON: " + monitor
-    statusbar.draw(530, 35)
+    statusbar.draw(540, 35)
+    statusbar.text = "-"*44
+    statusbar.draw(10, 60)
     
     # update mix out    
     for row in out_text: