It is currently December 9th, 2021, 5:02 am

Getting a sound to play at a specific time

Help with creating, editing & fixing problems with skins
HeyItsVal
Posts: 1
Joined: November 19th, 2021, 1:16 am

Getting a sound to play at a specific time

Post by HeyItsVal »

Hey all. I want to create a thing in rainmeter that plays a sound at a specific time on the clock. How would i go about doing that? I have pretty minimal coding experience, so I don't know where to start.
User avatar
Mordasius
Posts: 1084
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Getting a sound to play at a specific time

Post by Mordasius »

HeyItsVal wrote: November 19th, 2021, 1:22 am I want to create a thing in rainmeter that plays a sound at a specific time on the clock. How would i go about doing that?
There are dozens of ways to do this. Here is one.

Code: Select all

[Rainmeter]
MiddleMouseDownAction=!Refresh
AccurateText=1
Update=1000

[Variables]
;-- the time to play the sound as hours.minutes
TimeToPlaySound=11.28
;-- the wave file to play is placed in the @Resources folder.
TheSoundToPlay=#@#TheSoundToPlay.wav

[mHrMinNow]
;-- get the time now from the system clock
Measure=Time
Format=%H.%M

[cCheckIfTimeToPlaySound]
;-- compare the time now to the time to play sound
Measure=Time
Format=%H.%M
IfMatch=#TimeToPlaySound#
;-- if the times match play the sound
IfMatchAction=[PLAY #TheSoundToPlay#]

[MeterString]
Meter=String
MeasureName=mHrMinNow
SolidColor=000000
FontColor=ffffff
Text=" %1 "
User avatar
balala
Rainmeter Sage
Posts: 13533
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Getting a sound to play at a specific time

Post by balala »

Mordasius wrote: November 19th, 2021, 3:33 am There are dozens of ways to do this. Here is one.
If the time has been formatted this way (with dot as separator), would be much useful to use IfConditions, instead of IfMatch. IfCondition is much more versatile option and lets you to check much easier the condition. For instance:

Code: Select all

[cCheckIfTimeToPlaySound]
Measure=Time
Format=%H.%M
IfCondition=(#CURRENTSECTION#>=#TimeToPlaySound#)
IfTrueAction=[PLAY #TheSoundToPlay#]
My advice is to always use IfConditions instead of any other checking method (IfMatch or IfActions), if possible.
User avatar
Mordasius
Posts: 1084
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Getting a sound to play at a specific time

Post by Mordasius »

balala wrote: November 19th, 2021, 8:09 am My advice is to always use IfConditions instead of any other checking method (IfMatch or IfActions), if possible.
Sure, it's probably six of one and half-a-dozen of the other. But perhaps you could explain why, in this specific instance, instead of IfMatch
the IfCondition is much more versatile option and lets you to check much easier the condition
Seems to me the IfMatch condition I used is almost identical to the IfCondition you propose. Or am I missing something along the way?
Last edited by Mordasius on November 19th, 2021, 1:50 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22421
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Getting a sound to play at a specific time

Post by jsmorley »

Mordasius wrote: November 19th, 2021, 1:45 pm
Sure, it's probably six of one and half-a-dozen of the other. But perhaps you could explain why, in this specific instance, instead of IfMatch

Seems to me the IfMatch condition I used is identical to the IfCondition you propose. Or am I missing something along the way?
I think the advice about IfCondition is more "general" than it is specific to this instance. The advantage to IfCondition is that it can be used on any measure, and isn't, like IfMatch is, specific to the value of the measure it is on. Of course this depends on the value being tested being numeric in nature, as only IfMatch can test a string value. I don't see any real advantage in this case, where the test is already on the measure that is returning the data you are testing.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4499
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Getting a sound to play at a specific time

Post by eclectic-tech »

Mordasius wrote: November 19th, 2021, 1:45 pm

Sure, it's probably six of one and half-a-dozen of the other. But perhaps you could explain why, in this specific instance, instead of IfMatch

Seems to me the IfMatch condition I used is identical to the IfCondition you propose. Or am I missing something along the way?
Beaten again!
  Ah, well, here is my thought...  
Yes, the 2 methods are very similar, IfMatch is design to test STRING values and IfCondition test NUMERICAL values.

When deciding whether to use IfMatch or IfCondition to test values, I will mainly consider these 2 things:

IfMatch can use RegExp syntax to qualify what text is tested; case-insensitive, only certain characters, etc. but only on a value in the current measure.

IfCondition tests numerical values, but it's main advantage is it can test a value used anywhere in the skin, not limited to just the current measure value.

So depending on the type of value (STRING versus NUMERICAL) and whether the value is in the current measure or elsewhere in the code determine which method I choose.

In general, I try to use IfCondition because it is not bound to the current measure values.
User avatar
Mordasius
Posts: 1084
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Getting a sound to play at a specific time

Post by Mordasius »

jsmorley wrote: November 19th, 2021, 1:50 pm I think the advice about IfCondition is more "general" than it is specific to this instance.
And I think that is the essence of it. Whether to use IfCondition or IfMatch depends on the situation. I use IfCondition in my PrayerTime skin because it needs a numerical expression from using Adhan=1 or Adhan=0 to determine whether or not to play the Adhan.

Code: Select all

[mHrMinNow]
Measure=Time
Format=%H.%M

[mDecTimeNow]
Measure=Calc
Formula= (Trunc( mHrMinNow ) + ( Frac( mHrMinNow ) * 100 / 60 ) )

[cPlayAdhan]
Measure=Calc
Formula=(Trunc( #NextAdhanDecTime# ) + (Trunc( Frac( #NextAdhanDecTime# ) * 60 ) / 100) ) - mHrMinNow
IfCondition = (cPlayAdhan = 0 ) && ( #AdhanOn# )
IfTrueAction= [PLAY #AdhanSound#]
DynamicVariables=1
@HeyItsVal: You have got what you can expect from the Rainmeter Forums. A Rainmeter Developer, two Rainmeter Sages and a Rainmeter MisherMasher all trying to help you on your way. Good luck with your Rainmeter coding and you can always come back for more advice.
User avatar
jsmorley
Developer
Posts: 22421
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Getting a sound to play at a specific time

Post by jsmorley »

Yes, I think the confusion in this case came because Mordasius went to the bother of setting the Format option on the Time measure as Format=%H.%M, which makes the value "numeric" in nature, rather than using the more standard time format of Format=%H:%M. When using IfMatch, there is no advantage in having Rainmeter see the value as numeric, but it certainly does no harm in this case.

Either IfMatch or IfCondition will work identically and equally well in this case.
User avatar
balala
Rainmeter Sage
Posts: 13533
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Getting a sound to play at a specific time

Post by balala »

Mordasius wrote: November 19th, 2021, 1:45 pm Sure, it's probably six of one and half-a-dozen of the other. But perhaps you could explain why, in this specific instance, instead of IfMatch
Not in this "specific instance", but generally I think an IfCondition is, as said, much more versatile. For instance, what if I want to check the match of time and want to play the sound when the time match the specified moment, or when I restart my computer after it has been in sleeping / hibernating, if the moment has passed. With IfMatch this is not possible, the sound will be played only at the specified moment. But with a proper IfCondition, it is much easier to do this (my above code does it).
Or what if someone want to execute some action between the specified moment and for instance two minutes later. With IfCondition this is extremely easy:

Code: Select all

[cCheckIfTimeToPlaySound]
Measure=Time
Format=%H.%M
IfCondition=((#CURRENTSECTION#>=#TimeToPlaySound#)&&(#CURRENTSECTION#<=#TimeToPlaySound#+0.01))
IfTrueAction=[!ShowMeter "AnyMeter"][!Redraw]
IfFalseAction=[!HideMeter "AnyMeter"][!Redraw]
Yes, definitely not this was the intention of OP, I just wanted to show a way to easier check the condition and to modify it if needed on future.
Obviously which of these options is better, depends. The definitely can't be used in place of each other, at least not always.
Mordasius wrote: November 19th, 2021, 2:18 pm And I think that is the essence of it. Whether to use IfCondition or IfMatch depends on the situation.
Definitely.

I definitely didn't want to offense you with my post. Appologize if I did. Sorry.
User avatar
Mordasius
Posts: 1084
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

Re: Getting a sound to play at a specific time

Post by Mordasius »

balala wrote: November 19th, 2021, 3:52 pm I definitely didn't want to offense you with my post. Appologize if I did. Sorry.
I don't take offense easily and certainly not in this case. :bow: