Execute JS function when track is loaded

I would like to switch my hotcue LEDs when I load a track in a virtual deck (with the keyboard).
How can I trigger the execution of a corresponding “LED update” function?

You can use the logic inside the js file like

If track is loaded then send message illuminate button else switch off illumination.

How to get info if a track is loaded and how to send messages to LED is described in the wiki Javascript and commands explanations. Your file is not programed like to use components script so you better don’t mix it.

But I want to do something automatically every time a track is loaded.
I did see where this is described?

According to the Mixxx Controls doc, Control 143 is named track_loaded. It returns a bool that indicates “whether a track is loaded in the specified deck”. Maybe you can bind to that using something like this:

engine.connectControl("[Channel1]", "track_loaded", callback);

I’m not sure, but that seems like it should work.

Alternatively, run Mixxx in Developer Mode (which you should be doing already), open Developer Tools in the Developer Menu, and pick the Log tab. Then, load a track, and see what appears in the log.

better use inside the DDJ200.init:

engine.makeConnection("[Channel1]", "track_loaded", DDJ200.LED);

then your function for turning the LED status should look like this.

 DDJ200.LED = function () {
     if (engine.getValue("[Channel1]", "track_loaded") === 1) {
         midi.sendShortMsg(x,y,z)   // 3 byte midi signal for turning your LED on
     } else if (engine.getValue("[Channel1]", "track_loaded") === 0) {
         midi.sendShortMsg(x,y,z)   // 3 byte midi signal for turning your LED off
     }
 };

then repeat for all channels or put it into a loop

for binding several LEDs more easy check the Wiki page here. Read that whole site anyway…

1 Like

@OsZ - nice one, chap. I was unsure if it would even work (and suggested the wrong method).

@Aldous - One point I just wanted to add: Some controllers have a SysEx message for lighting up any subset of the LEDs in a single call, but I don’t know if you have something like that on your controller.

Thanks a lot. It is working very well like this:

   for (var i = 1; i <= 4; i++) {
    var vgroup = "[Channel" + i + "]";
    // run onTrackLoad after every track load to e.g. set LEDs accordingly
    engine.connectControl(vgroup, "track_loaded", "DDJ200.onTrackLoad");
}

Here is the full four deck mapping:

Cheers!

Awesome! Glad you managed to map it. Cheers!