Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sample view height #16

Merged
merged 2 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions src/components/SampleControls/SampleControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,21 @@ export const SampleControls: Component = () => {
</div>
</div>

<div class="px-1 pb-2">
<SampleView model={selected()} />
<div class="flex pt-2">
<Knob
value={selected().playbackRate}
updateFunc={(value: number) =>
mutateSelected((sampler) => {
sampler.playbackRate = value;
})
}
defaultValue={1}
min={0.01}
max={2.0}
size={50}
label="Playback Speed"
/>
</div>
<SampleView model={selected()} />
<div class="flex flex-auto align-items-end py-2">
<Knob
value={selected().playbackRate}
updateFunc={(value: number) =>
mutateSelected((sampler) => {
sampler.playbackRate = value;
})
}
defaultValue={1}
min={0.01}
max={2.0}
size={50}
label="Playback Speed"
/>
</div>
</div>
);
Expand Down
11 changes: 7 additions & 4 deletions src/components/SampleView/SampleView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ type SampleViewProps = {
* @returns
*/
export const SampleView: Component<SampleViewProps> = (props) => {
let divRef: HTMLDivElement | undefined;
let svgRef: SVGSVGElement | undefined;

// Container element size to set SVG size
const size = createElementSize(() => divRef);

// TODO: Waveform Pan/Zoom
const camera = (): Camera2D => ({
pan: { x: 0, y: 0 },
zoom: { x: 1, y: 1 },
Expand All @@ -131,9 +137,6 @@ export const SampleView: Component<SampleViewProps> = (props) => {
fetchAudioBuffer,
);

// SVG element size
const size = createElementSize(() => svgRef);

// Waveform zero crossing point
const y0 = (): number => (size.height || 0) / 2;

Expand Down Expand Up @@ -189,7 +192,7 @@ export const SampleView: Component<SampleViewProps> = (props) => {
});

return (
<SampleDropzone class={`${style.sampleView} overflow-hidden`}>
<SampleDropzone ref={divRef!} class={`${style.sampleView} overflow-hidden`}>
<svg
ref={svgRef!}
class="w-full h-full"
Expand Down