Add new project 'AudioControl'
[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
9 import sys, curses
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 ###########################################################################
16 # Setup views and controllers
17 #
18 # Display size: 77x17
19
20 Logger.init(main.viewmanager, 38, 0, 39, 10)
21
22 Joyboard.register(
23     viewmanager = main.viewmanager,
24     dispatcher = main.dispatcher,
25
26     context          = 'jb0',
27     label            = 'Foot Switch',
28     numeric_switches =  10,
29     alpha_switches   =   5,
30     x                =   2,
31     y                =  10,
32     size             =   6,
33
34     device           = '/dev/input/js0',
35     bits             = { 1:1, 3:2, 2:4, 0:8 }
36 )
37
38 Keyboard.register(
39     viewmanager = main.viewmanager,
40     dispatcher = main.dispatcher,
41
42     context          = 'kbd',
43     label            = 'Key Bindings',
44     x                =  0,
45     y                =  0,
46     dx               = 38,
47     dy               = 10
48 )
49
50 jackd = Process.Process("jackd -d alsa -S -r 44100 -p 256",'jack')
51
52 ###########################################################################
53 # Global keymap and auxilary actions
54
55 global_map = Bindings.KeyMap()
56
57 @action
58 def quit(binding):
59     sys.exit(0)
60
61 global_map.add( Binding( Event('jb0',0), '()', Actions.Nop() ) )
62 global_map.add( Binding( Event('jb0',1), '()', Actions.Nop() ) )
63 global_map.add( Binding( Event('jb0',10), '()', Actions.Nop() ) )
64
65 global_map.add( Binding( Event('kbd',key('q')), 'Quit', Action['quit'] ) )
66
67 Action.register( Actions.ChangeBindingsRelative( 'unset_this_map', 0, [] ) )
68
69 ###########################################################################
70 # Looper mode
71
72 looper_main_map = Bindings.KeyMap( 'Looper' )
73 looper_aux_map = Bindings.KeyMap( 'Aux' )
74
75 Action.register( Actions.ChangeBindingsAbsolute('set_mode_looper', 1, [looper_main_map]) )
76 Action.register( Actions.ChangeBindingsRelative('looper_set_aux_map', 1, [looper_aux_map]) )
77
78 looper = Looper.Controller('localhost',9951)
79
80 Action.register( Looper.Command('looper_record', looper, 'record') )
81 Action.register( Looper.Command('looper_overdub', looper, 'overdub') )
82 Action.register( Looper.Command('looper_multiply', looper, 'multiply') )
83 Action.register( Looper.Command('looper_mute', looper, 'mute') )
84 Action.register( Looper.Command('looper_undo', looper, 'undo') )
85 Action.register( Looper.Command('looper_redo', looper, 'redo') )
86 Action.register( Looper.Command('looper_trigger', looper, 'trigger') )
87 Action.register( Looper.Command('looper_insert', looper, 'insert') )
88 Action.register( Looper.Command('looper_replace', looper, 'replace') )
89 Action.register( Looper.Command('looper_substitute', looper, 'substitute') )
90 Action.register( Looper.Command('looper_reverse', looper, 'reverse') )
91 Action.register( Looper.Command('looper_oneshot', looper, 'oneshot') )
92
93 looper_main_map.add ( Binding( Event('jb0',2),  'Rec',     Action['looper_record'] ) )
94 looper_main_map.add ( Binding( Event('jb0',3),  'Over',    Action['looper_overdub'] ) )
95 looper_main_map.add ( Binding( Event('jb0',4),  'Mult',   Action['looper_multiply'] ) )
96 looper_main_map.add ( Binding( Event('jb0',5),  'Mute',       Action['looper_mute'] ) )
97 looper_main_map.add ( Binding( Event('jb0',6),  'Undo',       Action['looper_undo'] ) )
98 looper_main_map.add ( Binding( Event('jb0',7),  'Redo',       Action['looper_redo'] ) )
99 looper_main_map.add ( Binding( Event('jb0',8),  'Trig',    Action['looper_trigger'] ) )
100 looper_main_map.add ( Binding( Event('jb0',9),  'Aux',        Action['looper_set_aux_map'] ) )
101
102 looper_aux_map.add  ( Binding( Event('jb0',2),  'Ins',     Action['looper_insert'] ) )
103 looper_aux_map.add  ( Binding( Event('jb0',3),  'Repl',    Action['looper_replace'] ) )
104 looper_aux_map.add  ( Binding( Event('jb0',4),  'Subst', Action['looper_substitute'] ) )
105 looper_aux_map.add  ( Binding( Event('jb0',6),  'Rev',    Action['looper_reverse'] ) )
106 looper_aux_map.add  ( Binding( Event('jb0',7),  'Once',    Action['looper_oneshot'] ) )
107 looper_aux_map.add  ( Binding( Event('jb0',9),  'Main',       Action['unset_this_map'] ) )
108
109 ###########################################################################
110 # MegaPedal mode
111
112 megapedal_main_map = Bindings.KeyMap( 'MegaPedal' )
113
114 Action.register( Actions.ChangeBindingsAbsolute('set_mode_megapedal', 1, [megapedal_main_map]) )
115
116 megapedal_main_map.add ( Binding( Event('jb0',11), 'Looper', Action['set_mode_looper'] ) )
117 global_map.add ( Binding( Event('jb0',11), 'MegaPedal', Action['set_mode_megapedal'] ) )
118
119 ###########################################################################
120 # RythmBox mode
121
122 rythmbox_main_map = Bindings.KeyMap( 'RythmBox' )
123
124 Action.register( Actions.ChangeBindingsAbsolute('set_mode_rythmbox', 1, [rythmbox_main_map]) )
125
126 rythmbox_main_map.add ( Binding( Event('jb0',11), 'MegaPedal', Action['set_mode_megapedal'] ) )
127 global_map.add ( Binding( Event('jb0',11), 'RythmBox', Action['set_mode_rythmbox'] ) )
128
129 ###########################################################################
130
131 main.keylist.append(global_map)
132 main.keylist.append(looper_main_map)