Skip to content

Commit

Permalink
$mol_audio_room duration moved to $mol_audio_node
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Dec 29, 2023
1 parent 25aad23 commit af0de3d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
8 changes: 2 additions & 6 deletions audio/instrument/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,19 @@ 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<void>()

@ $mol_mem
wait() {
return this.promise
}

end() {
end(e: Event) {
this.active( false )
}

Expand Down
9 changes: 9 additions & 0 deletions audio/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ namespace $ {
return this.node_raw() as ReturnType<this['node_raw']>
}

@ $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 }

Expand Down
13 changes: 0 additions & 13 deletions audio/room/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions audio/vibe/vibe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit af0de3d

Please sign in to comment.