Trying to make a Task that mutes/unmutes sound automatically

nnCron and nnCron LITE discussion

Trying to make a Task that mutes/unmutes sound automatically

Postby LuckMan212 » Thu, 07 Jul 2005, 02:26

greetings again,

I have created the following pair of Tasks:
Code: Select all
#( idle_mute
Rule: IDLE: 600
Action:
   MIXER-STATE 0<>
   IF
      HINT-OFF
      HINT: "muting"
      MIXER-MUTE
      FILE-CREATE: "mute.sem"
   THEN
)#

#( idle_unmute
Rule: IDLE: 0
Rule: FILE-EXIST: "mute.sem"
Action:
   FILE-DELETE: "mute.sem"
   MIXER-STATE 0=
   IF
      HINT-OFF
      HINT: "un-muting"
      MIXER-UNMUTE
   THEN
)#



Well it does not really work as expected. It seems the "IDLE" timer is very "loose" by this I mean it checks very rarely and does not "catch" the IDLE: 0 event usually. So speaker does not un-mute when I come back to my keyboard.

Is there some better way to do this? I thought there was a WinAPI I can monitor that triggers when mouse/keyboard is moved or maybe just a better way to code it inside nnCron?

basically I want to mute speaker after 10mins and then unmute it when I come back -- but ONLY un-mute if the speaker was muted by nnCron. So if I have the speaker already muted, then do not un-mute upon return. This is why I have created the semaphore file "mute.sem". In theory it works, but this code does not work as expected.

help?
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Valery_Kondakoff » Thu, 07 Jul 2005, 10:36

Look, the 'IDLE' returns 'TRUE' if the current idle-counter value is bigger or equal to the specified one.

So, as far as I understand if idle-counter is bigger or equal to 10 minutes both of your tasks are executed. I think this causes the problem.
CU
VK
User avatar
Valery_Kondakoff
Site Admin
 
Posts: 769
Joined: Thu, 01 Jul 2004, 20:49
Location: Moscow, Russia

Postby LuckMan212 » Thu, 07 Jul 2005, 10:47

ok Valery I see what you are saying.

but even just this simple task by itself cannot seem to work right:
Code: Select all
#( idle_mute
Rule: IDLE: 10
Action:
   MIXER-STATE 0<>
   IF
      HINT-OFF
      HINT: "muting"
      MIXER-MUTE
      FILE-CREATE: "mute.sem"
   THEN
)#


this task by itself should mute speaker after 10 seconds of idle. But usually I wait more like 35-45 seconds for some reason. Sometimes up to 1 minute it seems. So perhaps IDLE counter is only checked 1 time per minute?

If this is the case, then I really cannot use nnCron for this feature, because when the user comes back to the keyboard, it may be a whole minute before the speaker is "un-muted" again.

Unless I am missing something, do you agree it cannot be done?
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Valery_Kondakoff » Thu, 07 Jul 2005, 10:58

Hey, 'IDLE' is not an event. This is just a word, that returns TRUE or FALSE when the task is executed. Your task is executed once a minute - so the check is performed once a minute as well. Make your task to start more frequently to reduce the time of IDLE check...
CU
VK
User avatar
Valery_Kondakoff
Site Admin
 
Posts: 769
Joined: Thu, 01 Jul 2004, 20:49
Location: Moscow, Russia

Postby LuckMan212 » Thu, 07 Jul 2005, 11:21

OK, 2 questions:

1) how to make a task that executes more than once per minute?

2) is there not some Windows API or something you can check like an Event for when the screensaver exits or some other way to check when a user returns from being IDLE?
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Valery_Kondakoff » Thu, 07 Jul 2005, 11:46

1) I have already answered on this question: http://www.nncron.ru/forums/viewtopic.php?p=2429#2429

2) I'm pretty sure you can watch for a screensaver using WatchProc* words. Like this: WatchProcStop: "*.scr".
CU
VK
User avatar
Valery_Kondakoff
Site Admin
 
Posts: 769
Joined: Thu, 01 Jul 2004, 20:49
Location: Moscow, Russia

Postby LuckMan212 » Thu, 07 Jul 2005, 12:48

Valery, I am confused... here you tell me:
Valery_Kondakoff wrote:...Your task is executed once a minute - so the check is performed once a minute as well. Make your task to start more frequently to reduce the time of IDLE check...

but then you are telling me, there is no way to make it check more than >1 per minute. :?:

in any case, thank you for the WatchProcStop suggestion, I have now a working solution:
Code: Select all
#( idle_mute
Rule: IDLE: 1800
Action:
   MIXER-STATE 0<>
   IF
      MIXER-MUTE
      FILE-CREATE: "mute.sem"
   THEN
)#

#( idle_unmute
WatchProcStop: "*.scr"
Rule: FILE-EXIST: "mute.sem"
Action:
   FILE-DELETE: "mute.sem"
   MIXER-STATE 0=
   IF
      MIXER-UNMUTE
   THEN
)#


This works reasonably well and my screen saver kicks in after 10mins so by the time the 30minutes (1800 seconds) gets around, it will definitely be running. So the check to see the screen saver exit works well, and takes effect immediately, un-muting the sound. Very nice! 8)
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Valery_Kondakoff » Thu, 07 Jul 2005, 13:03

LuckMan212 wrote:Valery, I am confused... you are telling me, there is no way to make it check more than >1 per minute. :?:


This is true if you use the condition (IDLE, for example) in Rule, which is checked only when the task is executed. But you can use the same condition in the body of the task (Action:) to check the condition at specified interval (for example in a loop).

Like this:
Code: Select all
Action:
IDLE: 600
IF
\ ...
THEN
CU
VK
User avatar
Valery_Kondakoff
Site Admin
 
Posts: 769
Joined: Thu, 01 Jul 2004, 20:49
Location: Moscow, Russia

Postby LuckMan212 » Thu, 07 Jul 2005, 13:15

ok I understand, thank you!
can I ask 1 more?

let's say I would like to move the following section to become a RULE:

Code: Select all
#( idle_mute
Rule: IDLE: 1800 MIXER-STATE 0<> AND
Action:
      MIXER-MUTE
      FILE-CREATE: "mute.sem"
)#
 

to me this is "cleaner" but for some reason it does not work, it executes even if the Mixer is already muted. I don't think the AND portion is working right, maybe my syntax is incorrect.

must I use POSTFIX notation for multiple rules on one line? What is Postfix notation for IDLE?
thanks
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Valery_Kondakoff » Thu, 07 Jul 2005, 13:29

How do you test this task? By starting it manually?
CU
VK
User avatar
Valery_Kondakoff
Site Admin
 
Posts: 769
Joined: Thu, 01 Jul 2004, 20:49
Location: Moscow, Russia

Postby LuckMan212 » Thu, 07 Jul 2005, 13:47

no, I just modify it to 10 seconds for testing purposes:
Code: Select all
#( idle_mute
Rule: IDLE: 10 MIXER-STATE 0<> AND
Action:
      MIXER-MUTE
      FILE-CREATE: "mute.sem"
)#
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby VK » Thu, 07 Jul 2005, 14:08

This task:
Code: Select all
#( idle_mute1
Rule: IDLE: 10 MIXER-STATE 0<> AND
Action:
    MSG: "mute"
)#]


works fine on my PC... Check the task has unique name and the crontab is reladed. What is in nncron.out and log files?..
CU
VK
User avatar
VK
 
Posts: 680
Joined: Wed, 14 Jul 2004, 19:17

Postby LuckMan212 » Fri, 08 Jul 2005, 07:36

ok you are right, I maybe had a typo or something!, it works now :)

can I ask, in theory will the following pair of tasks work so that the first task is only triggered ONCE and not repeatedly every 60 seconds:

Code: Select all
#( idle_mute
Rule: IDLE: 60
Action:
    MSG: "You Have Been asleep for 60 seconds!%crlf%you will not be warned again!"
    CUR-NODE CF-ACTIVE CLR-CRON-FLAG
)#

#( reset_idletimer
WatchProcStop: "*.scr"
Action:
   idle_mute @ CF-ACTIVE SET-CRON-FLAG
)#


I think I tried this yesterday and for some reason the "idle_mute" task did not disable itself, it kept running (I saw entries in the nncron.log) did I do something wrong :?
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby VK » Fri, 08 Jul 2005, 10:25

I think you can add an additional check for idlleness in the task body. If IDLE 80 > - that means, that the task was executed more than one time. Smth like this:

Code: Select all
Action:
IDLE 80 <
IF   
    MSG: "You Have Been asleep for 60 seconds!%crlf%you will not be warned again!"
    CUR-NODE CF-ACTIVE CLR-CRON-FLAG
THEN


HTH!
CU
VK
User avatar
VK
 
Posts: 680
Joined: Wed, 14 Jul 2004, 19:17

Postby LuckMan212 » Fri, 08 Jul 2005, 22:00

yes I suppose that will work,
but if I want to test for IDLE 1800, then such a test would execute every minute up to 30mins.

I suppose I can do something like

Code: Select all
Rule:  IDLE 1740 > 1859 < AND


i guess the above task will trigger somewhere between 29 and 30 minutes of IDLE... :roll:
but I am more curious why the
Code: Select all
CUR-NODE CF-ACTIVE CLR-CRON-FLAG

does not seem to be taking effect....
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19


Return to nnCron forum (English)

Who is online

Users browsing this forum: No registered users and 1 guest

cron