Open Socket on ModDuo

Hi,

playing with the browser JS console for modDuo interface (opening 192.168.51.1) to send my own websocket command.
But it will not work if I try to replicate the process from that console, or, and it’s what I really would like to do, from a new window.
for example, I’d try to open a socket: ds = new WebSocket(“ws://192.168.51.1/websocket”); but get a 403 if the not in the page. If I’m in the page I can: do a ds.send(“param_set /graph/Gain/:bypass 0”), using the existing ds object, and that will work (although the not being reflected on the web page).

Ideally I’d like to be able to create a JS client to the mod-duo, with two use cases in mind:

  • be able to program a tactile interface taylored for some music: touch my tablet screen and automatically change a whole set of settings which cannot be done without many pedals.
  • be able to program dynamic change of setting, like I could program a fade out on volume with different lengths and decide what happens when through a JS interface.

I like the current interface, but I think it’s more oriented to help creation / architecture of the pedalboard, not the live playing where you want to tweak quickly. As I play a lot with loop, it’s true that I can get my hand free easily.

One work around would be to build a TamperMonkey, still I was wondering if there was a more direct way.

Any information on the possibility to do that, maybe on how opening a valid websocket outside of the site.
thanks

1 Like

…while I’m not about to start scripting my own touchscreen controls for the MOD, I’m definitely interested in things becoming more performance-oriented within each pedalboard (hi/low ranges for externally assigned CCs would be amazing, as would the option to assign multiple functions to the same CC/program change number… (I could, in theory do this by layering multiple CCs on a single pedal on my Softstep, muting them all except one at a time to assign them all to different controls, and then unmuting them, but that’s a) a huge amount of work, and b) will be easily superceded when we can assign extra control within the MOD :slight_smile:

3 Likes

I tinkered a bit further, and I think I’m stuck.
I tried a simple tampermonkey, to work on a pedalboard where I have a Gain pedal (referred in the websocket as: '/graph/Gain_1’
From that I can easily set the Gain to a desired level by linking event such as for example:
document.getElementById('pedalboard-actions').onclick = function () { ws.send("param_set /graph/Gain_1/Gain 12'); };
But, if I want to get the original state using ws.onmessage(), I’m blocking the page loading.
However, I did a tamperMonkey on that, clicking on the revolving loading logo toggle:

  • my pedal gain back to the original level
  • or the level dynamically waving around that original level

For those interested, the code:
`// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://192.168.51.1/?v=1.1.1
// @grant none
// ==/UserScript==

(function() {
‘use strict’;
console.log (‘tamper starting’);
var effect_ = ‘/graph/Gain_1’; // param_set /graph/Gain_1 Gain -8.750000
var effect_charac = ‘Gain’;
var charac = 0;
var charac_amp = 10;
var charac_step = 0.1;
var charac_stepTime = 50;
var charac_init = 0;
var effect_increase = true;
var effect_on = false;
var effect_tampered;

window.addEventListener('load', function () {
    console.log ('tamper running');
    ws.onmessage = function (event) {
        if (event.data.indexOf(effect_ + ' ' + effect_charac) !== -1) {
            charac_init = charac = parseFloat(event.data.match(/-?\d*.?\d+$/)[0]);
            console.log (effect_ + ' / ' + effect_charac + ' initial state is: ' + charac); //param_set /graph/Gain_1 Gain -11.250000
        }
        if (event.data == 'ping') {
            ws.send('pong');
        }
    };

    document.getElementById('pedalboard-dashboard').onclick = function () {
        effect_on = !effect_on;
        if (effect_on) {
            effect_tampered = setInterval ( function () {
                if (effect_increase) {
                    charac += charac_step;
                } else {
                    charac -= charac_step;
                }
                ws.send("param_set " + effect_ + "/" + effect_charac + " " + charac);
                if (Math.abs(charac - charac_init) > charac_amp) {
                    effect_increase = !effect_increase;
                }
            }, charac_stepTime);
        } else {
            clearInterval(effect_tampered);
        }
    };

}, false);

})();`

FYI ranges in MIDI CC addressings is coming in 1.2.

And you guys know that the code that runs the webserver inside the mod is opensource, right?
See https://github.com/moddevices/mod-ui
It’s possible to tweak the code and copy over the new files, although of course we can’t support this directly or officially. (You’re on own on in this case)

1 Like

@leDamien interesting thing you’re doing there… unfortunately you’re on your own for now as we do not yet this.
However in the future we do have plans to make the entire UI experience also available as a full REST API that can be called by any client easily so other clients will naturally exist.

When that time comes I’ll reach back to this thread and see what you guys have in mind.

3 Likes

I stumbled upon the same issue (trying to make make a html/js page to install custom plugins). The MOD is protected against XSS. Or rather the browser you’re using is honoring Access-Control-Allow-Origin.

You can only make a connection to the server which provided the page. The mod-ui sends an Access-Control-Allow-Origin HTTP header which only allows the MOD itself and *.moddevices.com to perform requests. – You might be able to disable that in your web-browser, or use a different http client (such as curl or QT-webkit), or you could patch the mod-ui on the MOD to not send that header…

From a Plugin GUI itself however it’s rather straight forward to modify parameters. e.g. the “reset” buttons on the Step-Sequencer, set multiple inputs at the same time like this:

Rather than injecting JS client side, you could make a “dummy” plugin that ships the javascript and only controls other plugins.

1 Like

:+1: A fully restful API would be awesome.

1 Like

hmmm that’s a very interesting approach :smiley:
I understand it’s like developping a lv2 pedal in order to interact with the others that might be present.
I have to try that soon.
I got stuck in exploring lv2 plugin but as I do not understand python or settings around it I’m stuck with a blocking issue python linked when loading the docker.