Beispiel #1
0
 def __init__(self, beq_dir, user_source_dir, output_dir, config_file,
              dsp_type, failure_handler, success_handler, complete_handler,
              optimise_handler, optimise_filters, selected_channels,
              in_out_split):
     super().__init__()
     self.__optimise_filters = optimise_filters
     self.__beq_dir = beq_dir
     self.__user_source_dir = user_source_dir
     self.__output_dir = output_dir
     self.__config_file = config_file
     self.__dsp_type = dsp_type
     if DspType.MONOPRICE_HTP1 == self.__dsp_type:
         self.__parser = HTP1Parser(selected_channels)
     elif DspType.JRIVER_PEQ1 == self.__dsp_type:
         from model.jriver.parser import JRiverParser
         self.__parser = JRiverParser(0, selected_channels)
     elif DspType.JRIVER_PEQ2 == self.__dsp_type:
         from model.jriver.parser import JRiverParser
         self.__parser = JRiverParser(1, selected_channels)
     elif DspType.MINIDSP_TWO_BY_FOUR == self.__dsp_type:
         self.__parser = TwoByFourXmlParser(self.__dsp_type,
                                            self.__optimise_filters)
     else:
         self.__parser = HDXmlParser(self.__dsp_type,
                                     self.__optimise_filters,
                                     selected_channels=selected_channels,
                                     in_out_split=in_out_split)
     self.__signals = ProcessSignals()
     self.__signals.on_failure.connect(failure_handler)
     self.__signals.on_success.connect(success_handler)
     self.__signals.on_complete.connect(complete_handler)
     self.__signals.on_optimised.connect(optimise_handler)
Beispiel #2
0
def test_merge_2x4hd_output_with_split():
    dsp_type = DspType.MINIDSP_TWO_BY_FOUR_HD
    parser = HDXmlParser(dsp_type, False, in_out_split=['4', '6'])
    filt = xml_to_filt(os.path.join(os.path.dirname(__file__), 'input.xml'))
    with open(os.path.join(os.path.dirname(__file__), 'MiniDSP-2x4HD-setting.xml'), 'r') as f1:
        with open(os.path.join(os.path.dirname(__file__), 'expected_output_2x4HD_split.xml'), 'r') as f2:
            convert_and_compare(f1, f2, filt, parser)
Beispiel #3
0
def test_merge_2x4hd_output_with_output():
    dsp_type = DspType.MINIDSP_TWO_BY_FOUR_HD
    parser = HDXmlParser(dsp_type, False, selected_channels=[str(i) for i in range(1, 7)])
    filt = xml_to_filt(os.path.join(os.path.dirname(__file__), 'input.xml'))
    with open(os.path.join(os.path.dirname(__file__), 'MiniDSP-2x4HD-setting.xml'), 'r') as f1:
        with open(os.path.join(os.path.dirname(__file__), 'expected_output_2x4HD_output.xml'), 'r') as f2:
            convert_and_compare(f1, f2, filt, parser)
Beispiel #4
0
 def generate_avs_post(self):
     '''
     Creates the output content.
     '''
     metadata = self.__build_metadata()
     save_name = self.__get_file_name(metadata)
     file_name = QFileDialog(self).getSaveFileName(self,
                                                   'Export BEQ Filter',
                                                   f'{save_name}.xml',
                                                   'XML (*.xml)')
     if file_name:
         file_name = str(file_name[0]).strip()
         if len(file_name) > 0:
             if getattr(sys, 'frozen', False):
                 file_path = os.path.join(sys._MEIPASS, 'flat24hd.xml')
             else:
                 file_path = os.path.abspath(
                     os.path.join(os.path.dirname('__file__'),
                                  '../xml/flat24hd.xml'))
             filt = self.__filter_model.filter
             output_xml, _ = HDXmlParser(DspType.MINIDSP_TWO_BY_FOUR_HD,
                                         False).convert(
                                             str(file_path), filt, metadata)
             with open(file_name, 'w+') as f:
                 f.write(output_xml)
Beispiel #5
0
 def generate_avs_post(self):
     '''
     Creates the output content.
     '''
     metadata = self.__build_metadata()
     save_name = self.__get_file_name(metadata)
     file_name = QFileDialog(self).getSaveFileName(self,
                                                   'Export BEQ Filter',
                                                   f'{save_name}.xml',
                                                   'XML (*.xml)')
     if file_name:
         file_name = str(file_name[0]).strip()
         if len(file_name) > 0:
             if getattr(sys, 'frozen', False):
                 file_path = os.path.join(sys._MEIPASS, 'flat24hd.xml')
             else:
                 file_path = os.path.abspath(
                     os.path.join(os.path.dirname('__file__'),
                                  '../xml/flat24hd.xml'))
             filters = pad_with_passthrough(self.__filter_model.filter,
                                            96000, 10)
             output_xml = HDXmlParser('2x4 HD').overwrite(
                 filters, file_path, metadata)
             with open(file_name, 'w') as f:
                 f.write(output_xml)
Beispiel #6
0
def test_merge_2x4hd():
    from model.minidsp import xml_to_filt, HDXmlParser
    from model.merge import DspType
    dsp_type = DspType.MINIDSP_TWO_BY_FOUR_HD
    parser = HDXmlParser(dsp_type, False)
    filt = xml_to_filt(os.path.join(os.path.dirname(__file__), 'input.xml'))
    with open(
            os.path.join(os.path.dirname(__file__),
                         'MiniDSP-2x4HD-setting.xml'), 'r') as f1:
        with open(
                os.path.join(os.path.dirname(__file__),
                             'expected_output_2x4HD.xml'), 'r') as f2:
            convert_and_compare(f1, f2, filt, parser)
Beispiel #7
0
class XmlProcessor(QRunnable):
    '''
    Completes the batch conversion of config files in a separate thread.
    '''
    def __init__(self, beq_dir, user_source_dir, output_dir, config_file, dsp_type, failure_handler, success_handler,
                 complete_handler, optimise_handler, optimise_filters, selected_channels, in_out_split):
        super().__init__()
        self.__optimise_filters = optimise_filters
        self.__beq_dir = beq_dir
        self.__user_source_dir = user_source_dir
        self.__output_dir = output_dir
        self.__config_file = config_file
        self.__dsp_type = dsp_type
        if DspType.MONOPRICE_HTP1 == self.__dsp_type:
            self.__parser = HTP1Parser(selected_channels)
        elif DspType.MINIDSP_TWO_BY_FOUR == self.__dsp_type:
            self.__parser = TwoByFourXmlParser(self.__dsp_type, self.__optimise_filters)
        else:
            self.__parser = HDXmlParser(self.__dsp_type, self.__optimise_filters, selected_channels=selected_channels,
                                        in_out_split=in_out_split)
        self.__signals = ProcessSignals()
        self.__signals.on_failure.connect(failure_handler)
        self.__signals.on_success.connect(success_handler)
        self.__signals.on_complete.connect(complete_handler)
        self.__signals.on_optimised.connect(optimise_handler)

    def run(self):
        self.__process_dir(self.__beq_dir)
        self.__process_dir(self.__user_source_dir)
        self.__signals.on_complete.emit()

    def __process_dir(self, src_dir):
        if len(src_dir) > 0:
            beq_dir = Path(src_dir)
            base_parts_idx = len(beq_dir.parts)
            for xml in beq_dir.glob(f"**{os.sep}*.xml"):
                self.__process_file(base_parts_idx, xml)

    def __process_file(self, base_parts_idx, xml):
        '''
        Processes an individual file.
        :param base_parts_idx: the path index to start from.
        :param xml: the source xml.
        '''
        dir_parts = []
        try:
            dir_parts = xml.parts[base_parts_idx:-1]
            file_output_dir = os.path.join(self.__output_dir, *dir_parts)
            os.makedirs(file_output_dir, exist_ok=True)
            dst = Path(file_output_dir).joinpath(xml.name).with_suffix(self.__parser.file_extension())
            logger.info(f"Copying {self.__config_file} to {dst}")
            dst = shutil.copy2(self.__config_file, dst.resolve())
            filt = xml_to_filt(str(xml), fs=self.__dsp_type.target_fs)
            output_config, was_optimised = self.__parser.convert(str(dst), filt)
            with dst.open('w') as dst_file:
                dst_file.write(output_config)
            if was_optimised is False:
                self.__signals.on_success.emit()
            else:
                self.__signals.on_optimised.emit(' - '.join(dir_parts), xml.name)
        except Exception as e:
            logger.exception(f"Unexpected failure during processing of {xml}")
            self.__signals.on_failure.emit(' - '.join(dir_parts), xml.name, str(e))