diff --git a/templates/.dir-locals.el b/templates/.dir-locals.el new file mode 100644 index 0000000..d559d6b --- /dev/null +++ b/templates/.dir-locals.el @@ -0,0 +1,4 @@ +((nil . ((indent-tabs-mode . nil) + (tab-width . 4) + (fill-column . 80) + (projectile-project-run-cmd . "cd templates && parcel serve --no-autoinstall")))) diff --git a/templates/src/music/features/visualizer/Renderer.ts b/templates/src/music/features/visualizer/Renderer.ts index 4287b4e..cf67934 100644 --- a/templates/src/music/features/visualizer/Renderer.ts +++ b/templates/src/music/features/visualizer/Renderer.ts @@ -84,8 +84,16 @@ class Renderer { this.canvas.parentElement.getBoundingClientRect()); } - this.canvas.width = width; - this.canvas.height = height; + // Preserve the aspect ratio + const aspect_ratio = (this.analyser.frequencyBinCount * 2) / 512; + const target_height = width / aspect_ratio; + if (target_height > height) { + this.canvas.width = aspect_ratio * height; + this.canvas.height = height; + } else { + this.canvas.width = width; + this.canvas.height = width / aspect_ratio; + } gl.viewport(0, 0, this.canvas.clientWidth, this.canvas.clientHeight); this.updateProjection(gl, shader); @@ -230,12 +238,8 @@ class Renderer { this.rotation += (this.dTime / 1000.0) * ROTATION_SPEED; const modelViewMatrix = mat4.create(); - mat4.translate(modelViewMatrix, modelViewMatrix, [ - 0.0, - 0.025, - -((this.analyser.frequencyBinCount / gl.canvas.clientWidth) * 3), - ]); - mat4.rotateX(modelViewMatrix, modelViewMatrix, Math.PI / 16); + mat4.translate(modelViewMatrix, modelViewMatrix, [0.0, 0.0, -0.8]); + mat4.rotateX(modelViewMatrix, modelViewMatrix, Math.PI / 32); mat4.rotateY(modelViewMatrix, modelViewMatrix, this.rotation); mat4.translate(modelViewMatrix, modelViewMatrix, [-1.0, 0.0, 0.0]); gl.uniformMatrix4fv( diff --git a/templates/src/music/features/visualizer/Visualizer.tsx b/templates/src/music/features/visualizer/Visualizer.tsx index 9e51bc0..3a991df 100644 --- a/templates/src/music/features/visualizer/Visualizer.tsx +++ b/templates/src/music/features/visualizer/Visualizer.tsx @@ -1,6 +1,7 @@ import React, { useCallback, useState } from "react"; import { Renderer, RendererError } from "./Renderer"; import { ShaderError } from "./Shader"; +import classNames from "classnames"; import { useAppSelector } from "../../hooks"; import { PlayState, musicPlayer } from "../musicplayer/musicPlayerSlice"; @@ -125,7 +126,14 @@ function Visualizer() { return (