Compare commits
No commits in common. "254dbaf2fd03244882d1778cbd7b065ce5b4d56e" and "3a409dfe1e137a121e5a02dbd01af5c81b261c41" have entirely different histories.
254dbaf2fd
...
3a409dfe1e
4 changed files with 16 additions and 23 deletions
|
|
@ -40,23 +40,21 @@ export const TrafficLight = memo(function TrafficLight({state, speed, raiseUIEve
|
|||
|
||||
// preloadAudio(sndAtmosphere);
|
||||
|
||||
// play wind
|
||||
// the traffic light makes sound too:
|
||||
useEffect(() => {
|
||||
const stopPlaying = playURL(sndAtmosphere, true);
|
||||
return () => stopPlaying();
|
||||
}, []);
|
||||
|
||||
// for added realism, every light color has its own buzzing noise volume
|
||||
for (const [color, gain] of [[redOn, 0.5], [yellowOn, 1], [greenOn, 0.3]] as [boolean, number][]) {
|
||||
useEffect(() => {
|
||||
if (color) {
|
||||
const stopPlaying = playURL(sndBuzz, true, gain);
|
||||
return () => {
|
||||
stopPlaying();
|
||||
};
|
||||
}
|
||||
}, [color]);
|
||||
}
|
||||
useEffect(() => {
|
||||
if (redOn || yellowOn || greenOn) {
|
||||
const stopPlaying = playURL(sndBuzz, true);
|
||||
return () => {
|
||||
stopPlaying();
|
||||
};
|
||||
}
|
||||
else return () => {};
|
||||
}, [redOn || yellowOn || greenOn])
|
||||
|
||||
return <>
|
||||
<style>{`
|
||||
|
|
|
|||
|
|
@ -28,15 +28,12 @@ export function useAudioContext(speed: number) {
|
|||
.then(buf => ref.current!.ctx.decodeAudioData(buf));
|
||||
}), [ref.current]);
|
||||
|
||||
function play(url: string, loop: boolean, gain: number = 1) {
|
||||
function play(url: string, loop: boolean) {
|
||||
const srcPromise = url2AudioBuf(url)
|
||||
.then(audioBuf => {
|
||||
const src = ref.current!.ctx.createBufferSource();
|
||||
const gainNode = ref.current!.ctx.createGain();
|
||||
gainNode.gain.value = gain;
|
||||
gainNode.connect(ref.current!.hipass);
|
||||
src.buffer = audioBuf;
|
||||
src.connect(gainNode);
|
||||
src.connect(ref.current!.hipass);
|
||||
src.playbackRate.value = speed;
|
||||
src.loop = loop;
|
||||
src.start();
|
||||
|
|
@ -62,5 +59,5 @@ export function useAudioContext(speed: number) {
|
|||
}
|
||||
}, [speed]);
|
||||
|
||||
return [play, url2AudioBuf] as [(url: string, loop: boolean, gain?: number) => ()=>void, (url:string)=>void];
|
||||
return [play, url2AudioBuf] as [(url: string, loop: boolean) => ()=>void, (url:string)=>void];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -394,6 +394,7 @@ export function fire(simtime: number, t: Transition, ts: Map<string, Transition[
|
|||
// transition actions
|
||||
environment = addEventParam(environment.enterScope("<transition>"), label);
|
||||
for (const action of label.actions) {
|
||||
console.log('environment after adding event param:', environment);
|
||||
({environment, history, ...rest} = execAction(action, {environment, history, ...rest}, [t.uid]));
|
||||
}
|
||||
environment = environment.dropScope();
|
||||
|
|
|
|||
|
|
@ -115,7 +115,6 @@ export function coupledExecution<T extends {[name: string]: any}>(models: {[name
|
|||
if (events.length > 0) {
|
||||
const [event, ...rest] = events;
|
||||
const destination = conns[model+'.'+event.name];
|
||||
console.log(model, '.', event, destination);
|
||||
if (destination === undefined) {
|
||||
// ignore
|
||||
console.log(`${model}.${event.name} goes nowhere`);
|
||||
|
|
@ -161,13 +160,11 @@ export function coupledExecution<T extends {[name: string]: any}>(models: {[name
|
|||
// @ts-ignore
|
||||
state[modelName] = modelState;
|
||||
}
|
||||
console.log('all outputs:', allOutputs);
|
||||
// 2. handle all output events (models' outputs may be inputs for each other)
|
||||
let finalOutputs = [];
|
||||
for (const [modelName, outputEvent] of allOutputs) {
|
||||
console.log('what about', modelName, outputEvent);
|
||||
for (const [modelName, outputEvents] of allOutputs) {
|
||||
let newOutputs;
|
||||
[newOutputs, state] = processOutputs(0, [outputEvent], modelName, state);
|
||||
[newOutputs, state] = processOutputs(0, outputEvents, modelName, state);
|
||||
finalOutputs.push(...newOutputs);
|
||||
}
|
||||
return [finalOutputs, state];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue