Explorar o código

Merge branch 'feature/polish167p'

Ka1-S hai 1 mes
pai
achega
4a5f74fc

+ 12 - 1
cmake/LynxPatchJuce.cmake

@@ -15,6 +15,12 @@
 # 4. Every platform, juce_gui_basics/windows/juce_ComponentPeer.cpp: a file drop that no component took (an unsupported
 # 4. Every platform, juce_gui_basics/windows/juce_ComponentPeer.cpp: a file drop that no component took (an unsupported
 #    file, or dropped where nothing accepts files) kept `lastDragAndDropCompUnderMouse`, so the next drag that starts
 #    file, or dropped where nothing accepts files) kept `lastDragAndDropCompUnderMouse`, so the next drag that starts
 #    over that same component (the Playlist next to the file manager) never looked for a target and was refused.
 #    over that same component (the Playlist next to the file manager) never looked for a target and was refused.
+# 5. Every platform, juce_gui_basics/menus/juce_PopupMenu.cpp (issue #18, round 167p): LYNX opens a submenu beside its
+#    parent menu's outer edge (Theme.cpp preparePopupMenuWindow), so in a two-column menu the mouse crosses the other
+#    column on its way. JUCE keeps the open submenu only while the mouse stays in a thin triangle towards it; a pixel
+#    of drift highlighted the other column's item under the mouse and closed the submenu. The way across now also
+#    counts as "moving towards the submenu": the band of the item's row (one row above and below), between the item
+#    and the submenu, while the mouse moves towards it. Resting there (JUCE's 350 ms) still picks the item under it.
 #
 #
 # Used by CMake (lynx_patch_juce on the fetched JUCE) and by scripts/build-windows-zig.sh, which runs this file with
 # Used by CMake (lynx_patch_juce on the fetched JUCE) and by scripts/build-windows-zig.sh, which runs this file with
 # `cmake -DJUCE_DIR=<a copy of JUCE's juce_gui_basics module> -P cmake/LynxPatchJuce.cmake`.
 # `cmake -DJUCE_DIR=<a copy of JUCE's juce_gui_basics module> -P cmake/LynxPatchJuce.cmake`.
@@ -31,7 +37,7 @@ macro(lynx_juce_fix name marker old new)
         else()
         else()
             string(REPLACE "${old_text}" "${new_text}" text "${text}")
             string(REPLACE "${old_text}" "${new_text}" text "${text}")
             set(changed TRUE)
             set(changed TRUE)
-            message(STATUS "LYNX: JUCE drag & drop fix applied: ${name}")
+            message(STATUS "LYNX: JUCE fix applied: ${name}")
         endif()
         endif()
     endif()
     endif()
 endmacro()
 endmacro()
@@ -62,6 +68,10 @@ function(lynx_patch_juce_file file)
         lynx_juce_fix("no stale drop state" "LYNX patch (issue #11): not left over"
         lynx_juce_fix("no stale drop state" "LYNX patch (issue #11): not left over"
             "        dragInfo.clear();|NL|        srcMimeTypeAtomList.clear();|NL||NL|        dragAndDropCurrentMimeType = 0;"
             "        dragInfo.clear();|NL|        srcMimeTypeAtomList.clear();|NL||NL|        dragAndDropCurrentMimeType = 0;"
             "        dragInfo.clear();|NL|        srcMimeTypeAtomList.clear();|NL|        finishAfterDropDataReceived = false; // LYNX patch (issue #11): not left over from a failed drop|NL||NL|        dragAndDropCurrentMimeType = 0;")
             "        dragInfo.clear();|NL|        srcMimeTypeAtomList.clear();|NL|        finishAfterDropDataReceived = false; // LYNX patch (issue #11): not left over from a failed drop|NL||NL|        dragAndDropCurrentMimeType = 0;")
+    elseif(file MATCHES "juce_PopupMenu.cpp$")
+        lynx_juce_fix("submenu corridor" "LYNX patch (issue #18): the way across"
+            "        return areaTowardsSubMenu.contains (newGlobalPos.toFloat());|NL|    }"
+            "        if (areaTowardsSubMenu.contains (newGlobalPos.toFloat()))|NL|            return true;|NL||NL|        // LYNX patch (issue #18): the way across a two-column menu to a submenu beside its outer edge|NL|        if (auto* item = window.currentChild.getComponent())|NL|        {|NL|            const auto itemBounds = item->getScreenBounds();|NL|            const auto towardsRight = itemScreenBounds.getX() > window.getX();|NL|            const auto from = towardsRight ? itemBounds.getRight() : itemScreenBounds.getRight();|NL|            const auto to = towardsRight ? itemScreenBounds.getX() : itemBounds.getX();|NL|            return newGlobalPos.y >= itemBounds.getY() - itemBounds.getHeight() && newGlobalPos.y < itemBounds.getBottom() + itemBounds.getHeight()|NL|                   && newGlobalPos.x >= from - 2 && newGlobalPos.x <= to + 2|NL|                   && (towardsRight ? newGlobalPos.x >= lastMousePos.x : newGlobalPos.x <= lastMousePos.x);|NL|        }|NL||NL|        return false;|NL|    }")
     else()
     else()
         lynx_juce_fix("drop target search after an unused drop" "LYNX patch (issue #11): a drop nobody took"
         lynx_juce_fix("drop target search after an unused drop" "LYNX patch (issue #11): a drop nobody took"
             "bool ComponentPeer::handleDragDrop (const ComponentPeer::DragInfo& info)|NL|{|NL|    handleDragMove (info);|NL|"
             "bool ComponentPeer::handleDragDrop (const ComponentPeer::DragInfo& info)|NL|{|NL|    handleDragMove (info);|NL|"
@@ -77,6 +87,7 @@ endfunction()
 function(lynx_patch_juce juce_dir)
 function(lynx_patch_juce juce_dir)
     lynx_patch_juce_file("${juce_dir}/modules/juce_gui_basics/native/juce_DragAndDrop_linux.cpp")
     lynx_patch_juce_file("${juce_dir}/modules/juce_gui_basics/native/juce_DragAndDrop_linux.cpp")
     lynx_patch_juce_file("${juce_dir}/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp")
     lynx_patch_juce_file("${juce_dir}/modules/juce_gui_basics/windows/juce_ComponentPeer.cpp")
+    lynx_patch_juce_file("${juce_dir}/modules/juce_gui_basics/menus/juce_PopupMenu.cpp")
 endfunction()
 endfunction()
 
 
 # run as a script: cmake -DJUCE_DIR=<dir> -P cmake/LynxPatchJuce.cmake
 # run as a script: cmake -DJUCE_DIR=<dir> -P cmake/LynxPatchJuce.cmake

+ 50 - 0
docs/analise/REA_rodada167p.md

@@ -0,0 +1,50 @@
+# Round 167p (polish167p): MIDI Out editor polish (#17) and Channel Rack submenus (#18)
+
+Evidence: [SHOT] LYNX before = `/mnt/e/lynx-work/shot167q/*.png` (main 5d3f5c17), LYNX after =
+`/mnt/e/lynx-work/shot167p/*.png`; FL's MIDI Out = the issue's screenshot (568 x 420, FL 2026) and [DFM] FL's forms in
+`MIDI Out_x64.dll` (`TSynthEditorForm`, `TCtrlSetForm`, round 167i: `~/.claude/jobs/f8789b49/tmp/midiout167/dfm`);
+[DECOMP] FUN_006ff060 (knob labels, REA_rodada167i §1.4). [TEST] `tests/Polish167pTests.inc`.
+
+## 1. MIDI Out editor (issue #17)
+
+| item | reporter / brief | FL evidence | LYNX before | LYNX now |
+|---|---|---|---|---|
+| cog | "gear on each knob's top-right, as in FL; the label must never replace it" | [SHOT] FL: cog at each knob's top-right; [DECOMP FUN_006ff060] unassigned = cog | cog UNDER the knob, in the label's place; a configured knob lost its cog (its name replaced it) | cog at the top-right of every knob (`midiout::view::layout`), always opens *Configure...*; hover = accent + hand cursor + hint |
+| name | click toggles on/off | [DECOMP FUN_006ffa10] label click (de)activates; bold when active | name in the cog's place | name under the knob; bold white when sending, grey when off; click toggles (assigned only) |
+| looks | configured knob must look different | FL draws assigned / active knobs differently (bold label) | every knob drew "0" and the same grey arc | three looks (`midiout::view::look`): unassigned = dimmed, no arc, no value, no name; off = grey arc + pointer, grey value; sending = accent arc + pointer, bold value |
+| grid | more vertical space, label never near the next row | [SHOT] FL rows ~80 px apart | 88 px rows, label 2 px above the next knob | 100 px rows, knob 64 px, name 18 px, ≥ 8 px gap ([TEST] `polish167p_midiout_knob_cell`) |
+| page row | aligned with Channel / Patch | [SHOT] FL: Page under Channel / Patch | Page combo at its own x | "Page" label in the Channel column, combo exactly over the Patch column, pencil after it |
+| margins | no big empty side margins | FL's form is 558 x 389 | 560 px page centred in the 800 px channel window (Misc tab needs 800) → 120 px empty each side | the editor uses the window's 800 px; the title line ("MIDI Out", already the window title) is gone, Presets / Options moved onto the page row → the window is 30 px shorter |
+| bottom | | [SHOT] FL bottom bar: Reset, Deactivate all, Send pan…, Map note color | toggles on their own row | Reset, Deactivate all and both toggles on one row (FL's bar); LYNX's own Send to a plugin / Automate / "Plays:" on the next |
+| Configure | consistent −/+ sizes, no empty gap, dialog behaviour | [DFM TCtrlSetForm] compact 238 x 286 form | Controller's −/+ 72 px wide, Range's 15 px; fixed 360 x 300 with an empty band above the buttons; launched without `keepAboveMainWindow` | every number field 116 px (same −/+), Range "min – max", window height from its rows (274 px; on Windows the native title bar's height was added to the client area after showing — corrected once shown, so no empty band); launched like Export / Customize toolbar (`keepAboveMainWindow`: modal, above the LYNX windows) |
+| title | "MIDI Out (Insert 6)" | [EXEC round 149] FL names a channel window "<channel name> (<mixer track>)" | — | unchanged: it IS the channel's name + its insert, like every other channel window (rename the channel → the title follows). Checked, nothing to change. |
+| preset arrows | not here (167o) | | | room left free right of *Presets* (56 px) for 167o's ◀ ▶ |
+
+## 2. Submenus of two-column menus (issue #18)
+
+- Reporter: "I want the drop-down list to appear near the item to which it is linked, now you can select something in
+  the list either with a lot of luck". 0.1.19–0.1.21 (round 162) moved a submenu beside the whole menu, but kept JUCE's
+  vertical rule: an item in the lower half of the screen got a submenu growing UPWARDS, bottom-aligned with it — far
+  from the item. 167i went back to JUCE's own placement (beside the item), which paints the submenu OVER the menu's
+  right column ([SHOT] `shot167q/rack_ctx_insert_submenu.png`, `rack_ctx_replace_submenu.png`).
+- Now (`core/MenuPlacement.h`, used by `LookAndFeel::preparePopupMenuWindow`, so every LYNX menu: Channel Rack,
+  Playlist, Mixer, Piano Roll, menu bar…): beside the parent menu's OUTER edge, its first item level with the item that
+  opened it, growing downwards; moved up only by what the screen needs; to the left when the right has no room.
+  The item is the one under the mouse (hover/click) or the one JUCE placed it beside (keyboard → right arrow).
+- Crossing the right column: JUCE keeps the open submenu only while the mouse stays in a thin triangle towards it, so
+  one pixel of drift on the way highlighted a right-column item and closed the submenu (why 0.1.19 felt like "luck").
+  JUCE patch "submenu corridor" (`cmake/LynxPatchJuce.cmake` #5, applied to the fetched JUCE and to the Windows build's
+  copy): the band of the item's row (± one row), between the item and the submenu, while the mouse moves towards it,
+  also counts as "moving towards the submenu". Resting there for JUCE's 350 ms still selects the item under the mouse.
+- [TEST] `polish167p_submenu_beside_outer_edge` (outer edge, row-aligned, bottom of the screen, no room on the right,
+  taller than the screen, second monitor at negative x).
+
+## Windows GUI check (real mouse, fresh profile, test mode)
+`/mnt/e/lynx-work/shot167p/`: before_*.png (main 5d3f5c17) / after_*.png. Insert › submenu beside the outer edge,
+level with "Insert", downwards; a 40-step glide across the right column drifting 9 px up reaches the submenu (Kick
+highlighted, `after_rack_insert_submenu.png`); Replace › same; nested FL engines › at its parent's edge, moved up only
+by what the screen needs; MIDI Out editor (unassigned / configured "Cutoff" 34 / switched off by its name); Configure
+dialog without the empty band. build-local 1 890 633 checks, 0 failures.
+
+## Where I stopped
+- Done: everything above; landing via land.sh.

+ 38 - 0
src/core/MenuPlacement.h

@@ -0,0 +1,38 @@
+#pragma once
+
+// Where a popup submenu goes (round 167p, issue #18). Pure logic, no JUCE (unit-tested in tests/tests.cpp).
+//
+// JUCE puts a submenu right beside the item that opened it. In a two-column menu (the Channel Rack's channel menu,
+// the Playlist's, the Mixer's, the Piano Roll's) an item of the first column then opens its submenu OVER the second
+// column, and JUCE grows it upwards whenever the item is in the lower half of the screen, far from the item. LYNX puts
+// it beside the parent menu's outer edge instead, its first item level with the item that opened it, growing
+// downwards; it moves up only as much as the screen needs, and goes to the parent's left when the right has no room.
+
+#include <algorithm>
+
+#include "core/WindowFit.h"
+
+namespace lynx::menuplace
+{
+using Box = windowfit::Box;
+
+// `parent`: the parent menu window; `item`: the item that opened the submenu (screen coordinates); `w` x `h`: the
+// submenu window's size; `border`: the menu windows' border (the submenu's first item sits `border` px below its top);
+// `screen`: the usable screen area.
+inline Box placeSubmenu (Box parent, Box item, int w, int h, int border, Box screen)
+{
+    const auto right = screen.x + screen.w, bottom = screen.y + screen.h;
+    int x;
+    if (parent.x + parent.w + w <= right)
+        x = parent.x + parent.w;           // beside the outer edge (the usual case)
+    else if (parent.x - w >= screen.x)
+        x = parent.x - w;                  // no room on the right: beside the left edge
+    else
+        x = std::max (screen.x, right - w); // no room on either side: as far right as it fits
+    auto y = item.y - border;               // first item level with the item
+    if (y + h > bottom)
+        y = bottom - h;                     // up only as much as the screen needs
+    y = std::max (y, screen.y);
+    return { x, y, w, h };
+}
+} // namespace lynx::menuplace

+ 57 - 0
src/core/MidiOutView.h

@@ -0,0 +1,57 @@
+#pragma once
+
+// How the MIDI Out editor draws one of its 3 x 3 knobs (round 167p, issue #17). Pure logic, no JUCE (unit-tested in
+// tests/tests.cpp). FL draws the cog at the knob's top-right and the name under the knob; LYNX keeps the cog there
+// for every knob (it always opens "Configure..."), the name under it (a click switches the control on / off), and
+// makes the three states look different: unassigned (dimmed, no value), assigned but off, sending (value arc in the
+// accent colour).
+
+#include <algorithm>
+#include <string>
+
+#include "core/MidiOut.h"
+
+namespace lynx::midiout::view
+{
+struct Rect
+{
+    int x = 0, y = 0, w = 0, h = 0;
+    int right() const noexcept { return x + w; }
+    int bottom() const noexcept { return y + h; }
+    bool contains (int px, int py) const noexcept { return px >= x && py >= y && px < right() && py < bottom(); }
+    bool intersects (const Rect& o) const noexcept { return x < o.right() && o.x < right() && y < o.bottom() && o.y < bottom(); }
+    bool operator== (const Rect&) const = default;
+};
+
+struct Cell
+{
+    Rect knob, gear, label;
+};
+
+constexpr int labelHeight = 18, gearSize = 16, rowGap = 8, maxKnob = 64;
+
+// The knob (a square), its cog (top-right, outside the knob's circle) and its name (under it) inside one grid cell;
+// a gap of at least `rowGap` px stays under the name for the next row.
+inline Cell layout (Rect cell)
+{
+    Cell c;
+    const auto d = std::max (16, std::min ({ maxKnob, cell.h - labelHeight - rowGap - 8, cell.w - 2 * gearSize }));
+    const auto top = cell.y + std::max (4, (cell.h - d - labelHeight - rowGap) / 2);
+    c.knob = { cell.x + (cell.w - d) / 2, top, d, d };
+    c.gear = { c.knob.right() - gearSize / 4, c.knob.y - gearSize / 4, gearSize, gearSize };
+    c.label = { cell.x + 4, c.knob.bottom() + 3, cell.w - 8, labelHeight };
+    return c;
+}
+
+enum class Look
+{
+    unassigned, // dimmed knob, no arc, no value, no name
+    off,        // assigned but deactivated: grey arc, value and name greyed
+    sending     // value arc in the accent colour, bold name
+};
+
+inline Look look (const Control& c) { return ! c.assigned() ? Look::unassigned : c.active ? Look::sending : Look::off; }
+
+// The value shown inside the knob ("" when unassigned: an unset knob has no value to show)
+inline std::string readout (const Control& c, int value) { return c.assigned() ? std::to_string (value) : std::string(); }
+} // namespace lynx::midiout::view

+ 175 - 95
src/ui/MidiOutEditor.cpp

@@ -12,6 +12,7 @@
 
 
 #include "core/MidiControls.h"
 #include "core/MidiControls.h"
 #include "core/MidiOut.h"
 #include "core/MidiOut.h"
+#include "core/MidiOutView.h"
 #include "engine/PluginHost.h"
 #include "engine/PluginHost.h"
 #include "engine/Text.h"
 #include "engine/Text.h"
 #include "ui/AutomationUi.h"
 #include "ui/AutomationUi.h"
@@ -111,7 +112,7 @@ public:
         auto setupNumber = [this] (juce::Slider& s, int lo, int hi) {
         auto setupNumber = [this] (juce::Slider& s, int lo, int hi) {
             s.setSliderStyle (juce::Slider::IncDecButtons);
             s.setSliderStyle (juce::Slider::IncDecButtons);
             s.setRange (lo, hi, 1);
             s.setRange (lo, hi, 1);
-            s.setTextBoxStyle (juce::Slider::TextBoxLeft, false, 64, 22);
+            s.setTextBoxStyle (juce::Slider::TextBoxLeft, false, numberTextWidth, rowHeight);
             addAndMakeVisible (s);
             addAndMakeVisible (s);
         };
         };
         setupNumber (number, 0, 127);
         setupNumber (number, 0, 127);
@@ -160,33 +161,46 @@ public:
         for (auto* b : { &copy, &paste, &reset, &ok })
         for (auto* b : { &copy, &paste, &reset, &ok })
             addAndMakeVisible (*b);
             addAndMakeVisible (*b);
         show (control);
         show (control);
-        setSize (360, 300);
+        setSize (dialogWidth, dialogHeight);
     }
     }
 
 
-    void paint (juce::Graphics& g) override { g.fillAll (theme::colour::bg2); }
+    // Round 167p: every number field has the same size (its - / + buttons too), the window is as tall as its rows
+    static constexpr int rowHeight = 24, rowGap = 6, padding = 14, labelWidth = 116, numberTextWidth = 52, numberWidth = 116;
+    static constexpr int rows = 7, dialogWidth = padding + labelWidth + 2 * numberWidth + 24 + padding;
+    static constexpr int dialogHeight = padding + rows * (rowHeight + rowGap) + 8 + 28 + padding;
+
+    void paint (juce::Graphics& g) override
+    {
+        g.fillAll (theme::colour::bg2);
+        g.setColour (theme::colour::textSecondary);
+        g.setFont (theme::font (theme::type::small));
+        g.drawText (juce::CharPointer_UTF8 ("\xe2\x80\x93"), rangeDash, juce::Justification::centred); // between min and max
+    }
 
 
     void resized() override
     void resized() override
     {
     {
-        auto area = getLocalBounds().reduced (12);
-        auto row = [&] (juce::Label& l, std::initializer_list<juce::Component*> cs) {
-            auto r = area.removeFromTop (26);
-            l.setBounds (r.removeFromLeft (120));
-            const auto w = r.getWidth() / (int) cs.size();
-            for (auto* c : cs)
-                c->setBounds (r.removeFromLeft (w).reduced (cs.size() > 1 ? 2 : 0, 0));
-            area.removeFromTop (6);
+        auto area = getLocalBounds().reduced (padding);
+        auto row = [&] (juce::Label& l) {
+            auto r = area.removeFromTop (rowHeight);
+            area.removeFromTop (rowGap);
+            l.setBounds (r.removeFromLeft (labelWidth));
+            return r;
         };
         };
-        row (typeLabel, { &type });
-        row (fullLabel, { &fullName });
-        row (shortLabel, { &shortName });
-        row (numberLabel, { &number });
-        row (rangeLabel, { &minimum, &maximum });
-        row (channelLabel, { &channel });
-        row (noteOffLabel, { &noteOff });
-        auto buttons = area.removeFromBottom (26);
+        type.setBounds (row (typeLabel));
+        fullName.setBounds (row (fullLabel));
+        shortName.setBounds (row (shortLabel));
+        number.setBounds (row (numberLabel).removeFromLeft (numberWidth));
+        auto range = row (rangeLabel);
+        minimum.setBounds (range.removeFromLeft (numberWidth));
+        rangeDash = range.removeFromLeft (24);
+        maximum.setBounds (range.removeFromLeft (numberWidth));
+        channel.setBounds (row (channelLabel).removeFromLeft (numberWidth));
+        noteOff.setBounds (row (noteOffLabel).removeFromLeft (numberWidth));
+        area.removeFromTop (8);
+        auto buttons = area.removeFromTop (28);
         const auto w = buttons.getWidth() / 4;
         const auto w = buttons.getWidth() / 4;
         for (auto* b : { &copy, &paste, &reset, &ok })
         for (auto* b : { &copy, &paste, &reset, &ok })
-            b->setBounds (buttons.removeFromLeft (w).reduced (2, 0));
+            b->setBounds (buttons.removeFromLeft (w).reduced (3, 0));
     }
     }
 
 
 private:
 private:
@@ -237,6 +251,7 @@ private:
     juce::Slider number, minimum, maximum, noteOff;
     juce::Slider number, minimum, maximum, noteOff;
     juce::Label typeLabel, fullLabel, shortLabel, numberLabel, rangeLabel, channelLabel, noteOffLabel;
     juce::Label typeLabel, fullLabel, shortLabel, numberLabel, rangeLabel, channelLabel, noteOffLabel;
     juce::TextButton copy, paste, reset, ok;
     juce::TextButton copy, paste, reset, ok;
+    juce::Rectangle<int> rangeDash;
 };
 };
 
 
 // ---------------------------------------------------------------------------------------------------
 // ---------------------------------------------------------------------------------------------------
@@ -343,80 +358,95 @@ public:
         connect.setVisible (channel >= 0);
         connect.setVisible (channel >= 0);
         listeners.setFont (theme::font (theme::type::small));
         listeners.setFont (theme::font (theme::type::small));
         listeners.setColour (juce::Label::textColourId, theme::colour::textSecondary);
         listeners.setColour (juce::Label::textColourId, theme::colour::textSecondary);
-        listeners.setJustificationType (juce::Justification::topLeft);
+        listeners.setJustificationType (juce::Justification::centredLeft);
+        listeners.setMinimumHorizontalScale (1.0f);
         addAndMakeVisible (listeners);
         addAndMakeVisible (listeners);
 
 
         engine.addChangeListener (this);
         engine.addChangeListener (this);
         refresh();
         refresh();
-        setSize (560, 560);
+        setSize (editorWidth, editorHeight);
     }
     }
 
 
     ~MidiOutEditor() override { engine.removeChangeListener (this); }
     ~MidiOutEditor() override { engine.removeChangeListener (this); }
 
 
+    // Round 167p: the editor uses the channel window's whole width (its Misc tab is 800 px wide, so a narrower page
+    // left empty margins), the page row lines up with the Channel / Patch columns, and the knob grid has room for each
+    // knob's cog (top-right) and name (under it) without touching the next row.
+    static constexpr int editorWidth = 800, margin = 16, rowGap = 10, knobRowHeight = 100;
+    static constexpr int editorHeight = margin + 44 + rowGap + 26 + rowGap + (8 + 3 * knobRowHeight + 8) + rowGap + 28 + 8 + 30 + margin;
+
     void paint (juce::Graphics& g) override
     void paint (juce::Graphics& g) override
     {
     {
         g.fillAll (theme::colour::bg2);
         g.fillAll (theme::colour::bg2);
-        g.setColour (theme::colour::textPrimary);
-        g.setFont (theme::font (theme::type::title, true));
-        g.drawText (tr ("MIDI Out"), 14, 8, 200, 22, juce::Justification::centredLeft);
         g.setColour (theme::colour::bg3);
         g.setColour (theme::colour::bg3);
         g.fillRoundedRectangle (knobArea.toFloat(), 6.0f);
         g.fillRoundedRectangle (knobArea.toFloat(), 6.0f);
     }
     }
 
 
     void resized() override
     void resized() override
     {
     {
-        auto area = getLocalBounds().reduced (14);
-        auto head = area.removeFromTop (24);
-        options.setBounds (head.removeFromRight (90));
-        head.removeFromRight (6);
-        presets.setBounds (head.removeFromRight (90));
-        area.removeFromTop (10);
+        auto area = getLocalBounds().reduced (margin);
 
 
         auto top = area.removeFromTop (44);
         auto top = area.removeFromTop (44);
         auto column = [&] (juce::Label& l, int w, std::initializer_list<juce::Component*> cs) {
         auto column = [&] (juce::Label& l, int w, std::initializer_list<juce::Component*> cs) {
             auto c = top.removeFromLeft (w);
             auto c = top.removeFromLeft (w);
             l.setBounds (c.removeFromTop (18));
             l.setBounds (c.removeFromTop (18));
+            c = c.withSizeKeepingCentre (c.getWidth(), 24);
             const auto each = c.getWidth() / (int) cs.size();
             const auto each = c.getWidth() / (int) cs.size();
             for (auto* x : cs)
             for (auto* x : cs)
-                x->setBounds (c.removeFromLeft (each).reduced (cs.size() > 1 ? 1 : 0, 0));
-            top.removeFromLeft (8);
+                x->setBounds (c.removeFromLeft (each).reduced (cs.size() > 1 ? 2 : 0, 0));
+            top.removeFromLeft (10);
+            return l.getBounds().getUnion (c);
         };
         };
-        column (channelLabel, 60, { &midiChannel });
-        column (patchLabel, 190, { &patch });
-        column (bankLabel, 170, { &bankMsb, &bankLsb });
-        column (portLabel, juce::jmax (60, top.getWidth()), { &port });
-        area.removeFromTop (10);
-
+        const auto channelColumn = column (channelLabel, 64, { &midiChannel });
+        const auto patchWidth = juce::jmax (180, top.getWidth() - 236 - 10 - 120 - 10);
+        const auto patchColumn = column (patchLabel, patchWidth, { &patch });
+        column (bankLabel, 236, { &bankMsb, &bankLsb });
+        column (portLabel, top.getWidth(), { &port });
+        area.removeFromTop (rowGap);
+
+        // the page selector under Channel / Patch; Presets and Options on the right (room for the preset arrows that
+        // every plugin window header gets, right of Presets)
         auto pageRow = area.removeFromTop (26);
         auto pageRow = area.removeFromTop (26);
-        pageLabel.setBounds (pageRow.removeFromLeft (44));
-        page.setBounds (pageRow.removeFromLeft (220));
-        pageRow.removeFromLeft (6);
-        rename.setBounds (pageRow.removeFromLeft (22).reduced (2));
-        area.removeFromTop (8);
-
-        knobArea = area.removeFromTop (264);
-        auto grid = knobArea.reduced (8);
-        const auto cw = grid.getWidth() / 3, ch = grid.getHeight() / 3;
+        pageLabel.setBounds (channelColumn.getX(), pageRow.getY(), channelColumn.getWidth(), pageRow.getHeight());
+        page.setBounds (patchColumn.getX(), pageRow.getY(), patchColumn.getWidth(), pageRow.getHeight());
+        rename.setBounds (juce::Rectangle<int> (page.getRight() + 6, pageRow.getY(), 24, pageRow.getHeight()).reduced (3));
+        pageRow.removeFromRight (56);
+        presets.setBounds (pageRow.removeFromRight (90));
+        pageRow.removeFromRight (6);
+        options.setBounds (pageRow.removeFromRight (90));
+        area.removeFromTop (rowGap);
+
+        knobArea = area.removeFromTop (8 + 3 * knobRowHeight + 8);
+        auto grid = knobArea.reduced (24, 8);
+        const auto cw = grid.getWidth() / 3;
         for (int k = 0; k < midiout::knobsPerPage; ++k)
         for (int k = 0; k < midiout::knobsPerPage; ++k)
-            knobs[(std::size_t) k]->setBounds (grid.getX() + (k % 3) * cw, grid.getY() + (k / 3) * ch, cw, ch);
-        area.removeFromTop (8);
+            knobs[(std::size_t) k]->setBounds (grid.getX() + (k % 3) * cw, grid.getY() + (k / 3) * knobRowHeight, cw, knobRowHeight);
+        area.removeFromTop (rowGap);
 
 
-        auto buttons = area.removeFromTop (26);
+        // FL's bottom bar: Reset, Deactivate all, the two options
+        auto buttons = area.removeFromTop (28);
         resetButton.setBounds (buttons.removeFromLeft (80));
         resetButton.setBounds (buttons.removeFromLeft (80));
         buttons.removeFromLeft (6);
         buttons.removeFromLeft (6);
         deactivateAll.setBounds (buttons.removeFromLeft (120));
         deactivateAll.setBounds (buttons.removeFromLeft (120));
-        area.removeFromTop (4);
-        auto toggles = area.removeFromTop (24);
-        sendPanVol.setBounds (toggles.removeFromLeft (toggles.getWidth() / 2));
-        mapColour.setBounds (toggles);
+        buttons.removeFromLeft (16);
+        const auto toggleWidth = [] (juce::ToggleButton& b) {
+            return juce::roundToInt (juce::GlyphArrangement::getStringWidth (juce::Font (theme::font (theme::type::body)), b.getButtonText())) + 40;
+        };
+        sendPanVol.setBounds (buttons.removeFromLeft (juce::jmin (buttons.getWidth() / 2, toggleWidth (sendPanVol))));
+        buttons.removeFromLeft (8);
+        mapColour.setBounds (buttons);
         area.removeFromTop (8);
         area.removeFromTop (8);
 
 
-        auto extra = area.removeFromTop (26);
-        connect.setBounds (extra.removeFromLeft (180));
-        extra.removeFromLeft (8);
-        automate.setBounds (extra.removeFromLeft (220));
-        area.removeFromTop (6);
-        listeners.setBounds (area);
+        // LYNX's own: send to a plugin's MIDI input, automate a controller, who plays this port
+        auto extra = area.removeFromTop (30);
+        if (connect.isVisible())
+        {
+            connect.setBounds (extra.removeFromLeft (180).withSizeKeepingCentre (180, 28));
+            extra.removeFromLeft (8);
+            automate.setBounds (extra.removeFromLeft (220).withSizeKeepingCentre (220, 28));
+            extra.removeFromLeft (12);
+        }
+        listeners.setBounds (extra);
     }
     }
 
 
 private:
 private:
@@ -445,54 +475,85 @@ private:
             return s;
             return s;
         }
         }
 
 
-        juce::Rectangle<int> labelArea() const { return getLocalBounds().removeFromBottom (20); }
+        midiout::view::Cell cell() const { return midiout::view::layout ({ 0, 0, getWidth(), getHeight() }); }
+        static juce::Rectangle<int> rect (const midiout::view::Rect& r) { return { r.x, r.y, r.w, r.h }; }
+        juce::Rectangle<int> labelArea() const { return rect (cell().label); }
+        // the cog's click area: a little larger than the glyph
+        juce::Rectangle<int> gearArea() const { return rect (cell().gear).expanded (3); }
 
 
         void paint (juce::Graphics& g) override
         void paint (juce::Graphics& g) override
         {
         {
+            using midiout::view::Look;
             const auto& c = control();
             const auto& c = control();
-            auto area = getLocalBounds().toFloat();
-            const auto label = area.removeFromBottom (20.0f);
-            const auto size = juce::jmin (area.getWidth(), area.getHeight()) - 6.0f;
-            const auto box = juce::Rectangle<float> (size, size).withCentre (area.getCentre());
+            const auto layout = cell();
+            const auto look = midiout::view::look (c);
+            const auto box = rect (layout.knob).toFloat();
             const auto lo = (double) juce::jmin (c.min, c.max), hi = (double) juce::jmax (c.max, c.min + 1);
             const auto lo = (double) juce::jmin (c.min, c.max), hi = (double) juce::jmax (c.max, c.min + 1);
             const auto v = juce::jlimit (0.0, 1.0, ((double) value() - lo) / juce::jmax (1.0, hi - lo));
             const auto v = juce::jlimit (0.0, 1.0, ((double) value() - lo) / juce::jmax (1.0, hi - lo));
             constexpr float sweep = juce::MathConstants<float>::pi * 1.5f;
             constexpr float sweep = juce::MathConstants<float>::pi * 1.5f;
-            const auto live = c.sends();
+            const auto hover = isMouseOverOrDragging() && ! hoverGear && ! labelArea().contains (getMouseXYRelative());
+            const auto dim = look == Look::unassigned ? 0.45f : 1.0f;
 
 
-            g.setColour (theme::colour::bg4);
+            g.setColour (theme::colour::bg4.withMultipliedAlpha (dim));
             g.fillEllipse (box.reduced (6.0f));
             g.fillEllipse (box.reduced (6.0f));
-            juce::Path track, arc;
-            const auto radius = size * 0.5f - 2.0f;
+            juce::Path track;
+            const auto radius = box.getWidth() * 0.5f - 2.0f;
             track.addCentredArc (box.getCentreX(), box.getCentreY(), radius, radius, 0.0f, -sweep * 0.5f, sweep * 0.5f, true);
             track.addCentredArc (box.getCentreX(), box.getCentreY(), radius, radius, 0.0f, -sweep * 0.5f, sweep * 0.5f, true);
-            g.setColour (theme::colour::bg6);
+            g.setColour (theme::colour::bg6.withMultipliedAlpha (dim));
             g.strokePath (track, juce::PathStrokeType (3.5f));
             g.strokePath (track, juce::PathStrokeType (3.5f));
-            arc.addCentredArc (box.getCentreX(), box.getCentreY(), radius, radius, 0.0f, -sweep * 0.5f, -sweep * 0.5f + sweep * (float) v, true);
-            g.setColour (! live ? theme::colour::textDisabled : isMouseOverOrDragging() ? theme::colour::accent : theme::colour::knobArc);
-            g.strokePath (arc, juce::PathStrokeType (3.5f));
-            g.setColour (live ? theme::colour::textPrimary : theme::colour::textSecondary);
-            g.setFont (theme::font (theme::type::caption));
-            g.drawText (juce::String (value()), box, juce::Justification::centred);
-
-            if (! c.assigned())
+            if (look != Look::unassigned)
             {
             {
-                g.setColour (theme::colour::textSecondary);
-                g.fillPath (cogPath (juce::Rectangle<float> (14.0f, 14.0f).withCentre (label.getCentre())));
-                return;
+                juce::Path arc;
+                arc.addCentredArc (box.getCentreX(), box.getCentreY(), radius, radius, 0.0f, -sweep * 0.5f, -sweep * 0.5f + sweep * (float) v, true);
+                g.setColour (look == Look::sending ? (hover ? theme::colour::accent.brighter (0.25f) : theme::colour::accent)
+                                                   : (hover ? theme::colour::textSecondary : theme::colour::textDisabled));
+                g.strokePath (arc, juce::PathStrokeType (3.5f));
+                // the pointer from the centre, like the other LYNX knobs
+                const auto angle = -sweep * 0.5f + sweep * (float) v;
+                const auto inner = box.getCentre() + juce::Point<float> (std::sin (angle), -std::cos (angle)) * (radius - 9.0f);
+                const auto outer = box.getCentre() + juce::Point<float> (std::sin (angle), -std::cos (angle)) * (radius - 4.0f);
+                g.drawLine ({ inner, outer }, 2.0f);
+                g.setColour (look == Look::sending ? theme::colour::textPrimary : theme::colour::textSecondary);
+                g.setFont (theme::font (theme::type::caption, look == Look::sending));
+                g.drawText (utf (midiout::view::readout (c, value())), box.reduced (8.0f), juce::Justification::centred);
             }
             }
-            g.setColour (live ? theme::colour::textPrimary : theme::colour::textSecondary); // (bold when it sends, FL)
-            ui::drawFittingText (g, utf (midiout::label (c)), label.reduced (2.0f, 0.0f), juce::Justification::centred,
-                                 juce::Font (theme::font (theme::type::small, live)));
+
+            // the cog: always there, always "Configure..."
+            g.setColour (hoverGear ? theme::colour::accent : look == Look::unassigned ? theme::colour::textSecondary : theme::colour::textDisabled);
+            g.fillPath (cogPath (rect (layout.gear).toFloat().reduced (1.5f)));
+
+            if (look == Look::unassigned)
+                return;
+            const auto labelHover = isMouseOver() && labelArea().contains (getMouseXYRelative());
+            g.setColour (look == Look::sending ? theme::colour::textPrimary : labelHover ? theme::colour::textSecondary : theme::colour::textDisabled);
+            ui::drawFittingText (g, utf (midiout::label (c)), labelArea().toFloat(), juce::Justification::centredTop,
+                                 juce::Font (theme::font (theme::type::small, look == Look::sending)));
         }
         }
 
 
         void mouseMove (const juce::MouseEvent& e) override
         void mouseMove (const juce::MouseEvent& e) override
         {
         {
             const auto& c = control();
             const auto& c = control();
-            if (labelArea().contains (e.getPosition()))
-                ui::setHint (*this, c.assigned() ? tr ("{0}: click to activate / deactivate", { utf (midiout::label (c)) })
-                                                 : tr ("(right click to configure) Unassigned"));
+            const auto overGear = gearArea().contains (e.getPosition());
+            if (overGear != hoverGear)
+            {
+                hoverGear = overGear;
+                setMouseCursor (overGear ? juce::MouseCursor::PointingHandCursor : juce::MouseCursor::NormalCursor);
+            }
+            repaint();
+            if (overGear)
+                ui::setHint (*this, tr ("Configure..."));
+            else if (labelArea().contains (e.getPosition()) && c.assigned())
+                ui::setHint (*this, tr ("{0}: click to activate / deactivate", { utf (midiout::label (c)) }));
             else
             else
                 ui::setHint (*this, c.assigned() ? utf (midiout::description (c)) : tr ("(right click to configure) Unassigned"), true,
                 ui::setHint (*this, c.assigned() ? utf (midiout::description (c)) : tr ("(right click to configure) Unassigned"), true,
-                             owner.channel >= 0);
+                             c.assigned() && owner.channel >= 0);
+        }
+
+        void mouseExit (const juce::MouseEvent&) override
+        {
+            hoverGear = false;
+            setMouseCursor (juce::MouseCursor::NormalCursor);
+            repaint();
         }
         }
 
 
         void mouseDown (const juce::MouseEvent& e) override
         void mouseDown (const juce::MouseEvent& e) override
@@ -502,12 +563,16 @@ private:
                 showMenu();
                 showMenu();
                 return;
                 return;
             }
             }
+            if (gearArea().contains (e.getPosition()))
+            {
+                owner.configure (index());
+                return;
+            }
+            if (! control().assigned())
+                return; // nothing to turn: the cog (or a right-click) sets it up
             if (labelArea().contains (e.getPosition()))
             if (labelArea().contains (e.getPosition()))
             {
             {
-                if (! control().assigned())
-                    owner.configure (index());
-                else
-                    owner.edit ([i = index()] (State& s) { s.controls[(std::size_t) i].active = ! s.controls[(std::size_t) i].active; });
+                owner.edit ([i = index()] (State& s) { s.controls[(std::size_t) i].active = ! s.controls[(std::size_t) i].active; });
                 return;
                 return;
             }
             }
             if (ui::isResetClick (e))
             if (ui::isResetClick (e))
@@ -524,7 +589,7 @@ private:
                 return;
                 return;
             const auto s = spec();
             const auto s = spec();
             set (drag.update (e, s));
             set (drag.update (e, s));
-            ui::showValueTip (*this, getLocalBounds(), s.text (value()));
+            ui::showValueTip (*this, rect (cell().knob), s.text (value()));
         }
         }
 
 
         void mouseUp (const juce::MouseEvent&) override
         void mouseUp (const juce::MouseEvent&) override
@@ -535,6 +600,8 @@ private:
 
 
         void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel) override
         void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& wheel) override
         {
         {
+            if (! control().assigned())
+                return;
             const auto s = spec();
             const auto s = spec();
             if (const auto v = ui::wheelValue (value(), e, wheel, s))
             if (const auto v = ui::wheelValue (value(), e, wheel, s))
             {
             {
@@ -567,6 +634,7 @@ private:
 
 
         MidiOutEditor& owner;
         MidiOutEditor& owner;
         int slot;
         int slot;
+        bool hoverGear = false;
         ui::ValueDrag drag;
         ui::ValueDrag drag;
     };
     };
 
 
@@ -589,8 +657,20 @@ private:
         o.escapeKeyTriggersCloseButton = true;
         o.escapeKeyTriggersCloseButton = true;
         o.useNativeTitleBar = true;
         o.useNativeTitleBar = true;
         o.resizable = false;
         o.resizable = false;
+        // like LYNX's other dialogs (Export, Customize toolbar...): modal, above the LYNX windows, LYNX title bar
         if (auto* w = o.launchAsync())
         if (auto* w = o.launchAsync())
-            applyWindowChrome (*w);
+        {
+            keepAboveMainWindow (*w);
+            // On Windows the native title bar's height came out added to the client area once the window was shown,
+            // leaving an empty band under the buttons: give the client area back the content's height
+            juce::Timer::callAfterDelay (60, [safe = juce::Component::SafePointer<juce::DialogWindow> (w)] {
+                if (safe == nullptr)
+                    return;
+                const auto extra = safe->getHeight() - safe->getContentComponentBorder().getTopAndBottom() - ControlSettings::dialogHeight;
+                if (extra > 0)
+                    safe->setSize (safe->getWidth(), safe->getHeight() - extra);
+            });
+        }
     }
     }
 
 
     void renamePage()
     void renamePage()

+ 61 - 4
src/ui/Theme.cpp

@@ -1,9 +1,11 @@
 #include "ui/Theme.h"
 #include "ui/Theme.h"
 
 
 #include <algorithm>
 #include <algorithm>
+#include <limits>
 #include <unordered_map>
 #include <unordered_map>
 #include <vector>
 #include <vector>
 
 
+#include "core/MenuPlacement.h"
 #include "ui/Icons.h"
 #include "ui/Icons.h"
 #include "ui/PluginSkin.h"
 #include "ui/PluginSkin.h"
 
 
@@ -682,11 +684,66 @@ void LookAndFeel::positionComboBoxText (juce::ComboBox& box, juce::Label& label)
 
 
 void LookAndFeel::preparePopupMenuWindow (juce::Component& window)
 void LookAndFeel::preparePopupMenuWindow (juce::Component& window)
 {
 {
-    // A submenu opens where JUCE puts it: right beside the item that opened it, at the item's height (flipped to the
-    // left / moved up only when it does not fit on the screen). Issue #18: moving it beside the whole parent window
-    // (0.1.19…0.1.21) put a two-column menu's other column between the item and its submenu, and the mouse crossing
-    // that column opened the other items' submenus on the way.
     juce::LookAndFeel_V4::preparePopupMenuWindow (window);
     juce::LookAndFeel_V4::preparePopupMenuWindow (window);
+
+    // Issue #18 (round 167p): a submenu opens beside its parent menu's OUTER edge, its first item level with the item
+    // that opened it, growing downwards (core/MenuPlacement.h). JUCE put it beside the item, so in a two-column menu
+    // (Channel Rack, Playlist, Mixer, Piano Roll) it covered the other column, and grew upwards whenever the item was
+    // in the lower half of the screen. The mouse crossing that other column keeps the submenu open (the JUCE patch
+    // "submenu corridor" in cmake/LynxPatchJuce.cmake).
+    static std::vector<juce::Component::SafePointer<juce::Component>> menus;
+    menus.erase (std::remove_if (menus.begin(), menus.end(), [] (const auto& m) { return m == nullptr || ! m->isVisible(); }), menus.end());
+    const auto remember = [&window] { menus.push_back (&window); };
+    if (! window.isOnDesktop() || menus.empty())
+        return remember();
+
+    // the parent: the latest menu window still open (opening another item's submenu closes the previous one first)
+    juce::Component* parent = nullptr;
+    for (auto it = menus.rbegin(); it != menus.rend() && parent == nullptr; ++it)
+        if (auto* m = it->getComponent(); m != &window && m->isOnDesktop()
+                                          && std::abs (m->getDesktopScaleFactor() - window.getDesktopScaleFactor()) < 0.001f)
+            parent = m;
+    if (parent == nullptr)
+        return remember();
+
+    // the item that opened it: JUCE put the submenu right beside it (its right edge = the submenu's left, or the other
+    // way round), level with its top (upper half of the screen) or its bottom (lower half). The item under the mouse
+    // first (a hover), else the best match (the keyboard's right arrow).
+    const auto border = getPopupMenuBorderSize();
+    const auto sub = window.getBounds(), parentBox = parent->getBounds();
+    const auto beside = [&sub] (juce::Rectangle<int> r) { return std::abs (r.getRight() - sub.getX()) <= 2 || std::abs (r.getX() - sub.getRight()) <= 2; };
+    const auto mouse = juce::Desktop::getInstance().getMousePosition();
+    juce::Rectangle<int> item;
+    int best = std::numeric_limits<int>::max();
+    for (auto* c : parent->getChildren())
+    {
+        const auto r = c->getBounds() + parentBox.getPosition();
+        if (! c->isVisible() || ! beside (r))
+            continue;
+        if (r.contains (mouse))
+        {
+            item = r;
+            break;
+        }
+        const auto miss = juce::jmin (std::abs (r.getY() - (sub.getY() + border)), std::abs (r.getBottom() - (sub.getBottom() - border)));
+        if (miss < best)
+        {
+            best = miss;
+            item = r;
+        }
+    }
+    if (item.isEmpty())
+        return remember();
+
+    const auto scale = juce::jmax (0.01f, window.getDesktopScaleFactor() / juce::Desktop::getInstance().getGlobalScaleFactor());
+    const auto* display = juce::Desktop::getInstance().getDisplays().getDisplayForRect (parentBox * scale);
+    const auto area = display != nullptr ? (display->userArea / scale).toNearestInt() : parentBox.expanded (10000);
+    using menuplace::Box;
+    const auto box = [] (juce::Rectangle<int> r) { return Box { r.getX(), r.getY(), r.getWidth(), r.getHeight() }; };
+    const auto placed = menuplace::placeSubmenu (box (parentBox), box (item), sub.getWidth(), sub.getHeight(), border, box (area));
+    if (placed != box (sub))
+        window.setBounds (placed.x, placed.y, placed.w, placed.h);
+    remember();
 }
 }
 
 
 void LookAndFeel::drawPopupMenuBackground (juce::Graphics& g, int width, int height)
 void LookAndFeel::drawPopupMenuBackground (juce::Graphics& g, int width, int height)

+ 51 - 0
tests/Polish167pTests.inc

@@ -0,0 +1,51 @@
+// Round 167p: issue #18 (submenus beside the parent menu's outer edge, level with their item, growing downwards) and
+// issue #17 (MIDI Out knobs: cog top-right, name under the knob, three looks).
+#include "core/MenuPlacement.h"
+#include "core/MidiOutView.h"
+
+TEST (polish167p_submenu_beside_outer_edge)
+{
+    using lynx::menuplace::Box;
+    using lynx::menuplace::placeSubmenu;
+    const Box screen { 0, 0, 1920, 1040 };
+    // a two-column menu at x 195..525; "Insert" in the first column (right edge 515) at y 398
+    const Box parent { 195, 170, 330, 470 }, insert { 200, 398, 315, 21 };
+    // beside the OUTER edge (not over the second column), first item level with "Insert" (border 4), downwards
+    CHECK ((placeSubmenu (parent, insert, 165, 375, 4, screen) == Box { 525, 394, 165, 375 }));
+    // near the bottom of the screen: up only as much as needed (not bottom-aligned to the item like JUCE)
+    CHECK ((placeSubmenu (parent, { 200, 900, 315, 21 }, 165, 375, 4, screen) == Box { 525, 665, 165, 375 }));
+    // no room on the right: beside the left edge
+    CHECK ((placeSubmenu ({ 1600, 100, 300, 400 }, { 1605, 200, 290, 21 }, 200, 300, 4, screen) == Box { 1400, 196, 200, 300 }));
+    // taller than the screen: from its top
+    CHECK ((placeSubmenu (parent, insert, 165, 1200, 4, screen).y == 0));
+    // a second monitor on the left (negative x)
+    CHECK ((placeSubmenu ({ -1500, 300, 300, 400 }, { -1495, 350, 290, 21 }, 200, 300, 4, { -1920, 0, 1920, 1040 }) == Box { -1200, 346, 200, 300 }));
+}
+
+TEST (polish167p_midiout_knob_cell)
+{
+    using namespace lynx::midiout::view;
+    // the editor's cells (round 167p): 240 x 100
+    for (const auto& cellBox : { Rect { 0, 0, 240, 100 }, Rect { 0, 0, 180, 80 }, Rect { 10, 20, 300, 120 } })
+    {
+        const auto c = layout (cellBox);
+        CHECK (c.knob.w == c.knob.h);
+        CHECK (c.knob.w >= 40);
+        // the cog at the knob's top-right: right of its centre, above its centre, inside the cell
+        CHECK (c.gear.x > c.knob.x + c.knob.w / 2);
+        CHECK (c.gear.y + c.gear.h / 2 < c.knob.y + c.knob.h / 4);
+        CHECK (c.gear.right() <= cellBox.right() && c.gear.y >= cellBox.y);
+        // the name under the knob, never on the cog, and a gap before the next row
+        CHECK (c.label.y >= c.knob.bottom());
+        CHECK (! c.label.intersects (c.gear));
+        CHECK (c.label.bottom() + rowGap <= cellBox.bottom());
+    }
+    lynx::midiout::Control c;
+    CHECK (look (c) == Look::unassigned);
+    CHECK (readout (c, 0).empty()); // no "0" inside an unset knob
+    c.number = 74;
+    CHECK (look (c) == Look::off);
+    c.active = true;
+    CHECK (look (c) == Look::sending);
+    CHECK (readout (c, 64) == "64");
+}

+ 1 - 0
tests/tests.cpp

@@ -16875,3 +16875,4 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Score167Tests.inc"
 #include "Score167Tests.inc"
 #include "Ntt167Tests.inc"
 #include "Ntt167Tests.inc"
 #include "MidiOut167iTests.inc"
 #include "MidiOut167iTests.inc"
+#include "Polish167pTests.inc"