MIDI2LR 6.2.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
30 : command_set_ {command_set}, profile_ {profile}
31{
32}
const CommandSet & command_set_
Definition CommandTableModel.h:52
Profile & profile_
Definition CommandTableModel.h:53

Member Function Documentation

◆ CreateNewCommandMenu()

CommandMenu * CommandTableModel::CreateNewCommandMenu ( int  row_number,
juce::Component *  existing_component 
) const
private
113{
114 /* create a new command menu, delete old one if it exists */
115 delete existing_component; // NOLINT(cppcoreguidelines-owning-memory)
116 const auto& msg = profile_.GetMessageForNumber(gsl::narrow_cast<size_t>(row_number));
117 auto new_select {std::make_unique<CommandMenu>(msg, command_set_, profile_)};
118 new_select->SetSelectedItem(command_set_.CommandTextIndex(profile_.GetCommandForMessage(msg))
119 + 1);
120 return new_select.release();
121}
size_t CommandTextIndex(const std::string &command) const
Definition CommandSet.h:37
rsj::MidiMessageId GetMessageForNumber(size_t num) const
Definition Profile.h:97
const std::string & GetCommandForMessage(rsj::MidiMessageId message) const
Definition Profile.h:89

◆ getNumRows()

int CommandTableModel::getNumRows ( )
inlineoverrideprivate
38{ return gsl::narrow_cast<int>(profile_.Size()); }
size_t Size() const
Definition Profile.h:147

◆ paintCell()

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

◆ paintRowBackground()

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

◆ refreshComponentForCell()

juce::Component * CommandTableModel::refreshComponentForCell ( int  row_number,
int  column_id,
bool  is_row_selected,
juce::Component *  existing_component 
)
overrideprivate
136{
137 /* This is used to create or update a custom component to go in a cell. Any cell may contain a
138 * custom component, or can just be drawn with the paintCell() method and handle mouse clicks
139 * with cellClicked(). This method will be called whenever a custom component might need to be
140 * updated - e.g. when the table is changed, or TableListBox::updateContent() is called. If you
141 * don't need a custom component for the specified cell, then return nullptr. (Bear in mind that
142 * even if you're not creating a new component, you may still need to delete
143 * existingComponentToUpdate if it's non-null). If you do want a custom component, and the
144 * existingComponentToUpdate is null, then this method must create a new component suitable for
145 * the cell, and return it. If the existingComponentToUpdate is non - null, it will be a pointer
146 * to a component previously created by this method.In this case, the method must either update
147 * it to make sure it's correctly representing the given cell(which may be different from the one
148 * that the component was created for), or it can delete this component and return a new one.
149 * Because Juce recycles these components when scrolling, we need to reset their properties. */
150 try {
151 if (column_id != 2) { // Not LR command column
152 return nullptr;
153 }
154 const auto command_select {dynamic_cast<CommandMenu*>(existing_component)};
155 if (command_select == nullptr) {
156 return CreateNewCommandMenu(row_number, existing_component);
157 }
158 return UpdateCommandMenu(row_number, command_select);
159 }
160 catch (const std::exception& e) {
161 rsj::ExceptionResponse(e, std::source_location::current());
162 throw;
163 }
164}
Definition CommandMenu.h:29
CommandMenu * UpdateCommandMenu(int row_number, gsl::not_null< CommandMenu * > command_select) const
Definition CommandTableModel.cpp:123
CommandMenu * CreateNewCommandMenu(int row_number, juce::Component *existing_component) const
Definition CommandTableModel.cpp:111

◆ RemoveRow()

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

◆ sortOrderChanged()

void CommandTableModel::sortOrderChanged ( int  new_sort_column_id,
bool  is_forwards 
)
overrideprivate
167{
168 try {
169 const auto current_sort {std::make_pair(new_sort_column_id, is_forwards)};
170 profile_.Resort(current_sort);
171 }
172 catch (const std::exception& e) {
173 rsj::ExceptionResponse(e, std::source_location::current());
174 throw;
175 }
176}
void Resort(std::pair< int, bool > new_order)
Definition Profile.cpp:203

◆ UpdateCommandMenu()

CommandMenu * CommandTableModel::UpdateCommandMenu ( int  row_number,
gsl::not_null< CommandMenu * >  command_select 
) const
private
125{
126 /* Updates the existing command menu */
127 const auto& msg = profile_.GetMessageForNumber(gsl::narrow_cast<size_t>(row_number));
128 command_select->SetMsg(msg);
129 command_select->SetSelectedItem(command_set_.CommandTextIndex(profile_.GetCommandForMessage(msg))
130 + 1);
131 return command_select;
132}

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: