MIDI2LR 6.1.0.0
MIDI2LR is an application that interfaces MIDI controllers with Lightroom 6+/CC Classic. It processes MIDI input into develop parameter updates and photo actions, and sends MIDI output when parameters are changed for motorized feedback (on controllers that have motorized faders). A listing of available LightRoom commands is in the Wiki. Assistance on the code and design is welcome.
Loading...
Searching...
No Matches
CommandMenu Class Referencefinal

#include <CommandMenu.h>

+ Inheritance diagram for CommandMenu:

Public Member Functions

 CommandMenu (rsj::MidiMessageId message, const CommandSet &command_set, Profile &profile)
 
void SetMsg (rsj::MidiMessageId message) noexcept
 
void SetSelectedItem (size_t index)
 
void ShowCCDialog () const
 
- Public Member Functions inherited from TextButtonAligned
 TextButtonAligned (const juce::Justification::Flags alignment)
 
 TextButtonAligned (const juce::String &button_name, const juce::Justification::Flags alignment)
 
 TextButtonAligned (const juce::String &button_name, const juce::String &tool_tip, const juce::Justification::Flags alignment)
 
void paintButton (juce::Graphics &, bool, bool) override
 

Private Member Functions

void AddSubMenuItems (juce::PopupMenu &sub_menu, const juce::String &command, size_t index, bool &ticked) const
 
void AddSubMenusToMainMenu (juce::PopupMenu &main_menu, size_t index) const
 
void clicked (const juce::ModifierKeys &modifiers) override
 
void ProcessMenuItems ()
 
void ProcessUserSelection (juce::PopupMenu &main_menu)
 
void ShowDialogBasedOnMessageType () const
 
void ShowPWDialog () const
 

Private Attributes

const CommandSetcommand_set_
 
rsj::MidiMessageId message_
 
Profileprofile_
 
size_t selected_item_ {std::numeric_limits<decltype(selected_item_)>::max()}
 

Constructor & Destructor Documentation

◆ CommandMenu()

CommandMenu::CommandMenu ( rsj::MidiMessageId  message,
const CommandSet command_set,
Profile profile 
)
31 profile_(profile), message_{message} {
32}
33
34catch (const std::exception& e) {
36 throw;
37}
const CommandSet & command_set_
Definition CommandMenu.h:54
rsj::MidiMessageId message_
Definition CommandMenu.h:56
Profile & profile_
Definition CommandMenu.h:55
static const auto & UnassignedTranslated()
Definition CommandSet.h:57
Definition TextButtonAligned.h:23
void ExceptionResponse(gsl::czstring id, gsl::czstring fu, const std::exception &e) noexcept

Member Function Documentation

◆ AddSubMenuItems()

void CommandMenu::AddSubMenuItems ( juce::PopupMenu &  sub_menu,
const juce::String &  command,
size_t  index,
bool &  ticked 
) const
private
76{
78 const auto is_selected_item = (index == selected_item_);
79 ticked |= is_selected_item;
80 sub_menu.addColouredItem(gsl::narrow_cast<int>(index), command, juce::Colours::red, true,
81 is_selected_item);
82 }
83 else {
84 sub_menu.addItem(gsl::narrow_cast<int>(index), command, true, false);
85 }
86}
size_t selected_item_
Definition CommandMenu.h:57
const auto & CommandAbbrevAt(size_t index) const
Definition CommandSet.h:38
bool CommandHasAssociatedMessage(const std::string &command) const
Definition Profile.h:78

◆ AddSubMenusToMainMenu()

void CommandMenu::AddSubMenusToMainMenu ( juce::PopupMenu &  main_menu,
size_t  index 
) const
private
106{
107 const auto& menus {command_set_.GetMenus()};
108 const auto& menu_entries {command_set_.GetMenuEntries()};
109 const auto menu_entries_size = menu_entries.size();
110 for (size_t submenu_number = 0; submenu_number < menu_entries_size; ++submenu_number) {
111 juce::PopupMenu sub_menu;
112 auto ticked {false};
113 for (const auto& command : menu_entries[submenu_number]) {
114 AddSubMenuItems(sub_menu, command, index++, ticked);
115 }
116 main_menu.addSubMenu(menus[submenu_number], sub_menu, true, nullptr, ticked);
117 }
118}
void AddSubMenuItems(juce::PopupMenu &sub_menu, const juce::String &command, size_t index, bool &ticked) const
Definition CommandMenu.cpp:74
const auto & GetMenuEntries() const noexcept
Definition CommandSet.h:51
const auto & GetMenus() const noexcept
Definition CommandSet.h:49

◆ clicked()

void CommandMenu::clicked ( const juce::ModifierKeys &  modifiers)
overrideprivate
129{
130 try {
131 if (modifiers.isPopupMenu()) { ShowDialogBasedOnMessageType(); }
132 else {
134 }
135 }
136 catch (const std::exception& e) {
138 throw;
139 }
140}
void ProcessMenuItems()
Definition CommandMenu.cpp:120
void ShowDialogBasedOnMessageType() const
Definition CommandMenu.cpp:55

◆ ProcessMenuItems()

void CommandMenu::ProcessMenuItems ( )
private
121{
122 juce::PopupMenu main_menu;
123 main_menu.addItem(1, CommandSet::UnassignedTranslated(), true, 1 == selected_item_);
124 AddSubMenusToMainMenu(main_menu, 2);
125 ProcessUserSelection(main_menu);
126}
void ProcessUserSelection(juce::PopupMenu &main_menu)
Definition CommandMenu.cpp:88
void AddSubMenusToMainMenu(juce::PopupMenu &main_menu, size_t index) const
Definition CommandMenu.cpp:105

◆ ProcessUserSelection()

void CommandMenu::ProcessUserSelection ( juce::PopupMenu &  main_menu)
private
89{
90 if (auto result {gsl::narrow_cast<size_t>(main_menu.show())}) {
91 if (result - 1 < command_set_.CommandAbbrevSize()) {
92 profile_.InsertOrAssign(result - 1, message_);
93 juce::Button::setButtonText(command_set_.CommandLabelAt(result - 1));
94 }
95 else {
97 juce::Button::setButtonText(command_set_.CommandLabelAt(0));
98 result = 0;
99 }
100 selected_item_ = result;
101 // Map the selected command to the CC
102 }
103}
auto CommandAbbrevSize() const noexcept
Definition CommandSet.h:43
auto CommandLabelAt(size_t index) const
Definition CommandSet.h:45
void InsertOrAssign(const std::string &command, rsj::MidiMessageId message)
Definition Profile.h:110

◆ SetMsg()

void CommandMenu::SetMsg ( rsj::MidiMessageId  message)
inlinenoexcept
34{ message_ = message; }

◆ SetSelectedItem()

void CommandMenu::SetSelectedItem ( size_t  index)
inline
37 {
38 selected_item_ = index;
39 if (index - 1 < command_set_.CommandAbbrevSize()) {
40 setButtonText(command_set_.CommandLabelAt(index - 1));
41 }
42 }

◆ ShowCCDialog()

void CommandMenu::ShowCCDialog ( ) const
40{
41 CCoptions ccopt;
42 ccopt.BindToControl(message_.channel - 1, message_.control_number); // convert 1-based to 0-based
43 juce::DialogWindow::showModalDialog(juce::translate("Adjust CC dialog"), &ccopt, nullptr,
44 juce::Colours::white, true);
45}
Definition CCoptions.h:58
void BindToControl(int channel, int control_number)
Definition CCoptions.cpp:306
int channel
Definition MidiUtilities.h:146
int control_number
Definition MidiUtilities.h:147

◆ ShowDialogBasedOnMessageType()

void CommandMenu::ShowDialogBasedOnMessageType ( ) const
private
56{
57 switch (message_.msg_id_type) {
60 break;
63 break;
70 break; // do nothing for other types of controllers
71 }
72}
void ShowCCDialog() const
Definition CommandMenu.cpp:39
void ShowPWDialog() const
Definition CommandMenu.cpp:47
MessageType msg_id_type
Definition MidiUtilities.h:148

◆ ShowPWDialog()

void CommandMenu::ShowPWDialog ( ) const
private
48{
49 PWoptions pwopt;
50 pwopt.BindToControl(message_.channel - 1); // convert 1-based to 0-based
51 juce::DialogWindow::showModalDialog(juce::translate("Adjust PW dialog"), &pwopt, nullptr,
52 juce::Colours::white, true);
53}
Definition PWoptions.h:57
void BindToControl(int channel)
Definition PWoptions.cpp:172

Member Data Documentation

◆ command_set_

const CommandSet& CommandMenu::command_set_
private

◆ message_

rsj::MidiMessageId CommandMenu::message_
private

◆ profile_

Profile& CommandMenu::profile_
private

◆ selected_item_

size_t CommandMenu::selected_item_ {std::numeric_limits<decltype(selected_item_)>::max()}
private
57{std::numeric_limits<decltype(selected_item_)>::max()};

The documentation for this class was generated from the following files: