Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Welcome to the Rockbox Technical Forums!

+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  Here is a plugin for randomly changing the playlist with a timer(LUA)
« previous next »
  • Print
Pages: [1]

Author Topic: Here is a plugin for randomly changing the playlist with a timer(LUA)  (Read 1972 times)

Offline rokboxyo

  • Member
  • *
  • Posts: 17
Here is a plugin for randomly changing the playlist with a timer(LUA)
« on: September 14, 2018, 09:35:57 PM »
I wanted to make a plugin for the feature I requested in this thread
aka automatically change the playlist randomly after X minutes have passed.
Because I have a lot of different songs across lots of different playlists and having to select a playlist myself kinda kills the mood, especially while driving.
So I made this LUA plugin because I can't compile the C code right now.

The advantage of using a LUA script is that it can be easily modified to fit other needs

(ATTENTION : LUA plugins might not work with rockbox 3.14, you'll need to download the latest dev release)
« Last Edit: December 07, 2018, 04:50:06 PM by rokboxyo »
Logged

Offline rokboxyo

  • Member
  • *
  • Posts: 17
Re: Here is a plugin for randomly changing the playlist with a timer(LUA)
« Reply #1 on: September 14, 2018, 09:48:52 PM »
How it works:
first you need to make a file named "playlist_randomizer_config.txt" located in the plugin dir (/.rockbox/rocks/apps/).

It should look like this
Code: [Select]
/playlists/jingles.m3u8
25
funk.m3u8
rock.m3u8
new_wave.m3u8
(...)
  • First line should be the name (including path) of a playlist containing little transitions pieces  that will be played on each playlist changes (to make like a radio broadcast feel).  The plugin will choose one transition tune randomly from this playlist on each change.
    If this playlist doesn't exist, there will be no transitions played, so put a dummy value on the first line if you don't want transitions.
  • Second line should be an integer indicating the number of minutes before the playlist is randomly changed
  • Following lines should be a list of all the playlists among which the plugin will select a new playlist to play. One playlist name per line and at least 3 playlists minimum (because the plugin makes sure that the 2 last played playlists are not repeated)
    You must not indicate the path because the plugin assumes all the playlists are located in the "/playlists/" directory.




Then just copy this code to a lua file in the plugin app directory and run it, it's pretty straightforward, I think I have explained everything already

Code: [Select]
-- ROCKBOX META SHUFFLER
-- This script shuffles playlist on a timer
-- version 2.5 (december 7th 2018)
-- works with rockbox dev-release 9450689483-181207 and later
-- creator @rockboxyo
-- This program is free software; you can redistribute it and/or  modify it under the terms of the GNU General Public License  as
-- published by the Free Software Foundation; either version 2  of the License, or (at your option) any later version.

-- This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.


require("actions")   
require("rbcompat")

local pl={} -- array of playlist names
local pl_count=-2 -- total number of playlists
local minutes_of_play=40  --number of minutes for each playlist before switch
local trans_pl  -- name of transition playlist
local prev_pl={} -- keeps track of 2 previous playlists to avoid repeating
local prev_switch=0
local seconds_elapsed=0
local ticks_elapsed=0  -- time since new playlist started
local last_tick=0
local current_tick=0
local action -- input  management

function changePlaylist()
local trans_nr=0  -- number of available transitions
local trans_name
local nr=0
rb.lcd_clear_display()

-- first choose random indice not recently played
repeat
nr=math.random(0,pl_count-1)
until nr~=prev_pl[0] and nr~=prev_pl[1]
prev_pl[prev_switch]=nr
prev_switch=1-prev_switch
local playlist_name=pl[nr]

-- set playlist
rb.audio("stop")
rb.playlist("create","/Playlists/",playlist_name)
rb.playlist("shuffle",rb.current_tick(),0)

--add transition if apply
local file = io.open(trans_pl, "r")
if not file then
rb.splash(3*rb.HZ,"transition FILE NOT FOUND !")
else
for line in file:lines() do
trans_nr =trans_nr +1
end

nr=math.random(1,trans_nr)
file:seek("set")
for i=1,nr do
trans_name=file:read("*l")
end
rb.playlist("insert_track",trans_name,0 ,true,-1)
end

--start play
rb.sleep(2*rb.HZ)  -- added this to void buffering problems (?)
rb.playlist("start",0,0,0)
last_tick=rb.current_tick()
current_tick=last_tick
seconds_elapsed=0
ticks_elapsed=0
rb.lcd_clear_display()
rb.splash(2*rb.HZ, "now playing: "..playlist_name)
end


-- MAIN SCRIPT

math.randomseed(rb.current_tick())
rb.lcd_clear_display()
prev_pl[0]=-1
prev_pl[1]=-1

local file = io.open("/.rockbox/rocks/apps/playlist_randomizer_config.txt", "r")
if not file then
rb.splash(3*rb.HZ,"CONFIG FILE NOT FOUND !")
return nil
else

for line in file:lines() do
pl[pl_count]=line
pl_count=pl_count+1
end
if pl_count<=1 then
rb.splash(4*rb.HZ,"ERROR: No playlist found in file!")
return nil
end

trans_pl=pl[-2]
minutes_of_play=tonumber(pl[-1])

file:close()

--if rockbox is currently playing when plugin is started, then this will not change the playlist
if rb.audio("status")==0 then
changePlaylist()
else
rb.splash(3*rb.HZ,"Playlist randomized in "..minutes_of_play.." minutes...")
end

repeat
current_tick=rb.current_tick()
if current_tick>last_tick then
ticks_elapsed=ticks_elapsed+(current_tick-last_tick)
last_tick=current_tick
if ticks_elapsed>=rb.HZ then
ticks_elapsed=ticks_elapsed-rb.HZ
seconds_elapsed=seconds_elapsed+1
if seconds_elapsed>=(60*minutes_of_play) then
changePlaylist()
end
end

end

action = rb.get_action(rb.contexts.CONTEXT_STD, rb.HZ)
if action==rb.actions.ACTION_STD_OK then
changePlaylist()
end
until action == rb.actions.ACTION_STD_CANCEL or action == rb.actions.ACTION_STD_MENU

--rb.audio_stop()
end




-Use the EXIT or BACK button to stop the plugin and the OK button to force a playlist change immediately
-the plugin doesnt stop the music if something is already playing, so you will keep the current playlist until the delay is elapsed, you can still force a change with the OKAY button
-the music keeps playing when you leave the plugin, so if you want to remain on a particular playlist, you can just exit the plugin.

(version 2.5 - 07/12/2018)
« Last Edit: December 10, 2018, 02:24:49 PM by rokboxyo »
Logged

Offline rokboxyo

  • Member
  • *
  • Posts: 17
Re: Here is a plugin for randomly changing the playlist with a timer(LUA)
« Reply #2 on: September 25, 2018, 05:52:15 PM »
This plugin's display is currently pretty crude, but that's because the things exposed to LUA are rather limited at the moment.
I hope to be able to display a nice HUD with  song informations, etc as soon as more options get available in rockbox LUA.
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 537
Re: Here is a plugin for randomly changing the playlist with a timer(LUA)
« Reply #3 on: September 26, 2018, 02:19:42 AM »
Most of the backend for rliimage is in lua (last few dev versions of RB)  I'll have an update finished in the next week or so that speeds it up a bit but you can check out the sample programs to see how it works

http://forums.rockbox.org/index.php/topic,52352.0.html

Logged

Offline rokboxyo

  • Member
  • *
  • Posts: 17
Re: Here is a plugin for randomly changing the playlist with a timer(LUA)
« Reply #4 on: October 01, 2018, 12:28:22 PM »
Quote from: Bilgus on September 26, 2018, 02:19:42 AM
Most of the backend for rliimage is in lua (last few dev versions of RB)  I'll have an update finished in the next week or so that speeds it up a bit but you can check out the sample programs to see how it works

http://forums.rockbox.org/index.php/topic,52352.0.html

Thanks for your work on LUA. I think scripting will be a big next step for rockbox, it will fill many user needs such as in my case and reduce the requests for new features. It opens a whole world of possibilities for rockbox without having to mess with the source.

Those graphic routines are great, but my problem right now is that I need to retrieve informations on the song that is currently playing ; title, artist, album art, playtime, elapsed time, etc... I don't think this is possible in LUA at the moment. Or is it?
« Last Edit: October 01, 2018, 12:30:06 PM by rokboxyo »
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 537
Re: Here is a plugin for randomly changing the playlist with a timer(LUA)
« Reply #5 on: October 01, 2018, 06:51:54 PM »
Oh looking at it I guess it isn't I'll see about adding it with the global settings and status update
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 537
Re: Here is a plugin for randomly changing the playlist with a timer(LUA)
« Reply #6 on: October 11, 2018, 10:37:21 AM »
See here for grabbing track info:
http://forums.rockbox.org/index.php/topic,52509.0.html
Logged

Offline rokboxyo

  • Member
  • *
  • Posts: 17
Re: Here is a plugin for randomly changing the playlist with a timer(LUA)
« Reply #7 on: October 14, 2018, 10:59:27 PM »
Quote from: Bilgus on October 11, 2018, 10:37:21 AM
See here for grabbing track info:
http://forums.rockbox.org/index.php/topic,52509.0.html
Oh thanks, I'll test it when I have a chance 8)
Logged

Offline rokboxyo

  • Member
  • *
  • Posts: 17
Re: Here is a plugin for randomly changing the playlist with a timer(LUA)
« Reply #8 on: December 07, 2018, 04:45:47 PM »
I made it compatible with the latest LUA changes, I'll make a fancy interface later
Logged

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  Here is a plugin for randomly changing the playlist with a timer(LUA)
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.116 seconds with 22 queries.