added midi support just because
This commit is contained in:
parent
84a006d6ae
commit
0fc2da271f
22
audio.py
22
audio.py
@ -8,19 +8,23 @@ dll = None
|
|||||||
dllf = ""
|
dllf = ""
|
||||||
opus = ""
|
opus = ""
|
||||||
flac = ""
|
flac = ""
|
||||||
|
midi = ""
|
||||||
use_ctypes = False
|
use_ctypes = False
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
dllf = "bass.dll"
|
dllf = "bass.dll"
|
||||||
opus = "bassopus.dll"
|
opus = "bassopus.dll"
|
||||||
flac = "bassflac.dll"
|
flac = "bassflac.dll"
|
||||||
|
midi = "bassmidi.dll"
|
||||||
elif platform.system() == "Darwin":
|
elif platform.system() == "Darwin":
|
||||||
dllf = "libbass.dylib"
|
dllf = "libbass.dylib"
|
||||||
opus = "libbassopus.dylib"
|
opus = "libbassopus.dylib"
|
||||||
flac = "libbassflas.dylib"
|
flac = "libbassflac.dylib"
|
||||||
|
midi = "libbassmidi.dylib"
|
||||||
else:
|
else:
|
||||||
dllf = "libbass.so"
|
dllf = "libbass.so"
|
||||||
opus = "libbassopus.so"
|
opus = "libbassopus.so"
|
||||||
flac = "libbassflac.so"
|
flac = "libbassflac.so"
|
||||||
|
midi = "libbassmidi.so"
|
||||||
|
|
||||||
def checkAvailable():
|
def checkAvailable():
|
||||||
"""
|
"""
|
||||||
@ -41,17 +45,21 @@ def init(freq=48000):
|
|||||||
"""
|
"""
|
||||||
Initialize BASS and the opus plugin
|
Initialize BASS and the opus plugin
|
||||||
"""
|
"""
|
||||||
global dll, use_ctypes
|
global dll, bassmidi, use_ctypes
|
||||||
if not dll:
|
if not dll:
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
dll = ctypes.CDLL(dllf)
|
dll = ctypes.CDLL(dllf)
|
||||||
use_ctypes = True
|
use_ctypes = True
|
||||||
else:
|
else:
|
||||||
import pybass as dll
|
import pybass as dll
|
||||||
|
import pybass.pybassmidi as bassmidi
|
||||||
|
|
||||||
dll.BASS_Init(ini.read_ini_int("AO2XP.ini", "Audio", "device", -1), freq, 0, 0, 0)
|
dll.BASS_Init(ini.read_ini_int("AO2XP.ini", "Audio", "device", -1), freq, 0, 0, 0)
|
||||||
dll.BASS_PluginLoad(os.path.abspath(opus), 0)
|
dll.BASS_PluginLoad(os.path.abspath(opus), 0)
|
||||||
dll.BASS_PluginLoad(os.path.abspath(flac), 0)
|
dll.BASS_PluginLoad(os.path.abspath(flac), 0)
|
||||||
|
dll.BASS_PluginLoad(os.path.abspath(midi), 0)
|
||||||
|
|
||||||
|
dll.BASS_SetConfigPtr(bassmidi.BASS_CONFIG_MIDI_DEFFONT, "gm.sf2");
|
||||||
|
|
||||||
def free():
|
def free():
|
||||||
"""
|
"""
|
||||||
@ -88,9 +96,15 @@ Load a BASS stream handle from an URL
|
|||||||
|
|
||||||
def loadMOD(mem, file, offset=0, length=0, flags=0):
|
def loadMOD(mem, file, offset=0, length=0, flags=0):
|
||||||
"""
|
"""
|
||||||
Load a BASS stream handle from an URL
|
Load a BASS module file
|
||||||
"""
|
"""
|
||||||
return dll.BASS_MusicLoad(mem, file, QWORD(offset), length, flags, 0)
|
return dll.BASS_MusicLoad(mem, file, QWORD(offset), length, flags, 0)
|
||||||
|
|
||||||
|
def loadMIDI(mem, file, offset=0, length=0, flags=0):
|
||||||
|
"""
|
||||||
|
Load a BASS stream handle
|
||||||
|
"""
|
||||||
|
return bassmidi.BASS_MIDI_StreamCreateFile(mem, file, QWORD(offset), QWORD(length), flags, 0)
|
||||||
|
|
||||||
def freehandle(handle):
|
def freehandle(handle):
|
||||||
"""
|
"""
|
||||||
@ -100,7 +114,7 @@ Free a handle
|
|||||||
|
|
||||||
def freeMOD(handle):
|
def freeMOD(handle):
|
||||||
"""
|
"""
|
||||||
Free a handle
|
Free a module handle
|
||||||
"""
|
"""
|
||||||
return dll.BASS_MusicFree(handle)
|
return dll.BASS_MusicFree(handle)
|
||||||
|
|
||||||
|
21
bass_test.py
21
bass_test.py
@ -4,24 +4,23 @@ __builtin__.audio = AUDIO
|
|||||||
del AUDIO
|
del AUDIO
|
||||||
from pybass_constants import *
|
from pybass_constants import *
|
||||||
|
|
||||||
|
from urllib2 import Request, urlopen
|
||||||
|
|
||||||
audio.init()
|
audio.init()
|
||||||
|
|
||||||
Miles = unicode("Miles")
|
url = 'one_last_dance.mid'
|
||||||
|
music = audio.loadMIDI(False, url, 0, 0, BASS_SAMPLE_LOOP)
|
||||||
|
|
||||||
mus = "base/characters/"+str(Miles)+"/holdit.wav"
|
print "Trying to play", url
|
||||||
|
|
||||||
music = audio.loadhandle(False, mus, 0, 0, 0)
|
|
||||||
#music = audio.loadURLhandle(mus, 0, BASS_STREAM_BLOCK)
|
|
||||||
print "Trying to play", mus
|
|
||||||
|
|
||||||
if music:
|
if music:
|
||||||
audio.sethandleattr(music, BASS_ATTRIB_VOL, 1.0)
|
audio.sethandleattr(music, BASS_ATTRIB_VOL, 1.0)
|
||||||
audio.playhandle(music, True)
|
audio.playhandle(music, False)
|
||||||
else:
|
else:
|
||||||
print "Couldn't play music. Error", audio.getbasserror()
|
print "Couldn't play music. Error", audio.getbasserror()
|
||||||
|
print "Error?", audio.getbasserror()
|
||||||
while (1):
|
|
||||||
|
while 1:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
audio.free()
|
|
||||||
sys.exit(0)
|
|
||||||
|
24
gameview.py
24
gameview.py
@ -1109,7 +1109,7 @@ class gui(QtGui.QWidget):
|
|||||||
self.notguiltysfx = 0
|
self.notguiltysfx = 0
|
||||||
|
|
||||||
self.stream = 0
|
self.stream = 0
|
||||||
self.module = False
|
self.specialstream = 0
|
||||||
self.download_thread = None
|
self.download_thread = None
|
||||||
|
|
||||||
def resetOffsets(self):
|
def resetOffsets(self):
|
||||||
@ -2560,11 +2560,12 @@ class gui(QtGui.QWidget):
|
|||||||
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, but it also allows us to download and play modules and midis, because, why not?
|
# 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()
|
musl = mus.lower()
|
||||||
musext = os.path.splitext(basename(musl))[-1]
|
musext = os.path.splitext(basename(musl))[-1]
|
||||||
modules = ['.xm', '.mod', '.mo3', '.it', '.s3m', '.mtm', '.umx']
|
if musext in ['.mid', '.midi']:
|
||||||
self.module = musext in modules
|
self.specialstream = 1
|
||||||
midi = musext in ['.mid', '.midi']
|
elif musext in ['.xm', '.mod', '.mo3', '.it', '.s3m', '.mtm', '.umx']:
|
||||||
if musl.startswith("https") or self.module or midi:
|
self.specialstream = 2
|
||||||
|
if musl.startswith("https") or self.specialstream:
|
||||||
print "[audio] Downloading music with urllib2"
|
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)
|
||||||
@ -2574,9 +2575,10 @@ 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:
|
if self.specialstream:
|
||||||
audio.freeMOD(self.music)
|
if self.specialstream == 2:
|
||||||
self.module = False
|
audio.freeMOD(self.music)
|
||||||
|
self.specialstream = 0
|
||||||
else:
|
else:
|
||||||
audio.freehandle(self.music)
|
audio.freehandle(self.music)
|
||||||
if self.stream:
|
if self.stream:
|
||||||
@ -2589,7 +2591,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:
|
if self.specialstream == 1:
|
||||||
|
self.music = audio.loadMIDI(True, self.stream, 0, file_length, BASS_SAMPLE_LOOP)
|
||||||
|
elif self.specialstream == 2:
|
||||||
self.music = audio.loadMOD(True, self.stream, 0, file_length, BASS_SAMPLE_LOOP)
|
self.music = audio.loadMOD(True, self.stream, 0, file_length, BASS_SAMPLE_LOOP)
|
||||||
else:
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user