Audio/AudioControl: Commit loads of long uncommited changes
[audiocontrol.git] / config.py
1 import Bindings, Actions, Views, Events, Logger
2 from Bindings import Binding
3 from Actions import Actions as Action, action
4 from Views import EventWidget
5 from Events import Event
6 import main
7 import Joyboard, Keyboard, Process
8 import Looper, Mixer
9 import sys, curses, time, os
10 from curses.ascii import alt, ctrl
11
12 def shift(letter) : return ord(chr(letter).upper())
13 def key(letter) : return ord(letter.lower())
14
15 global_map = Bindings.KeyMap()
16
17 ###########################################################################
18 # Setup views and controllers
19 #
20 # Display size: 88x22
21
22 #Logger.init(main.viewmanager, 38, 0, 37, 10, 'audiocontroller.log')
23 Logger.init(main.viewmanager, 0, 17, 88, 5)
24
25 jb = None
26 ctl = None
27 if os.path.exists('/dev/input/js0'):
28     jb = Joyboard.register(
29         viewmanager = main.viewmanager,
30         dispatcher = main.dispatcher,
31         
32         context          = 'jb0',
33         label            = 'Foot Switch',
34         numeric_switches =  10,
35         alpha_switches   =   5,
36         x                =   0,
37         y                =  10,
38         dx               =  88,
39         size             =   7,
40         
41         device           = '/dev/input/js0',
42         bits             = { 1:1, 3:2, 2:4, 0:8 },
43     )
44
45     ctl = Joyboard.registerController(
46         viewmanager = main.viewmanager,
47         dispatcher = main.dispatcher,
48         keylist = main.keylist,
49         source = jb,
50         
51         context          = 'c0',
52         name             = 'Control',
53         x                = 75,
54         y                =  0,
55         dx               = 13,
56         dy               = 10,
57
58         controller       = 0,
59         low              = -27200,
60         high             = -32700,
61     )        
62
63 Keyboard.register(
64     viewmanager = main.viewmanager,
65     dispatcher = main.dispatcher,
66
67     context          = 'kbd',
68     label            = 'Key Bindings',
69     x                =  0,
70     y                =  0,
71     dx               = 52,
72     dy               = 10,
73     size             =  7
74 )
75
76 ###########################################################################
77 # Global keymap and auxilary actions
78
79 @action
80 def quit(binding):
81     sys.exit(1)
82
83 @action
84 def restart(binding):
85     sys.exit(0)
86
87 global_map.add( Binding( Event('kbd',key('q')), 'Quit', Action['quit'] ) )
88 global_map.add( Binding( Event('kbd',ctrl(key('r'))), 'Restart', Action['restart'] ) )
89
90 for i,k in enumerate(('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e' )):
91     Action.register( Events.EmitEvent('key_%s' % k, main.dispatcher, Event('jb0', i)) )
92     global_map.add( Binding( Event('kbd',key(k)), 'Foot %s' % k.upper(), Action['key_%s' % k] ) )
93     
94 if ctl is not None:
95     Action.register( Joyboard.StepController( 'controller_increment', ctl, +1 ) )
96     Action.register( Joyboard.StepController( 'controller_decrement', ctl, -1 ) )
97
98     global_map.add( Binding( Event('kbd', curses.KEY_UP), 'Increment', Action['controller_increment'] ) )
99     global_map.add( Binding( Event('kbd', curses.KEY_DOWN), 'Decrement', Action['controller_decrement'] ) )
100
101 Action.register( Actions.ChangeBindingsRelative( 'unset_this_map', 0, [] ) )
102
103 ###########################################################################
104 # Looper
105
106 looper_main_map = Bindings.KeyMap( 'Looper' )
107 Action.register( Actions.ChangeBindingsRelative( 'mode_looper', 0, [ looper_main_map ] ) )
108
109 looper = Looper.register(
110     oscserver = main.oscserver,
111
112     context = 'sl',
113     remote  = ('127.0.0.1',9951),
114 )
115
116 Action.register( Looper.Command('looper_record', looper, 'record') )
117 Action.register( Looper.Command('looper_overdub', looper, 'overdub') )
118 Action.register( Looper.Command('looper_multiply', looper, 'multiply') )
119 Action.register( Looper.Command('looper_mute', looper, 'mute') )
120 Action.register( Looper.Command('looper_undo', looper, 'undo') )
121 Action.register( Looper.Command('looper_redo', looper, 'redo') )
122 Action.register( Looper.Command('looper_trigger', looper, 'trigger') )
123 Action.register( Looper.Command('looper_insert', looper, 'insert') )
124 Action.register( Looper.Command('looper_replace', looper, 'replace') )
125 Action.register( Looper.Command('looper_substitute', looper, 'substitute') )
126 Action.register( Looper.Command('looper_reverse', looper, 'reverse') )
127 Action.register( Looper.Command('looper_oneshot', looper, 'oneshot') )
128 Action.register( Looper.Command('looper_undo_all', looper, 'undo_all') )
129 Action.register( Looper.Command('looper_redo_all', looper, 'redo_all') )
130
131 looper_main_map.add ( Binding( Event('jb0',0),  'Rec',    Action['looper_record'] ) )
132 looper_main_map.add ( Binding( Event('jb0',1),  'Over',   Action['looper_overdub'] ) )
133 looper_main_map.add ( Binding( Event('jb0',2),  'Mult',   Action['looper_multiply'] ) )
134 looper_main_map.add ( Binding( Event('jb0',3),  'Undo',   Action['looper_undo'] ) )
135 looper_main_map.add ( Binding( Event('jb0',4),  'Redo',   Action['looper_redo'] ) )
136 looper_main_map.add ( Binding( Event('jb0',5),  'Mute',   Action['looper_mute'] ) )
137 looper_main_map.add ( Binding( Event('jb0',6),  'Trig',   Action['looper_trigger'] ) )
138 looper_main_map.add ( Binding( Event('jb0',7),  'Once',   Action['looper_oneshot'] ) )
139 looper_main_map.add ( Binding( Event('jb0',8),  'Ins',    Action['looper_insert'] ) )
140 looper_main_map.add ( Binding( Event('jb0',9),  'Repl',   Action['looper_replace'] ) )
141 looper_main_map.add ( Binding( Event('jb0',12), 'Undo A', Action['looper_undo_all'] ) )
142 looper_main_map.add ( Binding( Event('jb0',13), 'Redo A', Action['looper_redo_all'] ) )
143 looper_main_map.add ( Binding( Event('jb0',14), 'Subst',  Action['looper_substitute'] ) )
144
145
146 looper_param_map = Bindings.KeyMap( 'Parameters' )
147 Action.register( Actions.ChangeBindingsRelative('looper_set_param_map', 1, [looper_param_map] ) )
148 looper_main_map.add ( Binding( Event('jb0',11), '[Param]', Action['looper_set_param_map'] ) )
149
150 if ctl is not None:
151     Action.register( Looper.AssignController( 'looper_parm_rec_thresh', looper, ctl, 'Rec.Thresh.',
152                                               'rec_thresh', 0.0, 1.0 ) )
153     Action.register( Looper.AssignController( 'looper_parm_feedback', looper, ctl, 'Feedback',
154                                               'feedback', 0.0, 1.0 ) )
155     Action.register( Looper.AssignController( 'looper_parm_dry', looper, ctl, 'Dry Level',
156                                               'global_dry', 0.0, 1.0 ) )
157     Action.register( Looper.AssignController( 'looper_parm_wet', looper, ctl, 'Wet Level',
158                                               'global_wet', 0.0, 1.0 ) )
159     Action.register( Looper.AssignController( 'looper_parm_igain', looper, ctl, 'In. Gain',
160                                               'global_input_gain', 0.0, 1.0 ) )
161
162     steps = [ 1.0 ]
163     for i in range(6):
164         x = pow(2.0,2.0*(i+1)/12.0)
165         steps.append(x)
166         steps[0:0] = [1/x]
167
168     Action.register( Looper.AssignController( 'looper_parm_rate', looper, ctl, 'Rate',
169                                               'rate', 0.5, 2.0, steps ) )
170
171     looper_param_map.add( Binding( Event('jb0',5),  'Feedb', Action['looper_parm_feedback'] ) )
172     looper_param_map.add( Binding( Event('jb0',6),  'Dry',   Action['looper_parm_dry'] ) )
173     looper_param_map.add( Binding( Event('jb0',7),  'Wet',   Action['looper_parm_wet'] ) )
174     looper_param_map.add( Binding( Event('jb0',8),  'Gain',  Action['looper_parm_igain'] ) )
175     looper_param_map.add( Binding( Event('jb0',9),  'Rec T', Action['looper_parm_rec_thresh'] ) )
176     looper_param_map.add( Binding( Event('jb0',12), '',      Actions.Nop() ) )
177     looper_param_map.add( Binding( Event('jb0',13), 'Rev',    Action['looper_reverse'] ) )
178     looper_param_map.add( Binding( Event('jb0',14), 'Rate',  Action['looper_parm_rate'] ) )
179
180 looper_param_map.add( Binding( Event('jb0',11), '[Main]',    Action['unset_this_map'] ) )
181
182 # Initialize looper: enable 'round' and set quantize to 'cycle'
183 looper.set('quantize',1)
184 looper.set('round',1)
185 looper.set('sync',1)
186
187 ###########################################################################
188 # Mixer and effects
189
190 mixer_map = Bindings.KeyMap('Mixer & Effects')
191 Action.register( Actions.ChangeBindingsRelative( 'mode_mixer', 0, [ mixer_map ] ) )
192
193 looper_main_map.add( Binding( Event('jb0',10),  '[Mixer]', Action['mode_mixer'] ) )
194
195 mixer = Mixer.register(
196     viewmanager = main.viewmanager,
197     oscserver = main.oscserver,
198
199     context  = 'mix',
200     label    = 'Mixer',
201     x        = 52,
202     y        =  0,
203     dx       = 23,
204     dy       = 4,
205
206     channels = ( 'Guitar', 'Voice' ),
207     remote  = ('127.0.0.1', 9901),
208 )
209
210 gain = Mixer.register(
211     viewmanager = main.viewmanager,
212     oscserver = main.oscserver,
213
214     context  = 'gain',
215     label    = 'Gain',
216     x        = 52,
217     y        =  7,
218     dx       = 23,
219     dy       = 3,
220
221     channels = ( 'Guitar', ),
222     remote  = ('127.0.0.1', 9902),
223 )
224
225 Action.register( Mixer.AssignController( 'mixer_guitar_level', mixer, ctl, 'Guitar', 1 ) )
226 Action.register( Mixer.ToggleMuteChannel( 'mixer_mute_guitar', mixer, 1 ) )
227 Action.register( Mixer.AssignController( 'mixer_voice_level', mixer, ctl, 'Voice', 2 ) )
228 Action.register( Mixer.ToggleMuteChannel( 'mixer_mute_voice', mixer, 2 ) )
229 Action.register( Mixer.AssignController( 'mixer_master_level', mixer, ctl, 'Master', 0 ) )
230 Action.register( Mixer.ToggleMuteAll( 'mixer_mute_all', mixer ) )
231 Action.register( Mixer.CycleVolume( 'mixer_cycle_gain', gain, 1, ( 0.0, 2.0, 4.0 ) ) )
232
233 mixer_map.add( Binding( Event('jb0',0),  'Rec',    Action['looper_record'] ) )
234 mixer_map.add( Binding( Event('jb0',1),  'Over',   Action['looper_overdub'] ) )
235 mixer_map.add( Binding( Event('jb0',2),  'Mult',   Action['looper_multiply'] ) )
236 mixer_map.add( Binding( Event('jb0',3),  'Undo',   Action['looper_undo'] ) )
237 mixer_map.add( Binding( Event('jb0',4),  'Redo',   Action['looper_redo'] ) )
238 mixer_map.add( Binding( Event('jb0',5), 'Un All', Action['looper_undo_all'] ) )
239
240 mixer_map.add( Binding( Event('jb0',6), 'Lead', Action['mixer_cycle_gain'] ) )
241 mixer_map.add( Binding( Event('jb0',7), 'Mute G', Action['mixer_mute_guitar'] ) )
242 mixer_map.add( Binding( Event('jb0',8), 'Mute V', Action['mixer_mute_voice'] ) )
243 mixer_map.add( Binding( Event('jb0',9), 'Mute', Action['mixer_mute_all'] ) )
244
245 mixer_map.add( Binding( Event('jb0',13), 'Vol G', Action['mixer_guitar_level'] ) )
246 mixer_map.add( Binding( Event('jb0',14), 'Vol V', Action['mixer_voice_level'] ) )
247
248 mixer.set(1,0.0)
249 mixer.set(2,0.0)
250 mixer.assignController( ctl, 'Guitar', 1 )
251 gain.set(1,0.0)
252     
253 ###########################################################################
254
255 mixer_map.add( Binding( Event('jb0',10), '[Loop]', Action['mode_looper'] ) )
256
257 main.keylist.append(global_map)
258 main.keylist.append(mixer_map)