Help needed withh the music.nvgt library

Hello again everyone.
So I wanted to loop this music track. I started by trying the sound object play_looped method, but it turns out that it and other ways like using the sound pool class or even looping it through a basic loop function like while() does not work the way I wanted.
I found out that there will always be a lack of sound after the ending of the track and before it begins again resulting in the loop being "gappy", if that even is a word.
I looked around, and found the music.nvgt include. It looks like it has the fix for the issue I am facing, however, am relatively new to using this toolkit so I have spent the last 12 hours scratching my head to get a grip on this one.
It's not as simple as loading a file through a string and then playing that file like you
would normally do with the sound object. How I wish it was that easy.
So, can somebody please explain how does the music.nvgt include work exactly.
What I want is simple.
Let's say I have two files in a folder, one of them is a music.wav file, and the other one is a test.nvgt.
I am wondering how to make the .wav file play as a music track using the way demonstrated in the music system reference.
I would be so happy if somebody wrote me a simple five line script doing just that, I'm sure I would be able to grasp the idea from a small working example.
What I originally wrote is this:

#include "music.nvgt"
void main()
{
music_manager bob;
bob.play("music.wav; loop;");
}

Apparently it doesn't work like this. I also found a section in the music system reference that talks about setting a callback function for loading the sound, which I have zero idea how it exactly works.
Thank you so much in advance and have a great day.

Hi,

So 2 of the methods you've described, using sound.play_looped() as well as music_manager.play("track.wav; loop"); should actually be valid, and we've had no reports of the audio engine inserting silence at loop points up until this time.

I assume the track you are trying to loop repeats OK in a media player with looping functionality? For example if you are dealing with an mp3 file, it might not loop as well because of the characteristics of some mp3 files.

It is important to call the music_manager's loop method, such as `bob.loop(ticks()); in your programs main loop so that the music manager can stay updated, should you go with the music manager option.

Can you please try with a few different tracks and let me know if the issue exists for all of them?

For example, attached is a file that should properly loop with NVGT. If this doesn't loop for you with sound.play_looped, we can continue troubleshooting.

The forum might embed this as an audio player for you, if so, you can shift+f10 on the play button and select the save audio as option, or whatever equivalent in your browser.

Thanks and sorry for the issue!

1 Like

Thank you so much for your help Mr. Sam.
It turns out that all the looping functionalities are working perfectly.
The audio file I was originally using was in wave format.
After I used the audio file you sent me, and it worked perfectly, I converted it to wave, which resulted in having that silence inserted in the end of the file.
I found out that after I edit sound using a blind friendly software called reaper, there's always a silence in the end of each track you render if everything is set to default, or something like that.
So yeah, to all users of reaper, test loop your audio before rendering it, and don't be as careless as me.
Sorry for the trouble, and thank you so much again.
Concerning the music library class thing, could you please be so kind to help me with this small example that poorly demonstrates how to use the music manager thing with one of the options, which is the loop option.
Just please point me in the right direction. I just want to know what is the missing line.
I'm using the latest version of nvgt from this website.
As before there is a folder which has two files, the first is test.nvgt with the void main() function, the second file is a file called music.wav.

#include "music.nvgt"
void main()
{
show_window("game test");
wait(50);

// So we start with declaring the music_manager object.
music_manager bob;
// then we load the sound, apparently using a call back function or whatever, correct me please if I'm wrong. Which I don't know how to do.

// Then we play the sound looped like this:
bob.play("music.wav; loop;");
// Nevermind the stupid loop below, it's just for the window to stay active
while(!key_pressed(KEY_Q))
{
wait(5);
}
}

If I hit enter on the .nvgt script file, a window appears but there is no sound playing, indicating that there is something missing here.
I really want to learn how to use this music class. As I kept reading its reference, I found a lot of interesting features.
Thank you so much again for your kindness.

Hi,

You actually have just about figured out the music manager, the only thing you are missing is the call to the loop that keeps everything running. For example, a modified version of your code looks like:

#include "music.nvgt"
void main()
{
show_window("game test");
wait(50);
// So we start with declaring the music_manager object.
music_manager bob;
// The callback function is only needed if you are trying to, for example, load a sound from a pack file. It is not needed normally.
// Then we play the sound looped like this, the music manager will load it from the disk as needed:
bob.play("music.wav; loop"); // I believe the loop flag is automatically applied unless another altering flag is given, but it doesn't hurt to add it anyway..
// The only way the music manager works is if something repeatedly calls bob.loop.
while(!key_pressed(KEY_Q))
{
wait(5);
bob.loop();
}
}

Hope this helps!

2 Likes

Well, it's true what they say. "If you have a problem with a dent, go to the dentist."
Yes it does help, and the script works just fine now.
Even though it's not as complicated or difficult as trying to grasp CPP, NVGT is still a challenge for newbies like me. But still, thanks to you blind folks like us have a chance now, to let loose all those bottled up ideas.
So thank you, really.

Oh yes I almost forgot that. I have a question concerning the way I am building up my knowledge about it.
You see, due to the incomplete state of the NVGT documentation, I went back a lot of times to the documentation of BGT whenever I ran into unanswered questions.
It had certainly helped with most of the issues so far. But I still wonder. Is it the right thing to do? Or am I setting up a wrong foundation for my learning journey and the best thing to do is wait for the completion of the NVGT documentation.
I mean, both programs look very similar to me. So what do you think?
And thank you again, for everything.

I believe until the NVGt docs are not complete or you can't find what you are looking for that's a good idea, and other people would suggest that as well. Indeed they are very simular at the moment, and if something isn't working as described there, just ask :slight_smile:

hello!
I found a bug with the music class when stopping music:
It turns out that sometimes the music stop function fails, causing it to mix with other music. As an alternative solution, at the moment I am using the pause method.
It would be nice if a function was added to delete the track that is playing, or for the stop function to perform that function. Another error I found is that when calling the stop method the music continues playing but at a very low volume. Sorry for my bad English but I'm using a translator. thanks in advance