From 683af1ca34a88770ff70e94f16b09128058e0d2e Mon Sep 17 00:00:00 2001 From: cidoku Date: Sun, 26 Oct 2025 20:27:36 -0300 Subject: [PATCH] sound: more channels for sound effects + simplify effects list --- gameview.py | 76 +++++++++++++++++++++++++++++++---------------------- ini.py | 16 +++++------ 2 files changed, 53 insertions(+), 39 deletions(-) diff --git a/gameview.py b/gameview.py index 6aacaaf..825a715 100644 --- a/gameview.py +++ b/gameview.py @@ -1033,7 +1033,13 @@ class Chatbox(QtGui.QLabel): class GUI(QtGui.QWidget): gamewindow = None - sound = None + # In theory 3 sounds may play at the same time: character, evidence sweep, + # effect + soundChannels = 3 + soundChannel = 0 + sound = [] + for i in range(soundChannels): + sound.append(None) music = None nextCharacterIsNotSpecial = False messageIsCentered = False @@ -2250,8 +2256,9 @@ class GUI(QtGui.QWidget): audio.playHandle(self.music, False) def changeSoundVolume(self, value): - if self.sound: - audio.setHandleAttr(self.sound, BASS_ATTRIB_VOL, value / 100.0) + for s in self.sound: + if s: + audio.setHandleAttr(self.sound, BASS_ATTRIB_VOL, value / 100.0) audio.setHandleAttr(self.sndRealization, BASS_ATTRIB_VOL, value / 100.0) audio.setHandleAttr(self.wtceSfx, BASS_ATTRIB_VOL, value / 100.0) audio.setHandleAttr(self.guiltySfx, BASS_ATTRIB_VOL, value / 100.0) @@ -3148,35 +3155,36 @@ class GUI(QtGui.QWidget): else: msg += "chat#" - msg += emote[1]+"#" #pre-anim + msg += emote[1] + "#" #pre-anim msg += self.charName.title() + "#" - msg += emote[2]+"#" #anim - msg += text+"#" - msg += self.charSide+"#" - msg += (ini.get_effect_sound(self.boxEffects.currentText(), self.charName) if self.boxEffects.currentIndex() > 0 else emote[4])+"#" #sfx - msg += str(modifier)+"#" #emote modifier - msg += str(self.myChar)+"#" #character ID - msg += emote[5]+"#" #sfx delay - msg += str(objection)+"#" - msg += str((self.selectedEvidence + 1) * int(self.present))+"#" #selected evidence + msg += emote[2] + "#" #anim + msg += text + "#" + msg += self.charSide + "#" + #msg += (ini.get_effect_sound(self.boxEffects.currentText(), self.charName) if self.boxEffects.currentIndex() > 0 else emote[4]) + "#" #sfx + msg += emote[4] + "#" + msg += str(modifier) + "#" #emote modifier + msg += str(self.myChar) + "#" #character ID + msg += emote[5] + "#" #sfx delay + msg += str(objection) + "#" + msg += str((self.selectedEvidence + 1) * int(self.present)) + "#" #selected evidence if self.present: self.present = False self.btnEvidencePresent.setPixmap(self.btnEvidencePresent.button_off) if "flipping" in self.features: - msg += str(self.myFlip)+"#" + msg += str(self.myFlip) + "#" else: - msg += str(self.myChar)+"#" # old AO servers send a second charID in the message because drunk fanat + msg += str(self.myChar) + "#" # old AO servers send a second charID in the message because drunk fanat - msg += str(int(self.btnRealization.isPressed()))+"#" - msg += str(self.myChatColor)+"#" + msg += str(int(self.btnRealization.isPressed())) + "#" + msg += str(self.myChatColor) + "#" if "cccc_ic_support" in self.features: showname = self.showname.decode('utf-8') if self.showname == "" and not self.charShowname == "": showname = self.charShowname - msg += showname+"#" # custom showname + msg += showname + "#" # custom showname if self.cbPair.isChecked(): msg += str(self.boxPair.currentIndex()) # pair charID if "effects" in self.features: @@ -3190,12 +3198,12 @@ class GUI(QtGui.QWidget): if "y_offset" in self.features: # AO 2.9 msg += str(self.sliPairOffset.value()) + "&" + str(-self.sliPairOffsetY.value()) + "#" else: - msg += str(self.sliPairOffset.value())+"#" + msg += str(self.sliPairOffset.value()) + "#" - msg += str(int(self.cbNoInterrupt.isChecked()))+"#" # NoInterrupt(TM) + msg += str(int(self.cbNoInterrupt.isChecked())) + "#" # NoInterrupt(TM) if "looping_sfx" in self.features: # AO 2.8 - msg += emote[6]+"#" # loop sound? + msg += emote[6] + "#" # loop sound? msg += "%d#" % self.btnShake.isPressed() # screen shake emotes_to_check = [emote[1], "(b)"+emote[2], "(b)/"+emote[2], "(a)"+emote[2], "(a)/"+emote[2] ] effects_to_check = ["_FrameScreenshake", "_FrameRealization", "_FrameSFX"] @@ -3209,7 +3217,7 @@ class GUI(QtGui.QWidget): if sfx_frames: packet += "|" + sfx_frames packet += "^" - msg += packet+"#" + msg += packet + "#" if "additive" in self.features: msg += "%d#" % self.cbAdditive.isChecked() @@ -4259,18 +4267,24 @@ class GUI(QtGui.QWidget): self.playSound(sfxName) def playSound(self, sfx): - if self.sound: - if audio.handleIsActive(self.sound): - audio.stopHandle(self.sound) - audio.freeHandle(self.sound) + self.soundChannel = (self.soundChannel + 1) % self.soundChannels + + if self.sound[self.soundChannel]: + if audio.handleIsActive(self.sound[self.soundChannel]): + audio.stopHandle(self.sound[self.soundChannel]) + audio.freeHandle(self.sound[self.soundChannel]) - path = testPath(AOpath + 'sounds/general/' + sfx, AOpath + 'sounds/general/' + sfx + '.wav', AOpath + 'sounds/general/' + sfx + '.opus') + path = testPath( + AOpath + 'sounds/general/' + sfx, + AOpath + 'sounds/general/' + sfx + '.wav', + AOpath + 'sounds/general/' + sfx + '.opus' + ) if path: - self.sound = audio.loadHandle(False, path, 0, 0, 0) - audio.setHandleAttr(self.sound, BASS_ATTRIB_VOL, self.sliSoundVolume.value() / 100.0) - if self.sound: - audio.playHandle(self.sound, True) + self.sound[self.soundChannel] = audio.loadHandle(False, path, 0, 0, 0) + audio.setHandleAttr(self.sound[self.soundChannel], BASS_ATTRIB_VOL, self.sliSoundVolume.value() / 100.0) + if self.sound[self.soundChannel]: + audio.playHandle(self.sound[self.soundChannel], True) def playMusic(self, mus): self.stopMusic() diff --git a/ini.py b/ini.py index dcfcbbc..c454d02 100644 --- a/ini.py +++ b/ini.py @@ -138,16 +138,16 @@ def get_effect_sound(fx_name, char): def get_effects(char): p_effect = read_ini("base/characters/"+char+"/char.ini", "options", "effects", "default/effects") p_path = "base/misc/"+p_effect+"/effects.ini" - default_path = "AO2XPbase/themes/default/effects/effects.ini" + # default_path = "AO2XPbase/themes/default/effects/effects.ini" - effects = [] + # effects = [] - if exists(default_path): - with open(default_path, 'r') as file: - for line in file: - effects.append(line.split("=")[0].strip()) - else: - effects = ["realization", "hearts", "reaction", "impact"] + # if exists(default_path): + # with open(default_path, 'r') as file: + # for line in file: + # effects.append(line.split("=")[0].strip()) + # else: + effects = ["realization", "hearts", "reaction", "impact"] if not exists(p_path): return effects