Need MIDI scripting timer(s)

Bug #368992 reported by Sean M. Pappalardo on 2009-04-29
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mixxx
Wishlist
Sean M. Pappalardo

Bug Description

We should probably implement a way for certain MIDI script functions to be called at regular intervals whether or not the controller was manipulated or a ControlObject::valueChanged signal was fired. This would be useful for spontaneous reactions (like flashing LEDs.) Scripts could set up these timers by calling engine.initTimer(<timer name>,<interval in ms>,<function name>) and destroy them with engine.removeTimer(<timer name>). Then engine.startTimer(<timer name>) and engine.stopTimer(<timer name>) would do what they imply.

A few script developers have asked about this functionality.

The current workaround involves connecting a function to [ChannelX] playposition (whose valueChanged signal fires every latency period) and setting/checking a global variable with the current time in milliseconds like so:

if (StantonSCS1m.displayFlash[deck]==-1) StantonSCS1m.displayFlash[deck] = new Date();
if (new Date() - StantonSCS1m.displayFlash[deck]>500) {
     StantonSCS1m.displayFlash[deck] = new Date();
     ...
}

It works, but it's inaccurate and only works while the track is playing.

Changed in mixxx:
assignee: nobody → pegasus-renegadetech
importance: Undecided → Wishlist
milestone: none → 1.8.0
status: New → Confirmed

Possible implementation:

Have something like a QMap in the MIDIScriptEngine that stores objects which contain the values passed to initTimer as well as a 'run' flag and a 'next trigger' value which is the interval value plus the current time (in ms) as the key. Then the event loop can continually check the QMap for time values that match the current time. When one does (and the 'run' flag is set,) update the 'next trigger' value and call the specified script function. startTimer and stopTimer would obviously just set and clear the 'run' flag respectively (and update the 'next trigger' value.)

Any problems with this?

Scratch that...rryan just told me of QTimers which will make implementing these relatively trivial. :)

Doesn't javascript come with this? setTimeout()?

On 28/04/2009, Pegasus <email address hidden> wrote:
> Public bug reported:
>
> We should probably implement a way for certain MIDI script functions to
> be called at regular intervals whether or not the controller was
> manipulated or a ControlObject::valueChanged signal was fired. This
> would be useful for spontaneous reactions (like flashing LEDs.) Scripts
> could set up these timers by calling engine.initTimer(<timer
> name>,<interval in ms>,<function name>) and destroy them with
> engine.removeTimer(<timer name>). Then engine.startTimer(<timer name>)
> and engine.stopTimer(<timer name>) would do what they imply.
>
> A few script developers have asked about this functionality.
>
> The current workaround involves connecting a function to [ChannelX]
> playposition (whose valueChanged signal fires every latency period) and
> setting/checking a global variable with the current time in milliseconds
> like so:
>
> if (StantonSCS1m.displayFlash[deck]==-1) StantonSCS1m.displayFlash[deck] =
> new Date();
> if (new Date() - StantonSCS1m.displayFlash[deck]>500) {
> StantonSCS1m.displayFlash[deck] = new Date();
> ...
> }
>
> It works, but feels wrong to me. What do you all think?
>
> ** Affects: mixxx
> Importance: Wishlist
> Assignee: Pegasus (pegasus-renegadetech)
> Status: Confirmed
>
> ** Changed in: mixxx
> Importance: Undecided => Wishlist
>
> ** Changed in: mixxx
> Status: New => Confirmed
>
> ** Changed in: mixxx
> Milestone: None => 1.8.0
> Assignee: (unassigned) => Pegasus (pegasus-renegadetech)
>
> --
> Need MIDI scripting timer(s)
> https://bugs.launchpad.net/bugs/368992
> You received this bug notification because you are a member of Mixxx
> Development Team, which is subscribed to Mixxx.
>

ironstorm (ironstorm-gmail) wrote :

I remember trying to do something with setTimeout() inside the early versions of MIDI scripting and it didn't work w/ Qt4.4 ... You can try it against 4.5 but I wouldn't hold out too much hope for it.

Timers are implemented and ready to go in the features_scriptTimers branch. Awaiting review & merge to trunk to mark this bug fixed.

Changed in mixxx:
status: Confirmed → In Progress
description: updated

features_scriptTimers has been merged to trunk. Marking fixed.

Changed in mixxx:
status: In Progress → Fix Committed
RJ Skerry-Ryan (rryan) on 2010-10-05
Changed in mixxx:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers