| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701 |
- // SPDX-FileCopyrightText: 2012-2023 MOD Audio UG
- // SPDX-License-Identifier: AGPL-3.0-or-later
- /*
- * effectBox
- *
- * The interface for searching, selecting and installing plugins
- *
- * Properties:
- * - mode: The search mode, indicated by top buttons
- * - searchbox: dom of search's input
- * - resultCanvas: dom div in which results will be shown
- * - categoryBrowse: dom div with category menu
- * - results: dictionary containing detailed data of all plugins
- * displayed
- */
- JqueryClass('effectBox', {
- init: function (options) {
- var self = $(this)
- options = $.extend({
- pedalboard: $('<div>'),
- windowManager: null,
- saveConfigValue: function (key, value) {},
- }, options)
- self.data(options)
- self.data('showPluginsRenderId', 0)
- var searchbox = self.find('input[type=search]')
- // make sure searchbox is empty on init
- searchbox.val("")
- self.data('searchbox', searchbox)
- searchbox.cleanableInput()
- var lastKeyTimeout = null
- searchbox.keydown(function (e) {
- if (e.keyCode == 13) { // detect enter
- if (lastKeyTimeout != null) {
- clearTimeout(lastKeyTimeout)
- lastKeyTimeout = null
- }
- self.effectBox('search')
- return false
- }
- else if (e.keyCode == 8 || e.keyCode == 46) { // detect delete and backspace
- if (lastKeyTimeout != null) {
- clearTimeout(lastKeyTimeout)
- }
- lastKeyTimeout = setTimeout(function () {
- self.effectBox('search')
- }, 400);
- }
- })
- searchbox.keypress(function (e) { // keypress won't detect delete and backspace but will only allow inputable keys
- if (e.which == 13) {
- return
- }
- if (lastKeyTimeout != null) {
- clearTimeout(lastKeyTimeout)
- }
- lastKeyTimeout = setTimeout(function () {
- self.effectBox('search')
- }, 400);
- })
- searchbox.on('cut', function(e) {
- if (lastKeyTimeout != null) {
- clearTimeout(lastKeyTimeout)
- }
- lastKeyTimeout = setTimeout(function () {
- self.effectBox('search')
- }, 400);
- })
- searchbox.on('paste', function(e) {
- if (lastKeyTimeout != null) {
- clearTimeout(lastKeyTimeout)
- }
- lastKeyTimeout = setTimeout(function () {
- self.effectBox('search')
- }, 400);
- })
- var settingsBox = self.find('#plugins-library-settings-window')
- settingsBox.window({
- windowName: "Plugin Library",
- windowManager: options.windowManager,
- trigger: self.find('.js-settings-trigger')
- })
- self.find('.js-settings-trigger').click(function(){
- $('#effectSearch').focus() // will focus the input when clicking the search icon
- })
- self.droppable({
- accept: '.js-available-effect',
- drop: function (event, ui) {
- //ui.helper.consumed = true
- }
- })
- self.data('category', null)
- // CATEGORY TABS
- self.find('ul.js-category-tabs li').click(function () {
- var category = $(this).attr('id').replace(/^effect-tab-/, '')
- self.effectBox('setCategory', category)
- })
- self.find('.js-effects-fold').click(function () {
- self.effectBox('toggle')
- options.saveConfigValue("plugins-folded", self.hasClass('folded') ? "true" : "false")
- })
- self.find('.nav-left').click(function () {
- self.effectBox('shiftLeft')
- })
- self.find('.nav-right').click(function () {
- self.effectBox('shiftRight')
- })
- // CATEGORY WRAPPERS
- self.find(".plugins-wrapper").each(function () {
- $(this).data("pos", 0);
- $(this).data("plug", 0);
- })
- // CATEGORY SCROLL
- self.on('DOMMouseScroll mousewheel', function ( event ) {
- if( event.originalEvent.detail > 0 || event.originalEvent.wheelDelta < 0 )
- self.effectBox('shiftNext');
- else
- self.effectBox('shiftPrev');
- self.effectBox('scrolling');
- return false;
- });
- self.data("scrollTO", false);
- //self.effectBox('fold')
- if (FAVORITES.length > 0) {
- self.effectBox('setCategory', 'Favorites')
- } else {
- self.effectBox('setCategory', 'All')
- }
- // don't search just yet.
- // it's a little expensive, let init time go for loading the pedalboard first
- self.effectBox('showPlugins', [])
- self.mouseenter(function () { self.effectBox('mouseEnter'); });
- $("#main-menu").mouseenter(function () { self.trigger("mouseenter") });
- return self
- },
- fold: function () {
- var self = $(this)
- //self.find('.js-effects-list').hide()
- self.addClass('folded')
- //self.find('.js-effects-fold').hide()
- },
- unfold: function () {
- var self = $(this)
- //self.find('.js-effects-list').show()
- self.removeClass('folded')
- //self.find('.js-effects-fold').show()
- },
- toggle: function () {
- var self = $(this);
- if (self.hasClass('auto')) {
- self.trigger("mouseleave");
- self.effectBox('unfold')
- } else
- self.effectBox('fold')
- self.toggleClass("auto");
- },
- mouseEnter: function (e) {
- var self = $(this);
- if (self.hasClass('auto')) {
- self.one("mouseleave", function () { self.effectBox('fold'); });
- self.effectBox('unfold');
- }
- },
- setCategory: function (category) {
- var self = $(this)
- self.find('ul.js-category-tabs li').removeClass('selected')
- self.find('.plugins-wrapper').removeClass("selected");
- self.find('#effect-tab-' + category).addClass('selected')
- self.find('#effect-content-' + category).addClass("selected");
- self.data('category', category)
- self.effectBox('unfold')
- self.effectBox('calculateNavigation')
- },
- search: function (callback) {
- var self = $(this)
- var searchbox = self.data('searchbox')
- var term = searchbox.val()
- if (term)
- {
- var allplugins = desktop.pluginIndexerData
- var plugins = []
- var ret = desktop.pluginIndexer.search(term)
- for (var i in ret) {
- var uri = ret[i].ref
- plugins.push(allplugins[uri])
- }
- self.effectBox('showPlugins', plugins)
- }
- else
- {
- $.ajax({
- method: 'GET',
- url: '/effect/list',
- success: function (plugins) {
- var i, plugin, allplugins = {}
- for (i in plugins) {
- plugin = plugins[i]
- plugin.installedVersion = [plugin.builder, plugin.minorVersion, plugin.microVersion, plugin.release]
- allplugins[plugin.uri] = plugin
- }
- desktop.resetPluginIndexer(allplugins)
- self.effectBox('showPlugins', plugins, callback)
- },
- cache: false,
- dataType: 'json'
- });
- }
- },
- showPlugins: function (plugins, callback) {
- var self = $(this)
- self.effectBox('cleanResults')
- plugins.sort(function (a, b) {
- a = a.label.toLowerCase()
- b = b.label.toLowerCase()
- if (a > b) {
- return 1
- }
- if (a < b) {
- return -1
- }
- return 0
- })
- // count plugins first
- var pluginCount = plugins.length
- var categories = {
- 'Favorites': 0,
- 'All': 0,
- 'ControlVoltage': 0,
- 'Delay': 0,
- 'Distortion': 0,
- 'Dynamics': 0,
- 'Filter': 0,
- 'Generator': 0,
- 'MIDI': 0,
- 'Modulator': 0,
- 'Reverb': 0,
- 'Simulator': 0,
- 'Spatial': 0,
- 'Spectral': 0,
- 'Utility': 0,
- 'MaxGen': 0,
- 'Camomile': 0,
- }
- var category
- for (i in plugins) {
- category = plugins[i].category[0]
- if (category) {
- if (categories[category] == null)
- categories[category] = 1
- else
- categories[category] += 1
- }
- if (FAVORITES.indexOf(plugins[i].uri) >= 0) {
- categories.Favorites += 1
- }
- categories.All += 1
- }
- // display plugin count
- for (category in categories) {
- var tab = self.find('#effect-tab-' + category)
- tab.find('.count').text('(' + categories[category] + ')')
- }
- if (categories[category] == 0) {
- self.find('#effect-tab-MaxGen').hide()
- } else {
- self.find('#effect-tab-MaxGen').show()
- }
- // disable navigation while we render plugins
- self.find('.nav-left').addClass('disabled')
- self.find('.nav-right').addClass('disabled')
- var renderedIndex = 0
- // current render id, to check if another render has been called
- var currentRenderId = self.data('showPluginsRenderId')+1
- self.data('showPluginsRenderId', currentRenderId)
- // render plugins
- var plugin
- function renderNextPlugin() {
- if (self.data('showPluginsRenderId') != currentRenderId) {
- // another render is in place, stop this one
- if (callback) { callback() }
- return
- }
- if (renderedIndex >= pluginCount) {
- // if we get here it means we finished rendering
- self.effectBox('calculateNavigation')
- if (self.data('showPluginsRenderId') == currentRenderId) {
- // no other renders in queue, take the chance and reset the id
- self.data('showPluginsRenderId', 0)
- }
- if (callback) { callback() }
- return
- }
- plugin = plugins[renderedIndex]
- category = plugin.category[0]
- self.effectBox('renderPlugin', plugin, self.find('#effect-content-All'))
- if (FAVORITES.indexOf(plugin.uri) >= 0) {
- self.effectBox('renderPlugin', plugin, self.find('#effect-content-Favorites'))
- }
- if (category && category != 'All') {
- self.effectBox('renderPlugin', plugin, self.find('#effect-content-' + category))
- }
- renderedIndex += 1
- setTimeout(renderNextPlugin, 1);
- }
- renderNextPlugin(0)
- },
- renderPlugin: function (plugin, container, replace) {
- var self = $(this)
- if (container.length == 0)
- return
- var uri = escape(plugin.uri)
- var ver = [plugin.builder, plugin.microVersion, plugin.minorVersion, plugin.release].join('_')
- var plugin_data = {
- uri : uri,
- brand : plugin.brand || " ",
- label : plugin.label,
- thumbnail_href: (plugin.gui && plugin.gui.thumbnail)
- ? ("/effect/image/thumbnail.png?uri=" + uri + "&v=" + ver)
- : "/resources/pedals/default-thumbnail.png",
- licensed: plugin.licensed > 0,
- demo: plugin.licensed < 0,
- }
- if (window.devicePixelRatio && window.devicePixelRatio >= 2) {
- plugin_data.thumbnail_href = plugin_data.thumbnail_href.replace("thumbnail","screenshot")
- }
- var div = document.createElement("div");
- div.innerHTML = Mustache.render(TEMPLATES.plugin, plugin_data);
- var rendered = $(Array.prototype.slice.call(div.childNodes, 0));
- self.data('pedalboard').pedalboard('registerAvailablePlugin', rendered, plugin, {
- distance: 2,
- delay: 100,
- start: function () {
- if (self.data('info'))
- self.data('info').remove()
- self.data('windowManager').closeWindows(null, true)
- self.window('fade')
- },
- stop: function () {
- self.window('unfade')
- }
- })
- rendered.click(function () {
- self.effectBox('showPluginInfo', plugin)
- })
- if (replace) {
- rendered.insertAfter(replace)
- replace.remove()
- } else {
- container.append(rendered)
- }
- var index = self.data('index')
- if (!index[plugin.uri])
- index[plugin.uri] = []
- index[plugin.uri].push([plugin, rendered, container])
- },
- showPluginInfo: function (plugin) {
- var self = $(this)
- var uri = escape(plugin.uri)
- var showInfo = function() {
- // formating numbers and flooring ranges up to two decimal cases
- for (var i = 0; i < plugin.ports.control.input.length; i++) {
- plugin.ports.control.input[i].formatted = format(plugin.ports.control.input[i])
- }
- if (plugin.ports.cv && plugin.ports.cv.input) {
- for (var i = 0; i < plugin.ports.cv.input.length; i++) {
- plugin.ports.cv.input[i].formatted = format(plugin.ports.cv.input[i])
- }
- }
- if (plugin.ports.cv && plugin.ports.cv.output) {
- for (var i = 0; i < plugin.ports.cv.output.length; i++) {
- plugin.ports.cv.output[i].formatted = format(plugin.ports.cv.output[i])
- }
- }
- var ver = [plugin.builder, plugin.microVersion, plugin.minorVersion, plugin.release].join('_')
- var metadata = {
- author: plugin.author,
- uri: plugin.uri,
- thumbnail_href: (plugin.gui && plugin.gui.thumbnail)
- ? "/effect/image/thumbnail.png?uri=" + uri + "&v=" + ver
- : "/resources/pedals/default-thumbnail.png",
- screenshot_href: (plugin.gui && plugin.gui.screenshot)
- ? "/effect/image/screenshot.png?uri=" + uri + "&v=" + ver
- : "/resources/pedals/default-screenshot.png",
- category: plugin.category[0] || "None",
- installed_version: version(plugin.installedVersion),
- latest_version: "DO NOT SHOW THIS!!", // not shown on local plugin bar
- package_name: plugin.bundles[0].replace(/\.lv2$/, ''),
- comment: plugin.comment.trim() || "No description available",
- brand : plugin.brand,
- name : plugin.name,
- label : plugin.label,
- ports : plugin.ports,
- demo : plugin.licensed < 0,
- licensed: plugin.licensed > 0,
- installed: true,
- favorite_class: FAVORITES.indexOf(plugin.uri) >= 0 ? "favorite" : "",
- plugin_href: PLUGINS_URL + '/' + btoa(plugin.uri),
- pedalboard_href: desktop.getPedalboardHref(plugin.uri),
- discussion_href: plugin.gui.discussionURL,
- documentation_href: (plugin.gui && plugin.gui.documentation)
- ? '/effect/file/documentation?uri=' + uri + '&v=' + ver
- : '',
- build_env_uppercase: (plugin.buildEnvironment || "LOCAL").toUpperCase(),
- show_build_env: plugin.buildEnvironment !== "prod",
- };
- var render = function(metadata) {
- var info = $(Mustache.render(TEMPLATES.cloudplugin_info, metadata))
- // hide install etc buttons
- info.find('.js-remove').hide()
- info.find('.js-install').hide()
- info.find('.js-upgrade').hide()
- info.find('.js-latest-version').hide()
- // hide control ports table if none available
- if (plugin.ports.control.input.length == 0) {
- info.find('.plugin-controlports').hide()
- }
- // hide cv inputs table if none available
- if (!plugin.ports.cv || (plugin.ports.cv && plugin.ports.cv.input && plugin.ports.cv.input.length == 0)) {
- info.find('.plugin-cvinputs').hide()
- }
- // hide cv ouputs ports table if none available
- if (!plugin.ports.cv || (plugin.ports.cv && plugin.ports.cv.output && plugin.ports.cv.output.length == 0)) {
- info.find('.plugin-cvoutputs').hide()
- }
- info.find('.favorite-button').on('click', function () {
- var isFavorite = $(this).hasClass('favorite'),
- widget = $(this)
- $.ajax({
- url: '/favorites/' + (isFavorite ? 'remove' : 'add'),
- type: 'POST',
- data: {
- uri: plugin.uri,
- },
- success: function (ok) {
- if (! ok) {
- console.log("favorite action failed")
- return
- }
- if (isFavorite) {
- // was favorite, not anymore
- widget.removeClass('favorite');
- remove_from_array(FAVORITES, plugin.uri)
- self.find('#effect-content-Favorites').find('[mod-uri="'+escape(plugin.uri)+'"]').remove()
- } else {
- // was not favorite, now is
- widget.addClass('favorite');
- FAVORITES.push(plugin.uri)
- self.effectBox('renderPlugin', plugin, self.find('#effect-content-Favorites'))
- }
- self.find('#effect-tab-Favorites').find('.count').text('(' + FAVORITES.length + ')')
- },
- cache: false,
- dataType: 'json'
- })
- });
- if (metadata.shopify_id && !metadata.licensed) {
- desktop.createBuyButton(metadata.shopify_id)
- }
- info.window({
- windowName: "Plugin Info",
- windowManager: self.data('windowManager'),
- close: function () {
- info.remove()
- self.data('info', null)
- }
- })
- info.appendTo($('body'))
- info.window('open')
- self.data('info', info)
- }
- render(metadata)
- if (!metadata.licensed) {
- desktop.fetchShopProduct(plugin.uri).then(function(product) {
- if (product) {
- metadata.shopify_id = product.id
- metadata.price = product.selectedVariant.price
- render(metadata)
- } else if (metadata.demo) {
- metadata.coming = true
- render(metadata)
- }
- })
- }
- }
- if (plugin.bundles) {
- showInfo()
- } else {
- var renderedVersion = [plugin.builder,
- plugin.microVersion,
- plugin.minorVersion,
- plugin.release].join('_');
- $.ajax({
- url: "/effect/get",
- data: {
- uri: plugin.uri,
- version: VERSION,
- plugin_version: renderedVersion,
- },
- success: function (pluginData) {
- plugin = $.extend(plugin, pluginData)
- // FIXME: needed?
- desktop.pluginIndexerData[plugin.uri] = plugin
- showInfo()
- },
- cache: !!plugin.buildEnvironment,
- dataType: 'json'
- })
- }
- },
- cleanResults: function () {
- var self = $(this)
- self.find('.plugins-wrapper').html('')
- self.find('ul.js-category-tabs li span.count').each(function () {
- $(this).text()
- });
- self.effectBox('resetShift')
- self.data('index', {})
- //$('#js-effect-info').hide()
- },
- calculateNavigation: function () {
- var self = $(this)
- var wrapper = self.find('.plugins-wrapper.selected')
- if (wrapper.length == 0)
- return
- var shift = wrapper.position().left
- var maxShift = Math.max(0, wrapper.width() - wrapper.parent().width())
- if (shift == 0)
- self.find('.nav-left').addClass('disabled')
- else
- self.find('.nav-left').removeClass('disabled')
- if (shift == maxShift)
- self.find('.nav-right').addClass('disabled')
- else
- self.find('.nav-right').removeClass('disabled')
- },
- resetShift: function () {
- $(this).find('.plugins-wrapper').css('left', 0)
- },
- shiftLeft: function () {
- $(this).effectBox('shiftDir', -1);
- },
- shiftRight: function () {
- $(this).effectBox('shiftDir', 1);
- },
- // This whole scrolling and shifting thing is very expensive due
- // to lots of relayouts and redraws. This is because we want to
- // snap to plugins on the left border of the container. We should
- // switch to a less greedy concept. Maybe next century.
- shiftDir: function (dir) {
- var self = $(this);
- var wrapper = self.find('.plugins-wrapper.selected');
- var parent = wrapper.parent().parent();
- var plugins = wrapper.children();
- var pos = wrapper.data("pos");
- var pw = parent.width();
- var ww = wrapper.width();
- var pos = Math.min(0,
- Math.max(-(ww - pw), pos - pw * dir + 64));
- var shift = 0;
- if (pos != -(ww - pw)) {
- for (var i = 0; i < plugins.length; i++) {
- var plugw = $(plugins[i]).outerWidth();
- if (shift + plugw >= -pos) {
- pos = -shift;
- wrapper.data("plug", i);
- break;
- }
- shift += plugw;
- }
- }
- wrapper.data("pos", pos);
- wrapper[0].style.left = pos + "px";
- },
- shiftPrev: function () {
- $(this).effectBox('shiftAlter', -1);
- },
- shiftNext: function () {
- $(this).effectBox('shiftAlter', 1);
- },
- shiftAlter: function (dir) {
- var self = $(this);
- var wrapper = self.find('.plugins-wrapper.selected');
- var parent = wrapper.parent().parent();
- var children = wrapper.children();
- var plug = wrapper.data("plug");
- var pw = parent.width();
- var ww = wrapper.width();
- if (ww < pw) return;
- plug = Math.min(children.length-1, Math.max(0, plug + dir));
- var pos = Math.max(-(ww - pw),
- -$(children[plug]).position().left);
- while (-$(children[plug]).position().left < pos)
- plug--;
- wrapper[0].style.left = pos + "px";
- wrapper.data("pos", pos);
- wrapper.data("plug", plug);
- },
- scrolling: function () {
- var self = $(this);
- var scrollTO = self.data("scrollTO");
- if (scrollTO) {
- clearTimeout(scrollTO);
- } else {
- self.addClass("scrolling");
- }
- self.data("scrollTO", setTimeout(function () {
- self.data("scrollTO", false);
- self.removeClass("scrolling");
- }, 200));
- }
- })
- function version(v) {
- if (!v || !v.length)
- return '0.0-0'
- return ""+v[1]+"."+v[2]+"-"+v[3]
- }
|