Last active
April 8, 2022 12:07
-
-
Save aaronamm/41dbf6f46ea3063e383666cda8f0d998 to your computer and use it in GitHub Desktop.
Lua script to pause between each track in seconds for Rockbox DAP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This script adjusted from https://forums.rockbox.org/index.php/topic,54047.0.html. | |
-- Credit to Bilgus | |
require("actions") | |
require("settings") | |
local pauseBetweenEachTrackInSeconds = 5 | |
-- Functions for reading / writing settings | |
local var = {offset = 1, size = 2, type = 3, fields = 3} | |
local function get_var_fields(s_var) | |
-- converts member string into table | |
-- var = {offset, size, "type"} | |
s_var = s_var or "" | |
local o, s, t = string.match(s_var, "(0x%x+),%s*(%d+),%s*(.+)") | |
local tvar = {o, s, t} | |
return #tvar == var.fields and tvar or nil | |
end | |
local function bytesLE_n(str) | |
str = str or "" | |
local tbyte={str:byte(1, -1)} | |
local bpos, num = 1, 0 | |
for k = 1,#tbyte do -- (k = #t, 1, -1 for BE) | |
num = num + tbyte[k] * bpos | |
bpos = bpos * 256 --1<<8 | |
end | |
return num | |
end | |
-- | |
local evt -- Timer handle | |
function playback_event(id, event_data) | |
if id == rb.PLAYBACK_EVENT_CUR_TRACK_READY then | |
rb.splash(0, "Track Ready") | |
elseif id == rb.PLAYBACK_EVENT_TRACK_SKIP then | |
rb.splash(0, "Track Skip") | |
elseif id == rb.PLAYBACK_EVENT_TRACK_BUFFER then | |
rb.splash(0, "Track Buffered") | |
elseif id == rb.PLAYBACK_EVENT_TRACK_CHANGE then | |
rb.splash(0, "Track Change") | |
--rb.audio("pause") | |
evt = rockev.register("timer", tmr_function, rb.HZ * pauseBetweenEachTrackInSeconds) | |
elseif id == rb.PLAYBACK_EVENT_START_PLAYBACK then | |
rb.splash(0, "Start Playback") | |
elseif id == rb.PLAYBACK_EVENT_TRACK_FINISH then | |
rb.splash(0, "Track Finished") | |
elseif id == rb.PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE then | |
rb.splash(0, "Next Track Id3 Available") | |
else | |
rb.splash(0, "unknown id " .. id) | |
end | |
end | |
function tmr_function(id, data) | |
rockev.unregister(evt) -- remove timer | |
rb.audio("resume") | |
rb.splash(rb.HZ * 2, "Timer Fired") | |
rb.lcd_clear_display() | |
rb.lcd_update() | |
rb.splash(0, "Waiting...") | |
end | |
do | |
local act = rb.actions | |
local quit = false | |
function action_event(action) | |
local event | |
if action == act.PLA_EXIT or action == act.PLA_CANCEL then | |
quit = true | |
end | |
end | |
function action_set_quit(bQuit) | |
quit = bQuit | |
end | |
function action_quit() | |
return quit | |
end | |
end | |
local function main() | |
local pbmode = nil; | |
local tvar = get_var_fields(rb.system.global_settings.single_mode) | |
local voffset, vsize, vtype = tvar[var.offset], tvar[var.size], tvar[var.type] | |
if (tvar ~= nil) then | |
local singlemode = 1 | |
pbmode = bytesLE_n(rb.global_settings(voffset, vsize)) | |
if (pbmode ~= nil and pbmode >= 0) then | |
-- set single mode | |
rb.global_settings(voffset, vsize, singlemode) | |
end | |
end | |
local TRACK_CHANGE = 16 | |
local TRACK_BUFFER = 2 | |
local eva = rockev.register("action", action_event) | |
local evp = rockev.register("playback", playback_event, TRACK_CHANGE) | |
rb.lcd_clear_display() | |
rb.lcd_update() | |
rb.splash(0, "Waiting...") | |
while not action_quit() do | |
rb.sleep(rb.HZ / 2) | |
end | |
--restore pbmode | |
if (pbmode ~= nil and pbmode >= 0) then | |
rb.global_settings(voffset, vsize, pbmode) | |
end | |
rb.splash(100, "Goodbye") | |
end | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment