Expose voice detune parameter of the lv2 plugin
[zyn.git] / lv2plugin.py
blob2a1bb6bdb6ce1b162280adec18cf60c2947346a7
1 #! /usr/bin/env python
2 # encoding: utf-8
4 # Copyright (C) 2008,2009 Nedko Arnaudov <nedko@arnaudov.name>
6 # waf tool for lv2 plugins
8 import Object
9 from Object import taskgen, after, before, feature
10 from Common import install_files
11 import os
12 import Params
13 import shutil
15 from Configure import g_maxlen
16 #g_maxlen = 40
18 def display_msg(msg, status = None, color = None):
19 sr = msg
20 global g_maxlen
21 g_maxlen = max(g_maxlen, len(msg))
22 if status:
23 print "%s :" % msg.ljust(g_maxlen),
24 Params.pprint(color, status)
25 else:
26 print "%s" % msg.ljust(g_maxlen)
28 def get_lv2_install_dir():
29 envvar = 'LV2_PATH'
31 has_lv2_path = os.environ.has_key(envvar)
32 if has_lv2_path:
33 display_msg("Checking LV2_PATH")
34 else:
35 display_msg("Checking LV2_PATH", "not set", 'YELLOW')
36 return None
38 if has_lv2_path:
39 lv2paths = os.environ[envvar].split(':')
40 for lv2path in lv2paths:
41 if not os.path.isdir(lv2path):
42 display_msg(' ' + lv2path, 'not directory!', 'YELLOW')
43 continue
45 if not os.access(lv2path, os.W_OK):
46 display_msg(' ' + lv2path, 'not writable', 'YELLOW')
47 continue
49 display_msg(' ' + lv2path, 'looks good', 'GREEN')
50 return lv2path
52 return None
54 class lv2plugin_proxy_abstract(Object.task_gen):
55 def __init__(self, tool, hook):
56 Object.task_gen.__init__(self)
57 self.tool = tool
58 self.hook = hook
60 def the_hook(self, obj, node):
61 #print "-------------- '%s'" % node
62 #print "tool '%s'" % self.tool
63 #print "tool.target '%s'" % self.tool.target
64 #print "hook '%s'" % self.hook
65 #print "obj '%s'" % obj
66 #print "self '%s'" % self
67 self.hook(self.tool, node)
69 class lv2plugin_taskgen(Object.task_gen):
70 def __init__(self, type = 'cpp', env=None):
71 Object.task_gen.__init__(self)
72 self.type = type
73 self.tool = Object.task_gen.classes[type]('shlib')
74 if type == 'cpp':
75 self.tool.m_type_initials = 'cpp'
76 self.tool.features.append('cc')
77 self.tool.ccflags = ''
78 self.tool.mappings['.c'] = Object.task_gen.mappings['.cc']
80 def apply_core(self):
81 #print "lv2plugin.apply_core() called."
82 #print "sources: " + repr(self.source)
83 #print "target: '%s'" % self.target
84 #print "ttl: '%s'" % self.ttl
85 self.tool.target = self.target
86 self.tool.env['shlib_PATTERN'] = '%s.so'
87 self.tool.uselib = self.uselib
88 self.tool.ttl = self.ttl
89 self.tool.lv2 = True
90 Object.task_gen.apply_core(self)
92 def get_hook(self, ext):
93 classes = Object.task_gen.classes
94 for cls in classes.keys():
95 if cls == 'lv2plugin':
96 continue
98 if cls != self.type:
99 continue
101 map = classes[cls].mappings
102 for x in map:
103 if x == ext:
104 hook = map[x]
105 obj = lv2plugin_proxy_abstract(self.tool, hook)
106 return obj.the_hook
108 return None
110 def set_options(opt):
111 opt.add_option('--lv2-dir', type='string', default='', dest='LV2_INSTALL_DIR', help='Force directory where LV2 plugin(s) will be installed.')
113 def detect(conf):
114 conf.env['LV2_INSTALL_DIR'] = getattr(Params.g_options, 'LV2_INSTALL_DIR')
115 status = conf.env['LV2_INSTALL_DIR']
116 if not status:
117 status = 'will be deduced from LV2_PATH'
118 display_msg('LV2 installation directory', status, 'GREEN')
120 @taskgen
121 @feature('normal')
122 @after('apply_objdeps')
123 @before('install_target')
124 def install_lv2(self):
125 if not getattr(self, 'lv2', None):
126 return
128 self.meths.remove('install_target')
130 if not Params.g_install:
131 return
133 if not self.env['LV2_INSTALL_DIR']:
134 self.env['LV2_INSTALL_DIR'] = get_lv2_install_dir()
135 if not self.env['LV2_INSTALL_DIR']:
136 Params.fatal('Cannot locate LV2 plugins directory')
138 display_msg('LV2 installation directory', self.env['LV2_INSTALL_DIR'], 'GREEN')
140 bundle_files = self.ttl
141 bundle_files.append(self.target + '.so')
142 install_files('LV2_INSTALL_DIR', self.target + '.lv2', bundle_files, self.env)