added module music support because why not
This commit is contained in:
parent
c02a1e2a2f
commit
3226ba3760
12
audio.py
12
audio.py
@ -86,12 +86,24 @@ Load a BASS stream handle from an URL
|
|||||||
"""
|
"""
|
||||||
return dll.BASS_StreamCreateURL(url, offset, flags, proc, user)
|
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):
|
def freehandle(handle):
|
||||||
"""
|
"""
|
||||||
Free a handle
|
Free a handle
|
||||||
"""
|
"""
|
||||||
return dll.BASS_StreamFree(handle)
|
return dll.BASS_StreamFree(handle)
|
||||||
|
|
||||||
|
def freeMOD(handle):
|
||||||
|
"""
|
||||||
|
Free a handle
|
||||||
|
"""
|
||||||
|
return dll.BASS_MusicFree(handle)
|
||||||
|
|
||||||
def playhandle(handle, restart):
|
def playhandle(handle, restart):
|
||||||
"""
|
"""
|
||||||
Play a handle
|
Play a handle
|
||||||
|
43
gameview.py
43
gameview.py
@ -495,7 +495,7 @@ class AOMovie(QtGui.QLabel):
|
|||||||
get_img_suffix(AOpath+"characters/"+p_char+"/"+p_image),
|
get_img_suffix(AOpath+"characters/"+p_char+"/"+p_image),
|
||||||
get_img_suffix(AOpath+"misc/default/"+p_image),
|
get_img_suffix(AOpath+"misc/default/"+p_image),
|
||||||
get_img_suffix(AO2XPpath+"themes/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:
|
for f in pathlist:
|
||||||
@ -1109,6 +1109,7 @@ class gui(QtGui.QWidget):
|
|||||||
self.notguiltysfx = 0
|
self.notguiltysfx = 0
|
||||||
|
|
||||||
self.stream = 0
|
self.stream = 0
|
||||||
|
self.module = False
|
||||||
self.download_thread = None
|
self.download_thread = None
|
||||||
|
|
||||||
def resetOffsets(self):
|
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
|
if not mus.endswith(".mp3") and "===MUSIC START===.mp3" in self.musiclist: #vidya workaround
|
||||||
mus += ".mp3"
|
mus += ".mp3"
|
||||||
|
|
||||||
if self.music:
|
# if self.music:
|
||||||
if audio.handleisactive(self.music):
|
# if audio.handleisactive(self.music):
|
||||||
audio.stophandle(self.music)
|
# audio.stophandle(self.music)
|
||||||
audio.freehandle(self.music)
|
# audio.freehandle(self.music)
|
||||||
if self.stream:
|
# if self.stream:
|
||||||
del self.stream
|
# self.stream = None
|
||||||
|
|
||||||
if self.download_thread:
|
# if self.download_thread:
|
||||||
self.download_thread.terminate() # Live dangerously
|
# self.download_thread.terminate() # Live dangerously
|
||||||
self.download_thread = None
|
# self.download_thread = None
|
||||||
|
|
||||||
|
self.stopMusic()
|
||||||
|
|
||||||
if exists(AOpath + 'sounds/music/' + mus):
|
if exists(AOpath + 'sounds/music/' + mus):
|
||||||
self.music = audio.loadhandle(False, AOpath + 'sounds/music/' + mus, 0, 0, BASS_SAMPLE_LOOP)
|
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)
|
audio.playhandle(self.music, True)
|
||||||
else:
|
else:
|
||||||
print "[audio] Couldn't play music. Error", audio.getbasserror()
|
print "[audio] Couldn't play music. Error", audio.getbasserror()
|
||||||
# Here comes the evil HTTPS hack for XP systems
|
# Here comes the evil HTTPS hack for XP systems, but it also allows us to download and play modules and midis, because, why not?
|
||||||
if mus.lower().startswith("https"):
|
musl = mus.lower()
|
||||||
print "[audio] Trying to download music with urllib2"
|
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 = DownloadThread(self, mus)
|
||||||
self.download_thread.finished_signal.connect(self.playDownloadedMusic)
|
self.download_thread.finished_signal.connect(self.playDownloadedMusic)
|
||||||
self.download_thread.start()
|
self.download_thread.start()
|
||||||
@ -2566,9 +2574,13 @@ class gui(QtGui.QWidget):
|
|||||||
if self.music:
|
if self.music:
|
||||||
if audio.handleisactive(self.music):
|
if audio.handleisactive(self.music):
|
||||||
audio.stophandle(self.music)
|
audio.stophandle(self.music)
|
||||||
|
if self.module:
|
||||||
|
audio.freeMOD(self.music)
|
||||||
|
self.module = False
|
||||||
|
else:
|
||||||
audio.freehandle(self.music)
|
audio.freehandle(self.music)
|
||||||
if self.stream:
|
if self.stream:
|
||||||
del self.stream
|
self.stream = None
|
||||||
|
|
||||||
if self.download_thread:
|
if self.download_thread:
|
||||||
self.download_thread.terminate() # Live dangerously
|
self.download_thread.terminate() # Live dangerously
|
||||||
@ -2577,6 +2589,9 @@ class gui(QtGui.QWidget):
|
|||||||
def playDownloadedMusic(self, file_length):
|
def playDownloadedMusic(self, file_length):
|
||||||
# Part of the evil HTTPS music download hack for XP systems
|
# Part of the evil HTTPS music download hack for XP systems
|
||||||
print "[audio] Done downloading; trying to play..."
|
print "[audio] Done downloading; trying to play..."
|
||||||
|
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)
|
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.sethandleattr(self.music, BASS_ATTRIB_VOL, self.musicslider.value() / 100.0)
|
||||||
audio.playhandle(self.music, False)
|
audio.playhandle(self.music, False)
|
||||||
|
Loading…
Reference in New Issue
Block a user