From 6b07a8e90b4eed5d83dbbca0e7ce125e405c47bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Clet?= Date: Wed, 5 Mar 2025 17:10:28 +0100 Subject: [PATCH] menu_mode and recall_filled --- docs/tc.preset.maxref.xml | 9 +++++++++ javascript/tc.preset.js | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/docs/tc.preset.maxref.xml b/docs/tc.preset.maxref.xml index 2a415db..788af07 100644 --- a/docs/tc.preset.maxref.xml +++ b/docs/tc.preset.maxref.xml @@ -78,6 +78,11 @@ If the word `pattrstorage`is sent alone, the jsui is unlinked from any pattrstorage. + + Recalls nth filled preset + Recalls the nth filled preset. Example: 'recall_filled 3' will recall the third available filled preset from the preset list, regardless of its slot number. + + Resync the jsui to the pattrstorage The word 'resync' will repopulate the jsui with the current preset list from the pattrstorage. It is usefull in case you add/remove/edit presets without using the jsui. @@ -174,6 +179,10 @@ Object margin Defines the size, in pixels, of the margin between the jsui border and the preset slots. + + Menu mode + Populates the umenu connected to 2nd outlet with preset number and name (0), preset number only (1), or name only (2). See recall_filled when using mode 2 + Minimum number of rows to display Defines the minimum number of rows to display if scrollable is enabled and layout is set to 1. diff --git a/javascript/tc.preset.js b/javascript/tc.preset.js index ae289a2..13ba487 100644 --- a/javascript/tc.preset.js +++ b/javascript/tc.preset.js @@ -70,7 +70,7 @@ var layout = 0; // 0: grid mode (same as [preset]). 1: list mode var display_interp = 1; // Enable/disable the UI feedback when interpolating between presets var ignore_slot_zero = 1; // Makes previous_active_slot and interpolation display to ignore slot 0. Can be usefull when using slot 0 as a temporary step for interpolation. var auto_writeagain = 0; // When enabled, will send a "writeagain" to pattrstorage any time a preset is stored/deleted/moved/renamed/(un)locked -var menu_number_only = 0; // Populates the umenu connected to 2nd outlet with stored preset number only, instead of number and name +var menu_mode = 0; // Populates the umenu connected to 2nd outlet with preset number and name (0), preset number only (1), or name only (2) var scrollable = 0; // Defines weither the object can be scrolled or not var min_rows = 10; // Minimum number of rows to display if scrollable is enabled var color_mode = 0; // Change the way the filled slots (stored presets) color is handeld. 0: stored_slot_color. 1: looping through color_1 to color_6. 2: Freely assign colors 1 to 6. 3: Set any color to any preset @@ -842,6 +842,15 @@ function recall() { mgraphics.redraw(); } +function recall_filled() { + // Recalling preset by its number in the filled_slots list. Useful when used menu_mode 2 + var args = arrayfromargs(arguments); + var index = args[0]; + if (index < filled_slots.length) { + to_pattrstorage('recall', filled_slots[args[0]]); + } +} + function recallmulti() { var args = arrayfromargs(arguments); var interp_slots = []; @@ -1091,11 +1100,18 @@ function update_umenu() { for (var i=0; i < filled_slots.length; i++) { var nb = filled_slots[i]; - var txt = null; - if (!menu_number_only) { - txt = slots[filled_slots[i]].name; + var txt = slots[filled_slots[i]].name; + switch(menu_mode){ + case 0: + outlet(1, "append", nb, txt); + break; + case 1: + outlet(1, "append", nb); + break; + case 2: + outlet(1, "append", txt); + break; } - outlet(1, "append", nb, txt); } if (layout == 1) { @@ -1597,6 +1613,17 @@ function setfontname(v){ } } +declareattribute("menu_mode", "getmenu_mode", "setmenu_mode", 1); +function getmenu_mode() { + return menu_mode; +} +function setmenu_mode(v){ + if (arguments.length == 1) { + menu_mode = Math.min(Math.max(0, parseInt(v)), 2); + update_umenu(); + } +} + declareattribute("autowriteagain", "getautowriteagain", "setautowriteagain", 1); function getautowriteagain() { return auto_writeagain;