Welcome to the Rockbox Technical Forums!
local print = require("print")local _draw = require("draw")local _poly = require("draw_poly")local _clr = require("color")require("actions")require("rbsettings")require("settings")local metadata = rb.settings.readlocal cur_trk = "audio_current_track"local track_data = {}-- grab only settings we are interested intrack_data.title = rb.metadata.mp3_entry.titletrack_data.path = rb.metadata.mp3_entry.pathdo -- free up some ram by removing items we don't need local function strip_functions(t, ...) local t_keep = {...} local keep for key, val in pairs(t) do keep = false for _, v in ipairs(t_keep) do if string.find (key, v) then keep = true; break end end if keep ~= true then t[key] = nil end end end strip_functions(rb.actions, "PLA_", "TOUCHSCREEN", "_NONE") rb.contexts = nil strip_functions(_draw, "^rect$", "^rect_filled$") strip_functions(_poly, "^polyline$") strip_functions(print.opt, "line", "get") _clr.inc = nil rb.metadata = nil -- remove metadata settings rb.system = nil -- remove system settings rb.settings.dump = nil collectgarbage("collect")endlocal t_icn = {}t_icn[1] = {16,16,16,4,10,10,10,4,4,10,10,16,10,10} -- rewindt_icn[2] = {4,5,4,15,10,9,10,15,12,15,12,5,10,5,10,11,4,5} -- play/pauset_icn[3] = {4,4,4,16,10,10,10,16,16,10,10,4,10,10} -- fast forwardlocal pb = {}local track_lengthlocal track_name = metadata(cur_trk, track_data.title) or metadata(cur_trk, track_data.path)local clr_active = _clr.set(1, 0, 255, 0)local clr_inactive = _clr.set(0, 255, 255, 255)local t_clr_icn = {clr_inactive, clr_inactive, clr_inactive}local function set_active_icon(idx) local tClr = t_clr_icn if idx == 4 and t_clr_icn[4] == clr_active then idx = 2 end for i = 1, 4 do t_clr_icn[i] = clr_inactive end if idx >= 1 and idx <= 4 then t_clr_icn[idx] = clr_active endendlocal function clear_actions() track_length = (rb.audio("length") or 0) local playback = rb.audio("status") if playback == 1 then set_active_icon(2) elseif playback == 3 then set_active_icon(4) return end rockev.trigger("timer", false, rb.current_tick() + rb.HZ * 60)endlocal audio_elapsed, audio_ff_rewdo local elapsed = 0 local ff_rew = 0 audio_elapsed = function() if ff_rew == 0 then elapsed = (rb.audio("elapsed") or 0) end return elapsed end audio_ff_rew = function(time_ms) if ff_rew ~= 0 and time_ms == 0 then rb.audio("stop") rb.audio("play", elapsed, 0) rb.sleep(100) elseif time_ms ~= 0 then elapsed = elapsed + time_ms if elapsed < 0 then elapsed = 0 end if elapsed > track_length then elapsed = track_length end end ff_rew = time_ms endenddo local act = rb.actions local quit = false local last_action = 0 local magnitude = 1 local skip_ms = 1000 local playback function action_event(action) local event if action == act.PLA_EXIT or action == act.PLA_CANCEL then quit = true elseif action == act.PLA_RIGHT_REPEAT then event = pb.TRACK_FF audio_ff_rew(skip_ms * magnitude) magnitude = magnitude + 1 elseif action == act.PLA_LEFT_REPEAT then event = pb.TRACK_REW audio_ff_rew(-skip_ms * magnitude) magnitude = magnitude + 1 elseif action == act.PLA_SELECT then playback = rb.audio("status") if playback == 1 then rb.audio("pause") collectgarbage("collect") elseif playback == 3 then rb.audio("resume") end event = rb.audio("status") + 1 elseif action == act.ACTION_NONE then magnitude = 1 audio_ff_rew(0) if last_action == act.PLA_RIGHT then rb.audio("next") elseif last_action == act.PLA_LEFT then rb.audio("prev") end end if event then -- pass event id to playback_event rockev.trigger(pb.EV, true, event) end last_action = action end function action_quit() return quit endenddo pb.EV = "playback" -- custom event ids pb.STOPPED = 1 pb.PLAY = 2 pb.PAUSE = 3 pb.PAUSED = 4 pb.TRACK_REW = 5 pb.PLAY_ = 6 pb.TRACK_FF = 7 function playback_event(id, event_data) if id == pb.PLAY then id = pb.PLAY_ elseif id == pb.PAUSE then id = 8 elseif id == rb.PLAYBACK_EVENT_TRACK_BUFFER or id == rb.PLAYBACK_EVENT_TRACK_CHANGE then track_name = metadata(cur_trk, track_data.title) or metadata(cur_trk, track_data.path) else -- rb.splash(0, id) end set_active_icon(id - 4) rockev.trigger("timer", false, rb.current_tick() + rb.HZ) endendlocal function pbar_init(img, x, y, w, h, fgclr, bgclr, barclr) local t -- when initialized table is returned that points back to this function if type(img) == "table" then t = img t.pct = x if not t.set then error("not initialized", 2) end else t = {} t.img = img or rb.lcd_framebuffer() t.x = x or 1 t.y = y or 1 t.w = w or 10 t.h = h or 10 t.pct = 0 t.fgclr = fgclr or _clr.set(-1, 255, 255, 255) t.bgclr = bgclr or _clr.set(0, 0, 50, 200) t.barclr = barclr or t.fgclr t.set = pbar_init setmetatable(t,{__call = t.set}) return t end -- initalization--============================================================================-- if t.pct < 0 then t.pct = 0 elseif t.pct > 100 then t.pct = 100 end local wp = t.pct * (t.w - 4) / 100 if wp < 1 and t.pct > 0 then wp = 1 end _draw.rect_filled(t.img, t.x, t.y, t.w, t.h, t.fgclr, t.bgclr, true) _draw.rect_filled(t.img, t.x + 2, t.y + 2, wp, t.h - 4, t.barclr, nil, true)end -- pbar_initlocal function main() clear_actions() local lcd = rb.lcd_framebuffer() local eva = rockev.register("action", action_event) local evc = rockev.register("custom", rb.lcd_update) local evp = rockev.register("playback", playback_event) local evt = rockev.register("timer", clear_actions, rb.HZ) rockev.trigger("custom", true) rb.lcd_clear_display() do -- configure print function local t_print = print.opt.get(true) t_print.autoupdate = false t_print.justify = "center" t_print.col = 2 end local progress = pbar_init(nil, 1, rb.LCD_HEIGHT - 5, rb.LCD_WIDTH - 1, 5) local i = 0 local colw = (rb.LCD_WIDTH - 16) / 4 local scr_col = {colw, colw * 2, colw * 3} --local mem = collectgarbage("count") --local mem_min = mem --local mem_max = mem while not action_quit() do elapsed = audio_elapsed() progress(track_length > 0 and elapsed / (track_length / 100) or 0) print.opt.line(1) print.f() -- clear the line print.f(track_name) print.f() -- clear the line _,_,_,h = print.f("%ds / %ds", elapsed / 1000, track_length / 1000) for i = 1, 3 do _poly.polyline(lcd, scr_col[i], h * 2 + 1, t_icn[i], t_clr_icn[i], true) end--[[ mem = collectgarbage("count") if mem < mem_min then mem_min = mem end if mem > mem_max then mem_max = mem end if i >= 10 then rb.splash(0, mem_min .. " : " .. mem .. " : " ..mem_max) i = 0 else i = i + 1 end]] rb.sleep(rb.HZ / 2) end rockev.trigger("custom", false) -- have to manually reset custom events rb.splash(100, "exiting")endmain()
print.f("Go To: %s", time_formatted(goToMs, goToMode), time_formatted(elapsed or 0), time_formatted(track_length or 0))
audio_seek(goToMs)
Page created in 0.148 seconds with 21 queries.