Mercurial > hg > mood-conductor
comparison visualclient/visclient.py @ 29:f5ca9dbabe83
concert april 2013
author | gyorgyf |
---|---|
date | Thu, 18 Apr 2013 16:51:36 +0100 |
parents | 6022a370c7dd |
children | 4a7fde8ff0fd |
comparison
equal
deleted
inserted
replaced
28:6022a370c7dd | 29:f5ca9dbabe83 |
---|---|
56 FADE = 15 | 56 FADE = 15 |
57 DIST = 0.1 # blob equivalence tolerance | 57 DIST = 0.1 # blob equivalence tolerance |
58 FRAMERATE = 60 | 58 FRAMERATE = 60 |
59 | 59 |
60 # Connection: | 60 # Connection: |
61 # IP = "192.168.2.184:8030" | 61 # IP = "127.0.0.1:8030" |
62 # IP = "192.168.2.158:8030" | |
62 IP = "138.37.95.215" | 63 IP = "138.37.95.215" |
63 HTTP_TIMEOUT = 3 | 64 HTTP_TIMEOUT = 3 |
64 SERVER_UPDATE_INTERVAL = 0.8 | 65 SERVER_UPDATE_INTERVAL = 0.8 |
66 | |
65 | 67 |
66 class Indicator(object): | 68 class Indicator(object): |
67 | 69 |
68 off_color = pg.Color(110,0,0) | 70 off_color = pg.Color(110,0,0) |
69 on_color = pg.Color(0,120,0) | 71 on_color = pg.Color(0,120,0) |
190 '''Main visualisation client.''' | 192 '''Main visualisation client.''' |
191 | 193 |
192 def __init__(self): | 194 def __init__(self): |
193 # self.conn = ht.HTTPConnection("192.168.2.184:8030") | 195 # self.conn = ht.HTTPConnection("192.168.2.184:8030") |
194 # self.conn = ht.HTTPConnection("138.37.95.215") | 196 # self.conn = ht.HTTPConnection("138.37.95.215") |
197 self.s_age = 10 | |
198 self.s_dist = DIST | |
199 self.s_ninp = 18 | |
195 | 200 |
196 pg.init() | 201 pg.init() |
197 | 202 |
198 # fontObj = pg.font.Font("freesansbold.ttf",18) | 203 # fontObj = pg.font.Font("freesansbold.ttf",18) |
199 white = ( 255, 255, 255) | 204 white = ( 255, 255, 255) |
394 self.indicators["conn"].on() | 399 self.indicators["conn"].on() |
395 self.FADE = 15 | 400 self.FADE = 15 |
396 for blob in self.blobs : | 401 for blob in self.blobs : |
397 blob.fade(15) | 402 blob.fade(15) |
398 blob.reset_time() | 403 blob.reset_time() |
404 # inc age | |
405 elif event.key == K_1 : | |
406 self.s_age += 1 | |
407 self.update_server_config(self.s_age,self.s_dist,self.s_ninp) | |
408 # dec age | |
409 elif event.key == K_2 : | |
410 self.s_age -= 1 | |
411 self.update_server_config(self.s_age,self.s_dist,self.s_ninp) | |
412 # inc dist | |
413 elif event.key == K_3 : | |
414 self.s_dist += 0.025 | |
415 self.update_server_config(self.s_age,self.s_dist,self.s_ninp) | |
416 # dec dist | |
417 elif event.key == K_4 : | |
418 self.s_dist -= 0.025 | |
419 if self.s_dist < 0.025 : self.s_dist = 0.025 | |
420 self.update_server_config(self.s_age,self.s_dist,self.s_ninp) | |
421 # inc ninp | |
422 elif event.key == K_5 : | |
423 self.s_ninp += 1 | |
424 self.update_server_config(self.s_age,self.s_dist,self.s_ninp) | |
425 # dec ninp | |
426 elif event.key == K_6 : | |
427 self.s_ninp -= 1 | |
428 if self.s_ninp < 2 : self.s_ninp = 2 | |
429 self.update_server_config(self.s_age,self.s_dist,self.s_ninp) | |
430 | |
431 pass | |
399 pass | 432 pass |
400 | 433 |
401 def toggle_screen_mode(self): | 434 def toggle_screen_mode(self): |
402 '''Go back and forth between full screen mode.''' | 435 '''Go back and forth between full screen mode.''' |
403 if self.fullscreen == False: | 436 if self.fullscreen == False: |
454 | 487 |
455 return True | 488 return True |
456 | 489 |
457 def configure_server(self): | 490 def configure_server(self): |
458 '''Send the server some configuration data.''' | 491 '''Send the server some configuration data.''' |
459 age = 10.0 | 492 # age = 10.0 |
460 dist = DIST | 493 # dist = DIST |
461 ninp = 18 | 494 # ninp = 18 |
462 self.conn.putrequest("GET","/moodconductor/config?age=%(age)s&dist=%(dist)s&ninp=%(ninp)s" %locals(), skip_host=True) | 495 self.update_server_config(self.s_age,self.s_dist,self.s_ninp) |
463 self.conn.putheader("Host", "www.isophonics.net") | 496 |
464 self.conn.endheaders() | 497 |
465 res = self.conn.getresponse() | 498 def update_server_config(self,age,dist,ninp,retry = 3): |
466 if not res.status == 200 : | 499 '''Send the server some configuration data.''' |
467 print "Server response:", res.status, res.reason | 500 try : |
468 self.indicators["conn"].off() | 501 self.conn.putrequest("GET","/moodconductor/config?age=%(age)s&dist=%(dist)s&ninp=%(ninp)s" %locals(), skip_host=True) |
469 time.sleep(1) | 502 self.conn.putheader("Host", "www.isophonics.net") |
470 self.conn.putrequest("GET","/moodconductor/getconf", skip_host=True) | 503 self.conn.endheaders() |
471 self.conn.putheader("Host", "www.isophonics.net") | 504 res = self.conn.getresponse() |
472 self.conn.endheaders() | 505 if not res.status == 200 : |
473 res = self.conn.getresponse() | 506 print "Server response:", res.status, res.reason |
474 if not res.status == 200 : | 507 self.indicators["conn"].off() |
475 print "Server response:", res.status, res.reason | 508 time.sleep(0.5) |
476 self.indicators["conn"].off() | 509 self.conn.putrequest("GET","/moodconductor/getconf", skip_host=True) |
477 print "Server configuration:", res.read() | 510 self.conn.putheader("Host", "www.isophonics.net") |
478 | 511 self.conn.endheaders() |
512 res = self.conn.getresponse() | |
513 if not res.status == 200 : | |
514 print "Server response:", res.status, res.reason | |
515 self.indicators["conn"].off() | |
516 print "Server configuration:", res.read() | |
517 except: | |
518 time.sleep(2) | |
519 retry -= 1 | |
520 self.update_server_config(age,dist,ninp,retry) | |
521 | |
479 | 522 |
480 def connect(self,retry = 5): | 523 def connect(self,retry = 5): |
481 '''Connect to the server and test connection.''' | 524 '''Connect to the server and test connection.''' |
482 if not retry : | 525 if not retry : |
483 print "Server unreachable" | 526 print "Server unreachable" |