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

Public Member Functions

 LrIpcInShared (asio::io_context &io_context)
 LrIpcInShared (asio::io_context &io_context)

Static Private Member Functions

static void Read (std::shared_ptr< LrIpcInShared > lr_ipc_shared)
static void Read (std::shared_ptr< LrIpcInShared > lr_ipc_shared)

Private Attributes

rsj::ConcurrentQueue< std::string > line_
friend LrIpcIn
std::shared_ptr< std::atomic< bool > > owner_alive_ {std::make_shared<std::atomic<bool>>(true)}
asio::ip::tcp::socket socket_
asio::streambuf streambuf_ {}
std::atomic< bool > thread_should_exit_ {false}

Constructor & Destructor Documentation

◆ LrIpcInShared() [1/2]

LrIpcInShared::LrIpcInShared ( asio::io_context & io_context)
inlineexplicit
66: socket_ {asio::make_strand(io_context)} {}
asio::ip::tcp::socket socket_
Definition LR_IPC_In.cpp:55

◆ LrIpcInShared() [2/2]

LrIpcInShared::LrIpcInShared ( asio::io_context & io_context)
inlineexplicit
66: socket_ {asio::make_strand(io_context)} {}

Member Function Documentation

◆ Read() [1/2]

void LrIpcInShared::Read ( std::shared_ptr< LrIpcInShared > lr_ipc_shared)
staticprivate
290{
291 using namespace std::string_literals;
292 try {
293 // if owner signalled stop or thread should exit, don't start a new async read
294 if (!lr_ipc_shared->owner_alive_->load(std::memory_order_acquire)
295 || lr_ipc_shared->thread_should_exit_.load(std::memory_order_acquire)) {
296 return;
297 }
298
299 asio::async_read_until(lr_ipc_shared->socket_, lr_ipc_shared->streambuf_, '\n',
300 [lr_ipc_shared, alive = lr_ipc_shared->owner_alive_](const asio::error_code& error,
301 const std::size_t bytes_transferred) mutable {
302 // if owner signalled Stop(), bail out early
303 if (!alive || !alive->load(std::memory_order_acquire)) { return; }
304
305 if (!error) [[likely]] {
306 if (bytes_transferred == 0) [[unlikely]] { std::this_thread::sleep_for(kEmptyWait); }
307 else {
308 auto& buf {lr_ipc_shared->streambuf_};
309 std::string command {buffers_begin(buf.data()),
310 buffers_begin(buf.data()) + gsl::narrow<std::ptrdiff_t>(bytes_transferred)};
311 if (command == "TerminateApplication 1\n"s) {
312 lr_ipc_shared->thread_should_exit_.store(true, std::memory_order_release);
313 }
314 lr_ipc_shared->line_.push(std::move(command));
315 buf.consume(bytes_transferred);
316 }
317 // before recursively re-arming, make sure owner still alive
318 if (alive && alive->load(std::memory_order_acquire)) { Read(std::move(lr_ipc_shared)); }
319 }
320 else {
321 rsj::Log(fmt::format("LR_IPC_In Read error: {}.", error.message()),
322 std::source_location::current());
323
324 if (error == asio::error::misc_errors::eof) {
325 if (auto* app = juce::JUCEApplication::getInstance()) { app->systemRequestedQuit(); }
326 }
327 }
328 });
329 }
330 catch (const std::exception& e) {
331 rsj::ExceptionResponse(e, std::source_location::current());
332 throw;
333 }
334}
rsj::ConcurrentQueue< std::string > line_
Definition LR_IPC_In.cpp:57
asio::streambuf streambuf_
Definition LR_IPC_In.cpp:56
std::shared_ptr< std::atomic< bool > > owner_alive_
Definition LR_IPC_In.cpp:62
static void Read(std::shared_ptr< LrIpcInShared > lr_ipc_shared)
Definition LR_IPC_In.cpp:289
std::atomic< bool > thread_should_exit_
Definition LR_IPC_In.cpp:58
void push(const T &value)
Definition Concurrency.h:162
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:112

◆ Read() [2/2]

void LrIpcInShared::Read ( std::shared_ptr< LrIpcInShared > lr_ipc_shared)
staticprivate

Member Data Documentation

◆ line_

rsj::ConcurrentQueue< std::string > LrIpcInShared::line_
private

◆ LrIpcIn

LrIpcIn
private

◆ owner_alive_

std::shared_ptr< std::atomic< bool > > LrIpcInShared::owner_alive_ {std::make_shared<std::atomic<bool>>(true)}
private
62{std::make_shared<std::atomic<bool>>(true)};

◆ socket_

asio::ip::tcp::socket LrIpcInShared::socket_
private

◆ streambuf_

asio::streambuf LrIpcInShared::streambuf_ {}
private
56{};

◆ thread_should_exit_

std::atomic< bool > LrIpcInShared::thread_should_exit_ {false}
private
58{false};

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