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
Devices Class Reference

#include <Devices.h>

Classes

struct  DevInfo
 

Public Member Functions

 Devices ()
 
 Devices (const Devices &other)=delete
 
 Devices (Devices &&other) noexcept=default
 
 ~Devices ()
 
bool Add (const juce::MidiDeviceInfo &info, const juce::String &io)
 
bool Enabled (const juce::MidiDeviceInfo &info, juce::String io) const
 
bool EnabledOrNew (const juce::MidiDeviceInfo &info, const juce::String &io)
 
Devicesoperator= (const Devices &other)=delete
 
Devicesoperator= (Devices &&other) noexcept=default
 

Private Member Functions

void CreateDefaultDeviceXml ()
 
void LoadDeviceXml ()
 
void ProcessDataList ()
 

Private Attributes

juce::XmlElement * column_list_ {nullptr}
 
juce::XmlElement * data_list_ {nullptr}
 
std::map< DevInfo, bool > device_listing_
 
std::unique_ptr< juce::XmlElement > device_xml_
 
int num_rows_ {0}
 

Constructor & Destructor Documentation

◆ Devices() [1/3]

Devices::Devices ( )
94{
98}
void LoadDeviceXml()
Definition Devices.cpp:40
void ProcessDataList()
Definition Devices.cpp:74
void CreateDefaultDeviceXml()
Definition Devices.cpp:59
std::unique_ptr< juce::XmlElement > device_xml_
Definition Devices.h:107

◆ ~Devices()

Devices::~Devices ( )
101{
102 try {
103 /* open file with xml list of devices */
104 const auto source {GetSource(MIDI2LR_UC_LITERAL("Controllers.xml"))};
105 // ReSharper disable once CppExpressionWithoutSideEffects
106 device_xml_->writeTo(source);
107 }
108 catch (const std::exception& e) {
110 }
111 catch (...) {
112 rsj::LogAndAlertError("Non-standard exception in ~Devices.");
113 }
114}
void ExceptionResponse(gsl::czstring id, gsl::czstring fu, const std::exception &e) noexcept
void LogAndAlertError(const juce::String &error_text, const std::source_location &location=std::source_location::current()) noexcept
Definition Misc.cpp:160

◆ Devices() [2/3]

Devices::Devices ( const Devices other)
delete

◆ Devices() [3/3]

Devices::Devices ( Devices &&  other)
defaultnoexcept

Member Function Documentation

◆ Add()

bool Devices::Add ( const juce::MidiDeviceInfo &  info,
const juce::String &  io 
)
117{
118 try {
119 const auto [it, success] {device_listing_.try_emplace({info, io}, true)};
120 if (success) {
121 if (const auto new_element {data_list_->createNewChildElement("item")}) {
122 new_element->setAttribute("devicename", info.name);
123 new_element->setAttribute("systemid", info.identifier);
124 new_element->setAttribute("inputoutput", io);
125 new_element->setAttribute("active", "1");
126 }
127 else {
128 rsj::Log("Failed to create new element in Devices::Add");
129 }
130 }
131 return success;
132 }
133 catch (const std::exception& e) {
135 throw;
136 }
137}
juce::XmlElement * data_list_
Definition Devices.h:109
std::map< DevInfo, bool > device_listing_
Definition Devices.h:106
void Log(const juce::String &info, const std::source_location &location=std::source_location::current()) noexcept
Definition Misc.cpp:131

◆ CreateDefaultDeviceXml()

void Devices::CreateDefaultDeviceXml ( )
private
60{
61 device_xml_ = juce::parseXML(R"===(<?xml version="1.0" encoding="UTF-8"?>
62 <table_data>
63 <heading>
64 <column columnId="1" name="devicename" label="device name" width="200"/>
65 <column columnId="2" name="systemid" label="system id" width="200"/>
66 <column columnId="3" name="inputoutput" label="input/output" width="50"/>
67 <column columnId="9" name="active" label="active" width="50"/>
68 </heading>
69 <data>
70 </data>
71 </table_data>)===");
72}

◆ Enabled()

bool Devices::Enabled ( const juce::MidiDeviceInfo &  info,
juce::String  io 
) const
140{
141 try {
142 const auto it {device_listing_.find({info, std::move(io)})};
143 if (it == device_listing_.end()) { return true; }
144 return it->second;
145 }
146 catch (const std::exception& e) {
148 throw;
149 }
150}

◆ EnabledOrNew()

bool Devices::EnabledOrNew ( const juce::MidiDeviceInfo &  info,
const juce::String &  io 
)
153{
154 try {
155 if (Add(info, io)) { return true; }
156 return Enabled(info, io);
157 }
158 catch (const std::exception& e) {
160 throw;
161 }
162}
bool Add(const juce::MidiDeviceInfo &info, const juce::String &io)
Definition Devices.cpp:116
bool Enabled(const juce::MidiDeviceInfo &info, juce::String io) const
Definition Devices.cpp:139

◆ LoadDeviceXml()

void Devices::LoadDeviceXml ( )
private
41{
42 try {
43 auto deviceXmlSource {GetSource(MIDI2LR_UC_LITERAL("Controllers.xml"))};
44 if (deviceXmlSource.existsAsFile()) { device_xml_ = juce::parseXML(deviceXmlSource); }
45 else {
46 deviceXmlSource = GetSource(MIDI2LR_UC_LITERAL("DisabledControllers.xml"));
47 if (deviceXmlSource.existsAsFile()) {
48 device_xml_ = juce::parseXML(deviceXmlSource);
49 std::ignore = deviceXmlSource.deleteFile(); // don't want to use name again
50 }
51 }
52 }
53 catch (const std::exception& e) {
55 device_xml_.reset();
56 }
57}

◆ operator=() [1/2]

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

◆ operator=() [2/2]

Devices & Devices::operator= ( Devices &&  other)
defaultnoexcept

◆ ProcessDataList()

void Devices::ProcessDataList ( )
private
75{
76 column_list_ = device_xml_->getChildByName("heading");
77 data_list_ = device_xml_->getChildByName("data");
78 if (data_list_) {
79 num_rows_ = data_list_->getNumChildElements();
80 for (const gsl::not_null<const juce::XmlElement*> dataElement :
81 data_list_->getChildIterator()) {
82 device_listing_.emplace(DevInfo {dataElement->getStringAttribute("devicename"),
83 dataElement->getStringAttribute("systemid"),
84 dataElement->getStringAttribute("inputoutput")},
85 dataElement->getIntAttribute("active"));
86 }
87 }
88 else {
89 data_list_ = device_xml_->createNewChildElement("data");
90 }
91}
int num_rows_
Definition Devices.h:110
juce::XmlElement * column_list_
Definition Devices.h:108

Member Data Documentation

◆ column_list_

juce::XmlElement* Devices::column_list_ {nullptr}
private
108{nullptr};

◆ data_list_

juce::XmlElement* Devices::data_list_ {nullptr}
private
109{nullptr};

◆ device_listing_

std::map<DevInfo, bool> Devices::device_listing_
private

◆ device_xml_

std::unique_ptr<juce::XmlElement> Devices::device_xml_
private

◆ num_rows_

int Devices::num_rows_ {0}
private
110{0};

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