Whenever this function is called, it will print this text to the console in Bitwig.
In order to get access to the function we just defined in our script we have to import this file into our main control script. As long as the file is in the same directory all we need to do is call the load() function somewhere in the global scope of our script where we load the API and define our MIDI ports:
Now we should place our test() function somewhere in our OnMidiPort1() function to verify that this import process has been successful:
If we send any type of MIDI data from our controller we will see the text appear in our console and we have successfully defined our first external function. This is great, but it’s not doing much except flooding the console. Let’s wrap up all of our conditionals regarding the transport into one function. You can do that easily by copying the code that controls our transport state, and placing it into a function definition in our functions.js file:
We have defined a function called transport_functions that takes the the two data bytes of a MIDI message as it’s arguments. Now that we have our transport_functions() defined, we can call this function in the note portion of our onMidiPort1() function and have the same transport functionality that we had previously. The differences are that our script is much more readable on a macro level, we can modify the function in our external file, and we won’t have to touch our main script.
This is a great way to consolidate and abstract pieces of code and it allows you to separate different collections of functionality into different files. When a script starts to reach any level of sophistication it will become very important to keep your code organized and clear. If the code is all put in one file it will become a huge undertaking to modify and troubleshoot.
Direct any questions, comments or concerns to email@example.com