MIDI2LR 6.3.0.1
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 )
32 profile_(profile), message_{message} {
33}
34
35catch (const std::exception& e) {
36 rsj::ExceptionResponse(e, std::source_location::current());
37 throw;
38}
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:64
TextButtonAligned(const juce::Justification::Flags alignment)
Definition TextButtonAligned.h:28
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
77{
78 if (profile_.CommandHasAssociatedMessage(command_set_.CommandAbbrevAt(index - 1))) {
79 const auto is_selected_item {index == selected_item_};
80 ticked |= is_selected_item;
81 sub_menu.addColouredItem(gsl::narrow_cast<int>(index), command, juce::Colours::red, true,
82 is_selected_item);
83 }
84 else {
85 sub_menu.addItem(gsl::narrow_cast<int>(index), command, true, false);
86 }
87}
size_t selected_item_
Definition CommandMenu.h:57

References command_set_, Profile::CommandHasAssociatedMessage(), profile_, and selected_item_.

◆ AddSubMenusToMainMenu()

void CommandMenu::AddSubMenusToMainMenu ( juce::PopupMenu & main_menu,
size_t index ) const
private
101{
102 const auto& menus {command_set_.GetMenus()};
103 const auto& menu_entries {command_set_.GetMenuEntries()};
104 const auto menu_entries_size {menu_entries.size()};
105 for (size_t submenu_number = 0; submenu_number < menu_entries_size; ++submenu_number) {
106 juce::PopupMenu sub_menu;
107 auto ticked {false};
108 for (const auto& command : menu_entries.at(submenu_number)) {
109 AddSubMenuItems(sub_menu, command, index++, ticked);
110 }
111 main_menu.addSubMenu(menus.at(submenu_number), sub_menu, true, nullptr, ticked);
112 }
113}
void AddSubMenuItems(juce::PopupMenu &sub_menu, const juce::String &command, size_t index, bool &ticked) const
Definition CommandMenu.cpp:75

References command_set_.

◆ clicked()

void CommandMenu::clicked ( const juce::ModifierKeys & modifiers)
overrideprivate
124{
125 try {
126 if (modifiers.isPopupMenu()) { ShowDialogBasedOnMessageType(); }
127 else {
129 }
130 }
131 catch (const std::exception& e) {
132 rsj::ExceptionResponse(e, std::source_location::current());
133 throw;
134 }
135}
void ProcessMenuItems()
Definition CommandMenu.cpp:115
void ShowDialogBasedOnMessageType() const
Definition CommandMenu.cpp:56

References ProcessMenuItems(), and ShowDialogBasedOnMessageType().

◆ ProcessMenuItems()

void CommandMenu::ProcessMenuItems ( )
private
116{ /* item result numbers are 1-based, as 0 represents "no selection" */
117 juce::PopupMenu main_menu;
118 main_menu.addItem(1, CommandSet::UnassignedTranslated(), true, 1 == selected_item_);
119 AddSubMenusToMainMenu(main_menu, 2);
120 ProcessUserSelection(main_menu);
121}
void ProcessUserSelection(juce::PopupMenu &main_menu)
Definition CommandMenu.cpp:89
void AddSubMenusToMainMenu(juce::PopupMenu &main_menu, size_t index) const
Definition CommandMenu.cpp:100

References selected_item_.

Referenced by clicked().

◆ ProcessUserSelection()

void CommandMenu::ProcessUserSelection ( juce::PopupMenu & main_menu)
private
90{
91 if (const auto result {gsl::narrow_cast<size_t>(main_menu.show())}) {
92 const auto cmd_size {command_set_.CommandAbbrevSize()};
93 const size_t idx {(result - 1 < cmd_size) ? result - 1 : 0};
94 profile_.InsertOrAssign(idx, message_);
95 juce::Button::setButtonText(command_set_.CommandLabelAt(idx));
96 selected_item_ = result;
97 }
98}

References Profile::InsertOrAssign(), message_, profile_, and selected_item_.

◆ SetMsg()

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

References 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 }

References command_set_, CommandSet::CommandAbbrevSize(), CommandSet::CommandLabelAt(), and selected_item_.

◆ ShowCCDialog()

void CommandMenu::ShowCCDialog ( ) const
41{
42 CCoptions ccopt;
43 ccopt.BindToControl(message_.channel - 1, message_.control_number); // convert 1-based to 0-based
44 juce::DialogWindow::showModalDialog(juce::translate("Adjust CC dialog"), &ccopt, nullptr,
45 juce::Colours::white, true);
46}

References rsj::MidiMessageId::channel, rsj::MidiMessageId::control_number, and message_.

Referenced by ShowDialogBasedOnMessageType().

◆ ShowDialogBasedOnMessageType()

void CommandMenu::ShowDialogBasedOnMessageType ( ) const
private
57{
58 switch (message_.msg_id_type) {
61 break;
64 break;
71 break; // do nothing for other types of controllers
72 }
73}
void ShowCCDialog() const
Definition CommandMenu.cpp:40
void ShowPWDialog() const
Definition CommandMenu.cpp:48
@ kChanPressure
Definition MidiUtilities.h:47
@ kSystem
Definition MidiUtilities.h:49
@ kCc
Definition MidiUtilities.h:45
@ kKeyPressure
Definition MidiUtilities.h:44
@ kNoteOff
Definition MidiUtilities.h:42
@ kNoteOn
Definition MidiUtilities.h:43
@ kPgmChange
Definition MidiUtilities.h:46
@ kPw
Definition MidiUtilities.h:48

References rsj::kCc, rsj::kChanPressure, rsj::kKeyPressure, rsj::kNoteOff, rsj::kNoteOn, rsj::kPgmChange, rsj::kPw, rsj::kSystem, message_, rsj::MidiMessageId::msg_id_type, ShowCCDialog(), and ShowPWDialog().

Referenced by clicked().

◆ ShowPWDialog()

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

References rsj::MidiMessageId::channel, and message_.

Referenced by ShowDialogBasedOnMessageType().

Member Data Documentation

◆ command_set_

const CommandSet& CommandMenu::command_set_
private

◆ message_

◆ 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()};

Referenced by AddSubMenuItems(), ProcessMenuItems(), ProcessUserSelection(), and SetSelectedItem().


The documentation for this class was generated from the following files:
  • C:/Users/rsjaf/source/repos/MIDI2LR/src/application/CommandMenu.h
  • C:/Users/rsjaf/source/repos/MIDI2LR/src/application/CommandMenu.cpp