About Store Forum Documentation Contact



Post Reply 
Music-ordered songs
Author Message
dragonfly3 Offline
Member

Post: #1
Music-ordered songs
The EE music tutorial seems to play songs in a music theme song list in random order. I am trying to play a song, then have about 2 minutes of silence, then play the next song, then the silence, and loop. But I want the songs played in a specific order, not in random order (I added the EE battle0 song as a third song to test to see if it would play in order or random). I can't seem to get them to play in order, nor can I get it to play the 2 minutes of silence other than during the initial load (the code I've added to have silence works as the game loads, whereas without the code for it, the music starts as soon as the game load starts). I'm also trying to add ambient sound in the background but currently have the code commented out while I try to work with the music so please ignore that part of the code.

Here is my code:

In Game.cpp
Variables:
Code:
MusicTheme mt_PvPmusic ; // this is the pvpisland.world music
/*MusicTheme mt_Ambient ; //this is the pvpisland.world ambient sound
Bool bAmbientPlaying=false; //don't play the mt_Ambient theme while loading the game*/
Int musicSongCounter; //counts the number of songs
Flt musicSilencePointer; //points to the song currently playing
Flt musicSilenceLength; //length of time to stop and start a song
Bool bInSilence=false; //we are not in silence mode

Under InitGame:
Code:
if(!mt_PvPmusic.songs()) // create 'mt_PvPmusic' theme if not yet created
   {
      mt_PvPmusic+="music/PvPupbeat.ogg"; // add "PvPupbeat.ogg" track to 'mt_PvPmusic' theme
      mt_PvPmusic+="music/battle0.ogg"; //add "PvPambientV2.ogg" track to 'mt_PvPmusic' theme
      mt_PvPmusic+="music/PvPdownbeat.ogg"; // add "PvPdownbeat.ogg" track to 'mt_PvPmusic' theme
      }
   /*if(!mt_Ambient.songs()) //create 'mt_Ambient' theme if not yet created
   {
       mt_Ambient+="music/PvPambientV2.ogg"; //add PvPambientV2.ogg to 'mt_Ambient' theme
   }
   Music.play(mt_Ambient);*/
   musicSilenceLength=120.0; //silence with no music for 120 frames
   bInSilence=true;//we are in silence mode
   return true;
}

Under UpdateGame:
Code:
{
       /*{
           //bAmbientPlaying=true;
           //Music.play(mt_Ambient); //start playing the mt_Ambient theme
       }*/
      Gui.update();
      if(bInSilence)
      {
          musicSilencePointer++;
      if(musicSilencePointer>=musicSilenceLength)
      {
              musicSilencePointer=0;
              Music.play(mt_PvPmusic,musicSongCounter);
              bInSilence=false;
      }
      }
      else
      {
          if(Music.length()-Music.time()<.5)
          {
              musicSongCounter++;
              if(musicSongCounter>2)
                  musicSongCounter=0;
              Music.play(NULL);
              bInSilence=true;
          }
      }


Any suggestions? Please be gentle, I'm a beginner when it comes to programmingwink
(This post was last modified: 01-10-2012 04:59 PM by dragonfly3.)
09-04-2011 03:29 AM
Visit this user's website Find all posts by this user Quote this message in a reply
dragonfly3 Offline
Member

Post: #2
RE: Music-ordered songs
Has anyone worked with adding music? No one has any ideas? Is my code completely off? Any hints at all?
09-06-2011 04:25 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #3
RE: Music-ordered songs
Never used MusicTheme or MusicManager classes (Music.play) before, but after doing some tests of my own and testing your code, I've managed to find the problem.

Replace:

Code:
Music.play(NULL);

with:

Code:
Music.set(NULL);

Also, you don't want to use frames for musicSilencePointer, you want to use time.

Replace:

Code:
musicSilencePointer++;

with:

Code:
musicSilencePointer += Time.d();

120 frames does not necessarily equal 120 seconds. Using Time.d() ensures that there will be a 120-second delay on all computers, whether they're slow or fast and whether V-Sync (Vertical Sync) is turned on or off (essentially limits FPS to the refresh rate of the monitor -- if turned on, typically 60 FPS; if turned off, FPS could in the hundreds, meaning 120 frames will happen much, much quicker -- this is why you use time instead).

That should fix it. Your code was actually pretty solid.
09-06-2011 05:51 AM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #4
RE: Music-ordered songs
Everything seems right to the best of my abilities..
I don't know, try instead of if(Music.length()-Music.time()<.5) put if(Kb.bp(KB_M)). Maybe for some reason Music.length() or Music.time() is not updating to the new song.

edit: ooh, just refreshed the page.
(This post was last modified: 09-06-2011 05:58 AM by Dandruff.)
09-06-2011 05:56 AM
Find all posts by this user Quote this message in a reply
dragonfly3 Offline
Member

Post: #5
RE: Music-ordered songs
Thanks Driklynsmile The time works properly now upon game load. Now we're working on trying to get it to play the song list in a specific order instead of random order, as well as playing a specified period of silence in between the songs.

[EDIT] Driklyn, you said you haven't done music using the MusicTheme or MusicManager. Have you used any other methods? Or have you not worked with any music at all?
(This post was last modified: 09-09-2011 05:29 AM by dragonfly3.)
09-09-2011 04:40 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #6
RE: Music-ordered songs
(09-09-2011 04:40 AM)dragonfly3 Wrote:  Now we're working on trying to get it to play the song list in a specific order instead of random order, as well as playing a specified period of silence in between the songs.

It should already be doing that, right? It is for me. There's one small tweak I would make though.

Replace:

Code:
if(musicSongCounter>2)

with:

Code:
if(musicSongCounter>Music.theme().songs())

This way the value is not hard-coded and will allow you to add/remove songs from the MusicTheme without having to adjust the value as well.

musicSilenceLength dictates the length of the silence (in seconds) between songs, so setting this to 120 will give a 2-minute silence between songs.

I have 4 "sounds" (not songs) in my MusicTheme test with a silence length of 3 seconds and it is playing all 4 "sounds" in order with silence in between them, plus repeating the playlist once it reaches the end. Seems like everything is working to me...

(09-09-2011 04:40 AM)dragonfly3 Wrote:  Have you used any other methods? Or have you not worked with any music at all?

I've only used the Sound class to play sound effects and some ambient noises, never had the need for any background music before.
09-09-2011 06:15 AM
Find all posts by this user Quote this message in a reply
dragonfly3 Offline
Member

Post: #7
RE: Music-ordered songs
ok, been working on this all night and here is what we have so far (we have some code commented out so we don't lose it in case this didn't work). We added in some code to try to stop a song after 60 seconds of playing just to see if we could stop a song from playing. The pattern that it should do is play in this order:

2 min silence
PvPupbeat for 60 sec
2 min silence
PvPambientV1 for 60 sec
2 min silence
PvPdownbeat for 60 sec
Loop

Here is our code:

Variables:
Code:
MusicTheme mt_PvPmusic ; // this is the pvpisland.world music
/*MusicTheme mt_Ambient ; //this is the pvpisland.world ambient sound
Bool bAmbientPlaying=false; //don't play the mt_Ambient theme while loading the game*/
Int musicSongCounter; //counts the number of songs
Flt musicSilencePointer; //points to the song currently playing
Flt musicSilenceLength; //length of time to stop and start silence
Flt songTimePointer; //song time counter
Flt songTimeLength; //tells the length of time to play a song
Bool bInSilence=false; //we are not in silence mode

In InitGame:
Code:
if(!mt_PvPmusic.songs()) // create 'mt_PvPmusic' theme if not yet created
   {
      mt_PvPmusic+="music/PvPupbeat.ogg"; // add "PvPupbeat.ogg" track to 'mt_PvPmusic' theme
      mt_PvPmusic+="music/PvPambientV1.ogg"; //add "PvPambientV2.ogg" track to 'mt_PvPmusic' theme
      mt_PvPmusic+="music/PvPdownbeat.ogg"; // add "PvPdownbeat.ogg" track to 'mt_PvPmusic' theme
      }
   /*if(!mt_Ambient.songs()) //create 'mt_Ambient' theme if not yet created
   {
       mt_Ambient+="music/PvPambientV2.ogg"; //add PvPambientV2.ogg to 'mt_Ambient' theme
   }
   Music.play(mt_Ambient);*/
   musicSilenceLength=120.0; //silence with no music for 120 frames
   songTimeLength=60.0; //play music for 60 seconds
   bInSilence=true;//we are in silence mode
   return true;
}

In UpdateGame:
Code:
if(bInSilence)
      {
          musicSilencePointer += Time.d();
      if(musicSilencePointer>=musicSilenceLength)
      {
              musicSilencePointer=0;
              Music.play(mt_PvPmusic,musicSongCounter);
              bInSilence=false;
      }
      }
      else
      {
          songTimePointer += Time.d();
if(songTimePointer>=songTimeLength)
      {
              songTimePointer=0;
              musicSongCounter++;
              if(musicSongCounter>mt_PvPmusic.songs())
                 musicSongCounter=0;
              Music.set(NULL);
              bInSilence=true;
      }

The result we have now is a definite pattern, but a pattern that makes no sense. Here is the pattern of music/silence we are getting:

initial 2 min silence upon game initiation, then:

PvPdownbeat in it's entirety
8 sec silence
PvPdownbeat in it's entirety
8 sec silence
PvPAmbientV1 for 1:39
40 sec silence
PvPupbeat in it's entirety
1:24 silence

This exact pattern repeats over and over. We are completely lost as to the random timing issues as well as why PvPdownbeat and 8 sec silence plays twice in a row.

Esenthel, is there an easier way to do this? lol
09-09-2011 09:15 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #8
RE: Music-ordered songs
MusicTheme always uses random track selection, I can only help by adding "bool shuffle" into music control. Silence is still something you will need to control manually
Also set Music.time_reset to zero
09-09-2011 09:33 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
RE: Music-ordered songs
in next sdk:

init:
Music.time_reset=0;
Music.shuffle=false;

inside game:
Music.play(theme); // start theme
..
Music.play(NULL); // start silence
..
Music.set(theme); // set theme but don't play yet
Music.next(); // play next song in theme
..
Music.play(NULL); // start silence
..
Music.set(theme); // set theme but don't play yet
Music.next(); // play next song in theme
09-09-2011 01:19 PM
Find all posts by this user Quote this message in a reply
dragonfly3 Offline
Member

Post: #10
RE: Music-ordered songs
ok great! Thanks! smile

We almost have it working right now. Soooo close! We've got the order working properly and we've got the 2 minutes of silence in between songs working properly. But now we're trying to get it to play the full songs without going directly into another song at random before cutting off and playing our period of silence. Currently it plays about 2 seconds of another song before cutting off. [EDIT] It only seems to be doing this upon initializing. It only does it after playing the first song for the first time. After that it plays all songs and silence properly.

We're trying to fix it using Music.length()

Can anyone please tell us what exactly does Music.length() do? We thought it was the length of the song but it doesn't seem to be. Once we know this we can get it working for now (until the new SDK changes)
(This post was last modified: 09-18-2011 07:31 AM by dragonfly3.)
09-18-2011 07:17 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #11
RE: Music-ordered songs
I believe this will do the trick:

Code:
Music.fade_out = 0;
09-18-2011 07:26 AM
Find all posts by this user Quote this message in a reply
dragonfly3 Offline
Member

Post: #12
RE: Music-ordered songs
Our music isn't set to fade in and out. It's set just to stop the songs when they finish (at least that's what we are attempting). I edited my post because I just discovered that the problem seems to only occur upon initializing the music

[EDIT] It seems to be working fine now. Tested it a couple more times and it's not doing the 2 second clip of another song anymore. Not sure what was causing that weird glitch the first time.

We now have our music and our ambient sound working! For anyone interested, here are our code snippets just in case it helps anyone else out with their music. smile

Code:
Variables:
MusicTheme mt_PvPmusic ; // this is the pvpisland.world music
MusicTheme mt_PvPAmbient; //this is the pvpisland.world ambient music
Bool bAmbientPlaying=false; //don't play the mt_Ambient theme while loading the game*/
Int musicSongCounter; //counts the number of songs
Flt musicSilencePointer; //points to the song currently playing
Flt musicSilenceLength; //length of time to stop and start silence
Flt songTimePointer; //song time counter
Flt songTimeLength; //tells the length of time to play a song
Bool bInSilence=false; //we are not in silence mode

InitGame:
Code:
if(!mt_PvPmusic.songs()) // create 'mt_PvPmusic' theme if not yet created
   {
      mt_PvPmusic+="music/PvPupbeat.ogg"; // add "PvPupbeat.ogg" track to 'mt_PvPmusic' theme
      mt_PvPmusic+="music/PvPdownbeat.ogg"; // add "PvPdownbeat.ogg" track to 'mt_PvPmusic' theme
      }
   musicSilenceLength=120.0; //silence with no music for 120 seconds
   musicSongCounter=0; //start from the first song in the playlist
   bInSilence=true;//we are in silence mode
   Music.time_reset = 1000.0; //if our songs last less than 1000 seconds, they will always start from the beginning when played after being stopped
  
   if (!mt_PvPAmbient.songs()) //create 'mt_PvPAmbient' theme if not yet created
   {
       mt_PvPAmbient+="music/PvPambientV1.ogg"; //add PvPambientV1.ogg track to 'mt_PvPAmbient' theme
   }

UpdateGame:
Code:
{
       {
           bAmbientPlaying=true;
           Ambient.play(mt_PvPAmbient); //start playing the mt_PvPAmbient theme
       }
      Gui.update();
    if(bInSilence)
    {
        musicSilencePointer += Time.d();
        if(musicSilencePointer>=musicSilenceLength)
        {
                musicSilencePointer=0;
                Music.play(mt_PvPmusic,musicSongCounter);
                bInSilence=false;
                songTimeLength=Music.length()-3.0;
        }
    }
    else
    {
        songTimePointer += Time.d();
        if(songTimePointer>=songTimeLength)
        {
                songTimePointer=0;
                musicSongCounter++;
                if(musicSongCounter>=mt_PvPmusic.songs())
                    musicSongCounter=0;
                Music.play(NULL);
                bInSilence=true;
        }

Thanks everyone for the help! grin
(This post was last modified: 09-18-2011 08:53 AM by dragonfly3.)
09-18-2011 07:33 AM
Visit this user's website Find all posts by this user Quote this message in a reply
dragonfly3 Offline
Member

Post: #13
RE: Music-ordered songs
(09-09-2011 01:19 PM)Esenthel Wrote:  in next sdk:

init:
Music.time_reset=0;
Music.shuffle=false;

inside game:
Music.play(theme); // start theme
..
Music.play(NULL); // start silence
..
Music.set(theme); // set theme but don't play yet
Music.next(); // play next song in theme
..
Music.play(NULL); // start silence
..
Music.set(theme); // set theme but don't play yet
Music.next(); // play next song in theme

Was this implemented yet? We tried to change our old code to this new method and we got no music at all, just complete silence. So I was just curious if this has been implemented yet or not s we can try to troubleshoot the problem.

Thanks:-)
01-10-2012 05:03 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #14
RE: Music-ordered songs
I've tested the
EsenthelEngineSDK\Tutorials\Source\Advanced\1 - Geometry, Graphics, Gui, Misc, Net, Sound\Sound\Music.cpp

with these lines added in Init:
Music.time_reset=0;
Music.shuffle=false;

and all works ok, (no silence, music plays)
01-13-2012 03:48 PM
Find all posts by this user Quote this message in a reply
Post Reply