Beispiel #1
0
 def add_ui(self, plugin, shell):
     self.drcDlg = DRCDlg(self)
     print("starting add_ui")
     action_group = ActionGroup(shell, 'DRCActionGroup')
     action_group.add_action(func=self.drcDlg.show_ui,
                             action_name='DRC', label=('_DRC'),
                             action_type='app')
     self._appshell = ApplicationShell(shell)
     self._appshell.insert_action_group(action_group)
     self._appshell.add_app_menuitems(ui_string, 'DRCActionGroup')
     print("add_ui done")
Beispiel #2
0
 def add_ui(self, plugin, shell):
     self.drcDlg = DRCDlg(self)
     print("starting add_ui")
     action_group = ActionGroup(shell, 'DRCActionGroup')
     action_group.add_action(func=self.drcDlg.show_ui,
                             action_name='DRC', label=('_DRC'),
                             action_type='app')
     self._appshell = ApplicationShell(shell)
     self._appshell.insert_action_group(action_group)
     self._appshell.add_app_menuitems(ui_string, 'DRCActionGroup')
     print("add_ui done")
Beispiel #3
0
class DRCPlugin(GObject.Object, Peas.Activatable):
    object = GObject.property(type=GObject.Object)

    def __init__(self):
        super(DRCPlugin, self).__init__()

    def set_kernel(self, filter_array):
        hasMultiKernel = True
        try:
            self.fir_filter.set_property('multi-channel-kernel', filter_array)
        except Exception as inst:
            print((
                'setting multi chanel filter: attempting to set single kernel',
                sys.exc_info()[0], type(inst), inst))
            hasMultiKernel = False
            self.fir_filter.set_property('kernel', filter_array[0])
            pass
        print("kernel set")
        return hasMultiKernel

    def updateFilter(self, filterFileName=None):
        aCfg = DRCConfig()
        if filterFileName is None:
            filterFileName = aCfg.filterFile
        if aCfg.FIRFilterMode == 1:
            #gstFIR
            self.set_filter()
            hasMultiKernel = False
            try:
                source = self.shell_player.get_playing_source()
                self.shell_player.pause()
                audioParams = DRCFileTool.LoadAudioFile(filterFileName,
                                                         aCfg.numFilterChanels)
                filter_array = audioParams.data
                # pass the filter data to the fir filter
                num_filter_coeff = len(filter_array)
                if num_filter_coeff > 0:
                    hasMultiKernel = self.set_kernel(filter_array)
                self.set_filter()
                if self.entry is not None:
                    self.shell_player.play_entry(self.entry, source)
            except Exception as inst:
                print(('error updating filter', sys.exc_info()[0], type(inst),
                    inst))
                pass
            return hasMultiKernel
        elif aCfg.FIRFilterMode == 1:
            #bruteFIF
            self.remove_Filter()
        else:
            #None : disable all filtering
            self.remove_Filter()
        return True

    def do_activate(self):
        try:
            self.duration = 0
            self.entry = None
            self.selfAllowTriggered = False
            self.filterSet = False
            self.shell = self.object
            self.shell_player = self.shell.props.shell_player
            self.player = self.shell_player.props.player
            self.fir_filter = Gst.ElementFactory.make('audiofirfilter',
                                                      'MyFIRFilter')
            # open filter files
            self.hasMultiKernel = self.updateFilter()
            # print( str(dir( self.shell.props)) )
        except Exception as inst:
            print('filter not set', sys.exc_info()[0], type(inst), inst)
            pass
        self.psc_id = self.shell_player.connect('playing-song-changed',
                                                self.playing_song_changed)
        # no possible workaround as somehow never reaches end of song :(
        self.shell_player.connect('elapsed-changed', self.elapsed_changed)
        # finally add UI
        self.add_ui(self, self.shell)

    def add_ui(self, plugin, shell):
        self.drcDlg = DRCDlg(self)
        print("starting add_ui")
        action_group = ActionGroup(shell, 'DRCActionGroup')
        action_group.add_action(func=self.drcDlg.show_ui,
                                action_name='DRC', label=('_DRC'),
                                action_type='app')
        self._appshell = ApplicationShell(shell)
        self._appshell.insert_action_group(action_group)
        self._appshell.add_app_menuitems(ui_string, 'DRCActionGroup')
        print("add_ui done")

    def set_filter(self):
        try:
            if not self.filterSet:
                print('adding filter')
                self.player.add_filter(self.fir_filter)
                print('done setting filter')
            self.filterSet = True
        except Exception as inst:
            print('unexpected exception', sys.exc_info()[0], type(inst), inst)
            pass

    def remove_Filter(self):
        try:
            if self.filterSet:
                self.player.remove_filter(self.fir_filter)
                print('filter disabled')
            self.filterSet = False
        except:
            pass

    def do_deactivate(self):
        print('entering do_deactivate')
        self.shell_player.disconnect(self.psc_id)

        try:
            self.remove_Filter()
            self._appshell.cleanup()
        except:
            pass

        del self.shell_player
        del self.shell
        del self.fir_filter

    def elapsed_changed(self, sp, elapsed):
        # workaround due to FIR filter issues during playing back multiple
        # songs
        # switching as well as new song select in UI seems to fix that
        # print("elapsed : " + str(elapsed) )
        diff = self.duration - elapsed
        # print("diff : " + str(diff))
        # allowing self triggered skip forth and back after last 15 seconds
        # to bad that diff is unreliable.. no idea why 0 never marks the
        # real end
        if self.duration < 1:
            return
        if diff <= 15 and diff > -1:
            print("end of song reached : allow triggering")
            self.selfAllowTriggered = True
            self.duration = 0
        else:
            self.selfAllowTriggered = False

    def playing_song_changed(self, sp, entry):
        self.duration = sp.get_playing_song_duration()
        self.entry = entry
        # print("playing song duration: " + str(self.duration))
        if entry is None or not self.selfAllowTriggered:
            return
        # workaround due to FIR filter issues during playing back multiple
        # songs
        # switching as well as new song select in UI seems to fix that
        '''TODO: this will fail for manually selecting last song in list in UI
            clean way would be to check has-prev/has-next but seems to be
            useless:
            returns true even if no son is previous in current UI list...
        '''
        source = sp.get_playing_source()
        sp.stop()
        sp.play_entry(entry, source)
        self.selfAllowTriggered = False

    def find_file(self, filename):
        info = self.plugin_info
        data_dir = info.get_data_dir()
        path = os.path.join(data_dir, filename)

        if os.path.exists(path):
            return path

        return RB.file(filename)
Beispiel #4
0
class DRCPlugin(GObject.Object, Peas.Activatable):
    object = GObject.property(type=GObject.Object)

    def __init__(self):
        super(DRCPlugin, self).__init__()

    def set_kernel(self, filter_array):
        hasMultiKernel = True
        try:
            self.fir_filter.set_property('multi-channel-kernel', filter_array)
        except Exception as inst:
            print((
                'setting multi chanel filter: attempting to set single kernel',
                sys.exc_info()[0], type(inst), inst))
            hasMultiKernel = False
            self.fir_filter.set_property('kernel', filter_array[0])
            pass
        print("kernel set")
        return hasMultiKernel

    def updateFilter(self, filterFileName=None):
        aCfg = DRCConfig()
        if filterFileName is None:
            filterFileName = aCfg.filterFile
        if aCfg.FIRFilterMode == 1:
            #gstFIR
            self.set_filter()
            hasMultiKernel = False
            try:
                source = self.shell_player.get_playing_source()
                self.shell_player.pause()
                #in case of a multichannel kernel with > 2 channels only
                #the first 2 channels shall be used for gstreamer filtering
                #as gstreamer FIR only supports at maximum 2 channels
                audioParams = DRCFileTool.LoadAudioFileStereoChannels(
                    filterFileName, aCfg.numFilterChanels, 2)
                filter_array = audioParams.data
                # pass the filter data to the fir filter
                num_filter_coeff = len(filter_array)
                if num_filter_coeff > 0:
                    hasMultiKernel = self.set_kernel(filter_array)
                self.set_filter()
                if self.entry is not None:
                    self.shell_player.play_entry(self.entry, source)
            except Exception as inst:
                print(('error updating filter', sys.exc_info()[0], type(inst),
                    inst))
                pass
            return hasMultiKernel
        elif aCfg.FIRFilterMode == 2:
            #bruteFIF
            #nothing ToDO
            self.remove_Filter()
        else:
            #None : disable all filtering
            self.remove_Filter()
        return True

    def do_activate(self):
        try:
            self.duration = 0
            self.entry = None
            self.selfAllowTriggered = False
            self.filterSet = False
            self.shell = self.object
            self.shell_player = self.shell.props.shell_player
            self.player = self.shell_player.props.player
            self.fir_filter = Gst.ElementFactory.make('audiofirfilter',
                                                      'MyFIRFilter')
            # open filter files
            self.hasMultiKernel = self.updateFilter()
            # print( str(dir( self.shell.props)) )
        except Exception as inst:
            print(('filter not set', sys.exc_info()[0], type(inst), inst))
            pass
        aCfg = DRCConfig()
        if aCfg.FIRFilterMode == 1:
            #only for gst-FIR filter the skip-workaround is needed
            self.psc_id = self.shell_player.connect('playing-song-changed',
                self.playing_song_changed)
            # no possible workaround as somehow never reaches end of song :(
            self.shell_player.connect('elapsed-changed', self.elapsed_changed)
        # finally add UI
        self.add_ui(self, self.shell)

    def add_ui(self, plugin, shell):
        self.drcDlg = DRCDlg(self)
        print("starting add_ui")
        action_group = ActionGroup(shell, 'DRCActionGroup')
        action_group.add_action(func=self.drcDlg.show_ui,
                                action_name='DRC', label=('_DRC'),
                                action_type='app')
        self._appshell = ApplicationShell(shell)
        self._appshell.insert_action_group(action_group)
        self._appshell.add_app_menuitems(ui_string, 'DRCActionGroup')
        print("add_ui done")

    def set_filter(self):
        try:
            if not self.filterSet:
                print('adding filter')
                self.player.add_filter(self.fir_filter)
                print('done setting filter')
            self.filterSet = True
        except Exception as inst:
            print(('unexpected exception', sys.exc_info()[0], type(inst), inst))
            pass

    def remove_Filter(self):
        try:
            if self.filterSet:
                self.player.remove_filter(self.fir_filter)
                print('filter disabled')
            self.filterSet = False
        except:
            pass

    def do_deactivate(self):
        print('entering do_deactivate')
        self.shell_player.disconnect(self.psc_id)

        try:
            self.remove_Filter()
            self._appshell.cleanup()
        except:
            pass

        del self.shell_player
        del self.shell
        del self.fir_filter

    def elapsed_changed(self, sp, elapsed):
        # workaround due to FIR filter issues during playing back multiple
        # songs
        # switching as well as new song select in UI seems to fix that
        # print("elapsed : " + str(elapsed) )
        diff = self.duration - elapsed
        # print("diff : " + str(diff))
        # allowing self triggered skip forth and back after last 15 seconds
        # to bad that diff is unreliable.. no idea why 0 never marks the
        # real end
        if self.duration < 1:
            return
        if diff <= 15 and diff > -1:
            print("end of song reached : allow triggering")
            self.selfAllowTriggered = True
            self.duration = 0
        else:
            self.selfAllowTriggered = False

    def change_song_timer(self, sp, entry):
        print("timer elapsed - perform start/play")
        source = sp.get_playing_source()
        sp.stop()
        sp.play_entry(entry, source)
        self.selfAllowTriggered = False

    def playing_song_changed(self, sp, entry):
        self.duration = sp.get_playing_song_duration()
        # print("playing song duration: " + str(self.duration))
        if entry is None or not self.selfAllowTriggered:
            return
        # workaround due to FIR filter issues during playing back multiple
        # songs
        # switching as well as new song select in UI seems to fix that
        '''TODO: this will fail for manually selecting last song in list in UI
            clean way would be to check has-prev/has-next but seems to be
            useless:
            returns true even if no son is previous in current UI list...
        '''
        t = Timer(1.5, self.change_song_timer, args=[sp,entry])
        t.start()
        print("timer done")

    def find_file(self, filename):
        info = self.plugin_info
        data_dir = info.get_data_dir()
        path = os.path.join(data_dir, filename)

        if os.path.exists(path):
            return path

        return RB.file(filename)