Ob-8 Controller Script

Post Reply New Topic
RELATED
PRODUCTS

Post

AUTO-ADMIN: Non-MP3, WAV, OGG, SoundCloud, YouTube, Vimeo, Twitter and Facebook links in this post have been protected automatically. Once the member reaches 5 posts the links will function as normal.
I am trying to write a script that will let me send midi CC's to an OB-8. I want to use the controller so I can throttle the midi and not crash the vintage synths processor. For the life of me I can't get this script (or any script I downloaded from the internet to test) to appear in the bitwig controllers Hardware Manufactures pulldown menu. I have tried making a subfolder with the name "company" and putting the script in there. I have tried just putting the .js file in the controllers folder. I have tried on both mac and pc. There must be something I am missing. Please help me with my inept implementation !! Thanks

Code: Select all (#)

loadAPI(1);

host.defineController("Oberheim", "OB8", "1.0", "2971ecb0-fdd8-11ef-ac77-0800200c9a66");
host.defineMidiPorts(1, 1);

var MIDI_DELAY_MS = 20;  // Adjust this value to throttle MIDI events (milliseconds)
var midiOut;
var midiQueue = [];
var isProcessingQueue = false;

// Mapping CC Numbers based on OB-8 CC Map
var CC_MAP = {
    "Osc1_Freq": 15,             // Oscillator 1 Frequency
    "Osc1_Waveform": 16,         // Oscillator 1 Waveform
    "Osc1_PulseWidth": 17,       // Oscillator 1 Pulse Width
    "Osc1_Level": 18,            // Oscillator 1 Level
    "Osc2_Freq": 19,             // Oscillator 2 Frequency
    "Osc2_Waveform": 20,         // Oscillator 2 Waveform
    "Osc2_PulseWidth": 21,       // Oscillator 2 Pulse Width
    "Osc2_Level": 22,            // Oscillator 2 Level
    "Osc2_Sync": 23,             // Oscillator 2 Sync
    "Osc2_Detune": 24,           // Oscillator 2 Detune
    "Osc2_CrossMod": 25,         // Oscillator 2 Cross Modulation
    "VCF_Cutoff": 27,            // Voltage Controlled Filter Cutoff Frequency
    "VCF_Resonance": 28,         // Voltage Controlled Filter Resonance
    "VCF_EnvAmount": 29,         // Voltage Controlled Filter Envelope Amount
    "VCF_EnvAttack": 30,         // Voltage Controlled Filter Envelope Attack
    "VCF_EnvDecay": 31,          // Voltage Controlled Filter Envelope Decay
    "VCF_EnvSustain": 32,        // Voltage Controlled Filter Envelope Sustain
    "VCF_EnvRelease": 33,        // Voltage Controlled Filter Envelope Release
    "VCF_Polarity": 34,          // Voltage Controlled Filter Polarity
    "LFO_Rate": 35,              // Low Frequency Oscillator Rate
    "LFO_Amount": 36,            // Low Frequency Oscillator Amount
    "LFO_Waveform": 37,          // Low Frequency Oscillator Waveform
    "Amp_EnvAttack": 38,         // Amplifier Envelope Attack
    "Amp_EnvDecay": 39,          // Amplifier Envelope Decay
    "Amp_EnvSustain": 40,        // Amplifier Envelope Sustain
    "Amp_EnvRelease": 41,        // Amplifier Envelope Release
    "Mod_Wheel": 42,             // Modulation Wheel
    "Pitch_Bend": 43,            // Pitch Bend
    "Portamento_Time": 44,       // Portamento Time
    "Portamento_Mode": 45,       // Portamento Mode
    "Unison_Mode": 46,           // Unison Mode
    "Unison_Detune": 47,         // Unison Detune
    "Glide": 48,                 // Glide
    "Volume": 49,                // Volume
    "Pan": 50,                   // Pan
    "Tune": 51,                  // Master Tune
    "Chorus": 52,                // Chorus
    "Arp_Mode": 53,              // Arpeggiator Mode
    "Arp_Rate": 54,              // Arpeggiator Rate
    "Arp_Range": 55,             // Arpeggiator Range
    "Arp_Latch": 56,             // Arpeggiator Latch
    // Add more parameters as needed
};

function init() {
    host.getMidiInPort(0).setMidiCallback(onMidi);
    midiOut = host.getMidiOutPort(0);

    var userControls = host.createUserControls(Object.keys(CC_MAP).length);
    var i = 0;
    
    for (var param in CC_MAP) {
        userControls.getControl(i).setLabel(param);
        userControls.getControl(i).addValueObserver(128, makeThrottledMidiSendFunction(CC_MAP[param]));
        i++;
    }

    // Print a message to confirm the script is loaded
    println("OB8 Controller initialized.");
}

// Function to add MIDI messages to the queue
function makeThrottledMidiSendFunction(ccNumber) {
    return function(value) {
        midiQueue.push([0xB0, ccNumber, value]);  // Store MIDI message in queue
        println("Queued MIDI message: CC=" + ccNumber + ", Value=" + value);
        processMidiQueue();
    };
}

// Process the MIDI queue with a delay
function processMidiQueue() {
    if (isProcessingQueue || midiQueue.length === 0) return;
    
    isProcessingQueue = true;
    var message = midiQueue.shift();  // Get the next message

    if (message) {
        midiOut.sendMidi.apply(midiOut, message);
        println("Sent MIDI message: " + message);
    }

    // Schedule the next MIDI message after the delay
    host.scheduleTask(function() {
        isProcessingQueue = false;
        processMidiQueue();  // Call again to process the next item
    }, null, MIDI_DELAY_MS);
}

function onMidi(status, data1, data2) {
    // Handle incoming MIDI if needed
    println("Received MIDI message: status=" + status + ", data1=" + data1 + ", data2=" + data2);
}

function exit() {
    // Cleanup if necessary
    println("OB8 Controller exited.");
}

Post

Oh I figured out I need to create a "New Project" under the HELP > Documentation section which seems a strange place to initiate something!! Forgive me. this is only day two. I will have a million silly questions

Post Reply

Return to “Controller Scripting”