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
CommandTableModel Class Referencefinal

#include <CommandTableModel.h>

Inheritance diagram for CommandTableModel:

Public Member Functions

 CommandTableModel (const CommandSet &command_set, Profile &profile) noexcept
void RemoveRow (size_t row)

Private Member Functions

CommandMenuCreateNewCommandMenu (int row_number, juce::Component *existing_component) const
int getNumRows () override
void paintCell (juce::Graphics &, int row_number, int column_id, int width, int height, bool row_is_selected) override
void paintRowBackground (juce::Graphics &, int row_number, int width, int height, bool row_is_selected) override
juce::Component * refreshComponentForCell (int row_number, int column_id, bool is_row_selected, juce::Component *existing_component) override
void sortOrderChanged (int new_sort_column_id, bool is_forwards) override
CommandMenuUpdateCommandMenu (int row_number, gsl::not_null< CommandMenu * > command_select) const

Private Attributes

const CommandSetcommand_set_
Profileprofile_

Constructor & Destructor Documentation

◆ CommandTableModel()

CommandTableModel::CommandTableModel ( const CommandSet & command_set,
Profile & profile )
noexcept
31 : command_set_ {command_set}, profile_ {profile}
32{
33}
const CommandSet & command_set_
Definition CommandTableModel.h:52
Profile & profile_
Definition CommandTableModel.h:53

References command_set_.

Member Function Documentation

◆ CreateNewCommandMenu()

CommandMenu * CommandTableModel::CreateNewCommandMenu ( int row_number,
juce::Component * existing_component ) const
nodiscardprivate
115{
116 /* create a new command menu, delete old one if it exists */
117 delete existing_component;
118 if (const auto profile_size = profile_.Size();
119 std::cmp_less_equal(profile_size, row_number) || row_number < 0) {
120 rsj::Log(fmt::format("Invalid row_number {} in CreateNewCommandMenu, profile size {}.",
121 row_number, profile_size),
122 std::source_location::current());
123 return nullptr;
124 }
125 const auto& msg {profile_.GetMessageForNumber(gsl::narrow_cast<size_t>(row_number))};
126 auto new_select {std::make_unique<CommandMenu>(msg, command_set_, profile_)};
127 new_select->SetSelectedItem(command_set_.CommandTextIndex(profile_.GetCommandForMessage(msg))
128 + 1);
129 return new_select.release();
130}
void Log(const juce::String &info, const std::source_location &location=std::source_location::current()) noexcept
Definition Misc.cpp:112

References command_set_, CommandSet::CommandTextIndex(), Profile::GetCommandForMessage(), Profile::GetMessageForNumber(), profile_, and Profile::Size().

◆ getNumRows()

int CommandTableModel::getNumRows ( )
inlinenodiscardoverrideprivate
38{ return gsl::narrow_cast<int>(profile_.Size()); }

References profile_, and Profile::Size().

◆ paintCell()

void CommandTableModel::paintCell ( juce::Graphics & g,
int row_number,
int column_id,
int width,
int height,
bool row_is_selected )
overrideprivate
72{
73 try {
74 g.setColour(juce::Colours::black);
75 g.setFont(std::min(16.0F, static_cast<float>(height) * 0.7F));
76 if (column_id != 1) { return; }
77 if (row_number < 0) { return; }
78 if (const auto profile_size = profile_.Size();
79 std::cmp_less_equal(profile_size, row_number)) {
80 g.drawText("Unknown control", 0, 0, width, height, juce::Justification::centred);
81 rsj::Log(fmt::format("Unknown control CommandTableModel::paintCell. {} rows in profile, "
82 "row number to be painted is {}.",
83 profile_size, row_number),
84 std::source_location::current());
85 return;
86 }
87 const auto cmd {profile_.GetMessageForNumber(gsl::narrow_cast<size_t>(row_number))};
88 const auto messageText {FormatMessageText(cmd)};
89 g.drawText(messageText, 0, 0, width, height, juce::Justification::centredLeft);
90 }
91 catch (const std::exception& e) {
92 rsj::ExceptionResponse(e, std::source_location::current());
93 throw;
94 }
95}
void ExceptionResponse(gsl::czstring id, gsl::czstring fu, const std::exception &e) noexcept

References Profile::GetMessageForNumber(), profile_, and Profile::Size().

◆ paintRowBackground()

void CommandTableModel::paintRowBackground ( juce::Graphics & g,
int row_number,
int width,
int height,
bool row_is_selected )
overrideprivate
99{
100 /* This must draw the background behind one of the rows in the table. The graphics context has
101 * its origin at the row's top-left, and your method should fill the area specified by the width
102 * and height parameters. Note that the rowNumber value may be greater than the number of rows in
103 * your list, so be careful that you don't assume it's less than getNumRows(). */
104 try {
105 if (row_is_selected) { g.fillAll(juce::Colours::lightblue); }
106 }
107 catch (const std::exception& e) {
108 rsj::ExceptionResponse(e, std::source_location::current());
109 throw;
110 }
111}

◆ refreshComponentForCell()

juce::Component * CommandTableModel::refreshComponentForCell ( int row_number,
int column_id,
bool is_row_selected,
juce::Component * existing_component )
overrideprivate
144{
145 try {
146 if (column_id != 2) { return nullptr; }
147 // Validate row_number before accessing profile
148 if (row_number < 0 || std::cmp_greater_equal(row_number, profile_.Size())) {
149 delete existing_component;
150 return nullptr;
151 }
152 const auto command_select {dynamic_cast<CommandMenu*>(existing_component)};
153 if (command_select == nullptr) {
154 return CreateNewCommandMenu(row_number, existing_component);
155 }
156 return UpdateCommandMenu(row_number, command_select);
157 }
158 catch (const std::exception& e) {
159 rsj::ExceptionResponse(e, std::source_location::current());
160 throw;
161 }
162}
CommandMenu * UpdateCommandMenu(int row_number, gsl::not_null< CommandMenu * > command_select) const
Definition CommandTableModel.cpp:132
CommandMenu * CreateNewCommandMenu(int row_number, juce::Component *existing_component) const
Definition CommandTableModel.cpp:113

References UpdateCommandMenu().

◆ RemoveRow()

void CommandTableModel::RemoveRow ( size_t row)
inline
32 {
33 /* called from CommandTable, forward to Profile */
34 profile_.RemoveRow(row);
35 }

References profile_, and Profile::RemoveRow().

◆ sortOrderChanged()

void CommandTableModel::sortOrderChanged ( int new_sort_column_id,
bool is_forwards )
overrideprivate
165{
166 try {
167 const auto current_sort {std::make_pair(new_sort_column_id, is_forwards)};
168 profile_.Resort(current_sort);
169 }
170 catch (const std::exception& e) {
171 rsj::ExceptionResponse(e, std::source_location::current());
172 throw;
173 }
174}

References profile_, and Profile::Resort().

◆ UpdateCommandMenu()

CommandMenu * CommandTableModel::UpdateCommandMenu ( int row_number,
gsl::not_null< CommandMenu * > command_select ) const
nodiscardprivate
134{ /* Updates the existing command menu */
135 const auto& msg {profile_.GetMessageForNumber(gsl::narrow_cast<size_t>(row_number))};
136 command_select->SetMsg(msg);
137 command_select->SetSelectedItem(command_set_.CommandTextIndex(profile_.GetCommandForMessage(msg))
138 + 1);
139 return command_select;
140}

References command_set_, CommandSet::CommandTextIndex(), Profile::GetCommandForMessage(), Profile::GetMessageForNumber(), and profile_.

Referenced by refreshComponentForCell().

Member Data Documentation

◆ command_set_

const CommandSet& CommandTableModel::command_set_
private

◆ profile_

Profile& CommandTableModel::profile_
private

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