Skip to content

Commit

Permalink
fix: Repeatedly attempt to connect to OLA. (#61)
Browse files Browse the repository at this point in the history
Connecting to OLA will now repeatedly attempt to connect until it
succeeds. This will allow for OLA to connect in inconsistent startup
scenarios.
  • Loading branch information
mdwn authored Jan 23, 2025
1 parent a37f2e7 commit 69f95ce
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mike@mdwn.dev>"]
edition = "2021"
repository = "https://github.com/mdwn/mtrack"
Expand Down
22 changes: 20 additions & 2 deletions src/dmx/universe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 69f95ce

Please sign in to comment.