Heya everybody.
In anticipation of support for Python returning to Construct 1.0, I was looking for creating some bindings for modplug.dll, aka libmodplug, a GPL mod replayer engine which is probably better than libmikmod (although maybe not as well-documented)..... I appreciate all the work Rich and Ashley did (especially granting my request for mod support in Construct), however, the solution which was implemented ended up being less than ideal for handling Impulse Tracker files
Since I am kinda new to python (and know little to no C++), getting this far was a pain in the butt, but I think using some specific tools (gccxml + xml2py from Python's ctypeslib), I got the beginnings of the proper bindings. This was all based on the source headers available with libmodplug, specifically, modplug.h. I'm not sure how to plug it into an audio output quite yet, but I'll let you guys know if I do! Here is what I have so far:
modplug.py
from ctypes import *
_libraries = {}
_libraries['C:\\python26\\scripts\\modplug\\modplug.dll'] = CDLL('C:\\python26\\scripts\\modplug\\modplug.dll')
STRING = c_char_p
MODPLUG_ENABLE_NOISE_REDUCTION = 2
MODPLUG_RESAMPLE_NEAREST = 0
MODPLUG_RESAMPLE_SPLINE = 2
MODPLUG_ENABLE_SURROUND = 16
MODPLUG_ENABLE_MEGABASS = 8
MODPLUG_ENABLE_REVERB = 4
MODPLUG_ENABLE_OVERSAMPLING = 1
MODPLUG_RESAMPLE_FIR = 3
MODPLUG_RESAMPLE_LINEAR = 1
class _ModPlugFile(Structure):
pass
_ModPlugFile._fields_ = [
]
ModPlugFile = _ModPlugFile
ModPlug_Load = _libraries['C:\\python26\\scripts\\modplug\\modplug.dll'].ModPlug_Load
ModPlug_Load.restype = POINTER(ModPlugFile)
ModPlug_Load.argtypes = [c_void_p, c_int]
ModPlug_Unload = _libraries['C:\\python26\\scripts\\modplug\\modplug.dll'].ModPlug_Unload
ModPlug_Unload.restype = None
ModPlug_Unload.argtypes = [POINTER(ModPlugFile)]
ModPlug_Read = _libraries['C:\\python26\\scripts\\modplug\\modplug.dll'].ModPlug_Read
ModPlug_Read.restype = c_int
ModPlug_Read.argtypes = [POINTER(ModPlugFile), c_void_p, c_int]
ModPlug_GetName = _libraries['C:\\python26\\scripts\\modplug\\modplug.dll'].ModPlug_GetName
ModPlug_GetName.restype = STRING
ModPlug_GetName.argtypes = [POINTER(ModPlugFile)]
ModPlug_GetLength = _libraries['C:\\python26\\scripts\\modplug\\modplug.dll'].ModPlug_GetLength
ModPlug_GetLength.restype = c_int
ModPlug_GetLength.argtypes = [POINTER(ModPlugFile)]
ModPlug_Seek = _libraries['C:\\python26\\scripts\\modplug\\modplug.dll'].ModPlug_Seek
ModPlug_Seek.restype = None
ModPlug_Seek.argtypes = [POINTER(ModPlugFile), c_int]
# values for enumeration '_ModPlug_Flags'
_ModPlug_Flags = c_int # enum
# values for enumeration '_ModPlug_ResamplingMode'
_ModPlug_ResamplingMode = c_int # enum
class _ModPlug_Settings(Structure):
pass
_ModPlug_Settings._fields_ = [
('mFlags', c_int),
('mChannels', c_int),
('mBits', c_int),
('mFrequency', c_int),
('mResamplingMode', c_int),
('mReverbDepth', c_int),
('mReverbDelay', c_int),
('mBassAmount', c_int),
('mBassRange', c_int),
('mSurroundDepth', c_int),
('mSurroundDelay', c_int),
('mLoopCount', c_int),
]
ModPlug_Settings = _ModPlug_Settings
ModPlug_GetSettings = _libraries['C:\\python26\\scripts\\modplug\\modplug.dll'].ModPlug_GetSettings
ModPlug_GetSettings.restype = None
ModPlug_GetSettings.argtypes = [POINTER(ModPlug_Settings)]
ModPlug_SetSettings = _libraries['C:\\python26\\scripts\\modplug\\modplug.dll'].ModPlug_SetSettings
ModPlug_SetSettings.restype = None
ModPlug_SetSettings.argtypes = [POINTER(ModPlug_Settings)]
__all__ = ['_ModPlug_Flags', 'MODPLUG_RESAMPLE_LINEAR',
'MODPLUG_ENABLE_OVERSAMPLING', 'MODPLUG_ENABLE_MEGABASS',
'MODPLUG_ENABLE_REVERB', '_ModPlug_Settings',
'ModPlug_Settings', 'ModPlug_SetSettings',
'ModPlug_GetName', 'MODPLUG_ENABLE_NOISE_REDUCTION',
'MODPLUG_RESAMPLE_NEAREST', 'ModPlug_Load',
'_ModPlug_ResamplingMode', 'ModPlug_Read',
'ModPlug_Unload', 'MODPLUG_ENABLE_SURROUND', 'ModPlugFile',
'MODPLUG_RESAMPLE_FIR', 'ModPlug_GetLength',
'_ModPlugFile', 'MODPLUG_RESAMPLE_SPLINE', 'ModPlug_Seek',
'ModPlug_GetSettings']
[/code:ahony2oi]
You'll probably need to replace the hardcoded paths to a dynamic path, replacing with modplug.dll for windows, and libmodplug.so for Linux. What's not finished yet is the code to call the proper function to play the song. I'm hoping someone smarter than me might be able to figure that out!
You can get Modplug.dll by downloading [url=http://alister.eu/jazz/oj/download.php]OpenJazz[/url] (an open source Jazz Jackrabbit clone). From there, this source file can presumably be called to load the functions. Whew....