-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathpirate-radio.lua
executable file
·165 lines (140 loc) · 3.83 KB
/
pirate-radio.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
158
159
160
161
162
163
164
165
---pirate radio
-- infinitedigits,eigen,jaseknighter,tyleretters, et al
-- lines: llllllll.co/t/pirate-radio
--
-- yar...
------------------------------
-- notes and todos
--
-- notes:
--
-- switch debug == true to false before publishing
--
-- todos:
-- implement screen_dirty for redrawing components
------------------------------
include "lib/includes"
------------------------------
-- init
------------------------------
function init()
debug=false
-- set sensitivity of the encoders
norns.enc.sens(1,6)
norns.enc.sens(2,6)
norns.enc.sens(3,1) -- needs some sensitivity for the tuner
pages=UI.Pages.new(1,NUM_PAGES)
prereqs.install()
tuner.init()
magic_eye.init()
eq.init()
oscin.init()
-- dust2dust needs to be defined after oscin
dust2dust=dust2dust_:new({room="pirateradio"})
sync.init()
radio.init()
playback.init()
debouncer_timer_init()
init_midi_16n()
parameters.add_params()
parameters.load_settings()
params:bang()
-- define the global marquee for the lower right banner
marquee=Marquee:new()
redraw_timer_init()
initializing = false
end
--------------------------
-- 16n
--------------------------
function init_midi_16n()
local prev_pos_eq_all_slider = nil
_16n.init(function(midi_msg)
local slider_id = _16n.cc_2_slider_id(midi_msg.cc)
local v = midi_msg.val
if pages.index == 1 then
if slider_id == 1 then
v = util.linlin(_16n.min_v(), _16n.max_v(),
tuner.dialer.pointer_min, tuner.dialer.pointer_max,
v)
tuner.dialer:set_pointer_loc(v)
end
elseif pages.index == 2 then
if slider_id <= eq.num_bands then
v = util.linlin(_16n.min_v(), _16n.max_v(),
eq.last_value, eq.first_value,
v)
eq:set_band(v, slider_id)
elseif slider_id == 16 then
if prev_pos_eq_all_slider == nil then
prev_pos_eq_all_slider = v
return
end
local delta = prev_pos_eq_all_slider - v
prev_pos_eq_all_slider = v
eq:set_all_bands_rel(delta)
screen_dirty = true
end
end
end)
end
--------------------------
-- encoders and keys
--------------------------
function enc(n,delta)
encoders_and_keys.enc(n,delta)
end
function key(n,z)
encoders_and_keys.key(n,z)
end
--------------------------
-- redraw
--------------------------
local menu_activated = false
function redraw_timer_init()
redrawtimer=metro.init(function()
local menu_status=norns.menu.status()
if menu_status==false and initializing==false then
pirate_radio_pages.update_pages()
screen_dirty=false
elseif menu_status==false and initializing==false and menu_activated == true then
menu_activated = false
screen_dirty = true
elseif menu_status==true and menu_activated == false then
menu_activated = true
end
if playback~=nil then
playback:update_state()
end
frame_counter = frame_counter+1
rel_frame_counter = rel_frame_counter + params:get("playback_rate")
end,SCREEN_FRAMERATE,-1)
redrawtimer:start()
end
--------------------------
-- debouncer
-- (and things that run async, like internet stuff,
-- that may fail if there is no connection)
--------------------------
function debouncer_timer_init()
local inited=false
debouncetimer=metro.init(function()
if not inited then
inited=true
weather.init()
sync:download()
dust2dust:send({message="need-sync"})
comments.init()
end
screen_dirty = true
end,1,-1)
debouncetimer:start()
end
function cleanup ()
-- redrawtimer.free_all()
magic_eye.cleanup()
dust2dust:stop()
playback:reroute_audio(false)
norns.system_cmd(_path.code.."pirate-radio/supercollider/classes/stopogg.sh &")
-- add more cleanup code
end