begin webaudio package
This commit is contained in:
parent
fb52227a92
commit
47a046ca1d
3 changed files with 167 additions and 0 deletions
28
packages/webaudio/scheduler.mjs
Normal file
28
packages/webaudio/scheduler.mjs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
class Scheduler {
|
||||
metro;
|
||||
constructor(interval = 0.2, lookahead = 0.2) {
|
||||
this.metro = new Metro(
|
||||
audioContext,
|
||||
(begin, end, lookahead) => {
|
||||
pattern.query(new State(new TimeSpan(begin - lookahead, end - lookahead))).forEach((e) => {
|
||||
if (!e.part.begin.equals(e.whole.begin)) {
|
||||
return;
|
||||
}
|
||||
if (e.context.createAudioNode) {
|
||||
e.context.createAudioNode(e);
|
||||
} else {
|
||||
console.warn('unplayable event: no audio node');
|
||||
}
|
||||
});
|
||||
},
|
||||
interval,
|
||||
lookahead,
|
||||
);
|
||||
}
|
||||
start() {
|
||||
this.metro.start();
|
||||
}
|
||||
stop() {
|
||||
this.metro.stop();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue