From 5b867ebf99a9b7c6879c25475af2478296e033b1 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Wed, 15 Jan 2025 11:05:16 +0300 Subject: [PATCH 1/2] $mol_audio_instrument error status, fail safe, idempotency fix in active api --- audio/instrument/instrument.ts | 12 +++++++----- audio/room/room.ts | 20 +++++++++++++++++--- audio/sample/sample.ts | 4 ++-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/audio/instrument/instrument.ts b/audio/instrument/instrument.ts index 6b6064312e8..772c38eb93d 100644 --- a/audio/instrument/instrument.ts +++ b/audio/instrument/instrument.ts @@ -66,22 +66,24 @@ namespace $ { @ $mol_mem override active(next?: boolean) { + this.node() + const start_at = this.start_at() + this.stop_at() + if (next) { this.context().active(true) this.start_at(0) this.stop_at(-1) + return true } if (next === false) { this.start_at(-1) this.stop_at(0) + return false } - this.node() - this.start_at() - this.stop_at() - - return this.start_at() !== -1 + return start_at !== -1 } @ $mol_action diff --git a/audio/room/room.ts b/audio/room/room.ts index 1c37043fc01..b066656406f 100644 --- a/audio/room/room.ts +++ b/audio/room/room.ts @@ -1,6 +1,6 @@ namespace $ { - export type $mol_audio_room_status = AudioContextState | 'playing' + export type $mol_audio_room_status = AudioContextState | 'playing' | 'error' /** * @see https://mol.hyoo.ru/#!section=demos/demo=mol_audio_demo @@ -34,13 +34,27 @@ namespace $ { return new this.$.$mol_after_timeout(time * 1000, () => $mol_wire_async(this).active(false)) } + @ $mol_mem + error() { + try { + this.output() + } catch (e) { + if (! $mol_promise_like(e)) return { value: e as Error } + } + + return null + } @ $mol_mem status(next?: $mol_audio_room_status | null): $mol_audio_room_status { - const state = this.context().state(next === 'playing' ? 'running' : next) + if (next === 'playing') next = 'running' + if (next === 'error') next = 'closed' + + const state = this.context().state(next) + if (state === 'closed') return state - this.output() + if ( this.error() ) return 'error' if (this.inputs_active() && state === 'running') return 'playing' diff --git a/audio/sample/sample.ts b/audio/sample/sample.ts index 70e4b57cdd3..f637598b57a 100644 --- a/audio/sample/sample.ts +++ b/audio/sample/sample.ts @@ -56,7 +56,7 @@ namespace $ { @ $mol_mem override active(next?: boolean) { - + const prev = super.active(next) if (this.node_started()) { if (next) this.context().active(true) this.rate(next ? null : 0) @@ -64,7 +64,7 @@ namespace $ { return next ?? false } - return super.active(next) + return prev } @ $mol_mem From 2eb140ebec730e65a0336c36f82212919a989268 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Wed, 15 Jan 2025 11:31:56 +0300 Subject: [PATCH 2/2] $mol_audio_status error icon added --- audio/status/status.view.tree | 1 + 1 file changed, 1 insertion(+) diff --git a/audio/status/status.view.tree b/audio/status/status.view.tree index 357776f3df1..a94d698142d 100644 --- a/audio/status/status.view.tree +++ b/audio/status/status.view.tree @@ -1,6 +1,7 @@ $mol_audio_status $mol_view icons * closed <= Closed $mol_icon_power_sleep + error <= Error $mol_icon_alert suspended <= Suspended $mol_icon_sleep playing <= Playing $mol_icon_play running <= Running $mol_icon_pause