Musician Code Flashcards

(7 cards)

1
Q

What’s the basic strategy in getting accurate timing in JavaScript/NextJs?

A

Uses Web Audio API’s scheduling system
It uses a function that allows you to store (in seconds) exactly when you want something to play

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What do you read when you see ‘SCHEDULE_DEADLINE’

    while (NEXT_NOTE_TIME() < SCHEDULE_DEADLINE()) {
        scheduleNote(currentBeat, NEXT_NOTE_TIME());
        nextNote();
    }
A

The next 25 milliseconds

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain nextNote()

const scheduler = useCallback(() => {
    const audioContext = audioContextRef.current;
    if (!audioContext) return;

    while (NEXT_NOTE_TIME() < SCHEDULE_DEADLINE()) {
        scheduleNote(currentBeat, NEXT_NOTE_TIME());
        nextNote();
    }

    timerIdRef.current = setTimeout(scheduler, lookAhead);
}, [currentBeat]);
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Please explain the code of the flow

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Using the code logic.. Doesn’t it mean that the first note will always be skipped since the time we get to scheduleNote(), the time has already passed for NEXT_NOTE_TIME().. How come it’s still playing?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is % (Modulo)?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain this line of code

timerIdRef.current = setTimeout(scheduler, lookAhead);

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly