Changes made ver 4: - Updated it to handle when no tracks are found - now gets proper title and artist info when available. - put a 4 on the box.
Changes made ver 3: Plays whole track now. I changed the way it changes tracks: If game is going from war to peace the track changes -- Changes to war only, even after skirmish has ceased it will finish said track. I didn't like it constantly stopping the track after raids
Changes made ver 2: - gets the list of music available no required configuration on the user's end. - allows for an over-ride directory this will allow mods to include this widget and if the user hates the music the gay moderwholikesjpop chose he/she can over ride it by placing music in the directories: *SPRINGDIR*/settings/musicoverride/war/ *SPRINGDIR*/'settings/musicoverride/peace/
Important notes:
if your spring is not in programfiles: *SPRINGDIR*/settings/musicoverride/war/ *SPRINGDIR*/'settings/musicoverride/peace/ if your spring is in program files, you may need to place it in userland like so: C:\Users\*username*\Documents\My Games\Spring\Settings\musicoverride\peace
This only supports ogg
Random props:
cake - original author
trepan - he did something, I don't know what though
Lurker - for the hook up on the ogg reading code!
Imkarn - for tracking down that some users need the music in userland.
Error in Update(): [string "C:\Games\KP36\LuaUI..."]:109: bad argument #2 to 'random' (interval is empty)
I suppose that's because I had .mp3 but no .ogg. Make it output something like "No music found!" instead of letting it crash like that.
Make it display just the filename instead of the complete path.
Code:
local function JustTheName(text) local EndIndex=(string.find(text,".",string.len(text)-4,true) or 1+string.len(text))-1 local BeginIndex=1 repeat local NewBeginIndex=string.find(text,"/",BeginIndex,true) or string.find(text,"\\",BeginIndex,true) BeginIndex=NewBeginIndex and NewBeginIndex+1 or BeginIndex until not NewBeginIndex return string.sub(text,BeginIndex,EndIndex) end
Code:
Spring.Echo("Track: " .. JustTheName(newTrack))
Note: In playedTime, totalTime = Spring.GetSoundStreamTime(), totalTime is always 4294967040, looks like a bug in Spring.exe
function widget:GetInfo() return { name = "Music", desc = "Plays music", author = "cake, Smoth, zwzsg", date = "Mar 01, 2008, Aug 20 2009", license = "GNU GPL, v2 or later", layer = 0, enabled = true -- loaded by default? } end
local AllTracks = VFS.DirList('music/','*.ogg') local CurrentTrack = nil local info = ""
local function JustTheName(text) local EndIndex=(string.find(text,".",string.len(text)-4,true) or 1+string.len(text))-1 local BeginIndex=1 repeat local NewBeginIndex=string.find(text,"/",BeginIndex,true) or string.find(text,"\\",BeginIndex,true) BeginIndex=NewBeginIndex and NewBeginIndex+1 or BeginIndex until not NewBeginIndex return string.sub(text,BeginIndex,EndIndex) end
function widget:Initialize() if not AllTracks or #AllTracks<1 then Spring.Echo("No music found!") else math.randomseed(os.clock()) math.random() math.random() end end
function widget:Shutdown() Spring.StopSoundStream() end
function widget:Update() local playedTime, totalTime = Spring.GetSoundStreamTime() info = "playedTime="..(playedTime or "nil").."\ntotalTime="..(totalTime or "nil") if not playedTime or playedTime==0 and #AllTracks>=1 then CurrentTrack = AllTracks[math.random(1, #AllTracks)] Spring.PlaySoundStream(CurrentTrack, WG.musicVolume or 0.5) Spring.Echo("Track: "..JustTheName(CurrentTrack)) end end
function widget:DrawScreen() gl.Text(info,0,150,16) end
And there are two huge bugs: 1) Always pick the same first track. Please make Spring.exe update the widget random generator! No, math.randomseed(os.clock()) does not help.
2) Just like Smoth version, when it's done playing a song, it gets stuck repeating the last seconds of it.
Joined: 08 Jan 2007, 06:13 Location: Don't be silly. If there's no machine heaven, where do all the toasters go?
zwzsg wrote:
Code:
local function JustTheName(text) local EndIndex=(string.find(text,".",string.len(text)-4,true) or 1+string.len(text))-1 local BeginIndex=1 repeat local NewBeginIndex=string.find(text,"/",BeginIndex,true) or string.find(text,"\\",BeginIndex,true) BeginIndex=NewBeginIndex and NewBeginIndex+1 or BeginIndex until not NewBeginIndex return string.sub(text,BeginIndex,EndIndex) end
Oh, and Smoth, don't bother making a volume bar, as the volume parameter is not taken into account in PlaySoundStream. Spring.SetConfigInt("snd_volmusic",volume) does nothing either.
Oh, and Smoth, don't bother making a volume bar, as the volume parameter is not taken into account in PlaySoundStream. Spring.SetConfigInt("snd_volmusic",volume) does nothing either.
Lol. I can't imagine why it wouldnt be the most desired addon.
With the creation of Spring, Total A has been completely recreated except for one thing: the award winning music that brings back both amazing memories and defines the emotion of both peace and war.
Thanks for updating the music lua. Me and the several people I play with are looking forward to it.
Not a problem, what time zone are you in? I am cst and usually can be found in #gundam. I should either have it updated or be working on it saturday. So feel free to hunt me down.
Updating it should not be a time consuming thing I am just busy during the week and the 1-1.5 hour drive everyday eats a lot of my time. If it wasn't for that I would already have a fix for you.
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
I had a lot of trouble with v3 sometimes stuttering. Any chance v4 might not do it so much? Also, a quick 0.5sec fade when the tracks change would be nice.
Users browsing this forum: No registered users and 1 guest
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum