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

#include <ProfileManager.h>

+ Inheritance diagram for ProfileManager:

Public Member Functions

 ProfileManager (const ProfileManager &other)=delete
 
 ProfileManager (ControlsModel &c_model, const Profile &profile, LrIpcOut &out, MidiReceiver &midi_receiver)
 
 ProfileManager (ProfileManager &&other)=delete
 
 ~ProfileManager ()=default
 
template<class T >
void AddCallback (_In_ T *const object, _In_ void(T::*const mf)(juce::XmlElement *, const juce::String &))
 
const juce::String & GetProfileDirectory () const noexcept
 
ProfileManageroperator= (const ProfileManager &other)=delete
 
ProfileManageroperator= (ProfileManager &&other)=delete
 
void SetProfileDirectory (const juce::File &directory)
 
void SwitchToProfile (const juce::String &profile)
 
void SwitchToProfile (int profile_index)
 

Private Types

enum class  SwitchState { kNone , kPrev , kNext }
 

Private Member Functions

void ConnectionCallback (bool, bool)
 
void handleAsyncUpdate () override
 
void MapCommand (rsj::MidiMessageId msg)
 
void MidiCmdCallback (rsj::MidiMessage mm)
 
void SwitchToNextProfile ()
 
void SwitchToPreviousProfile ()
 

Private Attributes

std::vector< std::function< void(juce::XmlElement *, const juce::String &)> > callbacks_
 
ControlsModelcontrols_model_
 
const Profilecurrent_profile_
 
int current_profile_index_ {0}
 
LrIpcOutlr_ipc_out_
 
juce::File profile_location_
 
std::vector< juce::String > profiles_
 
SwitchState switch_state_ {SwitchState::kNone}
 

Member Enumeration Documentation

◆ SwitchState

enum class ProfileManager::SwitchState
strongprivate
Enumerator
kNone 
kPrev 
kNext 

Constructor & Destructor Documentation

◆ ProfileManager() [1/3]

ProfileManager::ProfileManager ( ControlsModel c_model,
const Profile profile,
LrIpcOut out,
MidiReceiver midi_receiver 
)
34 : current_profile_ {profile}, controls_model_ {c_model}, lr_ipc_out_ {out}
35{
36 /* add ourselves as a listener to LR_IPC_OUT so that we can send plugin settings on connection */
37 midi_receiver.AddCallback(this, &ProfileManager::MidiCmdCallback);
39}
void AddCallback(_In_ T *const object, _In_ void(T::*const mf)(bool, bool))
Definition LR_IPC_Out.h:51
void AddCallback(_In_ T *const object, _In_ void(T::*const mf)(rsj::MidiMessage))
Definition MIDIReceiver.h:49
ControlsModel & controls_model_
Definition ProfileManager.h:79
LrIpcOut & lr_ipc_out_
Definition ProfileManager.h:82
const Profile & current_profile_
Definition ProfileManager.h:78
void MidiCmdCallback(rsj::MidiMessage mm)
Definition ProfileManager.cpp:141
void ConnectionCallback(bool, bool)
Definition ProfileManager.cpp:160

◆ ~ProfileManager()

ProfileManager::~ProfileManager ( )
default

◆ ProfileManager() [2/3]

ProfileManager::ProfileManager ( const ProfileManager other)
delete

◆ ProfileManager() [3/3]

ProfileManager::ProfileManager ( ProfileManager &&  other)
delete

Member Function Documentation

◆ AddCallback()

template<class T >
void ProfileManager::AddCallback ( _In_ T *const  object,
_In_ void(T::*)(juce::XmlElement *, const juce::String &)  mf 
)
inline
51 {
52 if (object && mf) { callbacks_.emplace_back(std::bind_front(mf, object)); }
53 }
std::vector< std::function< void(juce::XmlElement *, const juce::String &)> > callbacks_
Definition ProfileManager.h:84

◆ ConnectionCallback()

void ProfileManager::ConnectionCallback ( bool  connected,
bool  blocked 
)
private
161{
162 try {
163 if (connected && !blocked) {
164 lr_ipc_out_.SendCommand(fmt::format(FMT_STRING("ChangedToDirectory {}\n"),
165 juce::File::addTrailingSeparator(profile_location_.getFullPathName()).toStdString()));
166 }
167 }
168 catch (const std::exception& e) {
170 throw;
171 }
172}
void SendCommand(std::string &&command) const
Definition LR_IPC_Out.cpp:67
juce::File profile_location_
Definition ProfileManager.h:81
void ExceptionResponse(gsl::czstring id, gsl::czstring fu, const std::exception &e) noexcept

◆ GetProfileDirectory()

const juce::String & ProfileManager::GetProfileDirectory ( ) const
inlinenoexcept
56 {
57 return profile_location_.getFullPathName();
58 }

◆ handleAsyncUpdate()

void ProfileManager::handleAsyncUpdate ( )
overrideprivate
175{
176 try {
177 switch (switch_state_) {
181 break;
185 break;
187 break;
188 }
189 }
190 catch (const std::exception& e) {
192 throw;
193 }
194}
void SwitchToNextProfile()
Definition ProfileManager.cpp:93
SwitchState switch_state_
Definition ProfileManager.h:85
void SwitchToPreviousProfile()
Definition ProfileManager.cpp:106

◆ MapCommand()

void ProfileManager::MapCommand ( rsj::MidiMessageId  msg)
private
120{
121 try {
122 using namespace std::string_literals;
123 const auto cmd {current_profile_.GetCommandForMessage(msg)};
124 if (cmd == "PrevPro"s) {
126 triggerAsyncUpdate();
127 }
128 else if (cmd == "NextPro"s) {
130 triggerAsyncUpdate();
131 }
132 else { /* no action needed */
133 }
134 }
135 catch (const std::exception& e) {
137 throw;
138 }
139}
const std::string & GetCommandForMessage(rsj::MidiMessageId message) const
Definition Profile.h:89

◆ MidiCmdCallback()

void ProfileManager::MidiCmdCallback ( rsj::MidiMessage  mm)
private
142{
143 try {
144 const rsj::MidiMessageId cc {mm};
145 /* return if the value isn't high enough (notes may be < 1), or the command isn't a valid
146 * profile-related command */
147 if (controls_model_.ControllerToPlugin(mm, false) < 0.4
149 return;
150 }
151 MapCommand(cc);
152 }
153 catch (const std::exception& e) {
155 throw;
156 }
157}
double ControllerToPlugin(rsj::MidiMessage mm, bool wrap)
Definition ControlsModel.h:225
bool MessageExistsInMap(rsj::MidiMessageId message) const
Definition Profile.h:124
void MapCommand(rsj::MidiMessageId msg)
Definition ProfileManager.cpp:119
Definition MidiUtilities.h:145

◆ operator=() [1/2]

ProfileManager & ProfileManager::operator= ( const ProfileManager other)
delete

◆ operator=() [2/2]

ProfileManager & ProfileManager::operator= ( ProfileManager &&  other)
delete

◆ SetProfileDirectory()

void ProfileManager::SetProfileDirectory ( const juce::File &  directory)
42{
43 try {
44 profile_location_ = directory;
45 auto file_array {directory.findChildFiles(juce::File::findFiles, false, "*.xml")};
46 file_array.sort();
47 profiles_.resize(file_array.size());
48 std::ranges::transform(file_array, profiles_.begin(),
49 [](const auto& file) { return file.getFileName(); });
50 }
51 catch (const std::exception& e) {
53 throw;
54 }
55}
std::vector< juce::String > profiles_
Definition ProfileManager.h:83

◆ SwitchToNextProfile()

void ProfileManager::SwitchToNextProfile ( )
private
94{
95 try {
96 const auto profiles_size {gsl::narrow_cast<int>(profiles_.size())};
97 current_profile_index_ = (current_profile_index_ + 1) % profiles_size;
99 }
100 catch (const std::exception& e) {
102 throw;
103 }
104}
void SwitchToProfile(int profile_index)
Definition ProfileManager.cpp:57
int current_profile_index_
Definition ProfileManager.h:80

◆ SwitchToPreviousProfile()

void ProfileManager::SwitchToPreviousProfile ( )
private
107{
108 try {
109 const auto profiles_size {gsl::narrow_cast<int>(profiles_.size())};
110 current_profile_index_ = (current_profile_index_ + profiles_size - 1) % profiles_size;
112 }
113 catch (const std::exception& e) {
115 throw;
116 }
117}

◆ SwitchToProfile() [1/2]

void ProfileManager::SwitchToProfile ( const juce::String &  profile)
73{
74 try {
75 const auto profile_file {profile_location_.getChildFile(profile)};
76 if (profile_file.exists()) {
77 if (const auto parsed {juce::parseXML(profile_file)}) {
78 for (const auto& cb : callbacks_) { cb(parsed.get(), profile); }
79 lr_ipc_out_.SendCommand(fmt::format(FMT_STRING("ChangedToDirectory {}\n"),
80 juce::File::addTrailingSeparator(profile_location_.getFullPathName())
81 .toStdString()));
82 lr_ipc_out_.SendCommand(fmt::format(FMT_STRING("ChangedToFile {}\n"),
83 profile.toStdString()));
84 }
85 }
86 }
87 catch (const std::exception& e) {
89 throw;
90 }
91}

◆ SwitchToProfile() [2/2]

void ProfileManager::SwitchToProfile ( int  profile_index)
58{
59 try {
60 if (profile_index >= 0 && std::cmp_less(profile_index, profiles_.size())) {
61 SwitchToProfile(profiles_.at(gsl::narrow_cast<size_t>(profile_index)));
62 current_profile_index_ = profile_index;
63 }
64 }
65 catch (const std::exception& e) {
67 throw;
68 }
69}

Member Data Documentation

◆ callbacks_

std::vector<std::function<void(juce::XmlElement*, const juce::String&)> > ProfileManager::callbacks_
private

◆ controls_model_

ControlsModel& ProfileManager::controls_model_
private

◆ current_profile_

const Profile& ProfileManager::current_profile_
private

◆ current_profile_index_

int ProfileManager::current_profile_index_ {0}
private
80{0};

◆ lr_ipc_out_

LrIpcOut& ProfileManager::lr_ipc_out_
private

◆ profile_location_

juce::File ProfileManager::profile_location_
private

◆ profiles_

std::vector<juce::String> ProfileManager::profiles_
private

◆ switch_state_

SwitchState ProfileManager::switch_state_ {SwitchState::kNone}
private

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