From a4ce6ba861e412d2cf2ce15dbcfd247cdbabebe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Clet?= Date: Sun, 16 Jun 2024 16:47:38 +0200 Subject: [PATCH] format_slot_name --- README.md | 2 ++ tc.preset.js | 75 +++++++++++++------------------------------ tc.preset_demo.maxpat | 36 ++++++++++----------- 3 files changed, 43 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index dc5d833..4573015 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ A [jsui] replacement for the [preset] object in Cycling'74 Max. - `store`: send to [jsui] only - The js program send a lot of message to the [pattrstorage] (patch cord not required), which makes it output a lot of messages required for the [jsui] to stay in sync. Using one of the above messages incorrectly, or sending `getslotlist`, `getslotnamelist`, or any message that will impact the presets, it might cause the [pattrstorage] to get out of sync. In case something like that happens, you can send the `resync` message to the [jsui]. +## Known bugs +- Text in list layout is blurry (but not the dragged slot) ## Desired features (for someday) - No need for a patch cord (programmatically create a [send]/[receive] pair?) diff --git a/tc.preset.js b/tc.preset.js index d8e0f44..010d45f 100644 --- a/tc.preset.js +++ b/tc.preset.js @@ -196,15 +196,7 @@ function draw_slot(id, scale, cont) { // cont.rectangle_rounded(bg_txt_pos_x, bg_txt_pos_y, bg_txt_dim_w, bg_txt_dim_h, 4, 4); // slot name - var text = id; - // If slot is locked, add brackets around its number - if (slots[id][5] == 1) { - text = '[' + text + ']'; - } - // If slot has a name, append it to the preset name - if (slots[id][4] != null) { - text += ': ' + slots[id][4]; - } + var text = format_slot_name(id); draw_text_bubble(bg_txt_pos_x, bg_txt_pos_y, bg_txt_dim_w, bg_txt_dim_h, text, cont); // cont.fill(); @@ -264,7 +256,6 @@ function draw_text_bubble(x, y, w, h, text, cont) { cont.rectangle_rounded(x, y, w, h, 4, 4); cont.fill(); - text = text.toString(); var text_dim = cont.text_measure(text); var txt_pos_x = margin + slot_size + 2 * spacing; @@ -275,6 +266,21 @@ function draw_text_bubble(x, y, w, h, text, cont) { cont.show_text(text.toString()); } +function format_slot_name(id) { + var text = id; + // If slot is locked, add brackets around its number + if (slots[id][5] == 1) { + text = '[' + text + ']'; + } + // If slot has a name, append it to the preset name + if (slots[id][4] != null) { + text += ': ' + slots[id][4]; + } + text = text.toString(); + return text; +} +format_slot_name.local = 1; + function paint_base() { // We draw all slots (empty and stored ones) so we don't have to for every redraw @@ -299,34 +305,8 @@ function paint_base() { set_source_rgba(empty_slot_color); } draw_slot(i, 1, mg); - // fill(); } } - - // if (layout == 0) { - // for (var i = 1; i <= slots_count_display; i++) { - // if (slots[i][4] != null) { - // set_source_rgba(stored_slot_color); - // } else { - // set_source_rgba(empty_slot_color); - // } - // draw_slot_bubble(i, 1, mg); - // fill(); - // } - // } else { - - // for (var i = 1; i <= slots_count_display; i++) { - // if (slots[i][4] != null) { - // set_source_rgba(stored_slot_color); - // } else { - // set_source_rgba(empty_slot_color); - // } - // draw_slot(i, 1, mg); - // // fill(); - - - // } - // } } update_umenu(); base_drawing = new Image(mg); @@ -345,21 +325,21 @@ function paint() set_line_width(1); // Active slot - if (active_slot > 0 && active_slot <= slots_count_display && is_dragging == 0) { + if (is_dragging == 0 && active_slot > 0 && active_slot <= slots_count_display) { set_source_rgba(active_slot_color); draw_slot_bubble(slots[active_slot][0], slots[active_slot][1], slot_size, slot_size); fill(); } // Previous active slot - if (previous_active_slot > 0 && previous_active_slot <= slots_count_display) { + if (is_dragging == 0 && previous_active_slot > 0 && previous_active_slot <= slots_count_display) { set_source_rgba(active_slot_color); draw_slot_bubble(slots[previous_active_slot][0], slots[previous_active_slot][1], slot_size, slot_size); stroke(); } // Interpolated slots - if (display_interp && is_interpolating) { + if (is_dragging == 0 && display_interp && is_interpolating) { for (var i = 1; i <= slots_count_display; i++) { var interp = slots[i][6]; @@ -378,13 +358,11 @@ function paint() if (shift_hold) { if (option_hold) { // About to delete - post("about to delete\n"); set_source_rgba(empty_slot_color[0], empty_slot_color[1], empty_slot_color[2], 0.8); draw_slot_bubble(slots[last_hovered][0] + 1, slots[last_hovered][1] + 1, slot_size-2, slot_size-2); fill(); } else { // About to store - post("about to stàre\n"); set_source_rgba(active_slot_color[0], active_slot_color[1], active_slot_color[2], 0.7); draw_slot_bubble(slots[last_hovered][0] + 1, slots[last_hovered][1] + 1, slot_size-2, slot_size-2); fill(); @@ -397,15 +375,7 @@ function paint() if (layout == 0) { //Text (slot number and name) - var text = last_hovered; - if (slots[last_hovered][5] == 1) { - text = '[' + text + ']'; - } - - if (slots[last_hovered][4] != null) { - text += ': ' + slots[last_hovered][4]; - } - text = text.toString(); + var text = format_slot_name(last_hovered); select_font_face(font_name); set_font_size(font_size); var text_dim = text_measure(text); @@ -492,7 +462,7 @@ paint.local = 1; function anything() { // Here just to avoid error messages in case pattrstorage sends unhandled message, like when using getstoredvalue, getsubscriptionlist, getalias, etc. - // Handle the "delete" messages here because it is a reserevd word in js and cannot be used as a function name. + // Handle the "delete" messages here because we can't declare a "function delete" (it is a reserved word in js and cannot be used as a function name. if (messagename == "delete") { var v = arrayfromargs(arguments)[0]; v = Math.floor(v); @@ -765,7 +735,8 @@ function find_pattrstorage(name) { pattrstorage_obj = this.patcher.getnamed(name); if (pattrstorage_obj !== null) { pattrstorage_name = name; - // slots_clear(); + slots_clear(); + // this.patcher.hiddenconnect(pattrstorage_obj, 0, this.box, 0); to_pattrstorage("getslotlist"); to_pattrstorage("getlockedslots"); } else { diff --git a/tc.preset_demo.maxpat b/tc.preset_demo.maxpat index 5792fd5..67a4162 100755 --- a/tc.preset_demo.maxpat +++ b/tc.preset_demo.maxpat @@ -475,7 +475,7 @@ ] } , - "patching_rect" : [ 231.0, 833.0, 125.0, 22.0 ], + "patching_rect" : [ 227.0, 845.0, 125.0, 22.0 ], "saved_object_attributes" : { "description" : "", "digest" : "", @@ -494,7 +494,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 16.0, 457.0, 150.0, 33.0 ], + "patching_rect" : [ 30.0, 523.5, 150.0, 33.0 ], "text" : "Usefull when making changes to the js file" } @@ -506,7 +506,7 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 15.0, 496.0, 151.0, 22.0 ], + "patching_rect" : [ 29.0, 562.5, 151.0, 22.0 ], "text" : "loadbang, pattrstorage test" } @@ -529,7 +529,7 @@ "maxclass" : "comment", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 446.0, 37.5, 505.0, 100.0 ], + "patching_rect" : [ 120.0, 27.0, 505.0, 100.0 ], "text" : "In order to use that custom jsui, you need to:\n1. bind the jsui to a named pattrstorage, either by setting the pattrstorage name as the jsui jsarguments attribute, or by sending a message to the jsui starting by \"pattrstorage\" followed by the pattrstorage name (prefered). You can re-send this message manually at any time to re-sync the jsui with the pattstorage (in case you send some messages to the pattrstorage that doesn't trigger an output). An empty \"pattrstorage\" message to the jsui will unbind it.\n2. Connect the pattrstorage outlet to the jsui inlet." } @@ -659,7 +659,7 @@ "numinlets" : 1, "numoutlets" : 2, "outlettype" : [ "", "" ], - "patching_rect" : [ 169.0, 68.5, 29.5, 22.0 ], + "patching_rect" : [ 169.0, 374.0, 29.5, 22.0 ], "text" : "t l l" } @@ -758,7 +758,7 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 169.0, 37.5, 133.0, 22.0 ], + "patching_rect" : [ 169.0, 343.0, 133.0, 22.0 ], "text" : "recallmulti 1.5 2.1 3 5.2" } @@ -769,7 +769,7 @@ "maxclass" : "newobj", "numinlets" : 1, "numoutlets" : 0, - "patching_rect" : [ 72.0, 829.0, 135.0, 22.0 ], + "patching_rect" : [ 72.0, 845.0, 135.0, 22.0 ], "text" : "print jsui_out @popup 1" } @@ -781,7 +781,7 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 341.5, 37.5, 73.0, 22.0 ], + "patching_rect" : [ 16.0, 38.0, 73.0, 22.0 ], "text" : "pattrstorage" } @@ -793,7 +793,7 @@ "numinlets" : 1, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 428.0, 805.0, 93.0, 22.0 ], + "patching_rect" : [ 417.0, 803.0, 93.0, 22.0 ], "text" : "prepend setlock" } @@ -806,7 +806,7 @@ "numoutlets" : 1, "outlettype" : [ "int" ], "parameter_enable" : 0, - "patching_rect" : [ 428.0, 774.0, 24.0, 24.0 ], + "patching_rect" : [ 417.0, 772.0, 24.0, 24.0 ], "presentation" : 1, "presentation_rect" : [ 119.0, 62.5, 24.0, 24.0 ] } @@ -846,7 +846,7 @@ "numoutlets" : 4, "outlettype" : [ "", "int", "", "" ], "parameter_enable" : 0, - "patching_rect" : [ 309.0, 774.0, 100.0, 50.0 ], + "patching_rect" : [ 302.0, 772.0, 100.0, 50.0 ], "presentation" : 1, "presentation_rect" : [ 146.0, 63.5, 119.0, 22.0 ] } @@ -861,7 +861,7 @@ "numoutlets" : 3, "outlettype" : [ "int", "", "" ], "parameter_enable" : 0, - "patching_rect" : [ 191.0, 788.0, 100.0, 22.0 ], + "patching_rect" : [ 187.0, 800.0, 100.0, 22.0 ], "presentation" : 1, "presentation_rect" : [ 1.0, 63.5, 116.0, 22.0 ] } @@ -888,7 +888,7 @@ "numoutlets" : 2, "outlettype" : [ "", "bang" ], "parameter_enable" : 0, - "patching_rect" : [ 72.0, 37.5, 50.0, 22.0 ] + "patching_rect" : [ 72.0, 343.0, 50.0, 22.0 ] } } @@ -899,7 +899,7 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 72.0, 68.5, 74.0, 22.0 ], + "patching_rect" : [ 72.0, 374.0, 74.0, 22.0 ], "text" : "recall 1 4 $1" } @@ -936,7 +936,7 @@ "numinlets" : 2, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 341.5, 65.5, 95.0, 22.0 ], + "patching_rect" : [ 16.0, 66.0, 95.0, 22.0 ], "text" : "pattrstorage test" } @@ -953,7 +953,7 @@ "numoutlets" : 4, "outlettype" : [ "", "", "", "" ], "parameter_enable" : 0, - "patching_rect" : [ 72.0, 637.0, 375.0, 132.0 ], + "patching_rect" : [ 72.0, 637.0, 364.0, 124.0 ], "presentation" : 1, "presentation_rect" : [ 1.0, 103.0, 269.0, 77.0 ] } @@ -1011,7 +1011,7 @@ "numinlets" : 1, "numoutlets" : 1, "outlettype" : [ "" ], - "patching_rect" : [ 72.0, 108.5, 176.0, 22.0 ], + "patching_rect" : [ 72.0, 414.0, 176.0, 22.0 ], "saved_object_attributes" : { "client_rect" : [ 100, 100, 519, 600 ], "parameter_enable" : 0, @@ -1194,7 +1194,7 @@ , { "patchline" : { "destination" : [ "obj-1", 0 ], - "midpoints" : [ 240.5, 865.0, 57.0, 865.0, 57.0, 102.0, 81.5, 102.0 ], + "midpoints" : [ 236.5, 884.0, 57.0, 884.0, 57.0, 405.0, 81.5, 405.0 ], "source" : [ "obj-34", 0 ] }