From 3226ba3760a9df8a56f055399cbf90d0608a0dd8 Mon Sep 17 00:00:00 2001 From: cidoku Date: Fri, 14 Feb 2025 19:01:05 -0300 Subject: [PATCH] added module music support because why not --- audio.py | 12 ++++++++++++ gameview.py | 47 +++++++++++++++++++++++++++++++---------------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/audio.py b/audio.py index dfb69b4..a434355 100644 --- a/audio.py +++ b/audio.py @@ -85,12 +85,24 @@ def loadURLhandle(url, offset, flags, proc=DOWNLOADPROC(), user=0): Load a BASS stream handle from an URL """ return dll.BASS_StreamCreateURL(url, offset, flags, proc, user) + +def loadMOD(mem, file, offset=0, length=0, flags=0): + """ +Load a BASS stream handle from an URL + """ + return dll.BASS_MusicLoad(mem, file, QWORD(offset), length, flags, 0) def freehandle(handle): """ Free a handle """ return dll.BASS_StreamFree(handle) + +def freeMOD(handle): + """ +Free a handle + """ + return dll.BASS_MusicFree(handle) def playhandle(handle, restart): """ diff --git a/gameview.py b/gameview.py index 047148e..5ec4c5b 100644 --- a/gameview.py +++ b/gameview.py @@ -495,7 +495,7 @@ class AOMovie(QtGui.QLabel): get_img_suffix(AOpath+"characters/"+p_char+"/"+p_image), get_img_suffix(AOpath+"misc/default/"+p_image), get_img_suffix(AO2XPpath+"themes/default/"+p_image), - AO2XPpath+"themes/default/placeholder.gif" + #AO2XPpath+"themes/default/placeholder.gif" ] for f in pathlist: @@ -1109,6 +1109,7 @@ class gui(QtGui.QWidget): self.notguiltysfx = 0 self.stream = 0 + self.module = False self.download_thread = None def resetOffsets(self): @@ -2522,16 +2523,18 @@ class gui(QtGui.QWidget): if not mus.endswith(".mp3") and "===MUSIC START===.mp3" in self.musiclist: #vidya workaround mus += ".mp3" - if self.music: - if audio.handleisactive(self.music): - audio.stophandle(self.music) - audio.freehandle(self.music) - if self.stream: - del self.stream + # if self.music: + # if audio.handleisactive(self.music): + # audio.stophandle(self.music) + # audio.freehandle(self.music) + # if self.stream: + # self.stream = None - if self.download_thread: - self.download_thread.terminate() # Live dangerously - self.download_thread = None + # if self.download_thread: + # self.download_thread.terminate() # Live dangerously + # self.download_thread = None + + self.stopMusic() if exists(AOpath + 'sounds/music/' + mus): self.music = audio.loadhandle(False, AOpath + 'sounds/music/' + mus, 0, 0, BASS_SAMPLE_LOOP) @@ -2555,9 +2558,14 @@ class gui(QtGui.QWidget): audio.playhandle(self.music, True) else: print "[audio] Couldn't play music. Error", audio.getbasserror() - # Here comes the evil HTTPS hack for XP systems - if mus.lower().startswith("https"): - print "[audio] Trying to download music with urllib2" + # Here comes the evil HTTPS hack for XP systems, but it also allows us to download and play modules and midis, because, why not? + musl = mus.lower() + musext = os.path.splitext(basename(musl))[-1] + modules = ['.xm', '.mod', '.mo3', '.it', '.s3m', '.mtm', '.umx'] + self.module = musext in modules + midi = musext in ['.mid', '.midi'] + if musl.startswith("https") or self.module or midi: + print "[audio] Downloading music with urllib2" self.download_thread = DownloadThread(self, mus) self.download_thread.finished_signal.connect(self.playDownloadedMusic) self.download_thread.start() @@ -2566,9 +2574,13 @@ class gui(QtGui.QWidget): if self.music: if audio.handleisactive(self.music): audio.stophandle(self.music) - audio.freehandle(self.music) + if self.module: + audio.freeMOD(self.music) + self.module = False + else: + audio.freehandle(self.music) if self.stream: - del self.stream + self.stream = None if self.download_thread: self.download_thread.terminate() # Live dangerously @@ -2577,7 +2589,10 @@ class gui(QtGui.QWidget): def playDownloadedMusic(self, file_length): # Part of the evil HTTPS music download hack for XP systems print "[audio] Done downloading; trying to play..." - self.music = audio.loadhandle(True, self.stream, 0, file_length, BASS_SAMPLE_LOOP) + if self.module: + self.music = audio.loadMOD(True, self.stream, 0, file_length, BASS_SAMPLE_LOOP) + else: + self.music = audio.loadhandle(True, self.stream, 0, file_length, BASS_SAMPLE_LOOP) audio.sethandleattr(self.music, BASS_ATTRIB_VOL, self.musicslider.value() / 100.0) audio.playhandle(self.music, False)