Need MIDI scripting timer(s)

Bug #368992 reported by Sean M. Pappalardo
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mixxx
Fix Released
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
Revision history for this message
Sean M. Pappalardo (pegasus-renegadetech) wrote :

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?

Revision history for this message
Sean M. Pappalardo (pegasus-renegadetech) wrote :

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

Revision history for this message
Nick (kousu) wrote : Re: [Bug 368992] [NEW] Need MIDI scripting timer(s)

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.
>

Revision history for this message
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.

Revision history for this message
Sean M. Pappalardo (pegasus-renegadetech) wrote :

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
Revision history for this message
Sean M. Pappalardo (pegasus-renegadetech) wrote :

features_scriptTimers has been merged to trunk. Marking fixed.

Changed in mixxx:
status: In Progress → Fix Committed
Revision history for this message
Sean M. Pappalardo (pegasus-renegadetech) wrote :
Revision history for this message
Sean M. Pappalardo (pegasus-renegadetech) wrote :
RJ Skerry-Ryan (rryan)
Changed in mixxx:
status: Fix Committed → Fix Released
Revision history for this message
Swiftb0y (swiftb0y) wrote :

Mixxx now uses GitHub for bug tracking. This bug has been migrated to:
https://github.com/mixxxdj/mixxx/issues/5159

lock status: Metadata changes locked and limited to project staff
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.