@@ -49,6 +49,11 @@ MacroPanel::MacroPanel(SixSinesEditor &e) : jcmp::NamedPanel("Macros"), HasEdito
4949 editor.macroSubPanel ->setEnabledState ();
5050 };
5151 addAndMakeVisible (*power[i]);
52+
53+ usageButtons[i] = std::make_unique<jcmp::TextPushButton>();
54+ usageButtons[i]->setLabel (" 0" );
55+ usageButtons[i]->setOnCallback ([this , i]() { showUsageMenu (i); });
56+ addAndMakeVisible (*usageButtons[i]);
5257 }
5358
5459 highlight = std::make_unique<KnobHighlight>(editor);
@@ -64,7 +69,7 @@ void MacroPanel::resized()
6469 auto y = b.getY ();
6570 for (auto i = 0U ; i < numMacros; ++i)
6671 {
67- positionPowerKnobAndLabel (x, y, power[i], knobs [i], labels [i], true );
72+ positionPowerKnobSwitchAndLabel (x, y, power[i], usageButtons [i], knobs [i], labels[i] );
6873 x += uicPowerKnobWidth + uicMargin;
6974 }
7075}
@@ -92,6 +97,50 @@ void MacroPanel::mouseDown(const juce::MouseEvent &e)
9297 }
9398}
9499
100+ void MacroPanel::refreshUsage (size_t idx)
101+ {
102+ if (idx >= numMacros)
103+ return ;
104+ auto count = editor.macroUsageCache [idx].size ();
105+ if (usageButtons[idx])
106+ {
107+ usageButtons[idx]->setLabel (std::to_string (count));
108+ usageButtons[idx]->setEnabled (count > 0 );
109+ usageButtons[idx]->repaint ();
110+ }
111+ if (labels[idx])
112+ {
113+ labels[idx]->setEnabled (count > 0 );
114+ labels[idx]->repaint ();
115+ }
116+ }
117+
118+ void MacroPanel::showUsageMenu (size_t idx)
119+ {
120+ if (idx >= numMacros)
121+ return ;
122+ auto &uses = editor.macroUsageCache [idx];
123+ if (uses.empty ())
124+ return ;
125+
126+ auto p = juce::PopupMenu ();
127+ p.addSectionHeader (displayShortName (editor, idx));
128+ p.addSeparator ();
129+ for (auto &u : uses)
130+ {
131+ auto label = u.nodeLabel + " — " + u.targetName + (u.modulated ? " (mod)" : " " );
132+ auto refCopy = u;
133+ p.addItem (label,
134+ [w = juce::Component::SafePointer (this ), refCopy]()
135+ {
136+ if (w && w->editor .macroSubPanel )
137+ w->editor .macroSubPanel ->jumpTo (refCopy);
138+ });
139+ }
140+ p.showMenuAsync (juce::PopupMenu::Options ().withParentComponent (&editor),
141+ makeMenuAccessibleButtonCB (usageButtons[idx].get ()));
142+ }
143+
95144void MacroPanel::refreshLabel (size_t idx)
96145{
97146 if (idx >= numMacros || !labels[idx])
0 commit comments