Variable timer interval?

I’m trying to build a metronome. This code clicks once per second:

starttimer "metronome", "code",{beep }, "interval", 1

It also clicks once per second if I omit the “interval” parameter.

But if I want it to click more often than once per second, I’m stuck. If I make the interval any decimal fraction, e.g. .5, the code races through, making a low-pitched buzz.
I saw this in the doc:

This property specifies how often the timer task will be performed. For example, this procedure sets up a timer that checks email every 15 minutes.

starttimer "checkemail","interval",15*60,"code",{farcall myemail,check}

So I tried

starttimer "metronome", "code",{beep }, "interval", .005*60

which I reasoned should give me about 3 beeps per minute; but it didn’t give me even one.

Is my thinking skewed, or am I asking Pan to do something it can’t do?

The timer interval is not a floating point value, it is in an integer. Fractional seconds aren’t allowed. In other words, you can’t make a timer fire off more than once per second.

If I make the interval any decimal fraction, e.g. .5, the code races through, making a low-pitched buzz.

I believe this is being rounded down to zero, so it is firing off over and over again as fast as it can. This is what causes the buzz.

which I reasoned should give me about 3 beeps per minute

I’m not sure what your reasoning is – that evaluates to 0.3, or about 3 times per second. I’m not sure why that didn’t also give you a buzzing sound.

Even if fractional seconds were allowed, this feature would not really be very good for a metronome. It’s not designed to repeat precisely at a particular time for a musical application. If Panorama is busy doing something else when it’s time for the timer to fire, the timer won’t fire. So a 10 second timer could turn into 11, 12, or even 100 seconds.

The purpose of the timer feature is to allow background tasks to run periodically. For example, the Server Administration window uses a timer to periodically update the display of the server status. For that sort of application, it doesn’t really matter if timing is exact. And if a background task is running more than once per second, is it really a background task?

An application like a metronome is what’s called a “real time” task. There’s an entire speciality of programming devoted to that, which is used for video, audio, music, etc. Panorama is not designed for that sort of real time task.

You might be able to use the looping feature of the playsound statement to create a metronome. You would need a recording of one beat of a metronome which you could play over and over again. However, I’m not sure if the looping feature would be accurate enough for this application, but it could be worth a try.

Another possible approach for this would be to use a small Web Browser Object to play an audio file of a metronome. The HTML commands for playing this file would allow you to loop the file as well as adjusting the playback rate. If your audio file is a minute or so long the looping would be minimal and maybe unnoticable. The pitch of the playback is corrected automatically at the various playback speeds so it will sound natural either sped up or slowed down.

You can find info on the playbackRate property here:

There are many sources for metronome audio files of various types online. You could have a button to start and stop the playback as well as a slide control to adjust the playback speed. I have not tested this method with Panorama X so I’m not 100% sure it will work in the Web Browser Object but it is listed to work in most current browsers including Safari.