You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.8 KiB
79 lines
1.8 KiB
<?php
|
|
|
|
namespace App\Dataclasses;
|
|
|
|
class DatabaseFolkTuneDetails
|
|
{
|
|
public string $ID;
|
|
public string $Title;
|
|
|
|
public string $Copyright;
|
|
|
|
public array $Parts;
|
|
|
|
|
|
public function __construct(array $assocArray)
|
|
{
|
|
$this->ID = $assocArray['ID'];
|
|
$this->Title = $assocArray['Title'];
|
|
$this->Copyright = $assocArray['Copyright'];
|
|
|
|
|
|
$temp = json_decode($assocArray['Parts'], associative: true, flags: JSON_THROW_ON_ERROR);
|
|
foreach($temp as $part)
|
|
$this->Parts[] = new TunePart($part);
|
|
}
|
|
|
|
public function Build(): string
|
|
{
|
|
$builder = "X: {$this->ID}
|
|
T: {$this->Title}
|
|
C: {$this->Copyright}
|
|
L: 1/4";
|
|
$counter = 0;
|
|
|
|
$previousTimeSignature = "";
|
|
$previousKeySignature = "";
|
|
|
|
foreach($this->Parts as $part)
|
|
{
|
|
$builder .= "
|
|
P: {$this->Parts[$counter]->PartLetter} Part";
|
|
|
|
if($this->Parts[$counter]->TimeSignature != $previousTimeSignature)
|
|
{
|
|
$builder .= "
|
|
M: {$this->Parts[$counter]->TimeSignature}";
|
|
$previousTimeSignature = $this->Parts[$counter]->TimeSignature;
|
|
}
|
|
|
|
if($this->Parts[$counter]->KeySignature != $previousKeySignature)
|
|
{
|
|
$builder .= "
|
|
K: {$this->Parts[$counter]->KeySignature}";
|
|
$previousKeySignature = $this->Parts[$counter]->KeySignature;
|
|
}
|
|
|
|
|
|
$builder .= "
|
|
{$part->ABCNotation}";
|
|
|
|
$counter = $counter + 1;
|
|
}
|
|
return $builder;
|
|
}
|
|
|
|
public function BuildSimple(): string
|
|
{
|
|
$builder = "X: {$this->ID}
|
|
L: 1/4";
|
|
|
|
$builder .= "
|
|
K: {$this->Parts[0]->TimeSignature}
|
|
M: {$this->Parts[0]->KeySignature}";
|
|
|
|
$builder .= "
|
|
{$this->Parts[0]->ABCNotation}";
|
|
return $builder;
|
|
}
|
|
}
|