Sound/Windows

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: Sound/Windows

Post by Nyyrazzilyss »

Just as an aside btw - A lot of this has to do with me liking to dump stuff on the screen to make sure everything's working, then just remove the code that did that. The code -should- be working properly, but I want to make sure it's actually doing what I think (it's supposed to be) doing. The actual change i'd made was
Code: [show] | [select all] lua
(mudlet.h)

QList<QMediaPlayer *>		 MusicBoxList;

(mudlet.cpp)

void mudlet::stopSounds()
{
	QList<QMediaPlayer *>::iterator		i;

	for (i=MusicBoxList.begin(); i != MusicBoxList.end(); i++)
		(*i)->stop();
}

void mudlet::playSound( QString s )
{
	QList<QMediaPlayer *>::iterator		i;
	QMediaPlayer *					pPlayer;
	
	for (i=MusicBoxList.begin(); i != MusicBoxList.end(); i++)
	{	if ( (*i)->state() != QMediaPlayer::PlayingState )
		{	(*i)->setMedia( QUrl::fromLocalFile( s ) );
			(*i)->play();
			return;
		}
	}
	
	pPlayer = new QMediaPlayer(this);
	MusicBoxList.append(pPlayer);
	
	pPlayer->setMedia( QUrl::fromLocalFile( s ) );
	pPlayer->play();
}

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Sound/Windows

Post by SlySven »

If it is in the mudlet singleton class (only ONE ever gets created when the application runs) then look for and clone a snippet that gets the active host ("profile" as far as the user sees it) near the top of a function (a.k.a. class method).

Sorry but I don't have the project code open in front of me but for some strange reason I decided to boot up Windows (7) for the first time in six months and I have been battling to get through "Preparing Updates"/"Update Failed"/"Reverting Update"/"Restarting" cycles to get the machine clear of outstanding revisions for the last 24 hours...

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: Sound/Windows

Post by Nyyrazzilyss »

Thanks got on screen status/error messages working :)

Host * pH = getActiveHost();

if (pH) {
pH->postMessage("found unused media object\n");
}

Obviously not intended to be left behind, I just want to make sure the code is doing what it's supposed to be with a few messages spit out when specific things happen.

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Sound/Windows

Post by SlySven »

Humm, that might work except that I think you need to check more deeply why a player instance is not in the QMediaPlayer::Playing state before trying to reuse it. The QMediaPlayer::setMedia(...) call returns straight away and hands the task of loading/buffering/playing the given file to a separate thread IIRC so a given player could actually be getting to play (perfectly correctly) another file and not yet had a chance to reach the Playing state, I think there are specific other states for "Idle" or "Error" and it might be better to test for being in one of those two states instead. But that is my £0.02 worth.

Also, you've gone for using the STL (Standard Template Library) interator:

Code: Select all

        QList<QMediaPlayer *>::iterator         i;

        for (i=MusicBoxList.begin(); i != MusicBoxList.end(); i++) {
                (*i)->stop();
        } 
but some (me included) find the Java-style ones a bit easier to read (at the slight expense of a little performance but with the gain of safer code):

Code: Select all

        QListIterator<QMediaPlayer *> itMusicBox( MusicBoxList );
        while( itMusicBox.hasNext() ) {
                itMusicBox.next()->stop();
                /* You use QListIterator::next() to get the next value to iterate with but you can only use it once per iteration and must either store the value in a local variable or cheat and use QListIterator::peekPrevious() if you want it again inside the loop. 8-) */
        } 

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: Sound/Windows

Post by Nyyrazzilyss »

End result - I played varying sets of sounds, it created a new QmediaPlayer at need/ reused previous ones properly - The whole point of the messages was I wanted it showing me when it was creating new player vs reusing previous. I was up to a dozen sounds at once when I left testing, I don't know what the actual limit would be (if any) - I'll clean it up a bit re: your previous post.

I'll look at checking for idle/or error instead - That actually works much better when I don't have to be concerned about a 4 player limit.

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: Sound/Windows

Post by Nyyrazzilyss »

OK all done now, other then my notsogoodwithgithub. Thought I had it set properly for the pr, except it wanted to merge the src.pro pr with it - I'm guessing I should have forked again.

However: I'd changed the iterator, media status, and added a variable to playSoundFile for volume (defaulting to 100/full on nil for backward compatability) - It will play an unlimited number of simultaneous sound files now, with individual volume controls.

Looks like it added it to #254

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Sound/Windows

Post by SlySven »

Don't fork, that means creating a copy of the whole repository - you mean/need to branch. If you are using gitk you'd just select the starting point you want to work from (usually the github-mudlet->development or github-mudlet->release_30) and you can right-click to create a new branch. Don't forgetting to do a git fetch --all to grab all the updates that have been made remotely (this won't affect your current Work in Progress) BEFORE you do this. I'm not sure what ways this can be done from within the Qt Creator IDE so it is probably a good idea to have all the work on your current branch stored (as a commit or I suppose there is also the git "stash" functionality that might be worth learning about) as the action of "checking-out" the new branch will throw away any unstored changes in the current files in the local directory!

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: Sound/Windows

Post by Nyyrazzilyss »

OK I figured out how to make and use branches (hopefully properly), and resubmitted the pr on the sound changes. A setting to change volume when adding sounds to triggers through the gui wouldn't hurt (I haven't even looked at that code though so wouldn't be doing that myself anytime soon) - I'd guess it would involve not only a change to the gui, but a change to save the information.

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Sound/Windows

Post by SlySven »

Actually you might get away with it. The sound volume for a trigger can be stored in the Mudlet game save file (the timestamped .xml file in the profile's "./current" directory by default) as an Xml attribute for the trigger. Old files won't have it and new Mudlet versions going forward can assume the volume must then be 100% (as old versions will) when they don't see it. Old versions of Mudlet will silently ignore the extra attribute in new files - and play the sound file at the 100% level as they would in the past. The only problem would be for old versions using a sound file that has a LOUD SOUND but which is only played at a low level in new versions going forward. :geek:

Nyyrazzilyss
Posts: 334
Joined: Thu Mar 05, 2015 2:53 am

Re: Sound/Windows

Post by Nyyrazzilyss »

SlySven wrote:The only problem would be for old versions using a sound file that has a LOUD SOUND but which is only played at a low level in new versions going forward. :geek:
I'm not sure how much of an issue that would be - For a problem like that to pop up in the first place, the script would have had to be written with a recent specific version+ in mind. I've got countless things that require a specific version of Mudlet to be running/ just display an error message as much every time you try and do anything if it's not the correct version.

Post Reply