Installing Big Custom Module Directions

I was wondering if anyone can help me wrap my head around installing a big custom module.

  1. I created my custom module named OSC Midi Sequences.js
  2. Inside the script I defined the module.exports variable

module.exports = osc_midi_sequences {

oscOutFilter: function(data) {

    var {address, args, host, port} = data

    if (sequenceRouting[address]) {
        if (args[0].value == 1) controlSequence(host, port, ...sequenceRouting[address])
        return
    }

    return {address, args, host, port}

}

}

  1. Created a main.js as the documentation says to retrieve to my custom-modules.

var tap_tempo = require(’./tap_tempo.js’)
var osc_midi_sequences = require(’./osc_midi_sequences.js’)

module.exports = {
init: function(){
console.log(tap_tempo) // 1
console.log(osc_midi_sequences) // 2
},
oscInFilter: function(data){
// etc
}
}

  1. Created a custom-module.js to bundle my sources
    browserify main.js -o custom-module.js --standalone module.exports
  2. I saved them all in directory with the index.js under \resources\app
  3. I tried calling and not calling the custom-module.js in the launcher window. But neither worked.

I’m probably misunderstanding something as JS is not my language and I’m still learning. Can anyone point me in the right direction?

First of all, I think you should break your module into submodules only if it’s growing very big and hard to maintain. It adds a layer of complexity that doesn’t seem may not help you, considering the fact you’re not comfortable with javascript.

Now there is a syntax problem in osc_midi_sequences.js:
module.exports = osc_midi_sequences {
You should write:
module.exports = {

Also, calling console.log(tap_tempo) does nothing more than printing the object stored in the variable tap_tempo to the console. There’s no automatic “merging” function for submodules, you need to do that manually.

Long story short, I think you should write you custom module as a single file and let yourself getting more familiar with javascript before going into more advanced things.

1 Like

Thank you Jean! I appreciate the explanation still in my errors so I can learn and adapt. I think big modules are perhaps a bit too advance for me at the moment, I was assuming browserify would automatically merge my functions but I was wrong. I thought it was easier to understand based on the documentation but my little JS skills I think it was just confusing in the end for me lol.

My simple idea is just combining the two custom modules into one because I can’t load two custom modules at once. But, how do I deal with the different oscOutFilter: function(data) as I think that’s the only part that is confusing me since you can’t duplicate the same function as one will just be overridden?

EDIT: Nevermind I figured it out. I’m not sure why though as the var is in a different order for both scripts so I was assuming this wouldn’t work?

Edit2: After some researching and learning. I understand that the order doesn’t matter.

// This worked for some reason.
module.exports = {

oscOutFilter: function(data) {

    var {host, port, address, args} = data

    if (address === '/bpm/tap' && args[0].value === 1) {
        // update bpm when the interface sends /bpm/tap 1
        receiveTap(data)

        // bypass original osc message
        return
    }
  
  
    if (sequenceRouting[address]) {
        if (args[0].value == 1) controlSequence(host, port, ...sequenceRouting[address])
        return
    }

    // process other messages normally
    return data

}	

}

EDIT: Nevermind I figured it out

:+1:

1 Like