diff --git a/piaudio.py b/piaudio.py index 15b496f2..e3590c11 100644 --- a/piaudio.py +++ b/piaudio.py @@ -67,19 +67,21 @@ def Resample(data): while data: stream.write(data) data = f.readframes(chunk) - data = Resample(data) + try: + if data: + data = Resample(data) + except: + pass if stop_proc.value: stream.stop_stream() stream.close() break - # if stop_proc.value: - # return #stop stream - # stream.stop_stream() - # stream.close() + stream.stop_stream() + stream.close() # # #close PyAudio # p.terminate() diff --git a/piparty.py b/piparty.py index a3f90357..7e43d98f 100644 --- a/piparty.py +++ b/piparty.py @@ -4,7 +4,7 @@ import time, random, json, os, os.path, sys, glob from piaudio import Music, DummyMusic, Audio, InitAudio from enum import Enum -from multiprocessing import Process, Value, Array, Queue, Manager +from multiprocessing import Process, Value, Array, Queue, Manager, freeze_support from games import ffa, zombie, commander, swapper, tournament, speed_bomb, fight_club from sys import platform if platform == "linux" or platform == "linux2": @@ -240,10 +240,8 @@ def __init__(self): self.command_queue = Queue() self.joust_manager = Manager() self.ns = self.joust_manager.Namespace() - self.web_proc = Process(target=webui.start_web, args=(self.command_queue,self.ns)) self.web_proc.start() - self.ns.status = dict() self.ns.settings = dict() self.ns.battery_status = dict() @@ -253,7 +251,6 @@ def __init__(self): #defined outside of ns.settings as it's a purely dev option self.experimental = False - self.move_count = psmove.count_connected() self.dead_count = Value('i', 0) self.moves = [psmove.PSMove(x) for x in range(psmove.count_connected())] @@ -310,11 +307,9 @@ def __init__(self): self.joust_music = Music("joust") self.zombie_music = Music("zombie") self.commander_music = Music("commander") - self.choose_new_music() - def choose_new_music(self): self.joust_music.load_audio(random.choice(glob.glob("audio/Joust/music/*"))) self.zombie_music.load_audio(random.choice(glob.glob("audio/Zombie/music/*"))) @@ -335,6 +330,7 @@ def exclude_out_moves(self): def check_for_new_moves(self): self.enable_bt_scanning(True) #need to start tracking of new moves in here + if psmove.count_connected() != self.move_count: self.moves = [psmove.PSMove(x) for x in range(psmove.count_connected())] self.move_count = len(self.moves) @@ -366,7 +362,6 @@ def pair_usb_move(self, move): self.pair_one_move = False def pair_move(self, move, move_num): - print("NOW PAIRING MOVE") move_serial = move.get_serial() if move_serial not in self.tracked_moves: color = Array('i', [0] * 3) @@ -410,6 +405,7 @@ def pair_move(self, move, move_num): proc.start() self.move_opts[move_serial] = opts + self.tracked_moves[move_serial] = proc self.force_color[move_serial] = color self.controller_teams[move_serial] = team @@ -553,9 +549,14 @@ def game_loop(self): self.menu_music.load_audio(random.choice(glob.glob("audio/MenuMusic/*"))) self.menu_music.start_audio_loop() self.i=self.i+1 - if not self.pair_one_move and "0" in os.popen('lsusb | grep "PlayStation Move motion controller" | wc -l').read(): - self.pair_one_move = True - self.paired_moves = [] + if "linux" in platform: + if not self.pair_one_move and "0" in os.popen('lsusb | grep "PlayStation Move motion controller" | wc -l').read(): + self.pair_one_move = True + self.paired_moves = [] + else: + if not self.pair_one_move: + self.pair_one_move = True + self.paired_moves = [] if self.pair_one_move: #check if there are any controllers that were shut off if psmove.count_connected() > len(self.tracked_moves): @@ -765,7 +766,6 @@ def update_status(self,game_status): } battery_status = {} - # print(self.moves) for move in self.moves: move.poll() battery_status[move.get_serial()] = move.get_battery() @@ -938,6 +938,8 @@ def start_game(self, random_mode=False): if __name__ == "__main__": + if "win" in platform: + freeze_support() InitAudio() piparty = Menu() piparty.game_loop() diff --git a/win_pair.py b/win_pair.py index e9699b3b..35bcce54 100644 --- a/win_pair.py +++ b/win_pair.py @@ -72,7 +72,8 @@ def get_lowest_bt_device(self): # return '' def pair_move(self, move): - pass + result = move.pair() + return result # if move and move.get_serial(): # if move.connection_type == psmove.Conn_USB: # self.pre_existing_devices()