Skip to content

Commit

Permalink
Moved all the pygame mixer commands to the given subthread function
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Senior committed Jun 2, 2020
1 parent 82ad46d commit 2ae2c50
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
16 changes: 13 additions & 3 deletions src/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from log import Log
from error import Error

import pygame

class Audio(Log, Error):
'''
The Audio object takes the number of handbells and their tuning from the
Expand All @@ -34,7 +36,7 @@ class Audio(Log, Error):
logFile : string
The name and location of the log file to write to.
'''
def __init__(self, numberOfBells, mixer, config, logFile):
def __init__(self, numberOfBells, config, logFile):
# Set the working directory based on if ReBel is being run from an
# executable or the Python source code.
if getattr(sys, 'frozen', False):
Expand All @@ -50,7 +52,7 @@ def __init__(self, numberOfBells, mixer, config, logFile):

self.numberOfBells = numberOfBells
self.config = config
self.mixer = mixer
#self.mixer = mixer

self.bellSemitones = []
self.bells = {}
Expand Down Expand Up @@ -86,7 +88,7 @@ def __init__(self, numberOfBells, mixer, config, logFile):
self.generateBells()

# Load in the bell sounds.
self.loadBells()
#self.loadBells()

self.frameRate = 500
self.running = True
Expand Down Expand Up @@ -288,6 +290,14 @@ def loadBells(self):
self.bells[i+1] = self.mixer.Sound(os.path.join(self.exeDir, "..", "audio", "{}.wav".format(i+1)))

def playBell(self):
pygame.mixer.pre_init(frequency=44100, size=16, channels=self.config.get('numberOfBells'))
pygame.mixer.init()

self.mixer = pygame.mixer
#self.mixer.set_num_channels(self.config.get('numberOfBells'))

self.loadBells()

while self.running:
start = time.time()
try:
Expand Down
8 changes: 5 additions & 3 deletions src/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Display:

def __init__(self, width, height, caption=None, iconFile=None):

self.frameRate = 500
self.frameRate = 100

self.width = width
self.height = height
Expand Down Expand Up @@ -70,15 +70,17 @@ def _flip(self, args):
def display(self, win):
self.win = win
self.draw = Draw(self.win, displayThread=True)
clock = pygame.time.Clock()
while self.running:
start = time.time()
#start = time.time()
try:
displayObject = self.displayThreadQueue.get_nowait()
except:
pass
else:
self.displayFunctions[displayObject[0]](displayObject[1])
time.sleep(max(1./self.frameRate - (time.time() - start), 0))
#time.sleep(max(1./self.frameRate - (time.time() - start), 0))
clock.tick(self.frameRate)

def subprocess(self):
pass
4 changes: 2 additions & 2 deletions src/rebel.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def __init__(self, menuWidth, menuHeight, mainWidth, mainHeight, configFile=os.p

# initialize
pygame.init()
pygame.mixer.pre_init(frequency=44100, size=16, channels=1)
pygame.mixer.init()
#pygame.mixer.pre_init(frequency=44100, size=16, channels=1)
#pygame.mixer.init()
pygame.font.init()

if getattr(sys, 'frozen', False):
Expand Down
6 changes: 3 additions & 3 deletions src/ringingScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ def initialise(self):
except:
self.log("[WARNING] RingingScreen.initialise: Incorrect bell/key configuration of bell no. '{}' and key '{}'".format(self.config.get('ringableBells')[i], self.config.get('keys')[i]))

self.mixer = pygame.mixer
self.mixer.set_num_channels(self.config.get('numberOfBells'))
self.audio = Audio(self.config.get('numberOfBells'), self.mixer, self.config, self.logFile)
#self.mixer = pygame.mixer
#self.mixer.set_num_channels(self.config.get('numberOfBells'))
self.audio = Audio(self.config.get('numberOfBells'), self.config, self.logFile)

self.updateBellStates()

Expand Down

0 comments on commit 2ae2c50

Please sign in to comment.