changeset 41:38dd615b7465 moodplay

Fixes for the OLA DMX commands (and disabled OSC)
author Mood Play <m.barthet@qmul.ac.uk>
date Thu, 07 May 2015 20:23:03 +0100
parents 7656f048bbdf
children 86e27707b852
files visualclient2/.DS_Store visualclient2/visclient.py
diffstat 2 files changed, 64 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
Binary file visualclient2/.DS_Store has changed
--- a/visualclient2/visclient.py	Thu May 07 14:56:42 2015 +0100
+++ b/visualclient2/visclient.py	Thu May 07 20:23:03 2015 +0100
@@ -41,7 +41,6 @@
 
 ambicol = (224, 184, 30, 255)
 
-
 # X,Y=1140,900
 # X,Y = 600,400
 X,Y = 800,600
@@ -88,6 +87,8 @@
 HTTP_TIMEOUT = 3
 SERVER_UPDATE_INTERVAL = 0.8
 
+def DmxSent(state):
+	wrapper.Stop()
 
 class Indicator(object):
 	
@@ -140,7 +141,7 @@
 		
 	def now(self,screen):
 		# for i in self.indicators.itervalues() :
-		# 	i.draw()
+		#	i.draw()
 		self.draw()
 		screen.blit(self.bg, (0, 0))
 		pg.display.flip()
@@ -178,7 +179,7 @@
 	def draw(self):
 		if not self.visible : return
 
-		global xavg,yavg,moods,universe,totalActiveFixtures,totalPassiveFixtures,ambicol
+		global xavg,yavg,moods,universe,totalActiveFixtures,totalPassiveFixtures,ambicol,wrapper,client
 		# xspeed = (xavg - self.x) / self.speed_factor
 		# yspeed = (yavg - self.y) / self.speed_factor
 		# self.x = self.x + xspeed
@@ -200,7 +201,9 @@
 				self.mood = mood
 				self.c = mood.color
 				self.title = mood.word
-
+		
+		#print self.c
+		
 		# self.bg.blit(gradients.radial(self.size, (self.c[0],self.c[1],self.c[2],self.alpha), (0,0,0,self.alpha)), (self.xs-BLOBSIZE,self.ys-BLOBSIZE))
 		d=int(self.size)
 		# print d
@@ -214,13 +217,13 @@
 		textpos = text.get_rect()
 		#print textpos.width	
 		if self.xs > X- textpos.width:	
-			if self.ys > Y- textpos.height:	
+			if self.ys > Y- textpos.height: 
 				self.bg.blit(text, (self.xs - textpos.width,self.ys - textpos.height))
 			else:
 				self.bg.blit(text, (self.xs - textpos.width,self.ys))
 		
 		else :	
-			if self.ys > Y- textpos.height:	
+			if self.ys > Y- textpos.height: 
 				self.bg.blit(text, (self.xs,self.ys - textpos.height))
 			else: 
 				self.bg.blit(text, (self.xs,self.ys))
@@ -229,28 +232,27 @@
 		#if self.alpha < 5 : 
 		#	self.alpha = 1
 		#	self.visible = False
+		
+		dmxdata = array.array('B')
+		
+		print (self.c[0],self.c[1],self.c[2],self.alpha)
+		
+		for x in range(0, totalActiveFixtures):
+			#on SlimPAR_Pro_TRI: Brightness, R, G, B
+			dmxdata.append(self.alpha)
+			dmxdata.append(self.c[0])
+			dmxdata.append(self.c[1])
+			dmxdata.append(self.c[2])
+			
+		for x in range(0, totalPassiveFixtures):
+			#DMX address starts at 1 + totalActiveFixtures x 4
+			dmxdata.append(ambicol[3])
+			dmxdata.append(ambicol[0])
+			dmxdata.append(ambicol[1])
+			dmxdata.append(ambicol[2])
 
-		def DmxSent(state):
-        	wrapper.Stop()
-        	
-        dmxdata = array.array('B')
-
-        for x in range(0, totalActiveFixtures)
-            dmxdata.append(self.c[0])
-            dmxdata.append(self.c[1])
-            dmxdata.append(self.c[2])
-            dmxdata.append(self.alpha)
-
-        for x in range(0, totalPassiveFixtures)
-        	dmxdata.append(self.ambicol[0])
-        	dmxdata.append(self.ambicol[1])
-        	dmxdata.append(self.ambicol[2])
-        	dmxdata.append(self.ambicol[3])
-
-        wrapper = ClientWrapper()
-        client = wrapper.Client()
-        client.SendDmx(universe, dmxdata, DmxSent)
-        wrappper.Run()
+		client.SendDmx(universe, dmxdata, DmxSent)
+		wrapper.Run()
 				
 	def age(self):
 		return time.time() - self.time
@@ -348,7 +350,7 @@
 		if self.target_in_proximity is None and prox is True :
 			self.target_in_proximity = time.time()
 		# if prox is False :
-		# 	self.target_in_proximity = None		
+		#	self.target_in_proximity = None		
 		
 	def draw(self):
 		if not self.visible : return
@@ -542,8 +544,8 @@
 		pg.display.set_gamma(100.0)
 		
 		
-		self.scol   = (0,255,0,255)
-		self.ecol   = (0,0,0,255)
+		self.scol	= (0,255,0,255)
+		self.ecol	= (0,0,0,255)
 		coordstxt = "test"
 		
 		self.blobs = []
@@ -557,15 +559,15 @@
 		self.FADE = FADE
 		
 		self.indicators = {
-		"conn":Indicator(self.bg,(0.98,0.02)), 			# connection active
-		"update":Indicator(self.bg,(0.96,0.02)), 		# update thread executing
-		"data":Indicator(self.bg,(0.94,0.02)), 			# data status changed
-		"receive":Indicator(self.bg,(0.92,0.02)), 		# data received
-		"grow":Indicator(self.bg,(0.90,0.02)), 			# blob growth active
-		"ignore":Indicator(self.bg,(0.88,0.02),True), 	# little AI: ignore some clusters in certain condition
-		"suspend":Indicator(self.bg,(0.86,0.02),True), 	# prevent adding new blobs (key: d)
-		"config":Indicator(self.bg,(0.84,0.02),True), 	# sending config data
-		"fade":Indicator(self.bg,(0.82,0.02),True)} 	# fade on/off (key: s)
+		"conn":Indicator(self.bg,(0.98,0.02)),			# connection active
+		"update":Indicator(self.bg,(0.96,0.02)),		# update thread executing
+		"data":Indicator(self.bg,(0.94,0.02)),			# data status changed
+		"receive":Indicator(self.bg,(0.92,0.02)),		# data received
+		"grow":Indicator(self.bg,(0.90,0.02)),			# blob growth active
+		"ignore":Indicator(self.bg,(0.88,0.02),True),	# little AI: ignore some clusters in certain condition
+		"suspend":Indicator(self.bg,(0.86,0.02),True),	# prevent adding new blobs (key: d)
+		"config":Indicator(self.bg,(0.84,0.02),True),	# sending config data
+		"fade":Indicator(self.bg,(0.82,0.02),True)}		# fade on/off (key: s)
 		
 		self.thread = None		
 		self.running = False
@@ -580,8 +582,8 @@
 	
 	def read_mood_data(self):
 		'''Read the mood position and color information form csv file.'''
-		file = 'moods.csv'
-		#file = '../tags/mc_moodtags_lfm_curated2.csv'
+		#"file = 'moods.csv'
+		file = '../tags/mc_moodtags_lfm_curated2.csv'
 		with open(file) as mf:
 			data = mf.readlines()[1:]
 			for line in data :
@@ -697,7 +699,7 @@
 		countavg = tempcount/len(data)
 		# print xavg, yavg, countavg
 		# if not self.blobs :
-		# 	self.add_blob(xavg,yavg,countavg)
+		#	self.add_blob(xavg,yavg,countavg)
 		# self.indicators["receive"].toggle()
 
 		self.conn.close()
@@ -767,10 +769,10 @@
 			self.indicators["ignore"].off()
 		
 		# compute gravity force
-		# 	if self.movingBlob != None :
-		# 		x,y,c = blob.force(self.movingBlob)
-		# 		forces.append((x,y))
-		# 		if c : captured_by = blob
+		#	if self.movingBlob != None :
+		#		x,y,c = blob.force(self.movingBlob)
+		#		forces.append((x,y))
+		#		if c : captured_by = blob
 		# tx,ty = reduce(lambda a,b:(a[0]+b[0],a[1]+b[1]), forces, (0.5,0.5))
 
 		# print tx,ty
@@ -782,13 +784,13 @@
 		# xavg,yavg = tx,ty		
 		
 		# if tx <= 1.0 and tx >= 0.0 and ty <= 1.0 and ty >= 0.0 :
-		# 	xavg,yavg = tx,ty
-		# 	countavg = 15
-		# 	print tx,ty
+		#	xavg,yavg = tx,ty
+		#	countavg = 15
+		#	print tx,ty
 		# else :
-		# 	print "out of bounds:",tx,ty
+		#	print "out of bounds:",tx,ty
 		# if captured_by != None :
-		# 	xavg,yavg = captured_by.x,captured_by.y
+		#	xavg,yavg = captured_by.x,captured_by.y
 		l = copy.copy(self.bt)
 		l.reverse()
 		for trail in l:
@@ -804,7 +806,8 @@
 		pg.draw.line(self.bg, (G,G,G), (int(X/2.0),0),(int(X/2.0),Y), 1)
 		pg.draw.line(self.bg, (G,G,G), (0,int(Y/2.0)),(X,int(Y/2.0)), 1)
 		
-		self.sendCoordinates(xavg, yavg)
+		#Send coordinates of the average via OSC
+		#self.sendCoordinates(xavg, yavg)
 
 		# indicators
 		for i in self.indicators.itervalues() :
@@ -1087,8 +1090,10 @@
 		oscmsg = OSC.OSCMessage()
 		oscmsg.setAddress(OSCADDR)
 		oscmsg.append((xcoord, ycoord))
-		self.osc_client.sendto(oscmsg, (SCIP, SCPORT))
-
+		self.osc_client.connect((SCIP, SCPORT))
+		self.osc_client.send(oscmsg)
+		self.osc_client.close()
+		
 	def quit(self):
 		print "Quitting.."
 		self.indicators["conn"].off()		
@@ -1100,6 +1105,11 @@
 
 def main():
 	
+	#OLA
+	global wrapper,client
+	wrapper = ClientWrapper()
+	client = wrapper.Client()
+	
 	v = VisualClient()
 	v.run()