-
Notifications
You must be signed in to change notification settings - Fork 20
/
jalv_lv2_handler.py
103 lines (81 loc) · 3.2 KB
/
jalv_lv2_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
#********************************************************************
# ZYNTHIAN PROJECT: Zynthian Web Configurator
#
# Jalv LV2 Plugins Manager Handler
#
# Copyright (C) 2018 Markus Heidt <markus@heidt-tech.com>
#
#********************************************************************
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For a full copy of the GNU General Public License see the LICENSE.txt file.
#
#********************************************************************
import logging
import tornado.web
from collections import OrderedDict
from lib.zynthian_config_handler import ZynthianBasicHandler
import zyngine.zynthian_lv2 as zynthian_lv2
#------------------------------------------------------------------------------
# Jalv LV2 Configuration
#------------------------------------------------------------------------------
class JalvLv2Handler(ZynthianBasicHandler):
@tornado.web.authenticated
def get(self, errors=None):
config=OrderedDict([])
config['ZYNTHIAN_JALV_PLUGINS'] = zynthian_lv2.plugins_by_type
try:
config['ZYNTHIAN_ACTIVE_TAB'] = self.get_argument('ZYNTHIAN_ACTIVE_TAB')
except:
pass
if not 'ZYNTHIAN_ACTIVE_TAB' in config or len(config['ZYNTHIAN_ACTIVE_TAB']) == 0:
config['ZYNTHIAN_ACTIVE_TAB'] = zynthian_lv2.PluginType.MIDI_SYNTH.value.replace(" ", "_")
try:
config['ZYNTHIAN_JALV_FILTER'] = self.get_argument('ZYNTHIAN_JALV_FILTER')
except:
config['ZYNTHIAN_JALV_FILTER'] = ''
if errors:
logging.error("Configuring JALV LV2-Plugins failed: {}".format(errors))
self.clear()
self.set_status(400)
self.finish("Configuring JALV LV2-Plugins failed: {}".format(errors))
else:
super().get("jalv_lv2.html", "LV2-Plugins", config, errors)
@tornado.web.authenticated
def post(self):
action = self.get_argument('ZYNTHIAN_JALV_ACTION')
if action:
errors = {
'ENABLE_PLUGINS': lambda: self.do_enable_plugins(),
'REGENERATE_PLUGIN_LIST': lambda: self.do_regenerate_lv2_cache()
}[action]()
self.get(errors)
def do_enable_plugins(self):
try:
postedPlugins = tornado.escape.recursive_unicode(self.request.arguments)
for name, properties in zynthian_lv2.plugins.items():
if "ZYNTHIAN_JALV_ENABLE_{}".format(name) in postedPlugins:
zynthian_lv2.plugins[name]['ENABLED'] = True
else:
zynthian_lv2.plugins[name]['ENABLED'] = False
zynthian_lv2.save_plugins()
except Exception as e:
logging.error("Enabling jalv plugins failed: {}".format(e))
return format(e)
def do_regenerate_lv2_cache(self):
zynthian_lv2.generate_plugins_config_file()
zynthian_lv2.get_plugins_by_type()
zynthian_lv2.generate_all_presets_cache(False)
self.restart_ui_flag = True
self.restart_webconf_flag = True
#------------------------------------------------------------------------------