While controlling QuickTime Player via Applescript from within the image, I want to play a CD track until it reaches a certain point. QTP does not expose "playTo: aPosition" functionality, so I'm polling the track position until the time is reached. I don't want to lock up Morphic, so I'm doing this in another thread.
The following works, but I've never used threads before and wanted to get opinions. What do you think?
cd play.
[ [ cd position < endTime ] whileTrue: [ Processor yield ]. cd pause ] fork.
* "cd position" gets the track position via Applescript * endTime is a variable holding the time to play until
Sean
On Sun, 7 Nov 2010, Sean P. DeNigris wrote:
While controlling QuickTime Player via Applescript from within the image, I want to play a CD track until it reaches a certain point. QTP does not expose "playTo: aPosition" functionality, so I'm polling the track position until the time is reached. I don't want to lock up Morphic, so I'm doing this in another thread.
The following works, but I've never used threads before and wanted to get opinions. What do you think?
cd play.
[ [ cd position < endTime ] whileTrue: [ Processor yield ]. cd pause ] fork.
- "cd position" gets the track position via Applescript
- endTime is a variable holding the time to play until
This will starve lower priority processes, because Processor yield only activates same or higher priority processes. A short delay is better.
Levente
Sean
View this message in context: http://forum.world.st/Wait-for-an-external-app-tp3030911p3030911.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
This will starve lower priority processes, because Processor yield only activates same or higher priority processes. A short delay is better.
Okay, will do. Is there an idiomatic "short delay" (e.g. 50ms) or just make something up?
Sean
On 08.11.2010, at 17:12, Sean P. DeNigris wrote:
This will starve lower priority processes, because Processor yield only activates same or higher priority processes. A short delay is better.
Okay, will do. Is there an idiomatic "short delay" (e.g. 50ms) or just make something up?
Use the largest you can that gives you the needed accuracy. Polling 20 times per second is not that much but might still be overkill.
If you can estimate the time remaining then you could even use an adaptive delay. E.g. wait 90% of the remaining time:
cd play. [ [ (remaining := endTime - cd position) > 0 ] whileTrue: [ (Delay forSeconds: remaining * 0.9) wait ]. cd pause ] fork.
That's assuming "position" is in seconds, of course.
- Bert -
Bert Freudenberg wrote:
If you can estimate the time remaining then you could even use an adaptive delay.
Cool, wouldn't have thought of that. I'll add it to the bad of tricks!
Sean
On 11/8/2010 8:12 AM, Sean P. DeNigris wrote:
This will starve lower priority processes, because Processor yield only activates same or higher priority processes. A short delay is better.
Okay, will do. Is there an idiomatic "short delay" (e.g. 50ms) or just make something up?
FWIW, if your application is interactive, I would do that test in a step method rather than a background process. I.e.,
MyMorph>>startPlaying "Start playing and establish the time watcher"
cd play. self startStepping: #watchPlayTime at: Time millisecondClockValue arguments: nil stepTime: 20.
MyMorph>>watchPlayTime "is it time to stop playing?"
cd position > endTime ifTrue:[self stopPlaying].
MyMorph>>stopPlaying "Stop playing. Also stop the watcher."
cd pause. self stopStepping: #watchPlayTime.
Cheers, - Andreas
Teleplacer wrote:
FWIW, if your application is interactive, I would do that test in a step method rather than a background process. I.e.,
I went the process route because I wanted it to work with or without a GUI (maybe overkill, but it's been drilled into me).
Sean
Teleplacer wrote:
Is there an idiomatic "short delay"
FWIW, if your application is interactive, I would do that test in a step method rather than a background process.
I keep coming back to this. Now I want code to be run when a CD is inserted. What's the best way to do this?
I was thinking about a forked process again that checks every so often, but this seems wasteful, since it will be a relatively rare event. Then, I re-read the Morphic suggestions, but given that this has nothing to do with the UI (although the event handler may well launch a UI), that doesn't feel right either.
Thanks. Sean
beginners@lists.squeakfoundation.org