Skip to content

Commit

Permalink
Fix colors in music editor instrument/waveform previews
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaltby committed Mar 18, 2024
1 parent 5ed7e70 commit f1d184c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
9 changes: 5 additions & 4 deletions src/components/music/InstrumentVolumeEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useRef } from "react";
import React, { useContext, useEffect, useRef } from "react";
import l10n from "shared/lib/lang/l10n";
import { ThemeContext } from "styled-components";
import { FormRow } from "ui/form/FormLayout";
import { SliderField } from "ui/form/SliderField";

Expand All @@ -24,6 +25,8 @@ export const InstrumentVolumeEditor = ({
onChange,
}: InstrumentVolumeEditorProps) => {
const canvasRef = useRef<HTMLCanvasElement>(null);
const themeContext = useContext(ThemeContext);

useEffect(() => {
const canvas = canvasRef.current;
if (!canvas) {
Expand All @@ -37,9 +40,7 @@ export const InstrumentVolumeEditor = ({
const normalisedVolume = initialVolume / 15;
const secLength = length === null ? 1 : length / 256;

const defaultColor = getComputedStyle(
document.documentElement
).getPropertyValue("--highlight-color");
const defaultColor = themeContext.colors.highlight;

// eslint-disable-next-line no-self-assign
canvas.width = canvas.width;
Expand Down
9 changes: 5 additions & 4 deletions src/components/music/NoiseMacroEditorForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect, useRef } from "react";
import React, { useContext, useEffect, useRef } from "react";
import { ThemeContext } from "styled-components";
import { FormRow } from "ui/form/FormLayout";

interface NoiseMacroEditorFormProps {
Expand All @@ -11,6 +12,8 @@ export const NoiseMacroEditorForm = ({
onChange,
}: NoiseMacroEditorFormProps) => {
const canvasRef = useRef<HTMLCanvasElement>(null);
const themeContext = useContext(ThemeContext);

useEffect(() => {
const canvas = canvasRef.current;
if (!canvas) {
Expand All @@ -21,9 +24,7 @@ export const NoiseMacroEditorForm = ({
const drawHeight = canvas.height - 10;
const ctx = canvas.getContext("2d");

const defaultColor = getComputedStyle(
document.documentElement
).getPropertyValue("--highlight-color");
const defaultColor = themeContext.colors.highlight;

// eslint-disable-next-line no-self-assign
canvas.width = canvas.width;
Expand Down
9 changes: 5 additions & 4 deletions src/components/music/VibratoWaveformPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from "react";
import React, { useContext } from "react";
import { ThemeContext } from "styled-components";

interface VibratoWaveformPreviewProps {
waveform: string;
}
export const VibratoWaveformPreview = ({
waveform,
}: VibratoWaveformPreviewProps) => {
const themeContext = useContext(ThemeContext);

let path = "";

[...waveform].forEach((l: string, i: number) => {
Expand All @@ -14,9 +17,7 @@ export const VibratoWaveformPreview = ({
} `;
});

const defaultColor = getComputedStyle(
document.documentElement
).getPropertyValue("--highlight-color");
const defaultColor = themeContext.colors.highlight;

return (
<div style={{ height: 20 }}>
Expand Down
8 changes: 4 additions & 4 deletions src/components/music/WaveEditorForm.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useEffect, useRef } from "react";
import React, { useContext, useEffect, useRef } from "react";
import { useAppDispatch, useAppSelector } from "store/hooks";
import { Select } from "ui/form/Select";
import l10n from "shared/lib/lang/l10n";
import trackerDocumentActions from "store/features/trackerDocument/trackerDocumentActions";
import { FormRow, FormField } from "ui/form/FormLayout";
import { ThemeContext } from "styled-components";

interface WaveEditorFormProps {
waveId: number;
Expand All @@ -14,6 +15,7 @@ export const WaveEditorForm = ({ waveId, onChange }: WaveEditorFormProps) => {
const dispatch = useAppDispatch();

const song = useAppSelector((state) => state.trackerDocument.present.song);
const themeContext = useContext(ThemeContext);

const waveOptions = song?.waves.map((wave: Uint8Array, i: number) => ({
value: i,
Expand Down Expand Up @@ -47,9 +49,7 @@ export const WaveEditorForm = ({ waveId, onChange }: WaveEditorFormProps) => {

const ctx = canvas.getContext("2d");

const defaultColor = getComputedStyle(
document.documentElement
).getPropertyValue("--highlight-color");
const defaultColor = themeContext.colors.highlight;

// eslint-disable-next-line no-self-assign
canvas.width = canvas.width;
Expand Down

0 comments on commit f1d184c

Please sign in to comment.