Musics! - Page 2

Musics!

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

Moderator: Moderators

ZellSF
Posts: 1187
Joined: 08 Jul 2006, 19:07

Re: Musics!

Post by ZellSF »

Beherith wrote:
ZellSF wrote: hotkey solutions won't work you just can't easily hotkey every action, especially considering lots of key combinations are used by Spring, and considering Spring's a very mouse based game, there's lots of times when you don't even have your hands at they keyboard.
I think you misunderstood me. I have a music player app running in the background, and my keyboard has media keys that spring doesnt use. So i can control the media player while playing spring.

I dunno what kind of mouse you have, but mine only requires use of my right hand, so I always have my left hand on the keyboard.
Uh, it's a needless hassle to keep your left hand on your keyboard just to control your media player, it's also inconvenient to start/close the media player, and the media keys lacks some functions (playback order, playlist switcher and from what I can see, neither works easily as hotkeys in foobar2000). That's not even mentioning that changing two different volumes using seperate volume controls is sort of annoying and even with a hotkey to switch between building and battle music, I would still end up using more time managing my media player than playing the game.
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: Musics!

Post by Beherith »

ZellSF wrote: Uh, it's a needless hassle to keep your left hand on your keyboard just to control your media player, it's also inconvenient to start/close the media player, and the media keys lacks some functions (playback order, playlist switcher and from what I can see, neither works easily as hotkeys in foobar2000). That's not even mentioning that changing two different volumes using seperate volume controls is sort of annoying and even with a hotkey to switch between building and battle music, I would still end up using more time managing my media player than playing the game.
Oh... right. I rarely if ever actually access the music player for anything else than skipping to the next track while ingame, especially if im in a heavy battle: then the focus is totally elsewhere and I couldnt tell you what track played last.

On the other hand, I find Tchaikovskys Overture 1812 to be especially fitting for spring: no need to switch between building and battle tracks, as the recording has enough variance already :)
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Re: Musics!

Post by SinbadEV »

Seriously... are you people arguing over weather or not dynamic music would be awesome or not? Who do I need to hit to make you stop?

Dynamic music is awesome. There, argument over.

Suggesting you can implement a hotkey to change the music to simulate the effect of dynamic music is like saying you could have a DVD movie without soundtrack being accompanied with a CD that contains various tracks and you can switch to a different track if the music doesn't fit the on screen activity.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Musics!

Post by Forboding Angel »

Sinbad wins +1 internet.

100% agreement.
User avatar
LOrDo
Posts: 1154
Joined: 27 Feb 2006, 00:21

Re: Musics!

Post by LOrDo »

Naturally I agree. Can you name a single successful game that dosn't have at least some sort of soundtrack? If we get an OGG player, even if its not dynamic, spring WILL get a soundtrack. Thats one thing I can gauruntee. Now who wouldn't want that?
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Re: Musics!

Post by bobthedinosaur »

whos making the muzak?
User avatar
LOrDo
Posts: 1154
Joined: 27 Feb 2006, 00:21

Re: Musics!

Post by LOrDo »

Some guy whos name escapes me was supposed to be making an exclusive soundtrack for spring, but Im not sure where he ended up. I had someone else in mind though...
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Musics!

Post by Stealth870 »

PlaySoundStream("file.ogg" [, volume, x, y, z]) -> nil).

Can someone explain to me how this works a little better? I'm dabbling in a widget here just to see how LUA works. If I call something like:
PlaySoundStream("file.ogg",1)

That should mean play file.ogg at full (1.0) volume right? The rest of the parameters (x,y,z) are supposedly ignored in this function? Also, if I call the function twice, with the same file but different volumes, does it update the volume of the current playing ogg or start another at that level?

So far it seems that I can't call a second stream at all to update the volume. Plus, it seems my volume parameter is being ignored as well as I couldn't hear a difference in my tests with 1 and 0.1 volume levels.
User avatar
smartie
NOTA Developer
Posts: 146
Joined: 23 Jun 2005, 19:29

Re: Musics!

Post by smartie »

I wrote a quick and dirty music widget. You have to convert the mp3 files for the ta music to ogg and put them in Spring/music

There's a whole lot of ways this could be improved. I couldn't get the volume control working either, so it plays at full volume instead of 0.2. Another thing is the widget decides between battle music and peace music by how many allied units have been killed. Widgets don't have access to information like how much damage is being dealt, or how many enemy units you are killing. If you've got a krogoth an there's a big battle, and it's killing a bunch of guys, then there's nothing going on so far as the widget is concerned. Up until your team starts losing units. Also, I made it so that a big unit dying (units that cost over 1000 metal) will cause it to kick into battle music immediatly. This makes it a bit smarter for knowing when a battle is going on. Basiclly a big unit is worth 5 small units, and units that have died in the past 15 seconds count double towards the battle music counter.

I think you really have to make dynamic music into a gadget if you want to get it to be intelligent enough.

The biggest problem though is there doesn't seem to be any way to check if a track is finished playing. You can tell it to start playing a track, and you can tell it to stop, but there isnt' any way to know if it's finished the track, or if it's still going. The way around this is to have the widget constantly update, telling it to play a new track. If it's currently playing something it ignores the command. If it's finished playing then it starts the new track.

Just a warning, this isn't great coding. I coudn't remember how to do arrays in lua, so I have 15 seperate varibles, crap like that. Also if you look in the code I put HACK into the comments in the part where I changed the update from once every second to once every 3 seconds. Just pretend the doodsKilled_1sec, doodsKilled_2sec, doodsKilled_3sec instead say doodsKilled_3sec, doodsKilled_6sec, doodsKilled_9sec. 8)

Code: Select all

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--  file:    music.lua
--  brief:   yay music
--  author:  cake
--
--  Copyright (C) 2007.
--  Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function widget:GetInfo()
  return {
    name      = "Music",
    desc      = "Plays Music",
    author    = "cake",
    date      = "Feb 21, 2008",
    license   = "GNU GPL, v2 or later",
    layer     = 0,
    enabled   = true  --  loaded by default?
  }
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local musicType = 0  -- 0 peace, 1 war
local doodsKilled_1sec = 0
local doodsKilled_2sec = 0
local doodsKilled_3sec = 0
local doodsKilled_4sec = 0
local doodsKilled_5sec = 0
local doodsKilled_6sec = 0
local doodsKilled_7sec = 0
local doodsKilled_8sec = 0
local doodsKilled_9sec = 0
local doodsKilled_10sec = 0
local doodsKilled_11sec = 0
local doodsKilled_12sec = 0
local doodsKilled_13sec = 0
local doodsKilled_14sec = 0
local doodsKilled_15sec = 0
local millisecondcount = 0

local WarTrackPick = 2 -- war tracks are 02 thru 08
local PeaceTrackPick = 9 -- peace tracks are 09 thru 17

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


function widget:Initialize()
end


function widget:Shutdown()
  Spring.StopSoundStream()
end

function widget:Update(dt)
  millisecondcount = millisecondcount + dt
  if (millisecondcount > 3) then  -- hack for 3 seconds instead of 1
    millisecondcount = 0 -- one second has gone by -- HACK 3 seconds

    local totalKilled = ((doodsKilled_5sec + doodsKilled_4sec + doodsKilled_3sec + doodsKilled_2sec + doodsKilled_1sec) * 2) + (doodsKilled_6sec + doodsKilled_7sec + doodsKilled_8sec + doodsKilled_9sec + doodsKilled_10sec) + (doodsKilled_11sec + doodsKilled_12sec + doodsKilled_13sec + doodsKilled_14sec + doodsKilled_15sec)
    doodsKilled_15sec = doodsKilled_14sec
    doodsKilled_14sec = doodsKilled_13sec
    doodsKilled_13sec = doodsKilled_12sec
    doodsKilled_12sec = doodsKilled_11sec
    doodsKilled_11sec = doodsKilled_10sec
    doodsKilled_10sec = doodsKilled_9sec
    doodsKilled_9sec = doodsKilled_8sec
    doodsKilled_8sec = doodsKilled_7sec
    doodsKilled_7sec = doodsKilled_6sec
    doodsKilled_6sec = doodsKilled_5sec
    doodsKilled_5sec = doodsKilled_4sec
    doodsKilled_4sec = doodsKilled_3sec
    doodsKilled_3sec = doodsKilled_2sec
    doodsKilled_2sec = doodsKilled_1sec
    doodsKilled_1sec = 0
    
    if (totalKilled > 8) then -- interrupt and start battle music
      if (musicType == 0) then
        Spring.StopSoundStream()
        musicType = 1
      end
    end
    if (totalKilled == 0) then -- stop battle music and go back to peace
      if (musicType == 1) then
        Spring.StopSoundStream()
        musicType = 0
      end
    end
    if (musicType == 0) then
      PeaceTrackPick = PeaceTrackPick + 1
      if (PeaceTrackPick > 17) then
        PeaceTrackPick = 9
      end
      if (PeaceTrackPick == 9) then
        Spring.PlaySoundStream("music/09.ogg",0.2)
      end
      if (PeaceTrackPick == 10) then
        Spring.PlaySoundStream("music/10.ogg",0.2)
      end
      if (PeaceTrackPick == 11) then
        Spring.PlaySoundStream("music/11.ogg",0.2)
      end
      if (PeaceTrackPick == 12) then
        Spring.PlaySoundStream("music/12.ogg",0.2)
      end
      if (PeaceTrackPick == 13) then
        Spring.PlaySoundStream("music/13.ogg",0.2)
      end
      if (PeaceTrackPick == 14) then
        Spring.PlaySoundStream("music/14.ogg",0.2)
      end
      if (PeaceTrackPick == 15) then
        Spring.PlaySoundStream("music/15.ogg",0.2)
      end
      if (PeaceTrackPick == 16) then
        Spring.PlaySoundStream("music/16.ogg",0.2)
      end
      if (PeaceTrackPick == 17) then
        Spring.PlaySoundStream("music/17.ogg",0.2)
      end
    end
    if (musicType == 1) then
      WarTrackPick = WarTrackPick + 1
      if (WarTrackPick > 8) then
        WarTrackPick = 2
      end
      if (WarTrackPick == 2) then
        Spring.PlaySoundStream("music/02.ogg", 0.2)
      end
      if (WarTrackPick == 3) then
        Spring.PlaySoundStream("music/03.ogg", 0.2)
      end
      if (WarTrackPick == 4) then
        Spring.PlaySoundStream("music/04.ogg", 0.2)
      end
      if (WarTrackPick == 5) then
        Spring.PlaySoundStream("music/05.ogg", 0.2)
      end
      if (WarTrackPick == 6) then
        Spring.PlaySoundStream("music/06.ogg", 0.2)
      end
      if (WarTrackPick == 7) then
        Spring.PlaySoundStream("music/07.ogg", 0.2)
      end
      if (WarTrackPick == 8) then
        Spring.PlaySoundStream("music/08.ogg", 0.2)
      end
    end
  end
end

function widget:UnitDestroyed(unitID, unitDefID, teamID)
  local PlayerTeam = Spring.GetMyTeamID()
  --Spring.Echo(PlayerTeam)
  --if (teamID == PlayerTeam) then
    --Spring.Echo('thats my dude youre blowing up')
  --end
  doodsKilled_1sec = doodsKilled_1sec + 1
  if (UnitDefs[unitDefID].metalCost > 1000) then
  doodsKilled_1sec = doodsKilled_1sec + 4
  end
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Last edited by smartie on 23 Feb 2008, 23:31, edited 1 time in total.
user
Posts: 452
Joined: 22 Jan 2008, 16:33

Re: Musics!

Post by user »

use <name of array> = {}

to make a 2d array:

<name of array>[<number>] = {}

for a 3d array:

<name of array>[<number>][<number>] = {}

the problem of playing music using lua, is that the sound quality is not good, or something like that.
User avatar
Stealth870
Posts: 166
Joined: 13 Sep 2004, 00:25

Re: Musics!

Post by Stealth870 »

To me, the music sounded fine, definitely nothing horrendously bad to make me NOT want music ingame. However, there aren't enough Lua options to do this properly. Volume doesn't work, and there's no control over the sound file or it's position.
User avatar
TheFatController
Balanced Annihilation Developer
Posts: 1177
Joined: 10 Dec 2006, 18:46

Re: Musics!

Post by TheFatController »

Here's a stupid dynamic music widget I made for myself for fun

http://pw3n.net/gui_comnap_song.rar

It plays a song when you comnap someone! 8)
User avatar
smartie
NOTA Developer
Posts: 146
Joined: 23 Jun 2005, 19:29

Re: Musics!

Post by smartie »

I improved the dynamic music widget. It's on file universe now. The ogg files go into spring/music and the widget goes into your widgets folder. It works really well IMO. The only thing that bothers me about it right now is that it's a bit loud. The music is the old TA soundtrack.

http://www.fileuniverse.com/?p=show&a=it&id=5323

@ TheFatController: If you put stopsoundstream right before you tell it to play it should be compatible with the dynamic music. I like it though :P You should make one that plays yakety sax if you weezle rush
User avatar
BlueTemplar
Posts: 314
Joined: 28 Oct 2007, 22:37

Re: Musics!

Post by BlueTemplar »

Damn, I can only hear static with your widget... :( but maybe because I'm on a Mac?
User avatar
LordMatt
Posts: 3393
Joined: 15 May 2005, 04:26

Re: Musics!

Post by LordMatt »

Well, I'm on Linux, and the sound is a little staticy (and I get some OpenAL errors during playback), however I'm sure this is engine related.
User avatar
smartie
NOTA Developer
Posts: 146
Joined: 23 Jun 2005, 19:29

Re: Musics!

Post by smartie »

I dunno. I'm not really able to test it on a Mac or Linux, so I guess the engine just doesn't support them.
User avatar
BlueTemplar
Posts: 314
Joined: 28 Oct 2007, 22:37

Re: Musics!

Post by BlueTemplar »

I think I've found the culprit, it probably comes from the OpenAL Mac implementation:
elio wrote:the buzz sounds because some silly windows sound encoders don't encode endianess properly, thus causing corrupted replay on the mac. the easiest option is to get people to encode it properly, the other is I work out a better way to guess endianness. Currently though it's not too high on the list.
User avatar
LOrDo
Posts: 1154
Joined: 27 Feb 2006, 00:21

Re: Musics!

Post by LOrDo »

Im listening to it now with custom music... It works great for me. Nice job! keep it up, got a few complaints but its already better then AF's Music AI!
tombom
Posts: 1933
Joined: 18 Dec 2005, 20:21

Re: Musics!

Post by tombom »

BlueTemplar wrote:Damn, I can only hear static with your widget... :( but maybe because I'm on a Mac?
Woah what

Excuse me for not keeping up but since when have we had mac support for spring!
User avatar
MightySheep
Posts: 243
Joined: 11 Nov 2007, 02:17

Re: Musics!

Post by MightySheep »

It plays a song when you comnap someone! 8)
omg that is so cool. What a great idea.
Post Reply

Return to “Lua Scripts”