From a85adb05922b47e3e10625a2d2956a8c6e9a3693 Mon Sep 17 00:00:00 2001 From: Cerys Date: Tue, 28 Jan 2025 18:26:36 +0000 Subject: [PATCH] quick and dirty abc render in the tune search --- App/Dataclasses/DatabaseFolkTuneDetails.php | 14 +++++ Public/API/V1/GetABCFile.php | 3 +- Public/API/V1/GetBasicABC.php | 53 ------------------- Public/API/V1/GetBasicABCFile.php | 46 ++++++++++++++++ .../Static/JS/General/AlgoliaInteractions.js | 46 ++++++++++++++-- Templates/Pages/tune/uuid.html.twig | 4 +- Templates/Pages/tunes.html.twig | 2 + 7 files changed, 105 insertions(+), 63 deletions(-) delete mode 100644 Public/API/V1/GetBasicABC.php create mode 100644 Public/API/V1/GetBasicABCFile.php diff --git a/App/Dataclasses/DatabaseFolkTuneDetails.php b/App/Dataclasses/DatabaseFolkTuneDetails.php index 4c47b3f..bfb28db 100644 --- a/App/Dataclasses/DatabaseFolkTuneDetails.php +++ b/App/Dataclasses/DatabaseFolkTuneDetails.php @@ -62,4 +62,18 @@ K: {$this->Parts[$counter]->KeySignature}"; } return $builder; } + + public function BuildSimple(): string + { + $builder = "X: {$this->ID} +L: 1/4"; + + $builder .= " +M: {$this->Parts[0]->TimeSignature}"; + $previousTimeSignature = $this->Parts[0]->TimeSignature; + + $builder .= " +{$this->Parts[0]->ABCNotation}"; + return $builder; + } } \ No newline at end of file diff --git a/Public/API/V1/GetABCFile.php b/Public/API/V1/GetABCFile.php index 0c951aa..d3a77df 100644 --- a/Public/API/V1/GetABCFile.php +++ b/Public/API/V1/GetABCFile.php @@ -1,14 +1,13 @@ RunOneSelect( - queryBuilder: SQLQueryBuilderWrapper::SELECT_ONE( - table: 'TuneVariants', - id: $targetTuneVariantID - ) - ->cols([ - 'T.ID AS TuneVariantID', - 'T.TuneID AS TuneID', - "CONCAT('[', GROUP_CONCAT( - CONCAT( - '{\"TimeSignature\":', JSON_QUOTE(T_TVP.TimeSignature), ',', - '\"KeySignature\":', JSON_QUOTE(T_TVP.KeySignature), ',', - '\"ABCNotation\":', JSON_QUOTE(T_TVP.ABCNotation), '}' - ) - ), ']') AS Parts" - ]) - ->join( - join: 'INNER', - spec: 'TuneVariantParts AS T_TVP', - cond: 'T.ID = T_TVP.TuneVariantID' - ) - ->groupBy(spec: [ - 'T.ID', - ]) -); - -$tuneDetails = $db->RunOneSelect( - queryBuilder: SQLQueryBuilderWrapper::SELECT_ONE( - table: 'Tunes', - id: $variantDetails['TuneID'] - ) -); - - -$tuneDetails = new DatabaseFolkTuneDetails($tuneDetails); -$variantDetails = new TuneVariant($tuneDetails, $variantDetails); - - -header(header: "Content-type: text/text"); -echo $variantDetails->Build(); -die(); diff --git a/Public/API/V1/GetBasicABCFile.php b/Public/API/V1/GetBasicABCFile.php new file mode 100644 index 0000000..c8a0b74 --- /dev/null +++ b/Public/API/V1/GetBasicABCFile.php @@ -0,0 +1,46 @@ +RunOneSelect( + queryBuilder: SQLQueryBuilderWrapper::SELECT_ONE( + table: 'Tunes', + id: $targetTuneVariantID + ) + ->cols([ + 'T.ID AS TuneID', + "CONCAT('[', GROUP_CONCAT( + CONCAT( + '{\"TimeSignature\":', JSON_QUOTE(T_TP.TimeSignature), ',', + '\"KeySignature\":', JSON_QUOTE(T_TP.KeySignature), ',', + '\"PartLetter\":', JSON_QUOTE(T_TP.PartLetter), ',', + '\"ABCNotation\":', JSON_QUOTE(T_TP.ABCNotation), '}' + ) + ), ']') AS Parts" + ]) + ->join( + join: 'INNER', + spec: 'TuneParts AS T_TP', + cond: 'T.ID = T_TP.TuneID' + ) + ->groupBy(spec: [ + 'T.ID', + ]) +); + + +$tuneDetails = new DatabaseFolkTuneDetails($tuneDetails); + + +header(header: "Content-type: text/text"); +echo $tuneDetails->BuildSimple(); +die(); diff --git a/Public/Static/JS/General/AlgoliaInteractions.js b/Public/Static/JS/General/AlgoliaInteractions.js index 1617de3..e910044 100644 --- a/Public/Static/JS/General/AlgoliaInteractions.js +++ b/Public/Static/JS/General/AlgoliaInteractions.js @@ -1,6 +1,45 @@ + +function renderABCPartA(targetTuneID) +{ + console.log(targetTuneID); + API_GET_TEXT("/V1/GetBasicABCFile.php?tune-id=" + targetTuneID) + .then(payload => { + // Ensure required DOM elements exist + const notationContainer = document.getElementById("NotationContainer--" + targetTuneID); + + if (!notationContainer) { + console.error(`Missing DOM elements for targetTuneID: ${targetTuneID}`); + return; + } + + // Render the ABC notation + const tunes = window.ABCJS.renderAbc( + notationContainer.id, + payload, + { + add_classes: true, + format: { + gchordfont: "Atkinson Hyperlegible", + annotationfont: "Atkinson Hyperlegible", + headerfont: "Atkinson Hyperlegible", + infofont: "Atkinson Hyperlegible", + repeatfont: "Atkinson Hyperlegible", + tempofont: "Atkinson Hyperlegible", + titlefont: "Atkinson Hyperlegible", + voicefont: "Atkinson Hyperlegible", + wordsfont: "Atkinson Hyperlegible", + }, + } + ); + }) + .catch(error => { + console.error("Error fetching ABC data:", error); + }); +} + function searchTunes(query) { const resultsDiv = document.getElementById("AlgoliaResults"); @@ -15,12 +54,11 @@ function searchTunes(query) {

${hit.title}

time signature: ${hit.time_sig}
key signature: ${hit.key_sig}
-
- - +
`; resultsDiv.appendChild(tuneDiv); + renderABCPartA(hit.objectID); }); } else { resultsDiv.innerHTML = "

No tunes found. Try a different search!

"; @@ -30,5 +68,3 @@ function searchTunes(query) { resultsDiv.innerHTML = "

An error occurred. Please try again later.

"; }); } - - diff --git a/Templates/Pages/tune/uuid.html.twig b/Templates/Pages/tune/uuid.html.twig index ccfdf0b..341d1ac 100644 --- a/Templates/Pages/tune/uuid.html.twig +++ b/Templates/Pages/tune/uuid.html.twig @@ -105,7 +105,7 @@

Folk Tune Search