From af0de3d3a53a73492b223fbc6b92caa25b400224 Mon Sep 17 00:00:00 2001 From: Sergey Yuferev Date: Fri, 29 Dec 2023 21:26:37 +0300 Subject: [PATCH] $mol_audio_room duration moved to $mol_audio_node --- audio/instrument/instrument.ts | 8 ++------ audio/node/node.ts | 9 +++++++++ audio/room/room.ts | 13 ------------- audio/vibe/vibe.ts | 4 ++++ 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/audio/instrument/instrument.ts b/audio/instrument/instrument.ts index 2bb7a6fab36..621fd7c6160 100644 --- a/audio/instrument/instrument.ts +++ b/audio/instrument/instrument.ts @@ -7,15 +7,11 @@ namespace $ { @ $mol_mem override node() { const node = super.node() - node.onended = $mol_wire_async(() => this.end()) + node.onended = $mol_wire_async((e: Event) => this.end(e)) return node } - duration() { - return 1 - } - protected promise = $mol_promise() @ $mol_mem @@ -23,7 +19,7 @@ namespace $ { return this.promise } - end() { + end(e: Event) { this.active( false ) } diff --git a/audio/node/node.ts b/audio/node/node.ts index 5177ca1d2b9..9ad6e3de567 100644 --- a/audio/node/node.ts +++ b/audio/node/node.ts @@ -9,6 +9,15 @@ namespace $ { return this.node_raw() as ReturnType } + @ $mol_mem + duration() { + let duration = 0 + for (const input of this.input_connected()) duration = Math.max(duration, input.duration()) + + return duration + } + + @ $mol_mem input( next = [] as readonly $mol_audio_node[] ) { return next } diff --git a/audio/room/room.ts b/audio/room/room.ts index 5cc3c2819e5..4684f6ece70 100644 --- a/audio/room/room.ts +++ b/audio/room/room.ts @@ -5,19 +5,6 @@ namespace $ { */ export class $mol_audio_room extends $mol_audio_node { - duration_default() { - return .5 - } - - @ $mol_mem - duration() { - let duration = 0 - for (const input of this.input_connected()) { - if (input instanceof $mol_audio_instrument) duration += input.duration() - } - return duration || this.duration_default() - } - @ $mol_action play() { this.output() diff --git a/audio/vibe/vibe.ts b/audio/vibe/vibe.ts index 65d1f870cda..e7ac418568f 100644 --- a/audio/vibe/vibe.ts +++ b/audio/vibe/vibe.ts @@ -21,6 +21,10 @@ namespace $ { @ $mol_mem shape( next: $mol_audio_vibe_shape = 'sine' ) { return next } + override duration() { + return 0.5 + } + @ $mol_mem override node() { const node = super.node()