More clean up
This commit is contained in:
parent
c94ffcc506
commit
f03da42b5e
43 changed files with 818 additions and 1076 deletions
|
|
@ -4,7 +4,7 @@ export const DISABLED_FLAG_VALUE = '0';
|
|||
export const UNIT_INTERVAL_INPUT_MIN = '0';
|
||||
export const UNIT_INTERVAL_INPUT_MAX = '1';
|
||||
|
||||
export const DEFAULT_AUDIO_VOLUME = 0.42;
|
||||
export const DEFAULT_AUDIO_VOLUME = 0.5;
|
||||
|
||||
export const APP_STORAGE_KEYS = {
|
||||
audioMuted: 'fleeting-garden:audio-muted',
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { DEFAULT_AUDIO_VOLUME } from '../app-constants';
|
||||
import type { PianoNoteRole } from './garden-audio-types';
|
||||
|
||||
type GardenAudioChordQuality = 'major' | 'minor';
|
||||
|
|
@ -7,81 +8,106 @@ export interface GardenAudioChord {
|
|||
quality: GardenAudioChordQuality;
|
||||
}
|
||||
|
||||
export interface GardenAudioVibeProfile {
|
||||
export interface GardenAudioVibeSettings {
|
||||
idleIntensity: number;
|
||||
bpm: number;
|
||||
rampUpIntensity: number;
|
||||
rampUpTime: number;
|
||||
noteLength: number;
|
||||
notePitchOffset: number;
|
||||
brightness: number;
|
||||
}
|
||||
|
||||
export interface GardenAudioVibeProfile extends GardenAudioVibeSettings {
|
||||
rootMidi: number;
|
||||
scale: Array<number>;
|
||||
brightness: number;
|
||||
delayTimeMultiplier: number;
|
||||
progression: Array<GardenAudioChord>;
|
||||
}
|
||||
|
||||
export interface GardenAudioConfig {
|
||||
masterVolume: number;
|
||||
fadeInSeconds: number;
|
||||
updateRampSeconds: number;
|
||||
export const createGardenAudioConfig = () => ({
|
||||
masterVolume: DEFAULT_AUDIO_VOLUME,
|
||||
fadeInSeconds: 0.45,
|
||||
updateRampSeconds: 0.08,
|
||||
delay: {
|
||||
timeSeconds: number;
|
||||
feedback: number;
|
||||
wetGain: number;
|
||||
erasingActivity: number;
|
||||
activityFeedbackWeight: number;
|
||||
feedbackMax: number;
|
||||
feedbackMin: number;
|
||||
outputActivityWeight: number;
|
||||
outputBase: number;
|
||||
outputActivityDuck: number;
|
||||
timeRampSeconds: number;
|
||||
};
|
||||
timeSeconds: 0.46,
|
||||
feedback: 0.12,
|
||||
wetGain: 0.044,
|
||||
erasingActivity: 0.12,
|
||||
activityFeedbackWeight: 0.08,
|
||||
feedbackMax: 0.32,
|
||||
feedbackMin: 0.04,
|
||||
outputActivityWeight: 0.5,
|
||||
outputBase: 0.65,
|
||||
outputActivityDuck: 0.28,
|
||||
timeRampSeconds: 0.12,
|
||||
},
|
||||
piano: {
|
||||
maxVoices: number;
|
||||
gain: number;
|
||||
sustainSeconds: number;
|
||||
sustainLevel: number;
|
||||
releaseSeconds: number;
|
||||
lowpassHz: number;
|
||||
gainAttackSeconds: number;
|
||||
lowpassMaxHz: number;
|
||||
lowpassMinHz: number;
|
||||
sustainBase: number;
|
||||
sustainVelocityRange: number;
|
||||
};
|
||||
maxVoices: 24,
|
||||
gain: 0.48,
|
||||
sustainSeconds: 0.42,
|
||||
sustainLevel: 0.32,
|
||||
releaseSeconds: 0.24,
|
||||
lowpassHz: 7600,
|
||||
gainAttackSeconds: 0.006,
|
||||
lowpassMaxHz: 12000,
|
||||
lowpassMinHz: 1400,
|
||||
sustainBase: 0.45,
|
||||
sustainVelocityRange: 0.55,
|
||||
},
|
||||
rhythm: {
|
||||
bpm: number;
|
||||
stepsPerBeat: number;
|
||||
stepsPerBar: number;
|
||||
sparseActivity: number;
|
||||
};
|
||||
idleIntensity: 0.08,
|
||||
bpm: 74,
|
||||
stepsPerBeat: 4,
|
||||
stepsPerBar: 16,
|
||||
sparseActivity: 0.055,
|
||||
},
|
||||
eraser: {
|
||||
minIntervalSeconds: number;
|
||||
noiseGain: number;
|
||||
filterMinHz: number;
|
||||
filterMaxHz: number;
|
||||
durationSeconds: number;
|
||||
pan: number;
|
||||
pianoActivity: number;
|
||||
};
|
||||
minIntervalSeconds: 0.12,
|
||||
noiseGain: 0.028,
|
||||
filterMinHz: 650,
|
||||
filterMaxHz: 3600,
|
||||
durationSeconds: 0.08,
|
||||
pan: 0,
|
||||
pianoActivity: 0,
|
||||
},
|
||||
energy: {
|
||||
attackSeconds: number;
|
||||
decaySeconds: number;
|
||||
immediateActivityScale: number;
|
||||
releaseSeconds: number;
|
||||
strokeDecaySeconds: number;
|
||||
};
|
||||
attackSeconds: 0.08,
|
||||
decaySeconds: 0.9,
|
||||
immediateActivityScale: 0.85,
|
||||
releaseSeconds: 1.15,
|
||||
strokeDecaySeconds: 0.32,
|
||||
},
|
||||
graph: {
|
||||
pianoBusGains: Record<PianoNoteRole, number>;
|
||||
pianoBusActivityDucking: Record<PianoNoteRole, number>;
|
||||
noiseBusGain: number;
|
||||
};
|
||||
pianoBusGains: {
|
||||
pad: 0.86,
|
||||
support: 0.94,
|
||||
texture: 0.88,
|
||||
gesture: 1,
|
||||
brush: 0.9,
|
||||
stinger: 0.92,
|
||||
} satisfies Record<PianoNoteRole, number>,
|
||||
pianoBusActivityDucking: {
|
||||
pad: 0.42,
|
||||
support: 0.18,
|
||||
texture: -0.06,
|
||||
gesture: 0,
|
||||
brush: -0.08,
|
||||
stinger: 0,
|
||||
} satisfies Record<PianoNoteRole, number>,
|
||||
noiseBusGain: 0.72,
|
||||
},
|
||||
input: {
|
||||
fullActivitySpeed: number;
|
||||
activityNoiseFloorSpeed: number;
|
||||
activityCurve: number;
|
||||
activitySoftCeiling: number;
|
||||
activityAttackSeconds: number;
|
||||
activityReleaseSeconds: number;
|
||||
minAudibleDistance: number;
|
||||
manicActivityThreshold: number;
|
||||
manicReleaseThreshold: number;
|
||||
maniaSmoothingSeconds: number;
|
||||
};
|
||||
}
|
||||
fullActivitySpeed: 0.86,
|
||||
activityNoiseFloorSpeed: 0.025,
|
||||
activityCurve: 0.74,
|
||||
activitySoftCeiling: 0.96,
|
||||
activityAttackSeconds: 0.055,
|
||||
activityReleaseSeconds: 0.2,
|
||||
minAudibleDistance: 0.0025,
|
||||
manicActivityThreshold: 0.9,
|
||||
manicReleaseThreshold: 0.76,
|
||||
maniaSmoothingSeconds: 0.12,
|
||||
},
|
||||
});
|
||||
|
||||
export type GardenAudioConfig = ReturnType<typeof createGardenAudioConfig>;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { approach, clamp01 } from '../utils/math';
|
||||
import type { GardenAudioConfig } from './garden-audio-config';
|
||||
import type { GardenAudioConfig, GardenAudioVibeProfile } from './garden-audio-config';
|
||||
|
||||
export class GardenAudioEnergy {
|
||||
private isGestureActive = false;
|
||||
|
|
@ -19,13 +19,10 @@ export class GardenAudioEnergy {
|
|||
this.targetEnergy = 0;
|
||||
}
|
||||
|
||||
public recordStroke(strokeEnergy: number): void {
|
||||
public recordStroke(strokeEnergy: number, profile: GardenAudioVibeProfile): void {
|
||||
this.targetEnergy = Math.max(this.targetEnergy, strokeEnergy);
|
||||
if (this.isGestureActive) {
|
||||
this.energy = Math.max(
|
||||
this.energy,
|
||||
strokeEnergy * this.config.energy.immediateActivityScale
|
||||
);
|
||||
this.energy = Math.max(this.energy, strokeEnergy * profile.rampUpIntensity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -34,7 +31,7 @@ export class GardenAudioEnergy {
|
|||
this.energy = 0;
|
||||
}
|
||||
|
||||
public update(now: number): void {
|
||||
public update(now: number, profile: GardenAudioVibeProfile): void {
|
||||
if (this.lastEnergyUpdateAt <= 0) {
|
||||
this.lastEnergyUpdateAt = now;
|
||||
return;
|
||||
|
|
@ -51,7 +48,7 @@ export class GardenAudioEnergy {
|
|||
if (!this.isGestureActive) {
|
||||
timeConstant = this.config.energy.releaseSeconds;
|
||||
} else if (target > this.energy) {
|
||||
timeConstant = this.config.energy.attackSeconds;
|
||||
timeConstant = profile.rampUpTime;
|
||||
}
|
||||
this.energy = approach(this.energy, target, elapsedSeconds, timeConstant);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,17 @@
|
|||
import { clamp } from '../utils/math';
|
||||
import type { GardenAudioConfig, GardenAudioVibeProfile } from './garden-audio-config';
|
||||
import type { GardenAudioConfig } from './garden-audio-config';
|
||||
import type { PianoNoteRole } from './garden-audio-types';
|
||||
|
||||
type NavigatorWithAudioSession = Navigator & {
|
||||
audioSession?: { type: 'auto' | 'playback' | 'ambient' | 'transient' | 'transient-solo' | 'play-and-record' };
|
||||
audioSession?: {
|
||||
type:
|
||||
| 'auto'
|
||||
| 'playback'
|
||||
| 'ambient'
|
||||
| 'transient'
|
||||
| 'transient-solo'
|
||||
| 'play-and-record';
|
||||
};
|
||||
};
|
||||
|
||||
const outputHighPassFrequencyHz = 45;
|
||||
|
|
@ -113,19 +121,19 @@ export class GardenAudioGraph {
|
|||
);
|
||||
}
|
||||
|
||||
public applyDelayProfile(profile: GardenAudioVibeProfile): void {
|
||||
public applyDelayProfile(): void {
|
||||
if (!this.context || !this.delayNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.delayNode.delayTime.setTargetAtTime(
|
||||
this.config.delay.timeSeconds * profile.delayTimeMultiplier,
|
||||
this.config.delay.timeSeconds,
|
||||
this.context.currentTime,
|
||||
this.config.delay.timeRampSeconds
|
||||
);
|
||||
}
|
||||
|
||||
public updateDelay(profile: GardenAudioVibeProfile, activity: number): void {
|
||||
public updateDelay(activity: number): void {
|
||||
if (!this.context || !this.delayNode || !this.delayFeedback || !this.delayOutput) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -133,7 +141,7 @@ export class GardenAudioGraph {
|
|||
const now = this.context.currentTime;
|
||||
const normalizedActivity = clamp(activity, 0, 1);
|
||||
this.delayNode.delayTime.setTargetAtTime(
|
||||
this.config.delay.timeSeconds * profile.delayTimeMultiplier,
|
||||
this.config.delay.timeSeconds,
|
||||
now,
|
||||
this.config.delay.timeRampSeconds
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,34 @@
|
|||
import type { VibePreset } from '../vibes';
|
||||
import type { GardenAudioVibeProfile } from './garden-audio-config';
|
||||
import type { GardenAudioChord, GardenAudioVibeProfile } from './garden-audio-config';
|
||||
|
||||
export const PITCH_SEMITONES_PER_OCTAVE = 12;
|
||||
|
||||
export const getVibeProfile = (vibe: VibePreset): GardenAudioVibeProfile => vibe.audio;
|
||||
const DEFAULT_PROGRESSION: ReadonlyArray<GardenAudioChord> = [
|
||||
{ rootOffset: 0, quality: 'major' },
|
||||
{ rootOffset: 9, quality: 'minor' },
|
||||
{ rootOffset: 5, quality: 'major' },
|
||||
{ rootOffset: 7, quality: 'major' },
|
||||
];
|
||||
|
||||
const DEFAULT_ROOT_MIDI = 57;
|
||||
const DEFAULT_SCALE: ReadonlyArray<number> = [0, 2, 4, 7, 9];
|
||||
|
||||
const profileCache = new WeakMap<VibePreset, GardenAudioVibeProfile>();
|
||||
|
||||
export const getVibeProfile = (vibe: VibePreset): GardenAudioVibeProfile => {
|
||||
let profile = profileCache.get(vibe);
|
||||
if (!profile) {
|
||||
profile = {
|
||||
...vibe.audio,
|
||||
rootMidi: DEFAULT_ROOT_MIDI + vibe.audio.notePitchOffset,
|
||||
scale: DEFAULT_SCALE as Array<number>,
|
||||
progression: DEFAULT_PROGRESSION as Array<GardenAudioChord>,
|
||||
};
|
||||
profileCache.set(vibe, profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
Object.assign(profile, vibe.audio);
|
||||
profile.rootMidi = DEFAULT_ROOT_MIDI + vibe.audio.notePitchOffset;
|
||||
return profile;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ export interface PianoNote {
|
|||
role?: PianoNoteRole;
|
||||
delaySend?: number;
|
||||
lowpassHz?: number;
|
||||
sustainSeconds?: number;
|
||||
}
|
||||
|
||||
export type PianoNoteRole =
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ export class GardenAudio {
|
|||
|
||||
this.lifecycle = 'started';
|
||||
this.applyVibe(vibe);
|
||||
this.pianoEngine.prime(context.currentTime);
|
||||
this.pianoEngine.prime(context.currentTime, getVibeProfile(vibe));
|
||||
this.graph.setMasterGain(this.masterVolume, startupRampSeconds);
|
||||
|
||||
const pianoLoad = this.piano.loadIfIdle(context);
|
||||
|
|
@ -122,7 +122,7 @@ export class GardenAudio {
|
|||
void pianoLoad
|
||||
.then(() => {
|
||||
if (this.graph.context === context && this.lifecycle !== 'destroyed') {
|
||||
this.pianoEngine.cue(context.currentTime);
|
||||
this.pianoEngine.cue(context.currentTime, getVibeProfile(vibe));
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
|
|
@ -207,7 +207,8 @@ export class GardenAudio {
|
|||
}
|
||||
|
||||
this.applyVibe(snapshot.vibe);
|
||||
this.energy.update(context.currentTime);
|
||||
const profile = getVibeProfile(snapshot.vibe);
|
||||
this.energy.update(context.currentTime, profile);
|
||||
|
||||
if (snapshot.isErasing) {
|
||||
this.energy.silence();
|
||||
|
|
@ -254,7 +255,8 @@ export class GardenAudio {
|
|||
return;
|
||||
}
|
||||
|
||||
this.energy.recordStroke(strokeEnergy);
|
||||
const profile = getVibeProfile(stroke.vibe);
|
||||
this.energy.recordStroke(strokeEnergy, profile);
|
||||
this.pianoEngine.recordStroke({
|
||||
vibe: stroke.vibe,
|
||||
now,
|
||||
|
|
@ -347,11 +349,10 @@ export class GardenAudio {
|
|||
return;
|
||||
}
|
||||
|
||||
const profile = getVibeProfile(snapshot.vibe);
|
||||
const activity = snapshot.isErasing
|
||||
? this.config.delay.erasingActivity
|
||||
: this.energy.getLevel();
|
||||
this.graph.updateDelay(profile, activity);
|
||||
this.graph.updateDelay(activity);
|
||||
}
|
||||
|
||||
private applyVibe(vibe: VibePreset): void {
|
||||
|
|
@ -360,7 +361,8 @@ export class GardenAudio {
|
|||
}
|
||||
|
||||
this.currentVibeId = vibe.id;
|
||||
this.graph.applyDelayProfile(getVibeProfile(vibe));
|
||||
this.pianoEngine.cue(this.graph.context.currentTime);
|
||||
const profile = getVibeProfile(vibe);
|
||||
this.graph.applyDelayProfile();
|
||||
this.pianoEngine.cue(this.graph.context.currentTime, profile);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,10 +37,7 @@ const getChordIntervals = (
|
|||
: chordVoicings.minorClosed;
|
||||
};
|
||||
|
||||
const degreeToSemitone = (
|
||||
profile: GardenAudioVibeProfile,
|
||||
degree: number
|
||||
): number => {
|
||||
const degreeToSemitone = (profile: GardenAudioVibeProfile, degree: number): number => {
|
||||
const scaleIndex =
|
||||
((degree % profile.scale.length) + profile.scale.length) % profile.scale.length;
|
||||
const octave = Math.floor(degree / profile.scale.length);
|
||||
|
|
@ -96,6 +93,7 @@ interface BrushPhraseLayer {
|
|||
export class GenerativePianoEngine {
|
||||
private nextBeatStep: number | null = null;
|
||||
private timelineStartedAt: number | null = null;
|
||||
private activeProfile: GardenAudioVibeProfile | null = null;
|
||||
private isWaitingForGestureAccent = false;
|
||||
private lastGestureAccentAt = Number.NEGATIVE_INFINITY;
|
||||
private lastStrokeAccentStep = Number.NEGATIVE_INFINITY;
|
||||
|
|
@ -124,13 +122,17 @@ export class GenerativePianoEngine {
|
|||
return generativePianoTuning;
|
||||
}
|
||||
|
||||
public prime(now: number): void {
|
||||
public prime(now: number, profile: GardenAudioVibeProfile): void {
|
||||
this.activeProfile = profile;
|
||||
this.timelineStartedAt ??= now;
|
||||
this.nextBeatStep ??= 0;
|
||||
this.nextBrushStreamStep ??= 0;
|
||||
}
|
||||
|
||||
public cue(now: number): void {
|
||||
public cue(now: number, profile?: GardenAudioVibeProfile): void {
|
||||
if (profile) {
|
||||
this.activeProfile = profile;
|
||||
}
|
||||
this.nextBeatStep = 0;
|
||||
this.timelineStartedAt = now;
|
||||
this.nextBrushStreamStep = 0;
|
||||
|
|
@ -148,10 +150,9 @@ export class GenerativePianoEngine {
|
|||
}
|
||||
|
||||
public release(vibe: VibePreset, now: number): number {
|
||||
this.prime(now);
|
||||
this.isWaitingForGestureAccent = false;
|
||||
|
||||
const profile = getVibeProfile(vibe);
|
||||
this.prime(now, profile);
|
||||
this.isWaitingForGestureAccent = false;
|
||||
const releaseStep = this.getReleaseResolutionStep(now);
|
||||
const releaseStart = Math.max(now, this.getTimeForStep(releaseStep));
|
||||
|
||||
|
|
@ -198,7 +199,8 @@ export class GenerativePianoEngine {
|
|||
activity,
|
||||
maniaAmount = 0,
|
||||
}: StrokeAccentRequest): void {
|
||||
this.prime(now);
|
||||
const profile = getVibeProfile(vibe);
|
||||
this.prime(now, profile);
|
||||
const strength = clamp01(activity);
|
||||
const normalizedManiaAmount = clamp01(maniaAmount);
|
||||
const styleIndex = this.getStyleIndex(now);
|
||||
|
|
@ -242,14 +244,14 @@ export class GenerativePianoEngine {
|
|||
activity,
|
||||
lookaheadSeconds = GENERATIVE_LOOKAHEAD_SECONDS,
|
||||
}: RenderLookaheadRequest): void {
|
||||
this.prime(now);
|
||||
const profile = getVibeProfile(vibe);
|
||||
this.prime(now, profile);
|
||||
this.skipLateBeats(now);
|
||||
|
||||
if (this.nextBeatStep === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const profile = getVibeProfile(vibe);
|
||||
const lookaheadEnd = now + lookaheadSeconds;
|
||||
while (this.getTimeForStep(this.nextBeatStep) <= lookaheadEnd) {
|
||||
const beatIndex = this.getBeatIndexForStep(this.nextBeatStep);
|
||||
|
|
@ -286,7 +288,7 @@ export class GenerativePianoEngine {
|
|||
{ baseMidi: rootMidi, offsets },
|
||||
this.generation.padRegisters[index]
|
||||
);
|
||||
this.playNote({
|
||||
this.playProfileNote(profile, {
|
||||
midi,
|
||||
velocity: stinger.velocities[index],
|
||||
pan: stinger.pans[index],
|
||||
|
|
@ -302,6 +304,7 @@ export class GenerativePianoEngine {
|
|||
public reset(): void {
|
||||
this.nextBeatStep = null;
|
||||
this.timelineStartedAt = null;
|
||||
this.activeProfile = null;
|
||||
this.isWaitingForGestureAccent = false;
|
||||
this.lastGestureAccentAt = Number.NEGATIVE_INFINITY;
|
||||
this.lastStrokeAccentStep = Number.NEGATIVE_INFINITY;
|
||||
|
|
@ -314,6 +317,13 @@ export class GenerativePianoEngine {
|
|||
this.brushStreamNoteCountsByBar.clear();
|
||||
}
|
||||
|
||||
private playProfileNote(profile: GardenAudioVibeProfile, note: PianoNote): void {
|
||||
this.playNote({
|
||||
...note,
|
||||
sustainSeconds: profile.noteLength,
|
||||
});
|
||||
}
|
||||
|
||||
private renderBeat({
|
||||
profile,
|
||||
beatIndex,
|
||||
|
|
@ -398,7 +408,7 @@ export class GenerativePianoEngine {
|
|||
false
|
||||
);
|
||||
this.lastPadMidiByVoice[index] = midi;
|
||||
this.playNote({
|
||||
this.playProfileNote(profile, {
|
||||
midi,
|
||||
velocity:
|
||||
velocity + expression * this.generation.padChord.expressionVelocityWeight,
|
||||
|
|
@ -433,8 +443,13 @@ export class GenerativePianoEngine {
|
|||
|
||||
offsetsByVoice.forEach((offsets, index) => {
|
||||
const register = this.generation.padRegisters[index];
|
||||
const midi = this.chooseMidi({ baseMidi: rootMidi, offsets }, register, null, false);
|
||||
this.playNote({
|
||||
const midi = this.chooseMidi(
|
||||
{ baseMidi: rootMidi, offsets },
|
||||
register,
|
||||
null,
|
||||
false
|
||||
);
|
||||
this.playProfileNote(profile, {
|
||||
midi,
|
||||
velocity: release.velocities[index],
|
||||
startTime: startTime + index * release.strumSeconds,
|
||||
|
|
@ -470,7 +485,7 @@ export class GenerativePianoEngine {
|
|||
);
|
||||
|
||||
this.lastMidiByStyle[styleIndex] = midi;
|
||||
this.playNote({
|
||||
this.playProfileNote(profile, {
|
||||
midi,
|
||||
velocity:
|
||||
(this.generation.supportNote.velocityBase +
|
||||
|
|
@ -516,7 +531,7 @@ export class GenerativePianoEngine {
|
|||
);
|
||||
|
||||
this.lastMidiByStyle[styleIndex] = midi;
|
||||
this.playNote({
|
||||
this.playProfileNote(profile, {
|
||||
midi,
|
||||
velocity:
|
||||
(this.generation.textureNote.velocityBase +
|
||||
|
|
@ -563,7 +578,7 @@ export class GenerativePianoEngine {
|
|||
);
|
||||
|
||||
this.lastMidiByStyle[styleIndex] = midi;
|
||||
this.playNote({
|
||||
this.playProfileNote(profile, {
|
||||
midi,
|
||||
velocity:
|
||||
(this.generation.gestureAccent.velocityBase +
|
||||
|
|
@ -608,7 +623,7 @@ export class GenerativePianoEngine {
|
|||
|
||||
this.lastMidiByStyle[styleIndex] = midi;
|
||||
this.lastBrushStreamMidi = midi;
|
||||
this.playNote({
|
||||
this.playProfileNote(profile, {
|
||||
midi,
|
||||
velocity:
|
||||
(this.generation.touchNote.velocityBase +
|
||||
|
|
@ -818,7 +833,7 @@ export class GenerativePianoEngine {
|
|||
|
||||
this.lastBrushStreamMidi = midi;
|
||||
this.lastMidiByStyle[styleIndex] = midi;
|
||||
this.playNote({
|
||||
this.playProfileNote(profile, {
|
||||
midi,
|
||||
velocity:
|
||||
(this.generation.brushStream.velocityBase +
|
||||
|
|
@ -851,7 +866,7 @@ export class GenerativePianoEngine {
|
|||
this.generation.brushStreamEcho.maxMidi
|
||||
? midi + this.generation.brushStreamEcho.octaveSemitones
|
||||
: midi - this.generation.brushStreamEcho.octaveSemitones;
|
||||
this.playNote({
|
||||
this.playProfileNote(profile, {
|
||||
midi: echoMidi,
|
||||
velocity:
|
||||
(this.generation.brushStreamEcho.velocityBase +
|
||||
|
|
@ -1159,14 +1174,18 @@ export class GenerativePianoEngine {
|
|||
}
|
||||
|
||||
private getExpression(activity: number): number {
|
||||
const liftedActivity = Math.max(
|
||||
activity,
|
||||
this.activeProfile?.idleIntensity ?? this.config.rhythm.idleIntensity
|
||||
);
|
||||
return clamp01(
|
||||
(activity - this.config.rhythm.sparseActivity) /
|
||||
(liftedActivity - this.config.rhythm.sparseActivity) /
|
||||
(1 - this.config.rhythm.sparseActivity)
|
||||
);
|
||||
}
|
||||
|
||||
private getBeatDurationSeconds(): number {
|
||||
return 60 / this.config.rhythm.bpm;
|
||||
return 60 / (this.activeProfile?.bpm ?? this.config.rhythm.bpm);
|
||||
}
|
||||
|
||||
private getStepDurationSeconds(): number {
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ export class PianoSampler {
|
|||
role,
|
||||
delaySend = 0,
|
||||
lowpassHz = this.config.piano.lowpassHz,
|
||||
sustainSeconds: profileSustainSeconds = this.config.piano.sustainSeconds,
|
||||
}: PianoNote): void {
|
||||
const { context } = this.graph;
|
||||
const eventBus = this.graph.getPianoBus(role);
|
||||
|
|
@ -92,12 +93,11 @@ export class PianoSampler {
|
|||
this.config.piano.gain * noteVelocity
|
||||
);
|
||||
const sustainSeconds =
|
||||
this.config.piano.sustainSeconds *
|
||||
profileSustainSeconds *
|
||||
(this.config.piano.sustainBase +
|
||||
noteVelocity * this.config.piano.sustainVelocityRange);
|
||||
const sustainAt =
|
||||
scheduledStart +
|
||||
Math.max(pianoSamplerTuning.minDurationSeconds, durationSeconds);
|
||||
scheduledStart + Math.max(pianoSamplerTuning.minDurationSeconds, durationSeconds);
|
||||
const releaseAt = sustainAt + sustainSeconds;
|
||||
const stopAt = releaseAt + this.config.piano.releaseSeconds;
|
||||
const source = context.createBufferSource();
|
||||
|
|
@ -150,7 +150,7 @@ export class PianoSampler {
|
|||
const releaseAt =
|
||||
scheduledStart +
|
||||
clamp(
|
||||
durationSeconds + this.config.piano.sustainSeconds * 0.5,
|
||||
durationSeconds + profileSustainSeconds * 0.5,
|
||||
pianoSamplerTuning.minDurationSeconds,
|
||||
pianoSamplerTuning.synthMaxDurationSeconds
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { APP_STORAGE_KEYS, DEFAULT_AUDIO_VOLUME } from './app-constants';
|
||||
import { createGardenAudioConfig } from './audio/garden-audio-config';
|
||||
import { defaultSettings } from './config/default-settings';
|
||||
import { runtimeControls } from './config/runtime-controls';
|
||||
import type { GardenAppConfig } from './config/types';
|
||||
|
|
@ -14,90 +15,7 @@ export type {
|
|||
} from './config/types';
|
||||
|
||||
export const appConfig = {
|
||||
audio: {
|
||||
masterVolume: DEFAULT_AUDIO_VOLUME,
|
||||
fadeInSeconds: 0.45,
|
||||
updateRampSeconds: 0.08,
|
||||
delay: {
|
||||
timeSeconds: 0.46,
|
||||
feedback: 0.12,
|
||||
wetGain: 0.044,
|
||||
erasingActivity: 0.12,
|
||||
activityFeedbackWeight: 0.08,
|
||||
feedbackMax: 0.32,
|
||||
feedbackMin: 0.04,
|
||||
outputActivityWeight: 0.5,
|
||||
outputBase: 0.65,
|
||||
outputActivityDuck: 0.28,
|
||||
timeRampSeconds: 0.12,
|
||||
},
|
||||
piano: {
|
||||
maxVoices: 24,
|
||||
gain: 0.48,
|
||||
sustainSeconds: 0.42,
|
||||
sustainLevel: 0.32,
|
||||
releaseSeconds: 0.24,
|
||||
lowpassHz: 7600,
|
||||
gainAttackSeconds: 0.006,
|
||||
lowpassMaxHz: 12000,
|
||||
lowpassMinHz: 1400,
|
||||
sustainBase: 0.45,
|
||||
sustainVelocityRange: 0.55,
|
||||
},
|
||||
rhythm: {
|
||||
bpm: 74,
|
||||
stepsPerBeat: 4,
|
||||
stepsPerBar: 16,
|
||||
sparseActivity: 0.055,
|
||||
},
|
||||
eraser: {
|
||||
minIntervalSeconds: 0.12,
|
||||
noiseGain: 0.028,
|
||||
filterMinHz: 650,
|
||||
filterMaxHz: 3600,
|
||||
durationSeconds: 0.08,
|
||||
pan: 0,
|
||||
pianoActivity: 0,
|
||||
},
|
||||
energy: {
|
||||
attackSeconds: 0.08,
|
||||
decaySeconds: 0.9,
|
||||
immediateActivityScale: 0.85,
|
||||
releaseSeconds: 1.15,
|
||||
strokeDecaySeconds: 0.32,
|
||||
},
|
||||
graph: {
|
||||
pianoBusGains: {
|
||||
pad: 0.86,
|
||||
support: 0.94,
|
||||
texture: 0.88,
|
||||
gesture: 1,
|
||||
brush: 0.9,
|
||||
stinger: 0.92,
|
||||
},
|
||||
pianoBusActivityDucking: {
|
||||
pad: 0.42,
|
||||
support: 0.18,
|
||||
texture: -0.06,
|
||||
gesture: 0,
|
||||
brush: -0.08,
|
||||
stinger: 0,
|
||||
},
|
||||
noiseBusGain: 0.72,
|
||||
},
|
||||
input: {
|
||||
fullActivitySpeed: 0.86,
|
||||
activityNoiseFloorSpeed: 0.025,
|
||||
activityCurve: 0.74,
|
||||
activitySoftCeiling: 0.96,
|
||||
activityAttackSeconds: 0.055,
|
||||
activityReleaseSeconds: 0.2,
|
||||
minAudibleDistance: 0.0025,
|
||||
manicActivityThreshold: 0.9,
|
||||
manicReleaseThreshold: 0.76,
|
||||
maniaSmoothingSeconds: 0.12,
|
||||
},
|
||||
},
|
||||
audio: createGardenAudioConfig(),
|
||||
deltaTime: {
|
||||
maxDeltaTimeSeconds: 1 / 30,
|
||||
minDeltaTimeSeconds: 1 / 240,
|
||||
|
|
@ -124,7 +42,7 @@ export const appConfig = {
|
|||
noiseHashMultiplier: 43758.5453123,
|
||||
noiseHashX: 12.9898,
|
||||
noiseHashY: 78.233,
|
||||
noiseTextureFormat: 'rgba8unorm',
|
||||
noiseTextureFormat: 'r8unorm',
|
||||
noiseTextureSize: 2048,
|
||||
},
|
||||
brush: {
|
||||
|
|
@ -261,7 +179,7 @@ export const appConfig = {
|
|||
},
|
||||
},
|
||||
tuningPane: {
|
||||
expandedDepth: 1,
|
||||
showFpsOverlay: import.meta.env.DEV,
|
||||
startHidden: true,
|
||||
title: 'Garden Config',
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
import { colorInteractionSettings } from './color-interactions';
|
||||
import type { GardenAppConfig } from './types';
|
||||
|
||||
export const defaultSettings: GardenAppConfig['defaultSettings'] = {
|
||||
selectedColorIndex: 0,
|
||||
...colorInteractionSettings,
|
||||
|
||||
turnWhenLost: 0.8,
|
||||
forwardRotationScale: 0.25,
|
||||
sensorOffsetAngle: 32,
|
||||
introNearDistanceMin: 28,
|
||||
introNearDistanceInner: 4,
|
||||
introNearSensorOffsetMultiplier: 0.75,
|
||||
|
|
@ -19,7 +18,7 @@ export const defaultSettings: GardenAppConfig['defaultSettings'] = {
|
|||
introStepStopDistance: 0.5,
|
||||
randomTimeScale: 0.34816,
|
||||
|
||||
diffusionRateBrush: 0.35,
|
||||
diffusionRateTrails: 0.22,
|
||||
decayRateBrush: 18,
|
||||
diffusionDecayRateDivisor: 1000,
|
||||
diffusionNeighborDivisor: 8,
|
||||
|
|
@ -33,7 +32,6 @@ export const defaultSettings: GardenAppConfig['defaultSettings'] = {
|
|||
brushCurveSegmentBrushRadiusRatio: 0.65,
|
||||
brushSmoothingMinSampleDistance: 0.5,
|
||||
|
||||
brushSizeVariation: 0.5,
|
||||
brushAlpha: 1,
|
||||
brushDiscardThreshold: 0.02,
|
||||
brushCoarseNoiseScale: 160,
|
||||
|
|
@ -58,5 +56,4 @@ export const defaultSettings: GardenAppConfig['defaultSettings'] = {
|
|||
renderTraceNormalizationFloor: 1,
|
||||
renderBrushColorBase: 1.2,
|
||||
renderBrushColorStrengthMultiplier: 1.6,
|
||||
backgroundGrainStrength: 0.018,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,380 +11,100 @@ export const runtimeControls: GardenAppConfig['runtimeSettings']['controls'] = {
|
|||
color3ToColor1: colorInteractionControl('3 -> 1'),
|
||||
color3ToColor2: colorInteractionControl('3 -> 2'),
|
||||
color3ToColor3: colorInteractionControl('3 -> 3'),
|
||||
brushEffectDuration: {
|
||||
folder: 'Diffusion',
|
||||
min: 0.5,
|
||||
max: 20,
|
||||
step: 0.05,
|
||||
},
|
||||
|
||||
brushSize: {
|
||||
folder: 'Brush',
|
||||
label: 'brush size',
|
||||
min: 1,
|
||||
max: 60,
|
||||
step: 0.25,
|
||||
},
|
||||
spawnPerPixel: {
|
||||
folder: 'Brush',
|
||||
label: 'agents per brush pixel',
|
||||
min: 0.01,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
brushSizeVariation: {
|
||||
folder: 'Brush',
|
||||
label: 'brush variance',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.01,
|
||||
},
|
||||
brushAlpha: {
|
||||
folder: 'Brush',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
brushDiscardThreshold: {
|
||||
folder: 'Brush',
|
||||
min: 0,
|
||||
max: 0.25,
|
||||
step: 0.001,
|
||||
},
|
||||
brushCoarseNoiseScale: {
|
||||
folder: 'Brush',
|
||||
min: 1,
|
||||
max: 480,
|
||||
step: 1,
|
||||
},
|
||||
brushGrainNoiseScale: {
|
||||
folder: 'Brush',
|
||||
min: 1,
|
||||
max: 180,
|
||||
step: 1,
|
||||
},
|
||||
brushGrainNoiseOffsetX: {
|
||||
folder: 'Brush',
|
||||
min: -2,
|
||||
max: 2,
|
||||
step: 0.01,
|
||||
},
|
||||
brushGrainNoiseOffsetY: {
|
||||
folder: 'Brush',
|
||||
min: -2,
|
||||
max: 2,
|
||||
step: 0.01,
|
||||
},
|
||||
brushGrainMinStrength: {
|
||||
folder: 'Brush',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
brushGrainMaxStrength: {
|
||||
folder: 'Brush',
|
||||
min: 0,
|
||||
max: 2,
|
||||
step: 0.001,
|
||||
},
|
||||
brushCurveResolution: {
|
||||
folder: 'Brush',
|
||||
integer: true,
|
||||
label: 'curve resolution',
|
||||
min: 1,
|
||||
max: 32,
|
||||
step: 1,
|
||||
},
|
||||
brushSmoothingMinSampleDistance: {
|
||||
folder: 'Brush',
|
||||
min: 0,
|
||||
max: 4,
|
||||
step: 0.01,
|
||||
},
|
||||
brushCurveMinSegmentSpacing: {
|
||||
folder: 'Brush',
|
||||
min: 0.1,
|
||||
max: 32,
|
||||
step: 0.1,
|
||||
},
|
||||
brushCurveSegmentBrushRadiusRatio: {
|
||||
folder: 'Brush',
|
||||
min: 0,
|
||||
max: 4,
|
||||
step: 0.01,
|
||||
},
|
||||
brushCurveMinBrushRadius: {
|
||||
folder: 'Brush',
|
||||
min: 0.1,
|
||||
max: 16,
|
||||
step: 0.1,
|
||||
},
|
||||
brushCurveMirrorResolutionExponent: {
|
||||
folder: 'Brush',
|
||||
min: 0,
|
||||
max: 2,
|
||||
step: 0.01,
|
||||
},
|
||||
clarity: {
|
||||
folder: 'Render',
|
||||
min: 0.00001,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
renderTraceNormalizationFloor: {
|
||||
folder: 'Render',
|
||||
min: 0.01,
|
||||
max: 4,
|
||||
step: 0.01,
|
||||
},
|
||||
renderBrushColorBase: {
|
||||
folder: 'Render',
|
||||
min: 0,
|
||||
max: 4,
|
||||
step: 0.01,
|
||||
},
|
||||
renderBrushColorStrengthMultiplier: {
|
||||
folder: 'Render',
|
||||
min: 0,
|
||||
max: 4,
|
||||
step: 0.01,
|
||||
},
|
||||
backgroundGrainStrength: {
|
||||
folder: 'Render',
|
||||
min: 0,
|
||||
max: 0.12,
|
||||
step: 0.001,
|
||||
},
|
||||
internalRenderAreaMegapixels: {
|
||||
folder: 'Render',
|
||||
label: 'internal area (MP)',
|
||||
min: 0.5,
|
||||
max: 16.6,
|
||||
step: 0.1,
|
||||
},
|
||||
decayRateBrush: {
|
||||
folder: 'Diffusion',
|
||||
min: 0.1,
|
||||
max: 100,
|
||||
step: 0.1,
|
||||
},
|
||||
decayRateTrails: {
|
||||
folder: 'Diffusion',
|
||||
min: 0.1,
|
||||
max: 5000,
|
||||
step: 1,
|
||||
},
|
||||
diffusionRateBrush: {
|
||||
folder: 'Diffusion',
|
||||
folder: 'Brush',
|
||||
label: 'brush diffusion',
|
||||
min: 0.001,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
diffusionDecayRateDivisor: {
|
||||
folder: 'Diffusion',
|
||||
min: 1,
|
||||
max: 5000,
|
||||
step: 1,
|
||||
},
|
||||
diffusionNeighborDivisor: {
|
||||
folder: 'Diffusion',
|
||||
min: 1,
|
||||
max: 16,
|
||||
step: 0.1,
|
||||
},
|
||||
brushDecayAlphaOffset: {
|
||||
folder: 'Diffusion',
|
||||
min: 1,
|
||||
max: 1.1,
|
||||
step: 0.0001,
|
||||
},
|
||||
diffusionRateTrails: {
|
||||
folder: 'Diffusion',
|
||||
|
||||
sensorOffsetDistance: {
|
||||
folder: 'Agents',
|
||||
label: 'sensor distance',
|
||||
min: 0,
|
||||
max: 2,
|
||||
step: 0.001,
|
||||
},
|
||||
eraserSize: {
|
||||
folder: 'Brush',
|
||||
integer: true,
|
||||
min: 24,
|
||||
max: 240,
|
||||
step: 1,
|
||||
},
|
||||
eraserMaskAlphaThreshold: {
|
||||
folder: 'Eraser',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
eraserLineDistanceEpsilon: {
|
||||
folder: 'Eraser',
|
||||
min: 0,
|
||||
max: 0.01,
|
||||
step: 0.00001,
|
||||
},
|
||||
eraserClearRed: {
|
||||
folder: 'Eraser',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
eraserClearGreen: {
|
||||
folder: 'Eraser',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
eraserClearBlue: {
|
||||
folder: 'Eraser',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
eraserClearAlpha: {
|
||||
folder: 'Eraser',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
individualTrailWeight: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
adaptiveCapInitial: {
|
||||
folder: 'Agent',
|
||||
integer: true,
|
||||
label: 'adaptive cap initial',
|
||||
min: 50_000,
|
||||
max: 2_000_000,
|
||||
step: 10_000,
|
||||
},
|
||||
adaptiveCapMin: {
|
||||
folder: 'Agent',
|
||||
integer: true,
|
||||
label: 'adaptive cap min',
|
||||
min: 0,
|
||||
max: 500_000,
|
||||
step: 10_000,
|
||||
},
|
||||
maxAgentCount: {
|
||||
folder: 'Agent',
|
||||
integer: true,
|
||||
label: 'max agent count',
|
||||
step: 10_000,
|
||||
},
|
||||
mirrorSegmentCount: {
|
||||
folder: 'Brush',
|
||||
integer: true,
|
||||
min: 1,
|
||||
max: 12,
|
||||
max: 200,
|
||||
step: 1,
|
||||
},
|
||||
moveSpeed: {
|
||||
folder: 'Agent',
|
||||
folder: 'Agents',
|
||||
label: 'move speed',
|
||||
min: 10,
|
||||
max: 500,
|
||||
step: 1,
|
||||
},
|
||||
selectedColorIndex: {
|
||||
folder: 'Brush',
|
||||
integer: true,
|
||||
min: 0,
|
||||
max: 2,
|
||||
step: 1,
|
||||
},
|
||||
sensorOffsetAngle: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
max: 90,
|
||||
step: 1,
|
||||
},
|
||||
sensorOffsetDistance: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
max: 200,
|
||||
step: 1,
|
||||
},
|
||||
spawnPerPixel: {
|
||||
folder: 'Agent',
|
||||
min: 0.01,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
turnSpeed: {
|
||||
folder: 'Agent',
|
||||
folder: 'Agents',
|
||||
label: 'turn speed',
|
||||
min: 1,
|
||||
max: 200,
|
||||
step: 1,
|
||||
},
|
||||
turnWhenLost: {
|
||||
folder: 'Agent',
|
||||
individualTrailWeight: {
|
||||
folder: 'Agents',
|
||||
label: 'individual trail weight',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
forwardRotationScale: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
decayRateTrails: {
|
||||
folder: 'Agents',
|
||||
label: 'trail decay',
|
||||
min: 800,
|
||||
max: 1000,
|
||||
step: 1,
|
||||
},
|
||||
|
||||
clarity: {
|
||||
folder: 'Look',
|
||||
label: 'clarity',
|
||||
min: 0.00001,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
introNearDistanceMin: {
|
||||
folder: 'Agent',
|
||||
backgroundGrainStrength: {
|
||||
folder: 'Look',
|
||||
label: 'grain strength',
|
||||
min: 0,
|
||||
max: 100,
|
||||
max: 0.12,
|
||||
step: 0.001,
|
||||
},
|
||||
|
||||
maxAgentCount: {
|
||||
folder: 'Performance',
|
||||
integer: true,
|
||||
label: 'max agent count',
|
||||
min: 0,
|
||||
max: 2_000_000,
|
||||
step: 10_000,
|
||||
},
|
||||
internalRenderAreaMegapixels: {
|
||||
folder: 'Performance',
|
||||
label: 'internal resolution (MP)',
|
||||
min: 0.5,
|
||||
max: 16.6,
|
||||
step: 0.1,
|
||||
},
|
||||
introNearDistanceInner: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
max: 100,
|
||||
step: 0.1,
|
||||
},
|
||||
introNearSensorOffsetMultiplier: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
max: 4,
|
||||
step: 0.01,
|
||||
},
|
||||
introTargetAngleBlend: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
introProgressCutoff: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
introTurnRateMultiplier: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
max: 8,
|
||||
step: 0.01,
|
||||
},
|
||||
introRandomTurnMultiplier: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
max: 2,
|
||||
step: 0.001,
|
||||
},
|
||||
introFarMoveMultiplier: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
max: 6,
|
||||
step: 0.01,
|
||||
},
|
||||
introNearMoveMultiplier: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.001,
|
||||
},
|
||||
introStepStopDistance: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
max: 8,
|
||||
step: 0.01,
|
||||
},
|
||||
randomTimeScale: {
|
||||
folder: 'Agent',
|
||||
min: 0,
|
||||
max: 4,
|
||||
step: 0.00001,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type {
|
||||
GardenAudioConfig,
|
||||
GardenAudioVibeProfile,
|
||||
GardenAudioVibeSettings,
|
||||
} from '../audio/garden-audio-config';
|
||||
import type { AgentSettings } from '../pipelines/agents/agent-settings';
|
||||
import type { BrushSettings } from '../pipelines/brush/brush-settings';
|
||||
|
|
@ -45,19 +45,29 @@ export type GardenRuntimeSettings = {
|
|||
DiffusionSettings &
|
||||
RenderSettings;
|
||||
|
||||
type RuntimeSettingControlConfig = {
|
||||
[Key in keyof GardenRuntimeSettings]: NumberControlConfig;
|
||||
};
|
||||
type RuntimeSettingControlConfig = Partial<
|
||||
Record<keyof GardenRuntimeSettings, NumberControlConfig>
|
||||
>;
|
||||
|
||||
type GardenVibeSettings = Pick<
|
||||
GardenRuntimeSettings,
|
||||
| 'backgroundGrainStrength'
|
||||
| 'brushSize'
|
||||
| 'brushSizeVariation'
|
||||
| 'clarity'
|
||||
| 'color1ToColor1'
|
||||
| 'color1ToColor2'
|
||||
| 'color1ToColor3'
|
||||
| 'color2ToColor1'
|
||||
| 'color2ToColor2'
|
||||
| 'color2ToColor3'
|
||||
| 'color3ToColor1'
|
||||
| 'color3ToColor2'
|
||||
| 'color3ToColor3'
|
||||
| 'decayRateTrails'
|
||||
| 'diffusionRateTrails'
|
||||
| 'diffusionRateBrush'
|
||||
| 'individualTrailWeight'
|
||||
| 'moveSpeed'
|
||||
| 'sensorOffsetAngle'
|
||||
| 'sensorOffsetDistance'
|
||||
| 'spawnPerPixel'
|
||||
| 'turnSpeed'
|
||||
|
|
@ -83,7 +93,7 @@ export interface VibePreset {
|
|||
colors: [RgbColor, RgbColor, RgbColor];
|
||||
backgroundColor: RgbColor;
|
||||
settings: GardenVibeSettings;
|
||||
audio: GardenAudioVibeProfile;
|
||||
audio: GardenAudioVibeSettings;
|
||||
}
|
||||
|
||||
export interface GardenAppConfig {
|
||||
|
|
@ -239,7 +249,7 @@ export interface GardenAppConfig {
|
|||
};
|
||||
};
|
||||
tuningPane: {
|
||||
expandedDepth: number;
|
||||
showFpsOverlay: boolean;
|
||||
startHidden: boolean;
|
||||
title: string;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,25 +1,15 @@
|
|||
import type { GardenAudioChord } from '../audio/garden-audio-config';
|
||||
import type { GardenAudioVibeSettings } from '../audio/garden-audio-config';
|
||||
import { colorInteractionSettings } from './color-interactions';
|
||||
import { VibeId, type VibePreset } from './types';
|
||||
|
||||
const majorProgression: Array<GardenAudioChord> = [
|
||||
{ rootOffset: 0, quality: 'major' },
|
||||
{ rootOffset: 9, quality: 'minor' },
|
||||
{ rootOffset: 5, quality: 'major' },
|
||||
{ rootOffset: 7, quality: 'major' },
|
||||
];
|
||||
|
||||
const minorProgression: Array<GardenAudioChord> = [
|
||||
{ rootOffset: 0, quality: 'minor' },
|
||||
{ rootOffset: 8, quality: 'major' },
|
||||
{ rootOffset: 3, quality: 'major' },
|
||||
{ rootOffset: 10, quality: 'major' },
|
||||
];
|
||||
|
||||
const majorPentatonic = [0, 2, 4, 7, 9];
|
||||
const suspendedPentatonic = [0, 2, 5, 7, 9];
|
||||
const mixolydianPentatonic = [0, 2, 4, 7, 10];
|
||||
const dorianHexatonic = [0, 2, 3, 5, 7, 10];
|
||||
const darkMinorPentatonic = [0, 2, 3, 7, 10];
|
||||
const defaultAudioSettings = {
|
||||
idleIntensity: 0.08,
|
||||
bpm: 74,
|
||||
rampUpIntensity: 0.85,
|
||||
rampUpTime: 0.08,
|
||||
noteLength: 0.42,
|
||||
notePitchOffset: 0,
|
||||
} satisfies Omit<GardenAudioVibeSettings, 'brightness'>;
|
||||
|
||||
export const defaultVibeId = VibeId.CandyRain;
|
||||
|
||||
|
|
@ -34,23 +24,22 @@ export const vibePresets: Array<VibePreset> = [
|
|||
],
|
||||
backgroundColor: [16, 21, 31],
|
||||
settings: {
|
||||
...colorInteractionSettings,
|
||||
backgroundGrainStrength: 0.018,
|
||||
brushSize: 14,
|
||||
brushSizeVariation: 0.5,
|
||||
clarity: 0.62,
|
||||
decayRateTrails: 965,
|
||||
diffusionRateTrails: 0.22,
|
||||
diffusionRateBrush: 0.35,
|
||||
individualTrailWeight: 0.07,
|
||||
moveSpeed: 82,
|
||||
sensorOffsetAngle: 34,
|
||||
sensorOffsetDistance: 38,
|
||||
spawnPerPixel: 0.22,
|
||||
turnSpeed: 58,
|
||||
},
|
||||
audio: {
|
||||
rootMidi: 57,
|
||||
scale: majorPentatonic,
|
||||
...defaultAudioSettings,
|
||||
brightness: 1.04,
|
||||
delayTimeMultiplier: 0.92,
|
||||
progression: majorProgression,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -63,28 +52,22 @@ export const vibePresets: Array<VibePreset> = [
|
|||
],
|
||||
backgroundColor: [23, 32, 22],
|
||||
settings: {
|
||||
...colorInteractionSettings,
|
||||
backgroundGrainStrength: 0.014,
|
||||
brushSize: 16,
|
||||
brushSizeVariation: 0.35,
|
||||
clarity: 0.68,
|
||||
decayRateTrails: 975,
|
||||
diffusionRateTrails: 0.18,
|
||||
diffusionRateBrush: 0.28,
|
||||
individualTrailWeight: 0.06,
|
||||
moveSpeed: 70,
|
||||
sensorOffsetAngle: 28,
|
||||
sensorOffsetDistance: 46,
|
||||
spawnPerPixel: 0.18,
|
||||
turnSpeed: 44,
|
||||
},
|
||||
audio: {
|
||||
rootMidi: 53,
|
||||
scale: mixolydianPentatonic,
|
||||
...defaultAudioSettings,
|
||||
brightness: 0.92,
|
||||
delayTimeMultiplier: 1.08,
|
||||
progression: [
|
||||
{ rootOffset: 0, quality: 'major' },
|
||||
{ rootOffset: 7, quality: 'major' },
|
||||
{ rootOffset: 9, quality: 'minor' },
|
||||
{ rootOffset: 5, quality: 'major' },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -97,23 +80,22 @@ export const vibePresets: Array<VibePreset> = [
|
|||
],
|
||||
backgroundColor: [15, 24, 34],
|
||||
settings: {
|
||||
...colorInteractionSettings,
|
||||
backgroundGrainStrength: 0.022,
|
||||
brushSize: 13,
|
||||
brushSizeVariation: 0.58,
|
||||
clarity: 0.58,
|
||||
decayRateTrails: 955,
|
||||
diffusionRateTrails: 0.28,
|
||||
diffusionRateBrush: 0.42,
|
||||
individualTrailWeight: 0.055,
|
||||
moveSpeed: 90,
|
||||
sensorOffsetAngle: 36,
|
||||
sensorOffsetDistance: 35,
|
||||
spawnPerPixel: 0.25,
|
||||
turnSpeed: 62,
|
||||
},
|
||||
audio: {
|
||||
rootMidi: 50,
|
||||
scale: dorianHexatonic,
|
||||
...defaultAudioSettings,
|
||||
brightness: 1,
|
||||
delayTimeMultiplier: 1.12,
|
||||
progression: minorProgression,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -126,23 +108,22 @@ export const vibePresets: Array<VibePreset> = [
|
|||
],
|
||||
backgroundColor: [20, 18, 29],
|
||||
settings: {
|
||||
...colorInteractionSettings,
|
||||
backgroundGrainStrength: 0.018,
|
||||
brushSize: 12,
|
||||
brushSizeVariation: 0.45,
|
||||
clarity: 0.64,
|
||||
decayRateTrails: 968,
|
||||
diffusionRateTrails: 0.2,
|
||||
diffusionRateBrush: 0.32,
|
||||
individualTrailWeight: 0.065,
|
||||
moveSpeed: 76,
|
||||
sensorOffsetAngle: 32,
|
||||
sensorOffsetDistance: 42,
|
||||
spawnPerPixel: 0.2,
|
||||
turnSpeed: 52,
|
||||
},
|
||||
audio: {
|
||||
rootMidi: 49,
|
||||
scale: darkMinorPentatonic,
|
||||
...defaultAudioSettings,
|
||||
brightness: 0.9,
|
||||
delayTimeMultiplier: 1.24,
|
||||
progression: minorProgression,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -155,23 +136,22 @@ export const vibePresets: Array<VibePreset> = [
|
|||
],
|
||||
backgroundColor: [25, 23, 22],
|
||||
settings: {
|
||||
...colorInteractionSettings,
|
||||
backgroundGrainStrength: 0.024,
|
||||
brushSize: 15,
|
||||
brushSizeVariation: 0.62,
|
||||
clarity: 0.55,
|
||||
decayRateTrails: 948,
|
||||
diffusionRateTrails: 0.32,
|
||||
diffusionRateBrush: 0.48,
|
||||
individualTrailWeight: 0.05,
|
||||
moveSpeed: 96,
|
||||
sensorOffsetAngle: 40,
|
||||
sensorOffsetDistance: 32,
|
||||
spawnPerPixel: 0.24,
|
||||
turnSpeed: 70,
|
||||
},
|
||||
audio: {
|
||||
rootMidi: 56,
|
||||
scale: majorPentatonic,
|
||||
...defaultAudioSettings,
|
||||
brightness: 1.08,
|
||||
delayTimeMultiplier: 0.86,
|
||||
progression: majorProgression,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -184,28 +164,22 @@ export const vibePresets: Array<VibePreset> = [
|
|||
],
|
||||
backgroundColor: [16, 24, 32],
|
||||
settings: {
|
||||
...colorInteractionSettings,
|
||||
backgroundGrainStrength: 0.012,
|
||||
brushSize: 18,
|
||||
brushSizeVariation: 0.28,
|
||||
clarity: 0.7,
|
||||
decayRateTrails: 982,
|
||||
diffusionRateTrails: 0.14,
|
||||
diffusionRateBrush: 0.24,
|
||||
individualTrailWeight: 0.075,
|
||||
moveSpeed: 62,
|
||||
sensorOffsetAngle: 26,
|
||||
sensorOffsetDistance: 52,
|
||||
spawnPerPixel: 0.16,
|
||||
turnSpeed: 40,
|
||||
},
|
||||
audio: {
|
||||
rootMidi: 62,
|
||||
scale: suspendedPentatonic,
|
||||
...defaultAudioSettings,
|
||||
brightness: 0.88,
|
||||
delayTimeMultiplier: 1.32,
|
||||
progression: [
|
||||
{ rootOffset: 0, quality: 'major' },
|
||||
{ rootOffset: 5, quality: 'major' },
|
||||
{ rootOffset: 9, quality: 'minor' },
|
||||
{ rootOffset: 7, quality: 'major' },
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ export class GameLoopResources {
|
|||
public readonly eraserAgentPipeline: EraserAgentPipeline;
|
||||
public readonly eraserTexturePipeline: EraserTexturePipeline;
|
||||
public readonly diffusionPipeline: DiffusionPipeline;
|
||||
public readonly brushEffectDiffusionPipeline: DiffusionPipeline;
|
||||
public readonly renderPipeline: RenderPipeline;
|
||||
|
||||
private readonly frameRenderer: SimulationFrameRenderer;
|
||||
|
|
@ -74,7 +73,6 @@ export class GameLoopResources {
|
|||
);
|
||||
this.eraserTexturePipeline = new EraserTexturePipeline(this.device, this.commonState);
|
||||
this.diffusionPipeline = new DiffusionPipeline(this.device);
|
||||
this.brushEffectDiffusionPipeline = new DiffusionPipeline(this.device);
|
||||
this.renderPipeline = new RenderPipeline(context, this.device, this.commonState);
|
||||
|
||||
this.frameRenderer = new SimulationFrameRenderer(this.device, this.textures, {
|
||||
|
|
@ -83,7 +81,6 @@ export class GameLoopResources {
|
|||
eraserAgentPipeline: this.eraserAgentPipeline,
|
||||
eraserTexturePipeline: this.eraserTexturePipeline,
|
||||
diffusionPipeline: this.diffusionPipeline,
|
||||
brushEffectDiffusionPipeline: this.brushEffectDiffusionPipeline,
|
||||
renderPipeline: this.renderPipeline,
|
||||
});
|
||||
}
|
||||
|
|
@ -94,6 +91,7 @@ export class GameLoopResources {
|
|||
|
||||
public clearSimulation(): void {
|
||||
this.textures.clear();
|
||||
this.frameRenderer.resetSourceMapActivity();
|
||||
}
|
||||
|
||||
public setFrameParameters({
|
||||
|
|
@ -115,6 +113,7 @@ export class GameLoopResources {
|
|||
this.agentPipeline.setParameters({
|
||||
...settings,
|
||||
deltaTime,
|
||||
time,
|
||||
agentCount: activeAgentCount,
|
||||
moveSpeed:
|
||||
settings.moveSpeed *
|
||||
|
|
@ -138,6 +137,7 @@ export class GameLoopResources {
|
|||
this.eraserAgentPipeline.setParameters({
|
||||
agentCount: activeAgentCount,
|
||||
eraserMaskAlphaThreshold: settings.eraserMaskAlphaThreshold,
|
||||
maskSize: canvasSize,
|
||||
});
|
||||
this.eraserTexturePipeline.setParameters({
|
||||
eraserSize: eraserPixelSize,
|
||||
|
|
@ -147,7 +147,6 @@ export class GameLoopResources {
|
|||
eraserClearBlue: settings.eraserClearBlue,
|
||||
eraserClearAlpha: settings.eraserClearAlpha,
|
||||
});
|
||||
this.setBrushEffectDiffusionParameters();
|
||||
}
|
||||
|
||||
public executeFrame(
|
||||
|
|
@ -164,20 +163,8 @@ export class GameLoopResources {
|
|||
this.eraserAgentPipeline.destroy();
|
||||
this.eraserTexturePipeline.destroy();
|
||||
this.diffusionPipeline.destroy();
|
||||
this.brushEffectDiffusionPipeline.destroy();
|
||||
this.renderPipeline.destroy();
|
||||
this.commonState.destroy();
|
||||
this.textures.destroy();
|
||||
}
|
||||
|
||||
private setBrushEffectDiffusionParameters(): void {
|
||||
const framesToOneE = Math.max(
|
||||
1,
|
||||
settings.brushEffectDuration * appConfig.simulation.brushEffectFramesPerSecond
|
||||
);
|
||||
this.brushEffectDiffusionPipeline.setParameters({
|
||||
...settings,
|
||||
decayRateTrails: Math.exp(-1 / framesToOneE) * 1000,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ export default class GameLoop {
|
|||
private readonly agentPopulation: AgentPopulation;
|
||||
private readonly exportSnapshotRenderer: ExportSnapshotRenderer;
|
||||
private readonly framePerformance = new FramePerformance();
|
||||
private readonly devStatsOverlay: DevStatsOverlay | null;
|
||||
private devStatsOverlay: DevStatsOverlay | null = null;
|
||||
private readonly toolbarContrastMonitor: ToolbarContrastMonitor;
|
||||
private readonly seedValue = Math.floor(Math.random() * 0xffffffff);
|
||||
private readonly seed = this.seedValue.toString(16);
|
||||
|
|
@ -47,9 +47,6 @@ export default class GameLoop {
|
|||
ui: GardenUi
|
||||
) {
|
||||
this.resize();
|
||||
this.devStatsOverlay = import.meta.env.DEV
|
||||
? new DevStatsOverlay(canvas.parentElement ?? document.body)
|
||||
: null;
|
||||
this.resources = new GameLoopResources(
|
||||
canvas,
|
||||
device,
|
||||
|
|
@ -103,8 +100,12 @@ export default class GameLoop {
|
|||
});
|
||||
|
||||
window.addEventListener('resize', this.resizeListener);
|
||||
this.pointerInput.attach();
|
||||
this.eraserPreviewController.attach();
|
||||
this.syncDevStatsOverlay();
|
||||
}
|
||||
|
||||
public attachPointerInput(): void {
|
||||
this.pointerInput.attach();
|
||||
}
|
||||
|
||||
public setEraseMode(isErasing: boolean): void {
|
||||
|
|
@ -118,6 +119,7 @@ export default class GameLoop {
|
|||
|
||||
public onVibeChanged(): void {
|
||||
this.agentPopulation.onVibeChanged();
|
||||
this.syncDevStatsOverlay();
|
||||
}
|
||||
|
||||
public setAudioMuted(isMuted: boolean): void {
|
||||
|
|
@ -153,6 +155,7 @@ export default class GameLoop {
|
|||
this.pointerInput.detach();
|
||||
this.eraserPreviewController.detach();
|
||||
this.devStatsOverlay?.destroy();
|
||||
this.devStatsOverlay = null;
|
||||
this.toolbarContrastMonitor.destroy();
|
||||
this.introPrompt.destroy();
|
||||
await this.agentPopulation.waitForCompaction();
|
||||
|
|
@ -220,6 +223,18 @@ export default class GameLoop {
|
|||
requestAnimationFrame(this.render);
|
||||
};
|
||||
|
||||
private syncDevStatsOverlay(): void {
|
||||
if (appConfig.tuningPane.showFpsOverlay) {
|
||||
this.devStatsOverlay ??= new DevStatsOverlay(
|
||||
this.canvas.parentElement ?? document.body
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
this.devStatsOverlay?.destroy();
|
||||
this.devStatsOverlay = null;
|
||||
}
|
||||
|
||||
private updateAccentColor(color: RgbColor): void {
|
||||
const accentColor = rgbColorToCss(color);
|
||||
if (this.previousAccentColor === accentColor) {
|
||||
|
|
|
|||
|
|
@ -13,17 +13,26 @@ interface SimulationFramePipelines {
|
|||
eraserAgentPipeline: EraserAgentPipeline;
|
||||
eraserTexturePipeline: EraserTexturePipeline;
|
||||
diffusionPipeline: DiffusionPipeline;
|
||||
brushEffectDiffusionPipeline: DiffusionPipeline;
|
||||
renderPipeline: RenderPipeline;
|
||||
}
|
||||
|
||||
export class SimulationFrameRenderer {
|
||||
private static readonly SOURCE_ACTIVE_FRAMES_AFTER_WRITE = 600;
|
||||
|
||||
private sourceActiveFramesRemaining = 0;
|
||||
private sourceMapsCleared = true;
|
||||
|
||||
public constructor(
|
||||
private readonly device: GPUDevice,
|
||||
private readonly textures: SimulationTextures,
|
||||
private readonly pipelines: SimulationFramePipelines
|
||||
) {}
|
||||
|
||||
public resetSourceMapActivity(): void {
|
||||
this.sourceActiveFramesRemaining = 0;
|
||||
this.sourceMapsCleared = true;
|
||||
}
|
||||
|
||||
public execute(
|
||||
isErasing: boolean,
|
||||
canvasReadbackRequest?: CanvasReadbackRequest | null
|
||||
|
|
@ -31,6 +40,7 @@ export class SimulationFrameRenderer {
|
|||
const commandEncoder = this.device.createCommandEncoder();
|
||||
|
||||
this.textures.copyTrailMapAToB(commandEncoder);
|
||||
let wroteSourceMap = false;
|
||||
if (isErasing) {
|
||||
if (this.pipelines.eraserAgentPipeline.hasActiveMask()) {
|
||||
const eraserMask = this.textures.eraserMask.getTextureView();
|
||||
|
|
@ -38,18 +48,29 @@ export class SimulationFrameRenderer {
|
|||
commandEncoder,
|
||||
eraserMask,
|
||||
this.textures.sourceMapA.getTextureView(),
|
||||
this.textures.influenceMapA.getTextureView(),
|
||||
this.textures.trailMapB.getTextureView()
|
||||
);
|
||||
this.pipelines.eraserAgentPipeline.execute(commandEncoder, eraserMask);
|
||||
}
|
||||
} else {
|
||||
this.pipelines.brushPipeline.executeMultiTarget(
|
||||
wroteSourceMap = this.pipelines.brushPipeline.executeMultiTarget(
|
||||
commandEncoder,
|
||||
this.textures.sourceMapA.getTextureView(),
|
||||
this.textures.influenceMapA.getTextureView()
|
||||
this.textures.sourceMapA.getTextureView()
|
||||
);
|
||||
}
|
||||
|
||||
if (wroteSourceMap) {
|
||||
this.sourceActiveFramesRemaining =
|
||||
SimulationFrameRenderer.SOURCE_ACTIVE_FRAMES_AFTER_WRITE;
|
||||
this.sourceMapsCleared = false;
|
||||
}
|
||||
|
||||
const useSourceMap = this.sourceActiveFramesRemaining > 0;
|
||||
if (!useSourceMap && !this.sourceMapsCleared) {
|
||||
this.textures.clearSourceMaps(commandEncoder);
|
||||
this.sourceMapsCleared = true;
|
||||
}
|
||||
|
||||
this.pipelines.agentPipeline.execute(
|
||||
commandEncoder,
|
||||
this.textures.trailMapA.getTextureView(),
|
||||
|
|
@ -64,28 +85,24 @@ export class SimulationFrameRenderer {
|
|||
const canvasTexture = this.pipelines.renderPipeline.execute(
|
||||
commandEncoder,
|
||||
this.textures.trailMapA.getTextureView(),
|
||||
this.textures.sourceMapA.getTextureView()
|
||||
this.textures.sourceMapA.getTextureView(),
|
||||
useSourceMap
|
||||
);
|
||||
canvasReadbackRequest?.encode(commandEncoder, canvasTexture);
|
||||
|
||||
if (useSourceMap) {
|
||||
this.pipelines.diffusionPipeline.execute(
|
||||
commandEncoder,
|
||||
this.textures.sourceMapA.getTextureView(),
|
||||
this.textures.sourceMapB.getTextureView(),
|
||||
this.textures.sourceMapB.getSize()
|
||||
);
|
||||
}
|
||||
this.device.queue.submit([commandEncoder.finish()]);
|
||||
canvasReadbackRequest?.afterSubmit();
|
||||
|
||||
const postRenderCommandEncoder = this.device.createCommandEncoder();
|
||||
this.pipelines.diffusionPipeline.execute(
|
||||
postRenderCommandEncoder,
|
||||
this.textures.sourceMapA.getTextureView(),
|
||||
this.textures.sourceMapB.getTextureView(),
|
||||
this.textures.sourceMapB.getSize()
|
||||
);
|
||||
this.pipelines.brushEffectDiffusionPipeline.execute(
|
||||
postRenderCommandEncoder,
|
||||
this.textures.influenceMapA.getTextureView(),
|
||||
this.textures.influenceMapB.getTextureView(),
|
||||
this.textures.influenceMapB.getSize()
|
||||
);
|
||||
|
||||
this.device.queue.submit([postRenderCommandEncoder.finish()]);
|
||||
this.textures.swapBrushEffectMaps();
|
||||
if (useSourceMap) {
|
||||
this.textures.swapSourceMaps();
|
||||
this.sourceActiveFramesRemaining -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ export class SimulationTextures {
|
|||
public readonly trailMapB: ResizableTexture;
|
||||
public sourceMapA: ResizableTexture;
|
||||
public sourceMapB: ResizableTexture;
|
||||
public influenceMapA: ResizableTexture;
|
||||
public influenceMapB: ResizableTexture;
|
||||
public eraserMask: ResizableTexture;
|
||||
|
||||
public constructor(
|
||||
|
|
@ -20,8 +18,6 @@ export class SimulationTextures {
|
|||
this.trailMapB = this.createTexture(canvasSize);
|
||||
this.sourceMapA = this.createTexture(canvasSize);
|
||||
this.sourceMapB = this.createTexture(canvasSize);
|
||||
this.influenceMapA = this.createTexture(canvasSize);
|
||||
this.influenceMapB = this.createTexture(canvasSize);
|
||||
this.eraserMask = this.createEraserMask(canvasSize);
|
||||
}
|
||||
|
||||
|
|
@ -36,8 +32,6 @@ export class SimulationTextures {
|
|||
this.trailMapB.resize(nextSize);
|
||||
this.sourceMapA.resize(nextSize);
|
||||
this.sourceMapB.resize(nextSize);
|
||||
this.influenceMapA.resize(nextSize);
|
||||
this.influenceMapB.resize(nextSize);
|
||||
this.eraserMask.resize(nextSize);
|
||||
|
||||
return scale;
|
||||
|
|
@ -50,8 +44,6 @@ export class SimulationTextures {
|
|||
this.trailMapB,
|
||||
this.sourceMapA,
|
||||
this.sourceMapB,
|
||||
this.influenceMapA,
|
||||
this.influenceMapB,
|
||||
this.eraserMask,
|
||||
].forEach((texture) => {
|
||||
const passEncoder = commandEncoder.beginRenderPass({
|
||||
|
|
@ -79,9 +71,20 @@ export class SimulationTextures {
|
|||
);
|
||||
}
|
||||
|
||||
public swapBrushEffectMaps(): void {
|
||||
public clearSourceMaps(commandEncoder: GPUCommandEncoder): void {
|
||||
const passEncoder = commandEncoder.beginRenderPass({
|
||||
colorAttachments: [this.sourceMapA, this.sourceMapB].map((texture) => ({
|
||||
view: texture.getTextureView(),
|
||||
clearValue: appConfig.simulation.clearColor,
|
||||
loadOp: 'clear',
|
||||
storeOp: 'store',
|
||||
})),
|
||||
});
|
||||
passEncoder.end();
|
||||
}
|
||||
|
||||
public swapSourceMaps(): void {
|
||||
[this.sourceMapA, this.sourceMapB] = [this.sourceMapB, this.sourceMapA];
|
||||
[this.influenceMapA, this.influenceMapB] = [this.influenceMapB, this.influenceMapA];
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
|
|
@ -89,8 +92,6 @@ export class SimulationTextures {
|
|||
this.trailMapB.destroy();
|
||||
this.sourceMapA.destroy();
|
||||
this.sourceMapB.destroy();
|
||||
this.influenceMapA.destroy();
|
||||
this.influenceMapB.destroy();
|
||||
this.eraserMask.destroy();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ const getRelativeLuminance = (red: number, green: number, blue: number): number
|
|||
appConfig.toolbar.contrast.luminanceGreenWeight * getLinearChannel(green) +
|
||||
appConfig.toolbar.contrast.luminanceBlueWeight * getLinearChannel(blue);
|
||||
|
||||
export const getToolbarContrastMetrics = (
|
||||
const getToolbarContrastMetrics = (
|
||||
pixels: Uint8Array,
|
||||
sampleCount: number,
|
||||
isBgra: boolean
|
||||
|
|
|
|||
29
src/index.ts
29
src/index.ts
|
|
@ -16,7 +16,7 @@ import { CollapsiblePanelAnimator } from './page/collapsible-panel-animator';
|
|||
import { ConfigPane } from './page/config-pane';
|
||||
import { FullScreenHandler } from './page/full-screen-handler';
|
||||
import { MenuHider } from './page/menu-hider';
|
||||
import { activeVibe, applyVibeSettings, resetSettings, settings } from './settings';
|
||||
import { activeVibe, applyVibeSettings, settings } from './settings';
|
||||
import { readBrowserStorage, writeBrowserStorage } from './utils/browser-storage';
|
||||
import { DeltaTimeCalculator } from './utils/delta-time-calculator';
|
||||
import { queryRequiredElement, queryRequiredElements } from './utils/dom';
|
||||
|
|
@ -148,7 +148,6 @@ const LOADING_MESSAGES = {
|
|||
const VIBE_CHANGE_SOURCES = {
|
||||
nextButton: 'next-button',
|
||||
previousButton: 'previous-button',
|
||||
settings: 'settings',
|
||||
} as const;
|
||||
|
||||
const clampEraserSize = (value: number): number => {
|
||||
|
|
@ -432,6 +431,7 @@ const main = async () => {
|
|||
initAnalytics();
|
||||
|
||||
let shouldStop = false;
|
||||
let hasStarted = false;
|
||||
let game: GameLoop | null = null;
|
||||
let configPane: ConfigPane | null = null;
|
||||
|
||||
|
|
@ -477,6 +477,7 @@ const main = async () => {
|
|||
|
||||
const startAudioFromUserGesture = (event: Event) => {
|
||||
if (
|
||||
!hasStarted ||
|
||||
isAudioMuted ||
|
||||
(event.target instanceof Node && elements.startButton.contains(event.target)) ||
|
||||
(event.target instanceof Node && elements.soundButton.contains(event.target))
|
||||
|
|
@ -652,28 +653,6 @@ const main = async () => {
|
|||
},
|
||||
onOpenChange: () => undefined,
|
||||
onRuntimeChange: syncRuntimeUi,
|
||||
onRuntimeReset: () => {
|
||||
resetSettings();
|
||||
game?.onVibeChanged();
|
||||
syncRuntimeUi();
|
||||
},
|
||||
onRestart: () => game?.destroy(),
|
||||
onVibeChange: (vibeId) => {
|
||||
const vibe = VIBE_PRESETS.find((candidate) => candidate.id === vibeId);
|
||||
if (!vibe) {
|
||||
return;
|
||||
}
|
||||
|
||||
const activePreset = applyVibeSettings(vibe);
|
||||
trackVibeChange({
|
||||
vibeId: activePreset.id,
|
||||
vibeName: activePreset.name,
|
||||
source: VIBE_CHANGE_SOURCES.settings,
|
||||
});
|
||||
game?.onVibeChanged();
|
||||
syncRuntimeUi();
|
||||
game?.playVibeChangeAudio(false);
|
||||
},
|
||||
});
|
||||
infoPageHandler.onOpen = configPane.close.bind(configPane);
|
||||
await fontsReady;
|
||||
|
|
@ -702,6 +681,7 @@ const main = async () => {
|
|||
await new Promise<void>((resolve) => {
|
||||
const onClick = () => {
|
||||
elements.startButton.removeEventListener(DOM_EVENTS.click, onClick);
|
||||
hasStarted = true;
|
||||
game?.startAudio(true);
|
||||
trackStart();
|
||||
elements.splash.hidden = true;
|
||||
|
|
@ -731,6 +711,7 @@ const main = async () => {
|
|||
)
|
||||
);
|
||||
}
|
||||
game.attachPointerInput();
|
||||
await game.start();
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue