// SPDX-FileCopyrightText: 2012-2023 MOD Audio UG // SPDX-License-Identifier: AGPL-3.0-or-later // Special URI for non-addressed controls var kNullAddressURI = "null" // Special URIs for midi-learn var kMidiLearnURI = "/midi-learn" var kMidiUnlearnURI = "/midi-unlearn" var kMidiCustomPrefixURI = "/midi-custom_" // to show current one, ignored on save // URI for BPM sync (for non-addressed control ports) var kBpmURI ="/bpm" // Grouped options var deviceOption = "/hmi" var ccOption = "/cc" var cvOption = "/cv" // Port types supported by cv addressing var cvModes = ":float:integer:bypass:toggled:" // use pitchbend as midi cc, with an invalid MIDI controller number var MIDI_PITCHBEND_AS_CC = 131 function create_midi_cc_uri (channel, controller) { if (controller == MIDI_PITCHBEND_AS_CC) { return sprintf("%sCh.%d_Pbend", kMidiCustomPrefixURI, channel+1) } return sprintf("%sCh.%d_CC#%d", kMidiCustomPrefixURI, channel+1, controller) } function startsWith (value, pattern) { return value != null && value.indexOf(pattern) === 0; }; function is_control_chain_uri (uri) { if (startsWith(uri, deviceOption)) { return false; } if (uri == kMidiLearnURI || startsWith(uri, kMidiCustomPrefixURI)) { return false; } if (isCvUri(uri)) { return false; } return true; } function isCvUri (uri) { if (startsWith(uri, cvOption)) { return true; } return false; } function isHwCvUri (uri) { if (startsWith(uri, cvOption + '/graph/cv_')) { return true; } return false; } // Units supported for tap tempo (lowercase) var kTapTempoUnits = ['bpm'] function HardwareManager(options) { var self = this options = $.extend({ // This is the function that will actually make the addressing address: function (instanceAndSymbol, addressing, callback) { callback(true) }, // Callback to enable or disable a control in GUI setEnabled: function (instance, portSymbol, enabled, feedback, momentaryMode) {}, // Renders the address html template renderForm: function (instance, port) {}, // Running as mod-app isApp: function () { return false }, }, options) this.beatsPerMinutePort = { ranges: { // XXX would be good to have a centralized place for this data, currently it's also in transport.js and others minimum: 20.0, maximum: 280.0 }, value: null } this.cvOutputPorts = [] this.setBeatsPerMinuteValue = function (bpm) { if (self.beatsPerMinutePort.value === bpm) { return } self.beatsPerMinutePort.value = bpm } this.reset = function () { var addressingsByActuator = $.extend({}, self.addressingsByActuator) var cvOutputPorts = self.cvOutputPorts.slice() /* All adressings indexed by actuator key : "/actuator-uri" value: list("/instance/symbol") */ self.addressingsByActuator = {} self.cvOutputPorts = [] if (cvOutputPorts) { for (var i = 0; i < cvOutputPorts.length; i++) { // if hw cv port, keep it if (isHwCvUri(cvOutputPorts[i].uri)) { self.cvOutputPorts.push(cvOutputPorts[i]) } } } if (addressingsByActuator) { for (var act in addressingsByActuator) { if (isCvUri(act) && cvOutputPorts.find(function (port) { return port.uri === act })) { self.addressingsByActuator[act] = [] } } } /* All addressings indexed by instance + port symbol key : "/instance/symbol" value: "/actuator-uri" */ self.addressingsByPortSymbol = {} /* Saved addressing data key : "/instance/symbol" value: dict(AddressData) */ self.addressingsData = {} // Initializes actuators if (HARDWARE_PROFILE) { var uri for (var i in HARDWARE_PROFILE) { uri = HARDWARE_PROFILE[i].uri self.addressingsByActuator[uri] = [] } } self.addressingsByActuator[kMidiLearnURI] = [] self.addressingsByActuator[kBpmURI] = [] } this.reset() // Get all addressing types that can be used for a port // Most of these are 1:1 match to LV2 hints, but we have extra details. this.availableAddressingTypes = function (port, tempo) { if (tempo) { return ["enumeration"] } var properties = port.properties var available = [] // prevent some properties from going together if (properties.indexOf("trigger") >= 0) { available.push("trigger") } else if (properties.indexOf("enumeration") >= 0) { available.push("enumeration") } else if (properties.indexOf("toggled") >= 0) { available.push("toggled") } else if (properties.indexOf("integer") >= 0) { available.push("integer") } else { available.push("float") } if (properties.indexOf("logarithmic") >= 0) available.push("logarithmic") if (port.symbol === ":bpm" && properties.indexOf("tapTempo") >= 0 && kTapTempoUnits.indexOf(port.units.symbol.toLowerCase()) >= 0) available.push("taptempo") if (port.scalePoints.length >= 2) available.push("scalepoints") if (port.symbol == ":bypass") available.push("bypass") return available } this.availableActuatorsWithModes = function (list, types) { var available = {} if (list) { for (var i in list) { actuator = list[i] modes = actuator.modes // usedAddressings = self.addressingsByActuator[actuator.uri] // if (ADDRESSING_PAGES == 0 && usedAddressings.length >= actuator.max_assigns && usedAddressings.indexOf(key) < 0) { // continue // } if ( (types.indexOf("integer" ) >= 0 && modes.search(":integer:" ) >= 0) || (types.indexOf("float" ) >= 0 && modes.search(":float:" ) >= 0) || (types.indexOf("enumeration") >= 0 && modes.search(":enumeration:") >= 0) || (types.indexOf("logarithmic") >= 0 && modes.search(":logarithmic:") >= 0) || (types.indexOf("toggled" ) >= 0 && modes.search(":toggled:" ) >= 0) || (types.indexOf("trigger" ) >= 0 && modes.search(":trigger:" ) >= 0) || (types.indexOf("taptempo" ) >= 0 && modes.search(":taptempo:" ) >= 0) || (types.indexOf("scalepoints") >= 0 && modes.search(":scalepoints:") >= 0) || (types.indexOf("bypass" ) >= 0 && modes.search(":bypass:" ) >= 0) ) { available[actuator.uri] = actuator } } } return available } this.isCvAvailable = function (port) { var defaultTypes = self.availableAddressingTypes(port, false) var available = self.availableActuatorsWithModes([{ uri: cvOption, modes: cvModes }], defaultTypes) return available.hasOwnProperty(cvOption) } // Gets a list of available actuators for a port this.availableActuators = function (instance, port, tempo) { var key = instance+"/"+port.symbol var defaultTypes = self.availableAddressingTypes(port, false) var types = tempo ? self.availableAddressingTypes(port, tempo) : defaultTypes var available = self.availableActuatorsWithModes(HARDWARE_PROFILE, types) // midi-learn is always available, except for enumeration if (defaultTypes.indexOf("enumeration") < 0 || port.scalePoints.length == 2) { available[kMidiLearnURI] = { uri : kMidiLearnURI, name : "MIDI Learn...", modes: ":float:trigger:bypass:integer:toggled:", steps: [], max_assigns: 99 } } available = $.extend(self.availableActuatorsWithModes(self.cvOutputPorts, defaultTypes), available) return available } this.buildDividerOptions = function (select, port, curDividers) { select.children().remove() var filteredDividers = getDividerOptions(port, self.beatsPerMinutePort.ranges.minimum, self.beatsPerMinutePort.ranges.maximum) // And build html select options for (i = 0; i < filteredDividers.length; i++) { $('