From 69f95ce235ced0be0089dd07ddd6e5ceccc8e5ee Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Thu, 23 Jan 2025 03:32:11 -0500 Subject: [PATCH] fix: Repeatedly attempt to connect to OLA. (#61) Connecting to OLA will now repeatedly attempt to connect until it succeeds. This will allow for OLA to connect in inconsistent startup scenarios. --- CHANGELOG.md | 5 +++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/dmx/universe.rs | 22 ++++++++++++++++++++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d387670..b48d39d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.1] - Repeatedly attempt to connect to OLA on startup. + +Repeatedly attempt to connect to OLA, which should make connecting to DMX on startup +more reliable. + ## [0.2.0] - Fix hard coded DMX universe. The DMX universe was inadvertently hard coded to OLA universe 1. This diff --git a/Cargo.lock b/Cargo.lock index 8022d90..a178815 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -733,7 +733,7 @@ dependencies = [ [[package]] name = "mtrack" -version = "0.2.0" +version = "0.2.1" dependencies = [ "clap", "cpal", diff --git a/Cargo.toml b/Cargo.toml index 51e8cbc..8f8a771 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "mtrack" description = "A multitrack audio and MIDI player for live performances." license = "GPL-3.0" -version = "0.2.0" +version = "0.2.1" authors = ["Michael Wilson "] edition = "2021" repository = "https://github.com/mdwn/mtrack" diff --git a/src/dmx/universe.rs b/src/dmx/universe.rs index 4b168a3..7f7389e 100644 --- a/src/dmx/universe.rs +++ b/src/dmx/universe.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use std::thread::{self, JoinHandle}; use std::time::Instant; use std::{sync::RwLock, time::Duration}; -use tracing::error; +use tracing::{error, warn}; use crate::playsync::CancelHandle; @@ -127,7 +127,25 @@ impl Universe { thread::spawn(move || { let mut last_time = Instant::now(); let tick_duration = Duration::from_secs(1).div_f64(TARGET_HZ); - let mut client = ola::connect().unwrap(); + let maybe_client; + + // Repeatedly attempt to connect to OLA. + loop { + if let Ok(ola_client) = ola::connect() { + maybe_client = Some(ola_client); + break; + }; + + warn!("Error connecting to OLA, waiting 5 seconds and trying again."); + thread::sleep(Duration::from_secs(5)); + } + let mut client = match maybe_client { + Some(client) => client, + None => { + error!("Unable to connect to OLA."); + return; + } + }; let mut buffer = DmxBuffer::new(); loop {