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

Add project for guitar fingerings #358

Merged
merged 1 commit into from
Mar 4, 2024
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
195 changes: 195 additions & 0 deletions src/components/lib/GuitarFingering.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<script>
import { onMount } from "svelte";
import data from "./fingering.json";

// Mock data for chord fingerings. In a real application, you would fetch this from a database or API.
const chordData = data.EADGBE;
const notes = [
"A",
"A#",
"Bb",
"B",
"C",
"C#",
"Db",
"D",
"D#",
"Eb",
"E",
"F",
"F#",
"Gb",
"G",
"G#",
"Ab",
];
const options = [
"",
"+",
"+7",
"+7",
"+7b9",
"+9",
"11",
"13",
"13sus4",
"5",
"6",
"7",
"7b5",
"7b5",
"7b9",
"7sus2",
"7sus4",
"9",
"9b5",
"9sus4",
"add9",
"aug",
"dim",
"dim7",
"m",
"m11",
"m13",
"m6",
"m7",
"m7b5",
"m9",
"m9b5",
"madd9",
"Maj13",
"Maj7",
"Maj9",
"mb6",
"mMaj7",
"mMaj9",
"sus2",
"sus4",
];

// let chords = Object.keys(chordData);
// let search = "";
// let suggestions = [];

let selectedNote = "";
let selectedOption = "";
// let selectedChord = null;
let fingerings = [];

// function onChange(event) {
// selectedNote = event.currentTarget.value;
// console.log("selectedNote", selectedNote);

// const chord = `${selectedNote}`;
// selectedChord = chordData?.[chord];
// // fingerings = selectedChord.map((fingering) => fingering.p);
// }

// const selectChord = (chordName) => {
// search = chordName;
// selectedChord = chordData[chordName];
// };

$: selectedPositionsAndFingerings =
chordData?.[`${selectedNote}${selectedOption}`];
// $: fingerings = Array.isArray(selectedPositionsAndFingerings)
// ? selectedPositionsAndFingerings.map((fingering) => fingering?.f)
// : [];
// $: frets = Array.isArray(selectedPositionsAndFingerings)
// ? selectedPositionsAndFingerings.map((fingering) => fingering?.p)
// : [];

onMount(() => {
searchChords();
});
</script>

<div class="grid grid-cols-6 gap-4">
{#each notes as note}
<div
class="span-col-1 flex items-center ps-4 border border-gray-200 rounded dark:border-gray-700"
>
<input
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"
id={`note-${note}`}
type="radio"
name="note"
bind:group={selectedNote}
value={note}
/>
<label
class="w-full py-4 ms-2 text-md font-medium text-gray-900 dark:text-gray-300"
for={`note-${note}`}
>
{note}
</label>
</div>
{/each}
</div>

<hr class="my-4" />

<details>
<summary>Options</summary>

<div class="grid grid-cols-6 gap-8">
{#each options as option}
<div
class="span-col-1 flex items-center ps-4 border border-gray-200 rounded dark:border-gray-700"
>
<input
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"
id={`option-${option}`}
type="radio"
name="option"
bind:group={selectedOption}
value={option}
/>
<label
class="w-full py-4 ms-2 text-md font-medium text-gray-900 dark:text-gray-300"
for={`option-${option}`}
>
{option}
</label>
</div>
{/each}
</div>
</details>

<hr class="my-4" />

<p class="text-2xl mb-4">Selected Chord: {selectedNote}{selectedOption}</p>

{#if selectedPositionsAndFingerings}
<table>
<thead>
<tr>
<th class="px-4">Fingers</th>
<th class="px-4">Frets</th>
</tr>
</thead>
<tbody>
{#each selectedPositionsAndFingerings as selectedPositionAndFingering}
<tr class="border-2 border-zinc-800 dark:border-zinc-200">
<td class="px-4">{selectedPositionAndFingering.f}</td>
<td class="px-4">{selectedPositionAndFingering.p}</td>
</tr>
{/each}
</tbody>
</table>
{/if}

<!-- {#if selectedChord}
<div>
<p class="fingering">Main fingering: {selectedChord?.[0].join(" ")}</p>
<p>Alternative fingerings:</p>
<ul>
{#each selectedChord.alternatives as alternative}
<li class="fingering">{alternative.join(" ")}</li>
{/each}
</ul>
</div>
{/if} -->

<style>
</style>
Loading