4 changed files with 79 additions and 50 deletions
@ -1,50 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Dataclasses; |
|||
|
|||
class ABCWrapper |
|||
{ |
|||
public string $ID; |
|||
public string $Title; |
|||
|
|||
public string $Source; |
|||
|
|||
public string $TimeSignature; |
|||
public string $KeySignature; |
|||
|
|||
public string $DefaultNoteLength = "1/8"; |
|||
|
|||
public array $Parts; |
|||
|
|||
|
|||
public function __construct(array $assocArray) |
|||
{ |
|||
$this->ID = $assocArray['ID']; |
|||
$this->Title = $assocArray['Title']; |
|||
$this->Source = $assocArray['Copyright']; |
|||
$this->TimeSignature = $assocArray['TimeSignature']; |
|||
$this->KeySignature = $assocArray['KeySignature']; |
|||
$this->Parts = json_decode($assocArray['Parts'], true); |
|||
} |
|||
|
|||
|
|||
public function Build(): string |
|||
{ |
|||
$builder = "X: {$this->ID} |
|||
T: {$this->Title} |
|||
S: {$this->Source} |
|||
M: {$this->TimeSignature} |
|||
K: {$this->KeySignature} |
|||
L: {$this->DefaultNoteLength}"; |
|||
$counter = 0; |
|||
$letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']; |
|||
foreach($this->Parts as $part) |
|||
{ |
|||
$builder .= " |
|||
P: {$letters[$counter]} Part |
|||
{$part}"; |
|||
$counter = $counter + 1; |
|||
} |
|||
return $builder; |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
<?php |
|||
|
|||
namespace App\Dataclasses; |
|||
|
|||
class DatabaseFolkTuneDetails |
|||
{ |
|||
public string $ID; |
|||
public string $Title; |
|||
|
|||
public string $Copyright; |
|||
|
|||
public array $Variants; |
|||
|
|||
|
|||
public function __construct(array $assocArray) |
|||
{ |
|||
$this->ID = $assocArray['ID']; |
|||
$this->Title = $assocArray['Title']; |
|||
$this->Copyright = $assocArray['Copyright']; |
|||
} |
|||
} |
@ -0,0 +1,41 @@ |
|||
<?php |
|||
|
|||
namespace App\Dataclasses; |
|||
|
|||
class TuneVariant |
|||
{ |
|||
private DatabaseFolkTuneDetails $Tune; |
|||
public string $ID; |
|||
public array $Parts; |
|||
|
|||
public function __construct(DatabaseFolkTuneDetails $tuneDetails, array $assocArray) |
|||
{ |
|||
$this->ID = $assocArray['ID']; |
|||
$this->Tune = $tuneDetails; |
|||
|
|||
$temp = json_decode($assocArray['Parts'], associative: true, flags: JSON_THROW_ON_ERROR); |
|||
foreach($temp as $part) |
|||
$this->Parts[] = new TuneVariantPart($part); |
|||
} |
|||
|
|||
|
|||
public function Build(): string |
|||
{ |
|||
$builder = "X: {$this->Tune->ID}.{$this->ID} |
|||
T: {$this->Tune->Title} |
|||
S: {$this->Tune->Copyright} |
|||
M: {$this->Parts[0]->TimeSignature} |
|||
K: {$this->Parts[0]->KeySignature} |
|||
L: 1/8"; |
|||
$counter = 0; |
|||
$letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']; |
|||
foreach($this->Parts as $part) |
|||
{ |
|||
$builder .= " |
|||
P: {$letters[$counter]} Part |
|||
{$part->ABCNotation}"; |
|||
$counter = $counter + 1; |
|||
} |
|||
return $builder; |
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
<?php |
|||
|
|||
namespace App\Dataclasses; |
|||
|
|||
class TuneVariantPart |
|||
{ |
|||
public string $TimeSignature; |
|||
public string $KeySignature; |
|||
public string $ABCNotation; |
|||
|
|||
public function __construct(array $assocArray) |
|||
{ |
|||
$this->TimeSignature = $assocArray['TimeSignature']; |
|||
$this->KeySignature = $assocArray['KeySignature']; |
|||
$this->ABCNotation = $assocArray['ABCNotation']; |
|||
} |
|||
} |
Loading…
Reference in new issue