added midi support just because

This commit is contained in:
cidoku 2025-02-14 19:35:05 -03:00
parent 84a006d6ae
commit 0fc2da271f
3 changed files with 42 additions and 25 deletions

View File

@ -8,19 +8,23 @@ dll = None
dllf = ""
opus = ""
flac = ""
midi = ""
use_ctypes = False
if platform.system() == "Windows":
dllf = "bass.dll"
opus = "bassopus.dll"
flac = "bassflac.dll"
midi = "bassmidi.dll"
elif platform.system() == "Darwin":
dllf = "libbass.dylib"
opus = "libbassopus.dylib"
flac = "libbassflas.dylib"
flac = "libbassflac.dylib"
midi = "libbassmidi.dylib"
else:
dllf = "libbass.so"
opus = "libbassopus.so"
flac = "libbassflac.so"
midi = "libbassmidi.so"
def checkAvailable():
"""
@ -41,17 +45,21 @@ def init(freq=48000):
"""
Initialize BASS and the opus plugin
"""
global dll, use_ctypes
global dll, bassmidi, use_ctypes
if not dll:
if platform.system() == "Darwin":
dll = ctypes.CDLL(dllf)
use_ctypes = True
else:
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_PluginLoad(os.path.abspath(opus), 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():
"""
@ -88,10 +96,16 @@ Load a BASS stream handle from an URL
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)
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):
"""
Free a handle
@ -100,7 +114,7 @@ Free a handle
def freeMOD(handle):
"""
Free a handle
Free a module handle
"""
return dll.BASS_MusicFree(handle)

View File

@ -4,24 +4,23 @@ __builtin__.audio = AUDIO
del AUDIO
from pybass_constants import *
from urllib2 import Request, urlopen
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"
music = audio.loadhandle(False, mus, 0, 0, 0)
#music = audio.loadURLhandle(mus, 0, BASS_STREAM_BLOCK)
print "Trying to play", mus
print "Trying to play", url
if music:
audio.sethandleattr(music, BASS_ATTRIB_VOL, 1.0)
audio.playhandle(music, True)
audio.playhandle(music, False)
else:
print "Couldn't play music. Error", audio.getbasserror()
print "Error?", audio.getbasserror()
while (1):
while 1:
pass
audio.free()
sys.exit(0)

View File

@ -1109,7 +1109,7 @@ class gui(QtGui.QWidget):
self.notguiltysfx = 0
self.stream = 0
self.module = False
self.specialstream = 0
self.download_thread = None
def resetOffsets(self):
@ -2561,10 +2561,11 @@ class gui(QtGui.QWidget):
# 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:
if musext in ['.mid', '.midi']:
self.specialstream = 1
elif musext in ['.xm', '.mod', '.mo3', '.it', '.s3m', '.mtm', '.umx']:
self.specialstream = 2
if musl.startswith("https") or self.specialstream:
print "[audio] Downloading music with urllib2"
self.download_thread = DownloadThread(self, mus)
self.download_thread.finished_signal.connect(self.playDownloadedMusic)
@ -2574,9 +2575,10 @@ class gui(QtGui.QWidget):
if self.music:
if audio.handleisactive(self.music):
audio.stophandle(self.music)
if self.module:
audio.freeMOD(self.music)
self.module = False
if self.specialstream:
if self.specialstream == 2:
audio.freeMOD(self.music)
self.specialstream = 0
else:
audio.freehandle(self.music)
if self.stream:
@ -2589,7 +2591,9 @@ 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..."
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)
else:
self.music = audio.loadhandle(True, self.stream, 0, file_length, BASS_SAMPLE_LOOP)