cleaning things up

This commit is contained in:
Jade Rowland
2023-10-01 19:19:49 -04:00
parent 1d85d60b11
commit 2127a8f642
2 changed files with 12 additions and 6 deletions
+8 -2
View File
@@ -27,6 +27,9 @@ export class CyclistBridge extends Cyclist {
if (this.started !== started && started != null) {
if (started) {
// the time delay in ms that seems to occur when starting the clock. Unsure if this is standard across all clients
const evaluationTime = 140;
// when start message comes from abelink, delay starting cyclist clock until the start of the next abelink phase
this.start_timer = window.setTimeout(() => {
// TODO: evaluate the code so if another source triggers the play there will not be an error
@@ -34,7 +37,7 @@ export class CyclistBridge extends Cyclist {
logger('[cyclist] start');
this.clock.start();
this.setStarted(true);
}, timestamp - Date.now());
}, timestamp - Date.now() - evaluationTime);
} else {
this.stop();
}
@@ -46,6 +49,7 @@ export class CyclistBridge extends Cyclist {
if (!this.pattern) {
throw new Error('Scheduler: no pattern set! call .setPattern first.');
}
let x = Date.now();
const linkmsg = {
// TODO: change this to value of "main" clock cps
cps: 0.5,
@@ -53,7 +57,9 @@ export class CyclistBridge extends Cyclist {
timestamp: Date.now(),
phase: this.clock.getPhase(),
};
Invoke('sendabelinkmsg', { linkmsg });
Invoke('sendabelinkmsg', { linkmsg }).then(() => {
logger(`${Date.now() - x}`);
});
}
stop() {
+4 -4
View File
@@ -62,7 +62,7 @@ impl AbeLinkState {
let internal_time_at_next_phase = self.session_state.time_at_beat(beat + (quantum - phase), quantum);
let time_offset = Duration::from_micros((internal_time_at_next_phase - link_time_stamp) as u64);
let current_unix_time = current_unix_time();
let unix_time_at_next_phase = (current_unix_time + time_offset).as_millis() - 140;
let unix_time_at_next_phase = (current_unix_time + time_offset).as_millis();
return unix_time_at_next_phase as u64;
}
@@ -117,7 +117,7 @@ impl AbeLinkState {
pub fn init(_logger: Logger, abelink: Arc<Mutex<AbeLinkState>>) {
tauri::async_runtime::spawn(async move {
let mut prev_is_started = false;
let mut prev_cps = 0.5;
let mut prev_cps = 0.0;
let mut time_since_last_phase_send = 0;
let sleep_time = 10;
@@ -126,6 +126,7 @@ pub fn init(_logger: Logger, abelink: Arc<Mutex<AbeLinkState>>) {
........................................................................*/
loop {
let mut state = abelink.lock().await;
state.capture_app_state();
if state.link.is_enabled() == false {
state.link.enable(true);
state.link.enable_start_stop_sync(true);
@@ -133,8 +134,6 @@ pub fn init(_logger: Logger, abelink: Arc<Mutex<AbeLinkState>>) {
let started = state.session_state.is_playing();
state.capture_app_state();
if started != prev_is_started {
state.send_started();
prev_is_started = started;
@@ -158,6 +157,7 @@ pub fn init(_logger: Logger, abelink: Arc<Mutex<AbeLinkState>>) {
#[tauri::command]
pub async fn sendabelinkmsg(linkmsg: LinkMsg, state: tauri::State<'_, AbeLinkStateContainer>) -> Result<(), String> {
let mut abelink = state.abelink.lock().await;
abelink.capture_app_state();
let started = abelink.session_state.is_playing();
let time_stamp = abelink.link.clock_micros();
let quantum = abelink.quantum;