Skip to content

Commit

Permalink
feat: redesign the metronome page
Browse files Browse the repository at this point in the history
  • Loading branch information
threedalpeng committed Feb 26, 2024
1 parent bbac66b commit 7c31cd4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/lib/device/metronome/MetronomeBeats.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<div
{...$$restProps}
class="{$$props.class} relative flex w-5/6 flex-row flex-wrap items-center justify-center gap-[40px]"
class="{$$props.class} relative flex w-screen flex-row flex-wrap items-center justify-center gap-[40px]"
>
{#each new Array(beatPerBar) as _, i}
{#if i === 0}
Expand Down
35 changes: 35 additions & 0 deletions src/lib/device/metronome/MetronomePlayButton.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<script lang="ts">
import { getMetronomeContext } from '$/lib/device/metronome/context';
import { Play, Stop } from '@steeze-ui/heroicons';
import { Icon } from '@steeze-ui/svelte-icon';
import { onDestroy } from 'svelte';
const metronome = getMetronomeContext();
metronome.schedule();
let isRunning = false;
const cancelStart = metronome.timer.onStart(() => {
isRunning = true;
});
const cancelStop = metronome.timer.onStop(() => {
isRunning = false;
});
onDestroy(() => {
cancelStart();
cancelStop();
});
</script>

<button
{...$$restProps}
class="{$$props.class} flex aspect-square items-center justify-center rounded-full bg-indigo-900 p-0 focus:outline-none"
on:click={() => {
metronome.timer.toggle();
}}
>
{#if isRunning}
<Icon class="m-0 h-1/2 p-0 text-indigo-100" src={Stop} theme="solid" />
{:else}
<Icon class="m-0 h-1/2 p-0 text-indigo-100" src={Play} theme="solid" />
{/if}
</button>
1 change: 1 addition & 0 deletions src/lib/device/metronome/metronome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Metronome {
}

destroy() {
this.removeSchedule();
this.clearDerivedSchedule();
}
}
Expand Down
35 changes: 3 additions & 32 deletions src/routes/tools/metronome/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
<script lang="ts">
import MetronomeBeats from '$/lib/device/metronome/MetronomeBeats.svelte';
import MetronomeOptions from '$/lib/device/metronome/MetronomeOptions.svelte';
import { getMetronomeContext } from '$/lib/device/metronome/context';
import { Play, Stop } from '@steeze-ui/heroicons';
import { Icon } from '@steeze-ui/svelte-icon';
import { onDestroy } from 'svelte';
const metronome = getMetronomeContext();
metronome.schedule();
let isRunning = false;
const cancelStart = metronome.timer.onStart(() => {
isRunning = true;
});
const cancelStop = metronome.timer.onStop(() => {
isRunning = false;
});
onDestroy(() => {
cancelStart();
cancelStop();
});
import MetronomePlayButton from '$/lib/device/metronome/MetronomePlayButton.svelte';
</script>

<div class="h-full w-screen">
Expand All @@ -28,21 +10,10 @@
<div class="ml-4 flex h-full flex-row items-start justify-between gap-4">
<MetronomeOptions />
</div>
<button
class="mr-8 flex aspect-square h-3/4 items-center justify-center rounded-full bg-indigo-900 p-0 focus:outline-none"
on:click={() => {
metronome.timer.toggle();
}}
>
{#if isRunning}
<Icon class="m-0 h-[20px] w-[20px] p-0 text-indigo-100" src={Stop} theme="solid" />
{:else}
<Icon class="m-0 h-[20px] w-[20px] p-0 text-indigo-100" src={Play} theme="solid" />
{/if}
</button>
</div>
<div class="relative flex h-full flex-col items-center justify-center">
<MetronomeBeats />
<MetronomeBeats class="p-20" />
<MetronomePlayButton class="h-20" />
</div>
</div>
</div>

0 comments on commit 7c31cd4

Please sign in to comment.