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
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, 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:50
Profile & profile_
Definition CommandTableModel.h:51

Member Function Documentation

◆ CreateNewCommandMenu()

CommandMenu * CommandTableModel::CreateNewCommandMenu ( int  row_number,
juce::Component *  existing_component 
) const
private
112{
113 /* create a new command menu, delete old one if it exists */
114 delete existing_component; // NOLINT(cppcoreguidelines-owning-memory)
115 const auto& msg = profile_.GetMessageForNumber(gsl::narrow_cast<size_t>(row_number));
116 auto new_select {std::make_unique<CommandMenu>(msg, command_set_, profile_)};
117 new_select->SetSelectedItem(command_set_.CommandTextIndex(profile_.GetCommandForMessage(msg))
118 + 1);
119 return new_select.release();
120}
size_t CommandTextIndex(const std::string &command) const
Definition CommandSet.cpp:101
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 "
80 "in profile, row number to be painted is {}."),
81 profile_size, row_number));
82 return;
83 }
84 const auto cmd {profile_.GetMessageForNumber(gsl::narrow_cast<size_t>(row_number))};
85 const auto messageText {FormatMessageText(cmd)};
86 g.drawText(messageText, 0, 0, width, height, juce::Justification::centredLeft);
87 }
88 catch (const std::exception& e) {
90 throw;
91 }
92}
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:131

◆ paintRowBackground()

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

◆ refreshComponentForCell()

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

◆ 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:174

◆ 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) {
172 throw;
173 }
174}
void Resort(std::pair< int, bool > new_order)
Definition Profile.cpp:202

◆ UpdateCommandMenu()

CommandMenu * CommandTableModel::UpdateCommandMenu ( int  row_number,
CommandMenu command_select 
) const
private
123{
124 /* Updates the existing command menu */
125 const auto& msg = profile_.GetMessageForNumber(gsl::narrow_cast<size_t>(row_number));
126 command_select->SetMsg(msg);
128 + 1);
129 return command_select;
130}
void SetSelectedItem(size_t index)
Definition CommandMenu.h:36
void SetMsg(rsj::MidiMessageId message) noexcept
Definition CommandMenu.h:34

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: