View topic - music widget ver4.



All times are UTC + 1 hour


Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: music widget ver4.
PostPosted: 20 Aug 2009, 16:37 
Content Developer
User avatar

Joined: 13 Jan 2005, 00:46
Location: ModalitÃ
  • 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.


Attachments:
musicv4.lua [10.12 KiB]
Downloaded 129 times


Last edited by smoth on 14 Aug 2011, 04:30, edited 7 times in total.
Top
 Offline Profile  
 
PostPosted: 20 Aug 2009, 18:17 
Supreme Annihilation Maintainer
User avatar

Joined: 11 Jan 2008, 16:55
Small sugg.
If you haven't done it already than can you make the tracks fade out?instead of stopping abruptly.


Top
 Offline Profile  
 
PostPosted: 20 Aug 2009, 19:04 
Content Developer
User avatar

Joined: 13 Jan 2005, 00:46
Location: ModalitÃ
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.


Top
 Offline Profile  
 
PostPosted: 23 Aug 2009, 00:29 
Kernel Panic Co-Developer
User avatar

Joined: 16 Nov 2004, 13:08
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


Top
 Offline Profile  
 
PostPosted: 23 Aug 2009, 01:33 
Engines Of War Developer

Joined: 09 Jun 2005, 22:39
Location: Germany, the EU
Sounds pretty cool, will have to give it a try!


Top
 Offline Profile  
 
PostPosted: 23 Aug 2009, 01:41 
Kernel Panic Co-Developer
User avatar

Joined: 16 Nov 2004, 13:08
I simplified it into:
Code:
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.


Top
 Offline Profile  
 
PostPosted: 23 Aug 2009, 01:48 
Redacted
User avatar

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

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


Top
 Offline Profile  
 
PostPosted: 23 Aug 2009, 03:39 
Kernel Panic Co-Developer
User avatar

Joined: 16 Nov 2004, 13:08
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.


Top
 Offline Profile  
 
PostPosted: 23 Aug 2009, 04:03 
Content Developer
User avatar

Joined: 13 Jan 2005, 00:46
Location: ModalitÃ
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


Top
 Offline Profile  
 
PostPosted: 23 Aug 2009, 04:39 
Kernel Panic Co-Developer
User avatar

Joined: 16 Nov 2004, 13:08
Now shipping my installer with:


Attachments:
music.lua [2.15 KiB]
Downloaded 180 times
Top
 Offline Profile  
 
PostPosted: 24 Aug 2009, 21:56 
Community Lead
User avatar

Joined: 10 Apr 2006, 04:05
Location: Finland, 1944
Now I can reestablish contact with that composer who wanted to work for 1944.


Top
 Offline Profile  
 
PostPosted: 02 Sep 2009, 01:10 
Content Developer
User avatar

Joined: 13 Jan 2005, 00:46
Location: ModalitÃ
bumpity boo.


Top
 Offline Profile  
 
PostPosted: 10 Aug 2011, 04:42 

Joined: 10 Aug 2011, 04:39
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?


Top
 Offline Profile  
 
PostPosted: 10 Aug 2011, 19:09 
Content Developer
User avatar

Joined: 13 Jan 2005, 00:46
Location: ModalitÃ
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.


Top
 Offline Profile  
 
PostPosted: 12 Aug 2011, 06:43 
Moderator

Joined: 12 Oct 2007, 08:24
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.


Top
 Offline Profile  
 
PostPosted: 12 Aug 2011, 18:26 
Content Developer
User avatar

Joined: 13 Jan 2005, 00:46
Location: ModalitÃ
Lol, ok I'll put it on my to-do list for this weekend then.


Top
 Offline Profile  
 
PostPosted: 12 Aug 2011, 18:45 

Joined: 10 Aug 2011, 04:39
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.


Top
 Offline Profile  
 
PostPosted: 12 Aug 2011, 19:22 
Content Developer
User avatar

Joined: 13 Jan 2005, 00:46
Location: ModalitÃ
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.


Top
 Offline Profile  
 
 Post subject: Re: music widget ver4.
PostPosted: 13 Aug 2011, 01:37 
Content Developer
User avatar

Joined: 13 Jan 2005, 00:46
Location: ModalitÃ
because people cannot copy-paste


Attachments:
musicv4.lua [10.13 KiB]
Downloaded 108 times
Top
 Offline Profile  
 
 Post subject: Re: music widget ver4.
PostPosted: 13 Aug 2011, 05:11 
Evolution RTS Developer
User avatar

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.


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.