A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1--[[
2/***************************************************************************
3 * __________ __ ___.
4 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * \/ \/ \/ \/ \/
9 * $Id$
10 *
11 * Copyright (C) 2017 William Wilgus
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22]]
23if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end
24
25require("printtable")
26require("menucoresettings") --loads user settings from rockbox
27
28local _clr = require("color")
29
30
31local _LCD = rb.lcd_framebuffer()
32
33--[[ -- dpad requires:
34local BUTTON = require("menubuttons")
35local _timer = require("timer")
36]]
37--------------------------------------------------------------------------------
38--[[ cursor style button routine
39-- left / right are x, xi is increment xir is increment when repeat
40-- up / down are y, yi is increment yir is increment when repeat
41-- cancel is returned as 0,1
42-- select as 0, 1, 2, 3 (none, pressed, repeat, relesed)
43-- x_chg and y_chg are the amount x or y changed
44-- timeout == nil or -1 loop waits indefinitely till button is pressed
45-- time since last button press is returned in ticks..
46-- make xi, xir, yi, yir negative to flip direction...
47]]
48--[[
49local function dpad(x, xi, xir, y, yi, yir, timeout, overflow)
50 local scroll_is_fixed = overflow ~= "manual"
51 _timer("dpad") -- start a persistant timer; keeps time between button events
52 if timeout == nil then timeout = -1 end
53 local cancel, select = 0, 0
54 local x_chg, y_chg = 0, 0
55 local button
56 while true do
57 button = rb.get_plugin_action(timeout)
58
59 if button == BUTTON.CANCEL then
60 cancel = 1
61 break;
62 elseif button == BUTTON.EXIT then
63 cancel = 1
64 break;
65 elseif button == BUTTON.SEL then
66 select = 1
67 timeout = timeout + 1
68 elseif button == BUTTON.SELR then
69 select = 2
70 timeout = timeout + 1
71 elseif button == BUTTON.SELREL then
72 select = -1
73 timeout = timeout + 1
74 elseif button == BUTTON.LEFT then
75 x_chg = x_chg - xi
76 if scroll_is_fixed then
77 cancel = 1
78 break;
79 end
80 elseif button == BUTTON.LEFTR then
81 x_chg = x_chg - xir
82 elseif button == BUTTON.RIGHT then
83 x_chg = x_chg + xi
84 if scroll_is_fixed then
85 select = 1
86 timeout = timeout + 1
87 end
88 elseif button == BUTTON.RIGHTR then
89 x_chg = x_chg + xir
90 elseif button == BUTTON.UP then
91 y_chg = y_chg + yi
92 elseif button == BUTTON.UPR then
93 y_chg = y_chg + yir
94 elseif button == BUTTON.DOWN then
95 y_chg = y_chg - yi
96 elseif button == BUTTON.DOWNR then
97 y_chg = y_chg - yir
98 elseif timeout >= 0 then--and rb.button_queue_count() < 1 then
99 break;
100 end
101
102 if x_chg ~= 0 or y_chg ~= 0 then
103 timeout = timeout + 1
104 end
105 end
106
107 x = x + x_chg
108 y = y + y_chg
109
110 return cancel, select, x_chg, x, y_chg, y, _timer.check("dpad", true)
111end -- dpad
112]]
113--------------------------------------------------------------------------------
114-- displays text in menu_t calls function in same indice of func_t when selected
115function print_menu(menu_t, func_t, selected, settings, copy_screen)
116
117 local i, start, vcur, screen_img
118
119 if selected then vcur = selected + 1 end
120 if vcur and vcur <= 1 then vcur = 2 end
121
122 local c_table = rb.core_color_table or {}
123
124 if not settings then
125 settings = {}
126 settings.default = true
127 end
128
129 settings.justify = settings.justify or "center"
130 settings.wrap = settings.wrap or true
131 settings.hfgc = settings.hfgc or c_table.lst_color or _clr.set( 0, 000, 000, 000)
132 settings.hbgc = settings.hbgc or c_table.bg_color or _clr.set(-1, 255, 255, 255)
133 settings.ifgc = settings.ifgc or c_table.fg_color or _clr.set(-1, 000, 255, 060)
134 settings.ibgc = settings.ibgc or c_table.bg_color or _clr.set( 0, 000, 000, 000)
135 settings.iselc = settings.iselc or c_table.lss_color or _clr.set( 1, 000, 200, 100)
136
137 if not settings.linedesc or rb.core_list_settings_table then
138 settings.linedesc = settings.linedesc or {}
139 local t_l = rb.core_list_settings_table
140 local linedesc = {
141 separator_height = t_l.list_separator_height or 0,
142 show_cursor = (t_l.cursor_style or 0) == 0,
143 style = t_l.cursor_style or 0xFFFF, --just a random non used index
144 show_icons = t_l.show_icons or false,
145 text_color = c_table.fg_color or _clr.set(-1, 000, 255, 060),
146 line_color = c_table.bg_color or _clr.set( 0, 000, 000, 000),
147 line_end_color= c_table.bg_color or _clr.set( 0, 000, 000, 000),
148 }
149 local styles = {rb.STYLE_NONE, rb.STYLE_INVERT, rb.STYLE_GRADIENT, rb.STYLE_COLORBAR, rb.STYLE_DEFAULT}
150 linedesc.style = styles[linedesc.style + 1] or rb.STYLE_COLORBAR
151
152 for k, v in pairs(linedesc) do
153 --dont overwrite supplied settings
154 settings.linedesc[k] = settings.linedesc[k] or v
155 end
156 end
157
158 settings.hasheader = true
159 settings.co_routine = nil
160 settings.msel = false
161 settings.start = start
162 settings.curpos = vcur
163 --settings.dpad_fn = dpad
164
165 while not i or i > 0 do
166 if copy_screen == true then
167 --make a copy of screen for restoration
168 screen_img = screen_img or rb.new_image()
169 screen_img:copy(_LCD)
170 else
171 screen_img = nil
172 end
173
174 _LCD:clear(settings.ibgc)
175
176 settings.start = start
177 settings.curpos = vcur
178
179 i, start, vcur = print_table(menu_t, #menu_t, settings)
180 --vcur = vcur + 1
181 collectgarbage("collect")
182 if copy_screen == true then _LCD:copy(screen_img) end
183
184 if func_t and func_t[i] then
185 if func_t[i](i, menu_t, func_t) == true then break end
186 else
187 break
188 end
189 end
190 if settings.default == true then settings = nil end
191 return screen_img, i
192end