music widget ver4.

music widget ver4.

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

music widget ver4.

Post 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.
Attachments
musicv4.lua
(10.12 KiB) Downloaded 161 times
Last edited by smoth on 14 Aug 2011, 05:30, edited 7 times in total.
User avatar
Gota
Posts: 7151
Joined: 11 Jan 2008, 16:55

Re: Modified the music 2 widget.

Post by Gota »

Small sugg.
If you haven't done it already than can you make the tracks fade out?instead of stopping abruptly.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Modified the music 2 widget.

Post 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.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Modified the music 2 widget.

Post 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
SeanHeron
Engines Of War Developer
Posts: 614
Joined: 09 Jun 2005, 23:39

Re: Modified the music 2 widget.

Post by SeanHeron »

Sounds pretty cool, will have to give it a try!
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Modified the music 2 widget.

Post 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.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Modified the music 2 widget.

Post 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,"[^\\/]*$")
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Modified the music 2 widget.

Post 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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Modified the music 2 widget.

Post 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
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Modified the music 2 widget.

Post by zwzsg »

Now shipping my installer with:
Attachments
music.lua
(2.15 KiB) Downloaded 194 times
User avatar
Neddie
Community Lead
Posts: 9406
Joined: 10 Apr 2006, 05:05

Re: Modified the music 2 widget.

Post by Neddie »

Now I can reestablish contact with that composer who wanted to work for 1944.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Modified the music 3 widget.

Post by smoth »

bumpity boo.
imkharn
Posts: 7
Joined: 10 Aug 2011, 05:39

Re: Modified the music 3 widget.

Post 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?
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Modified the music 3 widget.

Post 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.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Modified the music 3 widget.

Post 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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Modified the music 3 widget.

Post by smoth »

Lol, ok I'll put it on my to-do list for this weekend then.
imkharn
Posts: 7
Joined: 10 Aug 2011, 05:39

Re: Modified the music 3 widget.

Post 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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Modified the music 3 widget.

Post 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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: music widget ver4.

Post by smoth »

because people cannot copy-paste
Attachments
musicv4.lua
(10.13 KiB) Downloaded 120 times
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: music widget ver4.

Post 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.
Post Reply

Return to “Lua Scripts”