XWidgetSoft Forum

XWidget & XLaunchpad , Desktop customization
It is currently 2017年 Jun 23日 11:09

All times are UTC - 8 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Play 2 sounds/mute
PostPosted: 2016年 Feb 23日 03:30 
Offline
User avatar

Joined: 2012年 Dec 5日 17:52
Posts: 4494
I need a litle help making this script..
I have two sounds (wav) and I want to use two right click options to play each one separately (on/off). Like this:

(right click options)
sound 1 on/off (checked/unchecked)
sound 2 on/off (checked/unchecked)

- When the sound 1 will play the sound 2 will mute. Conversely for the sound 2.
- 3rd option to mute both (all sounds)
- save ini for the sound status

Thanks in advance :)

_________________
Image
...and remember: don't take life too seriously...
My profile on Deviantart: http://jimking.deviantart.com/


Top
 Profile  
 
 Post subject: Re: Play 2 sounds/mute
PostPosted: 2016年 Feb 23日 05:51 
Offline
User avatar

Joined: 2013年 Jul 29日 09:13
Posts: 480
For the right click, you'll need to add three options to the default menu - Xwidget engine does not have the concept of context sensitive menus specific to the assigned object so you have to add the options to the default right click menu.

Image

Note: Xwidget menu options cannot be built dynamically in code so you just have to create the menus statically by hand in the designer..

Then it is a matter of assigning a function to each menu option incorporating the command playsound. As the Xwidget engine cannot handle the playing of more than one sound simultaneously, playing one sound will automatically mute the other. In this case this suits your requirement. The third menu option can play a blank wav file to mute any currently running sound. When the mute option is chosen, subsequently decide either to avoid using the playsound command or simply play a null sound instead.

One method of saving your prefs is done by having a hidden layer containing hidden text or memo boxes - see my U-Boat widget http://bbs.xwidget.com/viewtopic.php?f=11&t=6090 for how I typically do it.

Each text box is named as a preference variable according to its function.
My hidden prefs layer is called: showWidgetPreferences
My text boxes are named as such: preferencesHintPrefValue - this naming convention allows easy conversion to a yahoo widget which uses the following naming convention : preferences.hintPref.value .

The function getprefs is called when the widget starts:

//===========================================
// this function runs on startup
//===========================================
function widgetOnLoad() {
getPrefs();
}

//=========================================================================
// this function sets the preference values to saved values
//=========================================================================
function getPrefs(){
preferenceshoffsetprefvalue.text = Getinivalue(widgetpath+"prefs.ini","prefs","preferenceshoffsetprefvalue","350");
preferencesvoffsetprefvalue.text = Getinivalue(widgetpath+"prefs.ini","prefs","preferencesvoffsetprefvalue","350");
preferenceswidgetTooltipvalue.text = Getinivalue(widgetpath+"prefs.ini","prefs","preferenceswidgetTooltipvalue","Double-Click on me to set the widget command");
preferencesimageCmdPrefvalue.text = Getinivalue(widgetpath+"prefs.ini","prefs","preferencesimageCmdPrefvalue","");
print("preferencesclockSizevalue.percent "+preferencesclockSizevalue.percent);
preferencessoundprefvalue.text = Getinivalue(widgetpath+"prefs.ini","prefs","preferencessoundprefvalue","enabled");
preferencesclockSizevalue.percent = Getinivalue(widgetpath+"prefs.ini","prefs","preferencesclockSizevalue","100");
preferencesLicenceHideValue.text = Getinivalue(widgetpath+"prefs.ini","prefs","preferencesLicenceHideValue",0);
preferencesMouseWheelPrefValue.text = Getinivalue(widgetpath+"prefs.ini","prefs","preferencesMouseWheelPrefValue","up");
preferencesHintPrefValue.text = Getinivalue(widgetpath+"prefs.ini","prefs","preferencesHintPrefValue","enabled");
preferencesclockFaceSwitchPrefvalue.text = Getinivalue(widgetpath+"prefs.ini","prefs","preferencesclockFaceSwitchPrefvalue","stopwatch");
preferenceswidgetLockLandscapeModePrefvalue .text = Getinivalue(widgetpath+"prefs.ini","prefs","preferenceswidgetLockLandscapeModePrefvalue","enabled");

print("preferencesHintPrefValue.text "+preferencesHintPrefValue.text);

if (preferencessoundprefvalue.text != "disabled") {
soundbutton.src="bellpushed.png"; // this in place of a checkbutton which I could not get to work correctly
} else {
soundbutton.src="bell.png";
}
PlaySound(soundbutton);
}
//=====================
//End function
//=====================

As soon as the above function is called it plays a sound according to the value set in one of the prefs.

//=========================================================================
// this function saves the preferences to an ini file for later use
//=========================================================================
function SavePrefs()
{
print ("Saving Prefs ");
Setinivalue(widgetpath+"prefs.ini","prefs","preferenceshoffsetprefvalue",preferenceshoffsetprefvalue.text);
Setinivalue(widgetpath+"prefs.ini","prefs","preferencesvoffsetprefvalue",preferencesvoffsetprefvalue.text);
Setinivalue(widgetpath+"prefs.ini","prefs","preferenceswidgetTooltipvalue",preferenceswidgetTooltipvalue.text);
//print("preferencesimageCmdPrefvalue.text "+preferencesimageCmdPrefvalue.text);
Setinivalue(widgetpath+"prefs.ini","prefs","preferencesimageCmdPrefvalue",preferencesimageCmdPrefvalue.text);
Setinivalue(widgetpath+"prefs.ini","prefs","preferencessoundprefvalue",preferencessoundprefvalue.text);
Setinivalue(widgetpath+"prefs.ini","prefs","preferencesclockSizevalue",preferencesclockSizevalue.percent);
Setinivalue(widgetpath+"prefs.ini","prefs","preferencesLicenceHideValue",preferencesLicenceHideValue.text);
Setinivalue(widgetpath+"prefs.ini","prefs","preferencesMouseWheelPrefValue",preferencesMouseWheelPrefValue.text);
Setinivalue(widgetpath+"prefs.ini","prefs","preferencesHintPrefValue",preferencesHintPrefValue.text);
Setinivalue(widgetpath+"prefs.ini","prefs","preferencesclockFaceSwitchPrefvalue",preferencesclockFaceSwitchPrefvalue.text);
Setinivalue(widgetpath+"prefs.ini","prefs","preferenceswidgetLockLandscapeModePrefvalue",preferenceswidgetLockLandscapeModePrefvalue.text);


print("preferencesHintPrefValue.text "+preferencesHintPrefValue.text);

}
//=====================
//End function
//=====================


This shows how I get settings from an ini file and how I save them too. Sometimes I have to create the ini file manually the first time they are used. My hidden prefs layer can be made visible on request so I have a nice and pretty underlying image that holds the text boxes and descriptions. This allows you to view all the fields and change the preferences they hold manually. I make the preferences layer visible from the right click menu using a menu option named "Show Preferences" that runs this command showWidgetPreferences.visible = true; to make the layer and all the contained objects visible.

Image

This is taken directly from the style of the konfabulator/Yahoo widget engine that has built-in functionality to provide a GUI for the storage and handling of preferences. I have my own radio boxes showing here as I had problems making the Xwidget engine's radio buttons work the way I wanted them to.


Top
 Profile  
 
 Post subject: Re: Play 2 sounds/mute
PostPosted: 2016年 Feb 23日 06:31 
Offline
User avatar

Joined: 2012年 Dec 5日 17:52
Posts: 4494
Are you sure that it needs to be so complicated...? :?
Because as you know, in java there are more than one ways to assign the same function..

I was thinking like more simple like I did (with help) for this widget:
http://jimking.deviantart.com/art/Cucko ... -385323459

Please take a look at the script.

_________________
Image
...and remember: don't take life too seriously...
My profile on Deviantart: http://jimking.deviantart.com/


Top
 Profile  
 
 Post subject: Re: Play 2 sounds/mute
PostPosted: 2016年 Feb 23日 08:00 
Offline
User avatar

Joined: 2013年 Jul 29日 09:13
Posts: 480
Of course it doesn't have to be complicated - and that code is not complicated at all! There is just one line per preference saved, your widget might only have one preference to save and so it would have only one line. And of course you can do it anyway you like.

It should be quite clear what I am doing above. I am replicating the way that Yahoo widgets uses its preferences so they can be easily migrated to Xwidget through the use of a GUI.

Quote:
This is taken directly from the style of the konfabulator/Yahoo widget engine that has built-in functionality to provide a GUI for the storage and handling of preferences.


For the example code above there are lots of preferences that I am saving but that is what is required for the migration of that particular widget - it is just an example.

If you have a way of doing it already why are you asking for alternatives? Which bit are you asking for help? Please be clear.


Top
 Profile  
 
 Post subject: Re: Play 2 sounds/mute
PostPosted: 2016年 Feb 23日 08:07 
Offline
User avatar

Joined: 2012年 Dec 5日 17:52
Posts: 4494
The fact yereverluvinuncleber is that before ask for help I tried some things.. The script that I used in the "Cuckoo Clock" widget is only for one sound. I tried to edit it but at the end I had only errors..
Also I tested yesterday and the "Xwidget engine cannot handle the playing of more than one sound simultaneously, playing one sound will automatically mute the other." not works exactly like this because appears to be a conflit with more than one sounds and with the wrong script, the sound appears corrupted when you don't mute or completely stop the second one.

_________________
Image
...and remember: don't take life too seriously...
My profile on Deviantart: http://jimking.deviantart.com/


Top
 Profile  
 
 Post subject: Re: Play 2 sounds/mute
PostPosted: 2016年 Feb 23日 08:48 
Offline
User avatar

Joined: 2013年 Jul 29日 09:13
Posts: 480
Ah OK.

Do you remember my bug that I raised where playing more than one sound produced strange results? On my two laptop PCs, playing one sound stopped another from playing. Send me the script that is causing distortion and I'll check it here. If it does the same then we may have more of a sound bug.

I suggest that you try playing a blank sound instead. See if that helps. I used that trick sometimes when I had a sound overrun. I'd have to see/try your script in order to help any further.


Top
 Profile  
 
 Post subject: Re: Play 2 sounds/mute
PostPosted: 2016年 Feb 25日 03:12 
Offline
User avatar

Joined: 2012年 Dec 5日 17:52
Posts: 4494
Never mind... I found the solution by myself. :)
I used this script with two timercores.
The users will have to select/check/uncheck/mute each sound first to play the other one properly, but at least it works.
The mute sound is useless now and the sounds start with no delay.

Code:
function menuitem29OnClick(Sender)
{
  Sender.checked = !Sender.checked;
  timercore1.enabled = Sender.checked;
  playsound("bubbles.wav")
}

function timercore1OnUpdate(Sender)
{
  if(menuitem29.checked)
  {
    playsound("bubbles.wav")
  }
}

function menuitem30OnClick(Sender)
{
  Sender.checked = !Sender.checked;
  timercore2.enabled = Sender.checked;
  playsound("waves.wav")
}

function timercore2OnUpdate(Sender)
{
  if(menuitem30.checked)
  {
    playsound("waves.wav")
  }
}

_________________
Image
...and remember: don't take life too seriously...
My profile on Deviantart: http://jimking.deviantart.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: Google [Bot] and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Powered by phpBB® Forum Software © phpBB Group