def method_load_data(self, stream, name_stream='memory_stream'): if stream is not None: if isinstance(stream, (str, list, tuple, buffer)): self.stream = memory_stream(stream, name_stream) else: self.stream = stream if isinstance(self.stream, memory_stream): system = pybass.STREAMFILE_BUFFER flags = 0 def callback_close(user): self.stream.current_position = 0 self.callback_close = callback_close def callback_length(user): return len(self.stream.data) self.callback_length = callback_length def callback_read(buffer, length, user): b = pybass.ctypes.cast(buffer, pybass.ctypes.c_char_p) pybass.ctypes.memset(b, 0, length) data = pybass.ctypes.c_char_p(self.stream.read(length)) pybass.ctypes.memmove(b, data, length) return length self.callback_read = callback_read def callback_seek(offset, user): self.stream.seek(offset) return True self.callback_seek = callback_seek self.bass_file_procs = pybass.BASS_FILEPROCS() self.bass_file_procs.close = pybass.FILECLOSEPROC( self.callback_close) self.bass_file_procs.length = pybass.FILELENPROC( self.callback_length) self.bass_file_procs.read = pybass.FILEREADPROC( self.callback_read) self.bass_file_procs.seek = pybass.FILESEEKPROC( self.callback_seek) new_bass_handle = pybass.BASS_StreamCreateFileUser( system, flags, self.bass_file_procs, id(self.stream.data)) if new_bass_handle == 0: print 'BASS_StreamCreateFileUser error', pybass.get_error_description( pybass.BASS_ErrorGetCode()) else: self.method_stop_audio() self.bass_handle = new_bass_handle channel_info = self.method_get_channel_info() if channel_info.ctype == pybass.BASS_CTYPE_STREAM_OGG: import pyogginfo ogg_info = pyogginfo.VorbisStreamInfo() stream = pyogginfo.SimpleDemultiplexer(ogg_info) if isinstance(self.stream.data, str): stream.process(self.stream.data) else: stream.process(str(self.stream.data)) self.stream.decode_length = ogg_info.lastPosition self.stream.seconds = ogg_info.stop try: for key, value in ogg_info.comments.comments: if key == 'TITLE': if value.strip() > '': self.stream.name = value except: pass self.method_slider_set_range() self.method_check_controls()
def method_get_channel_info(self): channel_info = pybass.BASS_CHANNELINFO() if not pybass.BASS_ChannelGetInfo(self.bass_handle, channel_info): print 'BASS_ChannelGetInfo error', pybass.get_error_description( pybass.BASS_ErrorGetCode()) return channel_info
def __init__(self, *args, **kwargs): self.stream = kwargs.pop('stream', None) self.name_stream = kwargs.pop('name_stream', 'memory_stream') self.bass_handle = 0 wx.Panel.__init__(self, *args, **kwargs) sizer_h = wx.BoxSizer(wx.HORIZONTAL) self.btn_play = wx.Button(self, wx.ID_ANY, _('Play'), style=wx.NO_BORDER) self.btn_play.SetToolTipString(_('Play media data')) self.Bind(wx.EVT_BUTTON, self.event_play, self.btn_play) sizer_h.Add(self.btn_play) self.btn_stop = wx.Button(self, wx.ID_ANY, _('Stop'), style=wx.NO_BORDER) self.Bind(wx.EVT_BUTTON, self.event_stop, self.btn_stop) sizer_h.Add(self.btn_stop) self.btn_open = wx.Button(self, wx.ID_OPEN, _('Open'), style=wx.NO_BORDER) self.Bind(wx.EVT_BUTTON, self.event_open, self.btn_open) sizer_h.Add(self.btn_open) sizer_v = wx.BoxSizer(wx.VERTICAL) self.status_line = Ticker(self, fgcolor='#000062', bgcolor='#7F7F8F', start=False, ppf=1, fps=50, direction='ltr') sizer_v.Add(self.status_line, 0, wx.EXPAND) self.slider = slider_ctrl(self, wx.ID_ANY, 0, 0, 0) sizer_v.Add(self.slider, 0, wx.EXPAND) sizer_v.Add(sizer_h) self.SetSizer(sizer_v) self.SetAutoLayout(True) result = pybass.BASS_Init(-1, 44100, 0, 0, 0) if not result: bass_error_code = pybass.BASS_ErrorGetCode() if bass_error_code != pybass.BASS_ERROR_ALREADY: self.slider.Enable(False) self.btn_play.Enable(False) self.btn_stop.Enable(False) print 'BASS_Init error', pybass.get_error_description( bass_error_code) self.plugins = {} self.plugins['aac'] = (pybass.BASS_PluginLoad('bass_aac.dll', 0), '|AAC|*.aac') self.plugins['ac3'] = (pybass.BASS_PluginLoad('bass_ac3.dll', 0), '|AC3|*.ac3') self.plugins['aix'] = (pybass.BASS_PluginLoad('bass_aix.dll', 0), '|AIX|*.aix') self.plugins['ape'] = (pybass.BASS_PluginLoad('bass_ape.dll', 0), '|APE|*.ape') self.plugins['mpc'] = (pybass.BASS_PluginLoad('bass_mpc.dll', 0), '|MPC|*.mpc') self.plugins['ofr'] = (pybass.BASS_PluginLoad('bass_ofr.dll', 0), '|OFR|*.ofr') self.plugins['spx'] = (pybass.BASS_PluginLoad('bass_spx.dll', 0), '|SPX|*.spx') self.plugins['tta'] = (pybass.BASS_PluginLoad('bass_tta.dll', 0), '|TTA|*.tta') self.plugins['cda'] = (pybass.BASS_PluginLoad('basscd.dll', 0), '|CDA|*.cda') self.plugins['flac'] = (pybass.BASS_PluginLoad('bassflac.dll', 0), '|FLAC|*.flac') self.plugins['wma'] = (pybass.BASS_PluginLoad('basswma.dll', 0), '|WMA, WMV|*.wma;*.wmv') self.sound_font = 0 if pybassmidi: sound_font_file_name = 'CT4MGM.SF2' self.sound_font = pybassmidi.BASS_MIDI_FontInit( sound_font_file_name, 0) if self.sound_font == 0: print 'BASS_MIDI_FontInit error', pybass.get_error_description( pybass.BASS_ErrorGetCode( )), ' (sound font file must be', sound_font_file_name, ')' else: self.plugins['midi'] = (pybass.BASS_PluginLoad( 'bassmidi.dll', 0), '|MID|*.mid') else: print 'pybassmidi module not accessible' self.volume_slider = wx.Slider(self, wx.ID_ANY, pybass.BASS_GetVolume() * 100, 0, 100) self.Bind(wx.EVT_SCROLL, self.event_volume_slider, self.volume_slider) sizer_h.Add(self.volume_slider, 0, wx.EXPAND) self.method_check_controls()
else: bass_tta_module = ctypes.CDLL('libbass_tta.so', mode=ctypes.RTLD_GLOBAL) func_type = ctypes.CFUNCTYPE # BASS_CHANNELINFO type BASS_CTYPE_STREAM_TTA = 0x10f00 #HSTREAM BASSTTADEF(BASS_TTA_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags); BASS_TTA_StreamCreateFile = func_type(HSTREAM, ctypes.c_byte, ctypes.c_void_p, QWORD, QWORD, ctypes.c_ulong)( ('BASS_TTA_StreamCreateFile', bass_tta_module)) #HSTREAM BASSTTADEF(BASS_TTA_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *procs, void *user); BASS_TTA_StreamCreateFileUser = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_FILEPROCS), ctypes.c_void_p)( ('BASS_TTA_StreamCreateFileUser', bass_tta_module)) if __name__ == "__main__": if not pybass.BASS_Init(-1, 44100, 0, 0, 0): print(('BASS_Init error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))) else: handle = BASS_TTA_StreamCreateFile(False, b'test.tta', 0, 0, 0) pybass.play_handle(handle) if not pybass.BASS_Free(): print(('BASS_Free error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode())))
BASS_TAG_MP4 = 7 BASS_CTYPE_STREAM_ALAC = 0x10e00 #HSTREAM BASSALACDEF(BASS_ALAC_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags); BASS_ALAC_StreamCreateFile = func_type(HSTREAM, ctypes.c_byte, ctypes.c_void_p, QWORD, QWORD, ctypes.c_ulong)( ('BASS_ALAC_StreamCreateFile', bass_alac_module)) #HSTREAM BASSALACDEF(BASS_ALAC_StreamCreateURL)(const char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user); BASS_ALAC_StreamCreateURL = func_type(HSTREAM, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_ulong, DOWNLOADPROC, ctypes.c_void_p)( ('BASS_ALAC_StreamCreateURL', bass_alac_module)) #HSTREAM BASSALACDEF(BASS_ALAC_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *procs, void *user); BASS_ALAC_StreamCreateFileUser = func_type( HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_FILEPROCS), ctypes.c_void_p)(('BASS_ALAC_StreamCreateFileUser', bass_alac_module)) if __name__ == "__main__": if not pybass.BASS_Init(-1, 44100, 0, 0, 0): print 'BASS_Init error', pybass.get_error_description( pybass.BASS_ErrorGetCode()) else: handle = BASS_ALAC_StreamCreateFile(False, 'test.alac', 0, 0, 0) pybass.play_handle(handle) if not pybass.BASS_Free(): print 'BASS_Free error', pybass.get_error_description( pybass.BASS_ErrorGetCode())
bass_mpc_module = ctypes.WinDLL('bass_mpc') func_type = ctypes.WINFUNCTYPE else: bass_mpc_module = ctypes.CDLL('bass_mpc') func_type = ctypes.CFUNCTYPE # Additional tags available from BASS_StreamGetTags BASS_TAG_APE = 6# APE tags # BASS_CHANNELINFO type BASS_CTYPE_STREAM_MPC = 0x10a00 #HSTREAM BASSMPCDEF(BASS_MPC_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags); BASS_MPC_StreamCreateFile = func_type(HSTREAM, ctypes.c_byte, ctypes.c_void_p, QWORD, QWORD, ctypes.c_ulong)(('BASS_MPC_StreamCreateFile', bass_mpc_module)) #HSTREAM BASSMPCDEF(BASS_MPC_StreamCreateURL)(const char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user); BASS_MPC_StreamCreateURL = func_type(HSTREAM, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_ulong, DOWNLOADPROC, ctypes.c_void_p)(('BASS_MPC_StreamCreateURL', bass_mpc_module)) #HSTREAM BASSMPCDEF(BASS_MPC_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *proc, void *user); BASS_MPC_StreamCreateFileUser = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_FILEPROCS), ctypes.c_void_p)(('BASS_MPC_StreamCreateFileUser', bass_mpc_module)) if __name__ == "__main__": if not pybass.BASS_Init(-1, 44100, 0, 0, 0): print('BASS_Init error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode())) else: handle = BASS_MPC_StreamCreateFile(False, b'test.mpc', 0, 0, 0) pybass.play_handle(handle) if not pybass.BASS_Free(): print('BASS_Free error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
def method_set_position(self, value): if not pybass.BASS_ChannelSetPosition(self.bass_handle, value, pybass.BASS_POS_BYTE): print('BASS_ChannelSetPosition error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))