"Resettable" Delay?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

"Resettable" Delay?

Jim Rosenberg
I'm in the midst of a project in which I'm adding sound to some artistic
work I've been doing in Squeak for quite a few years now. I want a sound to
be played when (1) the mouse cursor enters a morph which is one of my own
subclasses of RectangleMorph; and then (2) the mouse cursor becomes
"quiet". Maybe this is not the right way to do this, but here's how I'm
thinking of doing it:

On mouseEnter, create a Delay and then fork a process which waits on the
Delay and plays the sound. (Duration of the Delay is an artistic decision
based on context.)

On mouseMove, if the Delay is notNil and is being waited on, "reset it".

On mouseLeave, kill the process waiting on the Delay if it hasn't already
fired.

It looks to me from reading the code (Squeak 4.3) that I can reset the
Delay using the Delay class method scheduleDelay: -- but [I haven't tried
it yet ...] this makes me nervous. scheduleDelay: is labelled Private. I
think that's telling me that calling this method from application code is a
No-no. I'm also nervous about what I might need to do regarding the
semaphore.

Comments please? Is there an easier way to do this? I need some way to
reset a Delay that's already being waited on to the original duration.

-Thanks in advance, Jim

Reply | Threaded
Open this post in threaded view
|

Re: "Resettable" Delay?

Kjell Godo
It sounds like it wants you to kill the Delay ( and Process? ) or something and create a new Delay on a replica of the Process ( or this same Process? ) But i am just guessing

On Sat, May 18, 2019 at 22:50 Jim Rosenberg <[hidden email]> wrote:
I'm in the midst of a project in which I'm adding sound to some artistic
work I've been doing in Squeak for quite a few years now. I want a sound to
be played when (1) the mouse cursor enters a morph which is one of my own
subclasses of RectangleMorph; and then (2) the mouse cursor becomes
"quiet". Maybe this is not the right way to do this, but here's how I'm
thinking of doing it:

On mouseEnter, create a Delay and then fork a process which waits on the
Delay and plays the sound. (Duration of the Delay is an artistic decision
based on context.)

On mouseMove, if the Delay is notNil and is being waited on, "reset it".

On mouseLeave, kill the process waiting on the Delay if it hasn't already
fired.

It looks to me from reading the code (Squeak 4.3) that I can reset the
Delay using the Delay class method scheduleDelay: -- but [I haven't tried
it yet ...] this makes me nervous. scheduleDelay: is labelled Private. I
think that's telling me that calling this method from application code is a
No-no. I'm also nervous about what I might need to do regarding the
semaphore.

Comments please? Is there an easier way to do this? I need some way to
reset a Delay that's already being waited on to the original duration.

-Thanks in advance, Jim



Reply | Threaded
Open this post in threaded view
|

Re: "Resettable" Delay?

timrowledge
In reply to this post by Jim Rosenberg
Given that you are unlikely to managed high precision timing in any of this (tell us if that is what you were hoping!) the simplest answer is probably to use Morphic stepping timers.

On mouseEnter, have your morph start stepping and set the interval to suit the needs of the startup delay. Come to think of it, there may just possibly be a method to say "next step at time t" but I'm not an expert in that arena. when the morph steps, you start the sound. If you were for example using shortish sounds and want to change them as time goes by you might also use the steps to do that changeover.
On mouseLeave, you could potentially stop the soundplayer to go silent, or just leave the sound to run out?

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Useful random insult:- His spirit guide is a three-toed sloth.



Reply | Threaded
Open this post in threaded view
|

Re: "Resettable" Delay?

K K Subbu
In reply to this post by Jim Rosenberg
On 19/05/19 11:20 AM, Jim Rosenberg wrote:
> I'm in the midst of a project in which I'm adding sound to some artistic
> work I've been doing in Squeak for quite a few years now. I want a sound
> to be played when (1) the mouse cursor enters a morph which is one of my
> own subclasses of RectangleMorph; and then (2) the mouse cursor becomes
> "quiet".
Morphs incorporate "liveness" through interaction and built-in timers.
The section "Adding Liveness" in the article below explains this very well:

  http://coweb.cc.gatech.edu/squeakbook/uploads/morphic.final.pdf

Briefly, in your subclass, override #wantsSteps to control live play.
Send #startStepping in your #mouseEnter handler and #stopStepping it in
#mouseLeave handler. Use #isStepping to detect if stepping is in progress.

Set your interval in #stepTime and play or stop sound in #step.

HTH .. Subbu

Reply | Threaded
Open this post in threaded view
|

Re: "Resettable" Delay?

Chris Muller-3
In reply to this post by Jim Rosenberg
The balloon help does this.  It uses #Morph>>#addAlarm:after:, et al.
On mouse leave, it kills the alarm if it hasn't already fired.  I used
it in Maui, too, worth checking out.

 - Chris



 - Chris

On Sun, May 19, 2019 at 12:50 AM Jim Rosenberg <[hidden email]> wrote:

>
> I'm in the midst of a project in which I'm adding sound to some artistic
> work I've been doing in Squeak for quite a few years now. I want a sound to
> be played when (1) the mouse cursor enters a morph which is one of my own
> subclasses of RectangleMorph; and then (2) the mouse cursor becomes
> "quiet". Maybe this is not the right way to do this, but here's how I'm
> thinking of doing it:
>
> On mouseEnter, create a Delay and then fork a process which waits on the
> Delay and plays the sound. (Duration of the Delay is an artistic decision
> based on context.)
>
> On mouseMove, if the Delay is notNil and is being waited on, "reset it".
>
> On mouseLeave, kill the process waiting on the Delay if it hasn't already
> fired.
>
> It looks to me from reading the code (Squeak 4.3) that I can reset the
> Delay using the Delay class method scheduleDelay: -- but [I haven't tried
> it yet ...] this makes me nervous. scheduleDelay: is labelled Private. I
> think that's telling me that calling this method from application code is a
> No-no. I'm also nervous about what I might need to do regarding the
> semaphore.
>
> Comments please? Is there an easier way to do this? I need some way to
> reset a Delay that's already being waited on to the original duration.
>
> -Thanks in advance, Jim
>