コード例 #1
0
ファイル: zynthian_gui.py プロジェクト: zynthian/zynthian-ui
	def reload_midi_config(self):
		zynconf.load_config()
		midi_profile_fpath=zynconf.get_midi_config_fpath()
		if midi_profile_fpath:
			zynconf.load_config(True,midi_profile_fpath)
			zynthian_gui_config.set_midi_config()
			self.init_midi()
コード例 #2
0
	def reload_midi_config(self):
		zynconf.load_config()
		midi_profile_fpath=zynconf.get_midi_config_fpath()
		if midi_profile_fpath:
			zynconf.load_config(True,midi_profile_fpath)
			zynthian_gui_config.set_midi_config()
			self.init_midi()
			self.init_midi_services()
			self.zynautoconnect(True)
コード例 #3
0
    def post(self):
        self.request.arguments[
            'ZYNTHIAN_MIDI_FILTER_OUTPUT'] = self.request.arguments.get(
                'ZYNTHIAN_MIDI_FILTER_OUTPUT', '0')
        self.request.arguments[
            'ZYNTHIAN_MIDI_SYS_ENABLED'] = self.request.arguments.get(
                'ZYNTHIAN_MIDI_SYS_ENABLED', '0')
        self.request.arguments[
            'ZYNTHIAN_MIDI_PRESET_PRELOAD_NOTEON'] = self.request.arguments.get(
                'ZYNTHIAN_MIDI_PRESET_PRELOAD_NOTEON', '0')
        self.request.arguments[
            'ZYNTHIAN_MIDI_SINGLE_ACTIVE_CHANNEL'] = self.request.arguments.get(
                'ZYNTHIAN_MIDI_SINGLE_ACTIVE_CHANNEL', '0')
        self.request.arguments[
            'ZYNTHIAN_MIDI_PROG_CHANGE_ZS3'] = self.request.arguments.get(
                'ZYNTHIAN_MIDI_PROG_CHANGE_ZS3', '0')
        self.request.arguments[
            'ZYNTHIAN_MIDI_RTPMIDI_ENABLED'] = self.request.arguments.get(
                'ZYNTHIAN_MIDI_RTPMIDI_ENABLED', '0')
        self.request.arguments[
            'ZYNTHIAN_MIDI_NETWORK_ENABLED'] = self.request.arguments.get(
                'ZYNTHIAN_MIDI_NETWORK_ENABLED', '0')
        self.request.arguments[
            'ZYNTHIAN_MIDI_TOUCHOSC_ENABLED'] = self.request.arguments.get(
                'ZYNTHIAN_MIDI_TOUCHOSC_ENABLED', '0')
        self.request.arguments[
            'ZYNTHIAN_MIDI_AUBIONOTES_ENABLED'] = self.request.arguments.get(
                'ZYNTHIAN_MIDI_AUBIONOTES_ENABLED', '0')

        escaped_request_arguments = tornado.escape.recursive_unicode(
            self.request.arguments)

        errors = {}

        try:
            freq = float(
                self.request.arguments.get('ZYNTHIAN_MIDI_FINE_TUNING',
                                           '440.0')[0])
            if freq < 392.0 or freq > 493.88:
                errors[
                    'ZYNTHIAN_MIDI_FINE_TUNING'] = "Frequency must be in the range 392.00 - 493.88 Hz!"
        except:
            self.request.arguments['ZYNTHIAN_MIDI_FINE_TUNING'] = 440.0
            errors['ZYNTHIAN_MIDI_FINE_TUNING'] = "Frequency must be a number!"

        filter_error = self.validate_filter_rules(escaped_request_arguments)
        if filter_error:
            errors['ZYNTHIAN_MIDI_FILTER_RULES'] = filter_error

        if not errors:
            # remove fields that start with FILTER_ADD from request_args, so that they won't be passed to update_config
            for filter_add_argument in list(escaped_request_arguments.keys()):
                if filter_add_argument.startswith('FILTER_ADD'):
                    del escaped_request_arguments[filter_add_argument]

            new_profile_script_name = self.get_argument(
                'zynthian_midi_profile_new_script_name')

            if new_profile_script_name:
                #New MIDI profile
                self.current_midi_profile_script = self.PROFILES_DIRECTORY + '/' + new_profile_script_name + '.sh'
                try:
                    #create file as copy of default:
                    zynconf.get_midi_config_fpath(
                        self.current_midi_profile_script)
                    zynconf.update_midi_profile(
                        escaped_request_arguments,
                        self.current_midi_profile_script)
                    mode = os.stat(self.current_midi_profile_script).st_mode
                    mode |= (mode & 0o444) >> 2  # copy R bits to X
                    os.chmod(self.current_midi_profile_script, mode)
                    errors = zynconf.save_config({
                        'ZYNTHIAN_SCRIPT_MIDI_PROFILE':
                        self.current_midi_profile_script
                    })
                    self.load_midi_profile_directories()
                except:
                    errors[
                        'zynthian_midi_profile_new_script_name'] = "Can't create new profile!"

            elif 'zynthian_midi_profile_delete_script' in self.request.arguments and self.get_argument(
                    'zynthian_midi_profile_delete_script') == "1":
                #DELETE
                if self.current_midi_profile_script.startswith(
                        self.PROFILES_DIRECTORY):
                    os.remove(self.current_midi_profile_script)
                    self.current_midi_profile_script = "{}/default.sh".format(
                        self.PROFILES_DIRECTORY)
                    errors = zynconf.save_config({
                        'ZYNTHIAN_SCRIPT_MIDI_PROFILE':
                        self.current_midi_profile_script
                    })
                    self.load_midi_profile_directories()
                else:
                    errors[
                        'zynthian_midi_profile_delete_script'] = 'You can only delete user profiles!'

            else:
                #SAVE
                if self.current_midi_profile_script:
                    updateParameters = []
                    for parameter in escaped_request_arguments:
                        if not parameter.startswith('ZYNTHIAN_'):
                            updateParameters.append(parameter)

                    for k in updateParameters:
                        del escaped_request_arguments[k]

                    zynconf.update_midi_profile(
                        escaped_request_arguments,
                        self.current_midi_profile_script)
                    errors = self.update_config(escaped_request_arguments)
                else:
                    errors[
                        'zynthian_midi_profile_new_script_name'] = 'No profile name!'

            self.reload_midi_config_flag = True

        self.get(errors)
コード例 #4
0
    def post(self):
        self.request.arguments[
            'ZYNTHIAN_MIDI_PRESET_PRELOAD_NOTEON'] = self.request.arguments.get(
                'ZYNTHIAN_MIDI_PRESET_PRELOAD_NOTEON', '0')
        self.request.arguments[
            'ZYNTHIAN_MIDI_SINGLE_ACTIVE_CHANNEL'] = self.request.arguments.get(
                'ZYNTHIAN_MIDI_SINGLE_ACTIVE_CHANNEL', '0')
        self.request.arguments[
            'ZYNTHIAN_MIDI_PROG_CHANGE_ZS3'] = self.request.arguments.get(
                'ZYNTHIAN_MIDI_PROG_CHANGE_ZS3', '0')
        self.request.arguments[
            'ZYNTHIAN_MIDI_NETWORK_ENABLED'] = self.request.arguments.get(
                'ZYNTHIAN_MIDI_NETWORK_ENABLED', '0')

        escaped_request_arguments = tornado.escape.recursive_unicode(
            self.request.arguments)

        filter_error = self.validate_filter_rules(escaped_request_arguments)
        errors = {}
        if not filter_error:
            # remove fields that start with FILTER_ADD from request_args, so that they won't be passed to update_config
            for filter_add_argument in list(escaped_request_arguments.keys()):
                if filter_add_argument.startswith('FILTER_ADD'):
                    del escaped_request_arguments[filter_add_argument]

            new_profile_script_name = self.get_argument(
                'zynthian_midi_profile_new_script_name')

            if new_profile_script_name:
                #New MIDI profile
                new_profile_script_path = self.PROFILES_DIRECTORY + '/' + new_profile_script_name + '.sh'
                #create file as copy of default:
                zynconf.get_midi_config_fpath(new_profile_script_path)
                zynconf.update_midi_profile(escaped_request_arguments,
                                            new_profile_script_path)
                mode = os.stat(new_profile_script_path).st_mode
                mode |= (mode & 0o444) >> 2  # copy R bits to X
                os.chmod(new_profile_script_path, mode)
                self.load_midi_profile_directories()

            elif 'zynthian_midi_profile_delete_script' in self.request.arguments and self.get_argument(
                    'zynthian_midi_profile_delete_script') == "1":
                #DELETE
                if self.current_midi_profile_script.startswith(
                        self.PROFILES_DIRECTORY):
                    os.remove(self.current_midi_profile_script)
                    self.current_midi_profile_script = None
                else:
                    errors[
                        'zynthian_midi_profile_delete_script'] = 'You can only delete user profiles!'

            else:
                #SAVE
                if self.current_midi_profile_script:
                    updateParameters = []
                    for parameter in escaped_request_arguments:
                        if not parameter.startswith('ZYNTHIAN_'):
                            updateParameters.append(parameter)

                    for k in updateParameters:
                        del escaped_request_arguments[k]

                    zynconf.update_midi_profile(
                        escaped_request_arguments,
                        self.current_midi_profile_script)
                    errors = self.update_config(escaped_request_arguments)
                else:
                    errors[
                        'zynthian_midi_profile_new_script_name'] = 'Profile name missing'

            #self.restart_ui()
            self.reload_midi_config()

        else:
            errors = {
                'ZYNTHIAN_MIDI_FILTER_RULES': filter_error
            }

        self.get(errors)