Page 1 of 2

music widget ver4.

Posted: 20 Aug 2009, 17:37
by smoth
  • 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/
[/size]

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.

Re: Modified the music 2 widget.

Posted: 20 Aug 2009, 19:17
by Gota
Small sugg.
If you haven't done it already than can you make the tracks fade out?instead of stopping abruptly.

Re: Modified the music 2 widget.

Posted: 20 Aug 2009, 20:04
by smoth
Probably not going to bother, works fine for me so far.

I am open to others modifying as I go, if someone wants to add that.

Re: Modified the music 2 widget.

Posted: 23 Aug 2009, 01:29
by zwzsg
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: Select all

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: Select all

Spring.Echo("Track: " .. JustTheName(newTrack))
Note: In playedTime, totalTime = Spring.GetSoundStreamTime(), totalTime is always 4294967040, looks like a bug in Spring.exe

Re: Modified the music 2 widget.

Posted: 23 Aug 2009, 02:33
by SeanHeron
Sounds pretty cool, will have to give it a try!

Re: Modified the music 2 widget.

Posted: 23 Aug 2009, 02:41
by zwzsg
I simplified it into:

Code: Select all

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.

Re: Modified the music 2 widget.

Posted: 23 Aug 2009, 02:48
by lurker
zwzsg wrote:

Code: Select all

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: Select all

string.match(text,"[^\\/]*$")

Re: Modified the music 2 widget.

Posted: 23 Aug 2009, 04:39
by zwzsg
That returned nil, lurker.

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.

Re: Modified the music 2 widget.

Posted: 23 Aug 2009, 05:03
by smoth
zwzsg wrote:That returned nil, lurker.

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.
worked for me honest

Re: Modified the music 2 widget.

Posted: 23 Aug 2009, 05:39
by zwzsg
Now shipping my installer with:

Re: Modified the music 2 widget.

Posted: 24 Aug 2009, 22:56
by Neddie
Now I can reestablish contact with that composer who wanted to work for 1944.

Re: Modified the music 3 widget.

Posted: 02 Sep 2009, 02:10
by smoth
bumpity boo.

Re: Modified the music 3 widget.

Posted: 10 Aug 2011, 05:42
by imkharn
The music.lua is not showing up in widget list in game.
I have restarted spring.

The files were placed in the following locations.

C:\Program Files (x86)\Spring\LuaUI\Widgets\music.lua

C:\Program Files (x86)\Spring\Settings\musicoverride\peace

C:\Program Files (x86)\Spring\Settings\musicoverride\war

What do I need to do differently?

Re: Modified the music 3 widget.

Posted: 10 Aug 2011, 20:09
by smoth
It may be dated and now have issues running with the current spring. I can check it tonight and see about updating it for you.

I honestly wasn't aware people still wanted this.

Re: Modified the music 3 widget.

Posted: 12 Aug 2011, 07:43
by Google_Frog
Of course people still want this. Zero-k uses a version of this that seems to be based off the same widget as the one in this thread.

Re: Modified the music 3 widget.

Posted: 12 Aug 2011, 19:26
by smoth
Lol, ok I'll put it on my to-do list for this weekend then.

Re: Modified the music 3 widget.

Posted: 12 Aug 2011, 19:45
by imkharn
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.

Re: Modified the music 3 widget.

Posted: 12 Aug 2011, 20:22
by smoth
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.

Re: music widget ver4.

Posted: 13 Aug 2011, 02:37
by smoth
because people cannot copy-paste

Re: music widget ver4.

Posted: 13 Aug 2011, 06:11
by Forboding Angel
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.