-
Notifications
You must be signed in to change notification settings - Fork 0
/
rack.lua
157 lines (143 loc) · 4.26 KB
/
rack.lua
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
local rack = {}
local log = hs.logger.new('rack', 'debug')
rack.hotkeys = {}
rack.colorPicker = dofile(hs.spoons.resourcePath('color_picker.lua'))
-----------
-- setup --
-----------
function rack:bindHotkeys(maps)
table.insert(rack.hotkeys, rack:color(maps))
table.insert(rack.hotkeys, rack:autoRoute(maps))
table.insert(rack.hotkeys, rack:browsePatches(maps))
table.insert(rack.hotkeys, rack:disconnectDevice(maps))
table.insert(rack.hotkeys, rack:resetDevice(maps))
table.insert(rack.hotkeys, rack:createMixChannel(maps))
table.insert(rack.hotkeys, rack:combine(maps))
end
function rack:activate(app)
for _, v in pairs(rack.hotkeys) do v:enable() end
rack.app = app
log.d('rack activated')
end
function rack:deactivate()
for _, v in pairs(rack.hotkeys) do v:disable() end
log.d('rack deactivated')
end
--------------
-- keybinds --
--------------
-- rack:autoRoute(m)
-- Method
-- Auto-routes the currently selected devices
--
-- Parameters:
-- * m - A table of hotkey mappings
--
-- Returns:
-- * An hs.hotkey object, to be addded to this module's hotkeys table
function rack:autoRoute(m)
return hs.hotkey.new(m.autoRoute[1], m.autoRoute[2], function()
rack.app:selectMenuItem({ 'Edit', 'Auto-route Device' })
log.d('auto routed')
end)
end
-- rack:browsePatches(m)
-- Method
-- Opens the patch browser with focus on the current device
--
-- Parameters:
-- * m - A table of hotkey mappings
--
-- Returns:
-- * An hs.hotkey object, to be addded to this module's hotkeys table
function rack:browsePatches(m)
return hs.hotkey.new(m.browsePatches[1], m.browsePatches[2], function()
rack.app:selectMenuItem({ 'Edit', 'Browse Patches…' })
log.d('browsing patches')
end)
end
-- rack:disconnectDevice(m)
-- Method
-- Disconnects all cables from the selected device
--
-- Parameters:
-- * m - A table of hotkey mappings
--
-- Returns:
-- * An hs.hotkey object, to be addded to this module's hotkeys table
function rack:disconnectDevice(m)
return hs.hotkey.new(m.disconnectDevice[1], m.disconnectDevice[2], function()
rack.app:selectMenuItem({ 'Edit', 'Disconnect Device' })
log.d('disconnected device')
end)
end
-- rack:resetDevice(m)
-- Method
-- Resets the selected device to its init patch
--
-- Parameters:
-- * m - A table of hotkey mappings
--
-- Returns:
-- * An hs.hotkey object, to be addded to this module's hotkeys table
function rack:resetDevice(m)
return hs.hotkey.new(m.resetDevice[1], m.resetDevice[2], function()
rack.app:selectMenuItem({ 'Edit', 'Reset Device' })
log.d('reset device')
end)
end
-- rack:createMixChannel(m)
-- Method
-- Creates a new mix channel
--
-- Parameters:
-- * m - A table of hotkey mappings
--
-- Returns:
-- * An hs.hotkey object, to be addded to this module's hotkeys table
function rack:createMixChannel(m)
return hs.hotkey.new(m.createMixChannel[1], m.createMixChannel[2], function()
rack.app:selectMenuItem({ 'Create', 'Create Mix Channel' })
log.d('created mix channel')
end)
end
-- rack:combine(m)
-- Method
-- Combines the selected rack devices in a new combinator
-- If a combinator is selected, it uncombines the devices
--
-- Parameters:
-- * m - A table of hotkey mappings
--
-- Returns:
-- * An hs.hotkey object, to be addded to this module's hotkeys table
function rack:combine(m)
return hs.hotkey.new(m.combine[1], m.combine[2], function()
local ok = rack.app:findMenuItem({ 'Edit', 'Combine' })
if ok.enabled then
rack.app:selectMenuItem({ 'Edit', 'Combine' })
log.d('combined devices')
else
rack.app:selectMenuItem({ 'Edit', 'Uncombine' })
log.d('uncombined devices')
end
end)
end
-- rack:color(m)
-- Method
-- Activates a colorPicker (hs.chooser) with available track colors
-- The selected color is then applied to the selected tracks
--
-- Parameters:
-- * m - A table of hotkey mappings
--
-- Returns:
-- * An hs.hotkey object, to be addded to this module's hotkeys table
function rack:color(m)
return hs.hotkey.new(m.color[1], m.color[2], function()
local picker = rack.colorPicker:setup(rack.app, 'Track Color')
rack.colorPicker:show()
log.d('showing rack device color picker')
end)
end
return rack