window.rigforgeBoundaryChannels = 4; // SPDX-FileCopyrightText: 2012-2023 MOD Audio UG // SPDX-License-Identifier: AGPL-3.0-or-later $.ui.intersect = function(draggable, droppable, toleranceMode) { if (!droppable.offset) { return false; } var draggableLeft, draggableTop, x1 = (draggable.positionAbs || draggable.position.absolute).left, y1 = (draggable.positionAbs || draggable.position.absolute).top, x2 = x1 + draggable.helperProportions.width, y2 = y1 + draggable.helperProportions.height, l = droppable.offset.left, t = droppable.offset.top, r = l + droppable.proportions.width, b = t + droppable.proportions.height; switch (toleranceMode) { case "custom": return (l < x1 + (draggable.helperProportions.width / 2) && // Right Half x2 - (draggable.helperProportions.width / 2) < r && // Left Half t < y1 + (draggable.helperProportions.height / 2.5) && // Bottom Half y2 - (draggable.helperProportions.height / 2.5) < b ); // Top Half case "custom-replace": { var scale = draggable.helper.data('scale'); if (!scale) { return false; } x1 = draggable.helper.offset().left; y1 = draggable.helper.offset().top; x2 = x1 + draggable.helper.children().width() * scale; y2 = y1 + draggable.helper.children().height() * scale; r = l + droppable.proportions.width * scale; b = t + droppable.proportions.height * scale; /* helper code for display drag and drop areas $('#dropable-area').css({ left: l, width: r - l, top: t, height: b - t, }) $('#draggable-area').css({ left: x1, top: y1, width: x2 - x1, height: y2 - y1, }) */ // touch return ( (y1 >= t && y1 <= b) || // Top edge touching (y2 >= t && y2 <= b) || // Bottom edge touching (y1 < t && y2 > b) // Surrounded vertically ) && ( (x1 >= l && x1 <= r) || // Left edge touching (x2 >= l && x2 <= r) || // Right edge touching (x1 < l && x2 > r) // Surrounded horizontally ); } case "fit": return (l <= x1 && x2 <= r && t <= y1 && y2 <= b); case "intersect": return (l < x1 + (draggable.helperProportions.width / 2) && // Right Half x2 - (draggable.helperProportions.width / 2) < r && // Left Half t < y1 + (draggable.helperProportions.height / 2) && // Bottom Half y2 - (draggable.helperProportions.height / 2) < b ); // Top Half case "pointer": draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left); draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top); return isOverAxis( draggableTop, t, droppable.proportions().height ) && isOverAxis( draggableLeft, l, droppable.proportions().width ); case "touch": return ( (y1 >= t && y1 <= b) || // Top edge touching (y2 >= t && y2 <= b) || // Bottom edge touching (y1 < t && y2 > b) // Surrounded vertically ) && ( (x1 >= l && x1 <= r) || // Left edge touching (x2 >= l && x2 <= r) || // Right edge touching (x1 < l && x2 > r) // Surrounded horizontally ); default: return false; } }; JqueryClass('pedalboard', { init: function (options) { var self = $(this) options = $.extend({ // baseScale is the initial scale (zoom level) of the pedalboard // The scale is the transform scale() css property that the pedalboard has baseScale: 0.5, // maxScale is the maximum zoom. maxScale: 1, // wherever to skip zoom animations skipAnimations: false, // WindowManager instance windowManager: new WindowManager(), // HardwareManager instance, must be specified hardwareManager: null, // Wait object, used to show waiting message to user wait: new WaitMessage(self), // current z index (last plugin added or moved around) z_index: 30, // This is a margin, in pixels, that will be disconsidered from pedalboard height when calculating // hardware ports positioning bottomMargin: 0, cvAddressing: false, // Below are functions that application uses to integrate functionality to pedalboard. // They all receive a callback as last parameter, which must be called with a true value // to indicate that operation was successfully executed. // In case of error, application is expected to communicate error to user and then call the // callback with false value. The pedalboard will silently try to keep consistency, with // no garantees. (TODO: do something if consistency can't be achieved) // Loads a plugin with given plugin uri and instance // Application MUST use this instance. Overriding this is mandatory. pluginLoad: function (uri, instance, x, y, callback, errorCallback) { callback(true) }, // Removes the plugin given by instance pluginRemove: function (instance, callback) { callback(true) }, // Loads a preset pluginPresetLoad: function (instance, uri, callback) { callback(true) }, // Save a new preset pluginPresetSaveNew: function (instance, name, callback) { callback({ok:false}) }, // Save a preset, replacing an existing one pluginPresetSaveReplace: function (instance, uri, bundlepath, name, callback) { callback({ok:false}) }, // Delete a preset pluginPresetDelete: function (instance, uri, bundlepath, callback) { callback(true) }, // Export the current plugin settings as a .modpreset file pluginPresetExport: function (instance, name, callback) { callback({ok:false}) }, // Import a .modpreset file as a user preset pluginPresetImport: function (instance, file, callback) { callback({ok:false}) }, // Changes the parameter of a plugin's control port pluginParameterChange: function (port, value) {}, // Get value of a plugin parameter pluginPatchGet: function (instance, uri) {}, // Set value of a plugin parameter pluginPatchSet: function (instance, uri, valuetype, value) {}, // Connects two ports portConnect: function (fromPort, toPort, callback) { callback(true) }, // Disconnect two ports portDisconnect: function (fromPort, toPort, callback) { callback(true) }, // Removes all plugins reset: function (callback) { callback(true) }, // Marks the position of a plugin pluginMove: function (instance, x, y) {}, // Takes a list of plugin URIs and gets a dictionary containing all those plugins's data, // indexed by URI getPluginsData: function (uris, callback) { callback({}) }, // Show dialog with plugin info, same as clicking on the bottom plugin bar showPluginInfo: function (pluginData) { }, // Show the plugin's native UI, in an external desktop window showExternalUI: function (instance) { }, // Sets the size of the pedalboard windowSize: function (width, height) {}, // inform dekstop instance that pedalboard has finished loading pedalboardFinishedLoading: function (callback) { callback() }, // Add new plugin cv output port to available addressable cv ports // or update existing cv port's name addCVAddressingPluginPort: function (uri, label, callback) { callback(true) }, // Remove plugin cv output port from available addressable cv ports removeCVAddressingPluginPort: function (uri, callback) { callback(true) }, // Show notification that we are using a demo plugin notifyDemoPluginLoaded: function () { }, }, options) self.pedalboard('wrapApplicationFunctions', options, [ 'pluginLoad', 'pluginRemove', 'pluginPresetLoad', 'pluginPresetSaveNew', 'pluginPresetSaveReplace', 'pluginPresetDelete', 'pluginPresetExport', 'pluginPresetImport', 'pluginParameterChange', 'pluginPatchGet', 'pluginPatchSet', 'pluginMove', 'portConnect', 'portDisconnect', 'reset', 'getPluginsData' ]) self.data(options) // When bypassApplication is set to true, the applicationFunctions provided by options will be bypassed self.data('bypassApplication', false) // minScale holds the minimum scale of the pedalboard. It's initialized as being the base scale // and gets smaller as pedalboard size grows self.data('minScale', options.baseScale) self.data('instanceCounter', -1) self.data('overCount', 0) // Holds all plugins loaded, indexed by instance self.data('plugins', {}) // Instances currently selected by shift-drag or shift-click, indexed by instance self.data('selected', {}) // Hardware inputs and outputs, which have an instance of -1 and symbol as given by application self.data('hwInputs', []) self.data('hwOutputs', []) // connectionManager keeps track of all connections self.data('connectionManager', new ConnectionManager()) // pending scheduleAdapt debounce, and since when it has been waiting self.data('adaptTimer', null) self.data('adaptWaitingSince', 0) // widgets on the arrive list self.data('callbacksToArrive', {}) // replacement plugin, used for recreating connections self.data('replacementPlugin', null) // teleported cables: names spoken for, and the boxes currently drawn for them self.data('teleportNames', {}) self.data('teleportBoxes', {}) // What each output was last called, so toggling a teleport back on restores your // label. Never counts as in use -- uniqueness reads teleportNames only -- and is // not serialised. self.data('teleportNamesRemembered', {}) // teleported cables named by a map that arrived before their connection existed // (applyTeleports, during a bundle load), keyed "from -> to" same as the saved // form -- consumed by connect() once the cable actually shows up self.data('pendingTeleports', {}) // true while resetData is tearing a pedalboard down, so teleportsChanged prunes // in memory but does not POST the shrinking map to the server -- see resetData self.data('teleportsTeardown', false) // the label size is a preference, so it has to be applied before any box is drawn self.pedalboard('applyTeleportScale') // t3k integration self.data('T3KIntegration', new T3KIntegration(self, T3K_API_KEY)) //'t3k_pub_7uGZokPvXdxakAUSGVxh_5HXH5PjIdoY')) // Pedalboard itself will get big dimensions and will have it's scale and position changed dinamically // often. So, let's wrap it inside an element with same original dimensions and positioning, with overflow // hidden, so that the visible part of the pedalboard is always occupying the area that was initially determined // by the css. var parent = $('