[jmsl] visual metronome

jmsl at music.columbia.edu jmsl at music.columbia.edu
Mon Feb 20 17:37:59 EST 2006

Hi Mike

The easiest way to do this is subclass MusicJob, and give it a visual 
component into which it can draw or write.  Give it a huge repeat count 
and have its repeat() method return playtime + 1 to delay it one sec 
every repeat

In order to synch it with audio, it will need to be initially delayed by 
JMSL.clock.getAdvance() + JSynLatency (assuming you are using JSyn)
Use myMetronome.setStartDelay(thatValue) to delay its startup
Launch it in parallel with your other Composables

There is no way currently to programmatically get the latency in JSyn so 
you need to set it by hand.

Something like:

package gui;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import com.didkovsky.portview.PVFrame;
import com.didkovsky.portview.PVLabel;
import com.didkovsky.portview.swing.ViewFactorySwing;
import com.softsynth.jmsl.JMSL;
import com.softsynth.jmsl.MusicJob;

 * @author Nick Didkovsky, (c) 2005 Nick Didkovsky, 
didkovn at mail.rockefeller.edu
public class VisualMetronome extends MusicJob {

    private PVLabel label = JMSL.getViewFactory().createLabel("Metronome");
    private String[] tictoc = { "TIC", "TOC" };

    public PVLabel getLabel() {
        return label;

    public double repeat(double playTime) {
        label.setText(tictoc[getRepeatCount() % tictoc.length]);
        return playTime + 1;

    public static void main(String[] args) {
        JMSL.setViewFactory(new ViewFactorySwing());

        VisualMetronome visualMetronome = new VisualMetronome();

        PVFrame frame = JMSL.getViewFactory().createFrame();
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
        frame.setSize(300, 200);
        double jsynLatency = 0.1;
        visualMetronome.setStartDelay(JMSL.clock.getAdvance() + 

Nick Didkovsky

jmsl at music.columbia.edu wrote:

> Now I am working on the electronic accompaniment to the new piece. I 
> want to
> script a visual metronome that runs in sync from the launched music 
> job that
> plays the electronics part. Before I waste a ton of time figuring how 
> to do
> it because I am not sure where to begin, I wanted to see if you have some
> code laying around for such a task, i.e. The visual metronome. Should 
> I be
> concerned about timing accuracy?
> Thanks,
> Mike
> _______________________________________________
> jmsl mailing list
> jmsl at music.columbia.edu
> http://music.columbia.edu/mailman/listinfo/jmsl

More information about the jmsl mailing list