Exemplo n.º 1
0
    def method_load_wav_file(self):
        import os
        wildcard = 'wav (*.wav)|*.wav|All files (*.*)|*.*'
        dlg = wx.FileDialog(self,
                            message=_('Choose a file'),
                            defaultDir=os.getcwd(),
                            defaultFile='',
                            wildcard=wildcard,
                            style=wx.OPEN | wx.CHANGE_DIR)
        if dlg.ShowModal() == wx.ID_OK:
            self.name_stream = file_name = dlg.GetPath()
            if os.path.isfile(file_name):
                flags = 0
                if isinstance(file_name, unicode):
                    flags |= pybass.BASS_UNICODE
                    try:
                        pybass.BASS_CHANNELINFO._fields_.remove(
                            ('filename', pybass.ctypes.c_char_p))
                    except Exception:
                        pass
                    else:
                        pybass.BASS_CHANNELINFO._fields_.append(
                            ('filename', pybass.ctypes.c_wchar_p))

                def stream_callback(handle, 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)
                    if self.stream.is_eof():
                        length |= pybass.BASS_STREAMPROC_END
                        self.stream.current_position = 0
                    return length

                self.stream_callback = stream_callback
                self.user_func = pybass.STREAMPROC(self.stream_callback)
                self.stream = memory_stream(
                    open(file_name, 'rb').read(), file_name)
                new_bass_handle = pybass.BASS_StreamCreate(
                    44100, 2, flags, self.user_func, 0)
                if new_bass_handle == 0:
                    print(
                        'BASS_StreamCreate error',
                        pybass.get_error_description(
                            pybass.BASS_ErrorGetCode()))
                else:
                    self.method_stop_audio()
                    self.bass_handle = new_bass_handle
                    self.stream = None
                    self.method_slider_set_range()
                    self.method_check_controls()
Exemplo n.º 2
0
 def method_load_file(self):
     import os
     wildcard = 'music sounds (MO3, IT, XM, S3M, MTM, MOD, UMX)|*.mo3;*.it;*.xm;*.s3m;*.mtm;*.mod;*.umx'
     wildcard += '|stream sounds (MP3, MP2, MP1, OGG, WAV, AIFF)|*.mp3;*.mp2;*.mp1;*.ogg;*.wav;*.aiff'
     for plugin in self.plugins.itervalues():
         if plugin[0] > 0:
             wildcard += plugin[1]
     wildcard += '|All files (*.*)|*.*'
     dlg = wx.FileDialog(self,
                         message=_('Choose a file'),
                         defaultDir=os.getcwd(),
                         defaultFile='',
                         wildcard=wildcard,
                         style=wx.OPEN | wx.CHANGE_DIR)
     if dlg.ShowModal() == wx.ID_OK:
         self.name_stream = file_name = dlg.GetPath()
         if os.path.isfile(file_name):
             flags = 0
             if isinstance(file_name, unicode):
                 flags |= pybass.BASS_UNICODE
                 try:
                     pybass.BASS_CHANNELINFO._fields_.remove(
                         ('filename', pybass.ctypes.c_char_p))
                 except Exception:
                     pass
                 else:
                     pybass.BASS_CHANNELINFO._fields_.append(
                         ('filename', pybass.ctypes.c_wchar_p))
             error_msg = 'BASS_StreamCreateFile error'
             new_bass_handle = 0
             if dlg.GetFilterIndex() == 0:  # BASS_CTYPE_MUSIC_MOD
                 flags |= pybass.BASS_MUSIC_PRESCAN
                 new_bass_handle = pybass.BASS_MusicLoad(
                     False, file_name, 0, 0, flags, 0)
                 error_msg = 'BASS_MusicLoad error'
             else:  # other sound types
                 new_bass_handle = pybass.BASS_StreamCreateFile(
                     False, file_name, 0, 0, flags)
             if new_bass_handle == 0:
                 print(
                     error_msg,
                     pybass.get_error_description(
                         pybass.BASS_ErrorGetCode()))
             else:
                 self.method_stop_audio()
                 self.bass_handle = new_bass_handle
                 self.stream = None
                 self.method_slider_set_range()
                 self.method_check_controls()