It is currently April 28th, 2024, 3:00 am
Getting a sound to play at a specific time
-
- Posts: 2
- Joined: November 19th, 2021, 1:16 am
Getting a sound to play at a specific time
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.
-
- Posts: 1173
- Joined: January 22nd, 2011, 4:23 pm
- Location: GMT +8
Re: Getting a sound to play at a specific time
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 "
-
- Rainmeter Sage
- Posts: 16182
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Getting a sound to play at a specific time
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#]
-
- Posts: 1173
- Joined: January 22nd, 2011, 4:23 pm
- Location: GMT +8
Re: Getting a sound to play at a specific time
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 almost identical to the IfCondition you propose. Or am I missing something along the way?the IfCondition is much more versatile option and lets you to check much easier the condition
Last edited by Mordasius on November 19th, 2021, 1:50 pm, edited 1 time in total.
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Getting a sound to play at a specific time
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.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?
-
- Rainmeter Sage
- Posts: 5407
- Joined: April 12th, 2012, 9:40 pm
- Location: Cedar Point, Ohio, USA
Re: Getting a sound to play at a specific time
Beaten again!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?
Ah, well, here is my thought... |
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.
:: My DA Gallery :: Rainmeter DA Gallery :: Rainmeter Workshops :: Rainmeter Documentation :: BBCode Guide ::
-
- Posts: 1173
- Joined: January 22nd, 2011, 4:23 pm
- Location: GMT +8
Re: Getting a sound to play at a specific time
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
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Getting a sound to play at a specific time
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.
Either IfMatch or IfCondition will work identically and equally well in this case.
-
- Rainmeter Sage
- Posts: 16182
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Getting a sound to play at a specific time
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]
Obviously which of these options is better, depends. The definitely can't be used in place of each other, at least not always.
Definitely.
I definitely didn't want to offense you with my post. Appologize if I did. Sorry.
-
- Posts: 1173
- Joined: January 22nd, 2011, 4:23 pm
- Location: GMT +8