Author Topic: Playing music tracks in sequence  (Read 537 times)

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Playing music tracks in sequence
« on: February 13, 2012, 04:36:40 pm »


                I was wondering if there is a proven way to play music tracks in sequence. I don't see any way to detect when a track ends or begins.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Playing music tracks in sequence
« Reply #1 on: February 13, 2012, 08:00:10 pm »


               Well, I suppose for the tracks in question I'll just run a delay script... one for each track, and start the next piece at the right time if a PC is present. It should work.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Playing music tracks in sequence
« Reply #2 on: February 13, 2012, 11:14:29 pm »


                I posted my solution to pastebin.

The idea is that you execute a recursive script on an area in which you want to cycle through musical tracks.
The area should not have any battle music which could disrupt the background music.
The area also should track whether pcs are present. In on enter I increase th PC count, and on exit I decrement the exit count.
Each track ID and length in seconds are set as INTs on the area.
SONG_ID_01  = song index in ambientmusic.2da for Track 1
SONG_LENGTH_01 = length in senconds that Track 1 will play
SONG_ID_02 .... etc....

aa_ex_music is executed in onAreaEnter.

See 
aa_ex_music   for details of how it works.

[Edit: already found a bug and fixed it. When PCs leave... all music stops and track 1 is set as the first music to play]
               
               

               


                     Modifié par henesua, 13 février 2012 - 11:33 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Playing music tracks in sequence
« Reply #3 on: February 13, 2012, 11:34:58 pm »


               Hmm,   Since there is no module level music player and the tracks will always start anew when a new area is gone into anyway. why not just make a sound object and list the tracks on it.   Select either the play in order or random option.  basicly use the sound object in place of the Areas background music option.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Playing music tracks in sequence
« Reply #4 on: February 13, 2012, 11:36:11 pm »


               You can put background music on a sound object?

I just checked. The only ambient music I was able to select was the battle music.
               
               

               


                     Modifié par henesua, 13 février 2012 - 11:38 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Playing music tracks in sequence
« Reply #5 on: February 14, 2012, 12:18:45 am »


                Ok... finished bg testing. I pasted the revised code: aa_ex_music

So... some of these DelayCommands are exceptionally long. One of the tracks has an 673 second delay. Is that a problem?

Anyway, it works. I've got the entire sound track to Before The Rain playing in the Arnheim character creation area. (here's the first track on You-tube. You can find the whole movie there too if you dig.)  Awesome film by the way, Macedonian, about the Balkans, was released in 1994. The soundtrack is by Anastasia, and is as far as I can tell there least electronic sounding album. Many of the instruments used are traditional to the area.

Anyway... the music fits Arnheim. So I am glad to get this script working.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Playing music tracks in sequence
« Reply #6 on: February 15, 2012, 04:35:29 am »


               Although the last version works, I decided to polish this further and am now very happy with the way this works.
aa_ex_music

This is called by both the enter and exit event. That way the exit event can clean up the music (turn it off completely) when the last player exits. You still need to track player count on the area.

I also added a column to ambientmusic which includes the length of the song in seconds. You'd have to do this as well to use these revisions - in addition to the data entry required for each track. But this way you only have to enter the song lengths once whihc will reduce the chance that you'll make mistakes later.

I also created a juke box using zdlg which changes which track list the area will play. I called each track list a "theme" and created 5 for the out of character lounge.

[edit]
I keep editing that music script. The delays weren't always working right, so I removed them.
               
               

               


                     Modifié par henesua, 15 février 2012 - 02:50 .