summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-12-08 14:38:49 +0100
committerDavid Robillard <d@drobilla.net>2019-12-08 17:43:34 +0100
commit07821c99f75c574bff76cb6c7ceefa4f3d597140 (patch)
treee163bafe2f7e8012c0b98b0e4fa558c01f1905a2 /scripts
parent6cc39a1ae4b407cbb1a5174d2adadfd90d28dee7 (diff)
downloadingen-07821c99f75c574bff76cb6c7ceefa4f3d597140.tar.gz
ingen-07821c99f75c574bff76cb6c7ceefa4f3d597140.tar.bz2
ingen-07821c99f75c574bff76cb6c7ceefa4f3d597140.zip
Cleanup: Format Python code to be mostly flake8 clean
Diffstat (limited to 'scripts')
-rw-r--r--scripts/ingen.py122
-rwxr-xr-xscripts/ingenams45
-rwxr-xr-xscripts/ingenish14
3 files changed, 89 insertions, 92 deletions
diff --git a/scripts/ingen.py b/scripts/ingen.py
index 6f9b5ed5..d56d7e0b 100644
--- a/scripts/ingen.py
+++ b/scripts/ingen.py
@@ -25,6 +25,7 @@ try:
except ImportError:
from io import StringIO as StringIO
+
class NS:
atom = rdflib.Namespace('http://lv2plug.in/ns/ext/atom#')
ingen = rdflib.Namespace('http://drobilla.net/ns/ingen#')
@@ -35,6 +36,7 @@ class NS:
rsz = rdflib.Namespace('http://lv2plug.in/ns/ext/resize-port#')
xsd = rdflib.Namespace('http://www.w3.org/2001/XMLSchema#')
+
class Interface:
'The core Ingen interface'
def put(self, subject, body):
@@ -58,10 +60,12 @@ class Interface:
def delete(self, subject):
pass
+
class Error(Exception):
def __init__(self, msg, cause):
Exception.__init__(self, '%s; cause: %s' % (msg, cause))
+
def lv2_path():
path = os.getenv('LV2_PATH')
if path:
@@ -77,13 +81,14 @@ def lv2_path():
'/boot/common/add-ons/lv2'])
elif sys.platform == 'win32':
return os.pathsep.join([
- os.path.join(os.getenv('APPDATA'), 'LV2'),
- os.path.join(os.getenv('COMMONPROGRAMFILES'), 'LV2')])
+ os.path.join(os.getenv('APPDATA'), 'LV2'),
+ os.path.join(os.getenv('COMMONPROGRAMFILES'), 'LV2')])
else:
return os.pathsep.join(['~/.lv2',
'/usr/lib/lv2',
'/usr/local/lib/lv2'])
+
def ingen_bundle_path():
for d in lv2_path().split(os.pathsep):
bundle = os.path.abspath(os.path.join(d, 'ingen.lv2'))
@@ -91,6 +96,7 @@ def ingen_bundle_path():
return bundle
return None
+
class Remote(Interface):
def __init__(self, uri='unix:///tmp/ingen.sock'):
self.msg_id = 1
@@ -137,15 +143,13 @@ class Remote(Interface):
put = i[0]
subject = update.value(put, NS.patch.subject, None)
body = update.value(put, NS.patch.body, None)
- desc = {}
for i in update.triples([body, None, None]):
self.model.add([subject, i[1], i[2]])
return update
def uri_to_path(self, uri):
- path = uri
if uri.startswith(self.server_base):
- return uri[len(self.server_base)-1:]
+ return uri[len(self.server_base) - 1:]
return uri
def recv(self):
@@ -184,10 +188,10 @@ class Remote(Interface):
raise Error(fmt, cause)
def send(self, msg):
+ if type(msg) == list:
+ msg = '\n'.join(msg)
+
# Send message to server
- payload = msg
- if sys.version_info[0] == 3:
- payload = bytes(msg, 'utf-8')
self.sock.send(self.msgencode(msg))
# Receive response and parse into a model
@@ -203,18 +207,17 @@ class Remote(Interface):
# Add new prefixes to prepend to future responses because rdflib sucks
for line in response_str.split('\n'):
if line.startswith('@prefix'):
- match = re.search('@prefix ([^:]*): <(.*)> *\.', line)
+ match = re.search('@prefix ([^:]*): <(.*)> *\\.', line)
if match:
name = match.group(1)
uri = match.group(2)
- self.ns_manager.bind(match.group(1), match.group(2))
+ self.ns_manager.bind(name, uri)
# Handle response (though there should be only one)
blanks = []
response_desc = []
for i in response_model.triples([None, NS.rdf.type, NS.patch.Response]):
response = i[0]
- subject = response_model.value(response, NS.patch.subject, None)
body = response_model.value(response, NS.patch.body, None)
response_desc += [i]
@@ -240,70 +243,57 @@ class Remote(Interface):
return self.update_model(response_model)
def get(self, subject):
- return self.send('''
-[]
- a patch:Get ;
- patch:subject <%s> .
-''' % subject)
+ return self.send(['[]',
+ ' a patch:Get ;',
+ ' patch:subject <%s> .' % subject])
def put(self, subject, body):
- return self.send('''
-[]
- a patch:Put ;
- patch:subject <%s> ;
- patch:body [
-%s
- ] .
-''' % (subject, body))
+ return self.send(['[]',
+ ' a patch:Put ;',
+ ' patch:subject <%s> ;' % subject,
+ ' patch:body [',
+ ' ' + body,
+ ' ] .'])
def patch(self, subject, remove, add):
- return self.send('''
-[]
- a patch:Patch ;
- patch:subject <%s> ;
- patch:remove [
-%s
- ] ;
- patch:add [
-%s
- ] .
-''' % (subject, remove, add))
+ return self.send(['[]',
+ ' a patch:Patch ;',
+ ' patch:subject <%s> ;' % subject,
+ ' patch:remove [',
+ remove,
+ ' ] ;',
+ ' patch:add [',
+ add,
+ ' ] .'])
def set(self, subject, key, value):
- return self.send('''
-[]
- a patch:Set ;
- patch:subject <%s> ;
- patch:property <%s> ;
- patch:value %s .
-''' % (subject, key, value))
+ return self.send(['[]',
+ ' a patch:Set ;',
+ ' patch:subject <%s> ;' % subject,
+ ' patch:property <%s> ;' % key,
+ ' patch:value %s .' % value])
def connect(self, tail, head):
- return self.send('''
-[]
- a patch:Put ;
- patch:subject <%s> ;
- patch:body [
- a ingen:Arc ;
- ingen:tail <%s> ;
- ingen:head <%s> ;
- ] .
-''' % (os.path.commonprefix([tail, head]), tail, head))
+ subject = os.path.commonprefix([tail, head])
+ return self.send(['[]',
+ ' a patch:Put ;',
+ ' patch:subject <%s> ;' % subject,
+ ' patch:body [',
+ ' a ingen:Arc ;',
+ ' ingen:tail <%s> ;' % tail,
+ ' ingen:head <%s> ;' % head,
+ ' ] .'])
def disconnect(self, tail, head):
- return self.send('''
-[]
- a patch:Delete ;
- patch:body [
- a ingen:Arc ;
- ingen:tail <%s> ;
- ingen:head <%s> ;
- ] .
-''' % (tail, head))
+ return self.send(['[]',
+ ' a patch:Delete ;',
+ ' patch:body [',
+ ' a ingen:Arc ;',
+ ' ingen:tail <%s> ;' % tail,
+ ' ingen:head <%s> ;' % head,
+ ' ] .'])
def delete(self, subject):
- return self.send('''
-[]
- a patch:Delete ;
- patch:subject <%s> .
-''' % subject)
+ return self.send(['[]',
+ ' a patch:Delete ;',
+ ' patch:subject <%s> .' % subject])
diff --git a/scripts/ingenams b/scripts/ingenams
index a183586a..a88f96d0 100755
--- a/scripts/ingenams
+++ b/scripts/ingenams
@@ -23,6 +23,7 @@ ams_prefix = 'http://github.com/blablack/ams-lv2/'
fomp_prefix = 'http://drobilla.net/plugins/fomp/'
note_uri = 'http://drobilla.net/ns/ingen-internals#Note'
+
class World:
def __init__(self, server_uri):
self.server_uri = server_uri
@@ -37,10 +38,10 @@ class World:
def add_block(self, mod_id, plugin_uri, x, y):
self.mod_prototypes[self.mod_sym(mod_id)] = plugin_uri
self.server.put('/' + self.mod_sym(mod_id),
- ('\t\ta ingen:Block ;\n'
- + 'lv2:prototype <%s> ;\n' % plugin_uri
- + 'ingen:canvasX %f ;\n' % x
- + 'ingen:canvasY %f' % y).replace('\n', '\n\t\t'))
+ ('\t\ta ingen:Block ;\n' +
+ 'lv2:prototype <%s> ;\n' % plugin_uri +
+ 'ingen:canvasX %f ;\n' % x +
+ 'ingen:canvasY %f' % y).replace('\n', '\n\t\t'))
def add_arc(self,
head_port_id, tail_port_id,
@@ -84,7 +85,7 @@ class World:
port_index = int(port_id)
if world.mod_prototypes[self.mod_sym(mod_id)] == note_uri:
# Adapt MCV/ADVMCV port index to Note port index
- port_mapping = [ 3, 0, 2, 4, 6, 5, -1, -1, -1, -1 ]
+ port_mapping = [3, 0, 2, 4, 6, 5, -1, -1, -1, -1]
port_index = port_mapping[port_index]
if port_index == -1:
sys.stderr.write('warning: unsupported MCV port %d\n' % int(port_id))
@@ -107,9 +108,10 @@ class World:
if tail and head:
self.server.connect(self.server.uri_to_path(tail),
self.server.uri_to_path(head))
- except:
+ except Exception:
pass
+
# Static enumeration of special module type IDs
class Special:
CUSTOM = 0
@@ -119,17 +121,18 @@ class Special:
SCQUANTIZER = 31
ADVMCV = 35
+
# Module types list, indexed by numeric ID in file
# Except where otherwise commented, these correspond to internal modules,
# and the string is the suffix of the corresponding AMS LV2 plugin URI
module_types = [
- "custom", # 0 = custom (unsupported)
+ "custom", # 0 = custom (unsupported)
"vco",
"vca",
"lfo",
"delay",
"ringmod",
- "ladspa", # 6 = LADSPA plugin
+ "ladspa", # 6 = LADSPA plugin
"pcmout",
"mix",
"vcf",
@@ -153,8 +156,8 @@ module_types = [
"jackin",
"jackout",
"midiout",
- "scmcv", # Scala module (different line format)
- "scquantizer", # Scala module (different line format)
+ "scmcv", # Scala module (different line format)
+ "scquantizer", # Scala module (different line format)
"stereomix",
"conv",
"vcenv",
@@ -171,6 +174,7 @@ module_types = [
"vco2"
]
+
class Module:
def __init__(self, num, plugin_uri, properties={}):
self.num = num
@@ -178,10 +182,12 @@ class Module:
self.properties = properties
self.ports = []
+
class Patch:
def __init__(self):
self.modules = []
+
def ladspa_module(world, mod_id, x, y, poly, lib, label):
lv2_uri = ''
# Kludge LADSPA library and label to LV2 URIs where applicable
@@ -197,8 +203,10 @@ def ladspa_module(world, mod_id, x, y, poly, lib, label):
else:
print('MOD %3d LADSPA %s %s %s' % (mod_id, poly, lib, label))
+
def scala_module(world, mod_id, scala_name):
- sys.stderr.write('warning: scala module %3d (%s) unsupported\n' % (d, scala_name))
+ sys.stderr.write('warning: scala module %3d (%s) unsupported\n' % (mod_id, scala_name))
+
def standard_module(world, mod_id, x, y, name, arg):
if name == 'vca':
@@ -212,15 +220,18 @@ def standard_module(world, mod_id, x, y, name, arg):
lv2_uri = ams_prefix + name
world.add_block(mod_id, lv2_uri, x, y)
+
def float_control(world, mod_id, port_index, value,
logarithmic, minimum, maximum, midi_sign):
- #print('FLOAT CONTROL %s:%s = %s' % (mod_id, port_index, value))
+ # print('FLOAT CONTROL %s:%s = %s' % (mod_id, port_index, value))
pass
+
def control(world, mod_id, port_index, value, midi_sign):
- #print('CONTROL %s:%s = %s' % (mod_id, port_index, value))
+ # print('CONTROL %s:%s = %s' % (mod_id, port_index, value))
pass
+
if len(sys.argv) != 2 and len(sys.argv) != 3:
sys.stderr.write('Usage: %s AMS_PATCH_FILE [SERVER_URI]\n' % sys.argv[0])
sys.exit(1)
@@ -267,10 +278,10 @@ for l in in_file:
(expr[8], expr[9], expr[10]))
elif expr[0] == 'FSlider':
float_control(world, mod_id,
- expr[2], expr[3], expr[4], expr[5], expr[6], expr[7])
+ expr[2], expr[3], expr[4], expr[5], expr[6], expr[7])
elif expr[0] == 'ISlider' or expr[0] == 'LSlider':
- control(world, mod_id, expr[2], expr[3], expr[4])
- #else:
+ control(world, mod_id, expr[2], expr[3], expr[4])
+ # else:
# sys.stderr.write('warning: unsupported form %s\n' % expr[0])
except ingen.Error:
e = sys.exc_info()[1]
@@ -278,6 +289,6 @@ for l in in_file:
world.create_arcs()
-#print(world.server.model.serialize(format='n3'))
+# print(world.server.model.serialize(format='n3'))
in_file.close()
diff --git a/scripts/ingenish b/scripts/ingenish
index ee53c4a5..4fac6307 100755
--- a/scripts/ingenish
+++ b/scripts/ingenish
@@ -15,15 +15,8 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import ingen
-import os.path
-import re
import shlex
import sys
-import time
-try:
- import readline
-except:
- pass
# Python 2 compatibility
try:
@@ -31,6 +24,7 @@ try:
except NameError:
pass
+
def print_usage():
print('''Usage: ingenish [OPTION]... [COMMAND [ARGUMENT]...]
@@ -70,6 +64,7 @@ Example:
set /main/tone/output ingen:value 0.7
''')
+
def run(cmd):
if cmd[0] == 'help':
print_usage()
@@ -91,6 +86,7 @@ def run(cmd):
return ingen.delete(cmd[1])
return False
+
a = 1
server = 'unix:///tmp/ingen.sock'
if len(sys.argv) > 1:
@@ -110,12 +106,12 @@ if len(sys.argv) - a == 0:
run(shlex.split(input('> ')))
except (EOFError, KeyboardInterrupt, SystemExit):
break
- except:
+ except Exception:
print('error: %s' % sys.exc_info()[1])
else:
try:
update = run(sys.argv[a:])
if update:
print(update.serialize(format='n3'))
- except:
+ except Exception:
print('error: %s' % sys.exc_info()[1])