<?php
include 'MajorTriad.php'
$triad = new MajorTriad('C');
echo $triad->getRoot();
?>
<?php
class MajorTriad {
private $root;
private $rootNumber;
private $third;
private $thirdNumber;
private $fifth;
private $fifthNumber;
function __construct($root)
{
$this->root = $root;
}
protected function getChord()
{
$this->rootNumber = $this->getCorrespondingRootNumber($this->root);
$this->thirdNumber = $this->getThirdNumber($this->rootNumber);
$this->fifthNumber = $this->getFifthNumber($this->rootNumber);
$this->third = $this->getChordNote($this->root, $this->thirdNumber);
$this->fifth = $this->getChordNote($this->third, $this->fifthNumber);
$chord = $this->root . $this->third . $this->fifth;
return $chord;
}
protected function getRoot()
{
return $this->root;
}
protected function getThird()
{
return $this->third;
}
protected function getFifth()
{
return $this->fifth;
}
protected function getThirdNumber($rootNumber)
{
$this->thirdNumber = $rootNumber + 4;
}
protected function getFifthNumber($rootNumber)
{
$this->fifthNumber = $rootNumber + 7;
}
protected function getCorrespondingRootNumber($rootNote)
{
switch ($rootNote) {
case 'G♯':
$this->rootNumber = 1;
break;
case 'A♭':
$this->rootNumber = 1;
break;
case 'A':
$this->rootNumber = 2;
break;
case 'A♯':
$this->rootNumber = 3;
break;
case 'B♭':
$this->rootNumber = 3;
break;
case 'B':
$this->rootNumber = 4;
break;
case 'C':
$this->rootNumber = 5;
break;
case 'C♯':
$this->rootNumber = 6;
break;
case 'D♭':
$this->rootNumber = 6;
break;
case 'D':
$this->rootNumber = 7;
break;
case 'D♯':
$this->rootNumber = 8;
break;
case 'E♭':
$this->rootNumber = 8;
break;
case 'E':
$this->rootNumber = 9;
break;
case 'F':
$this->rootNumber = 10;
break;
case 'F♯':
$this->rootNumber = 11;
break;
case 'G♭':
$this->rootNumber = 11;
break;
case 'G':
$this->rootNumber = 12;
break;
default:
die('Error assigning root number');
}
}
protected function getChordNote($thirdBelow, $number)
{
$letterNote = $this->getLetter($thirdBelow);
$currentLetter = $this->thirdUp($letterNote);
switch ($number) {
case 1:
if (strpos('G♯', $currentLetter)) $chordTone = 'G♯';
elseif (strpos('A♭', $currentLetter)) $chordTone = 'A♭';
break;
case 2:
if (strpos( 'G𝄪', $currentLetter)) $chordTone = 'G𝄪';
elseif (strpos('A', $currentLetter)) $chordTone = 'A';
elseif (strpos('B𝄫', $currentLetter)) $chordTone = 'B𝄫';
break;
case 3:
if (strpos('A♯', $currentLetter)) $chordTone = 'A♯';
elseif (strpos('C𝄫', $currentLetter)) $chordTone = 'C𝄫';
elseif (strpos('B♭', $currentLetter)) $chordTone = 'B♭';
break;
case 4:
if (strpos('A𝄪', $currentLetter)) $chordTone = 'A𝄪';
elseif (strpos('B', $currentLetter)) $chordTone = 'B';
elseif (strpos('C♭', $currentLetter)) $chordTone = 'C♭';
break;
case 5:
if (strpos('B♯', $currentLetter)) $chordTone = 'B♯';
elseif (strpos('C', $currentLetter)) $chordTone = 'C';
elseif (strpos('D𝄫', $currentLetter)) $chordTone = 'D𝄫';
break;
case 6:
if (strpos('B𝄪', $currentLetter)) $chordTone = 'B𝄪';
elseif (strpos('C♯', $currentLetter)) $chordTone = 'C♯';
elseif (strpos('D♭', $currentLetter)) $chordTone = 'D♭';
break;
case 7:
if (strpos('C𝄪', $currentLetter)) $chordTone = 'C𝄪';
elseif (strpos('D', $currentLetter)) $chordTone 'D';
elseif (strpos('E𝄫', $currentLetter)) $chordTone = 'E𝄫';
break;
case 8:
if (strpos('D♯', $currentLetter)) $chordTone = 'D♯';
elseif (strpos('E♭', $currentLetter)) $chordTone = 'E♭';
elseif (strpos('F𝄫', $currentLetter)) $chordTone = 'F𝄫';
break;
case 9:
if (strpos('D𝄪', $currentLetter)) $chordTone = 'D𝄪';
elseif (strpos('E', $currentLetter)) $chordTone = 'E';
elseif (strpos ('F♭', $currentLetter)) $chordTone = 'F♭';
break;
case 10:
if (strpos('E𝄪', $currentLetter)) $chordTone = 'E♯';
elseif (strpos('F', $currentLetter)) $chordTone = 'F';
elseif (strpos('G𝄫', $currentLetter)) $chordTone = 'G𝄫';
break;
case 11:
if (strpos('E𝄪', $currentLetter)) $chordTone = 'E𝄪';
elseif (strpos('F♯', $currentLetter)) $chordTone = 'F♯';
elseif (strpos('G♭', $currentLetter)) $chordTone = 'G♭';
break;
case 12:
if (strpos('F𝄪', $currentLetter)) $chordTone = 'F𝄪';
elseif (strpos('G', $currentLetter)) $chordTone = 'G';
elseif (strpos('A𝄫', $currentLetter)) $chordTone = 'A𝄫';
break;
default:
die('Error in getChordNote method');
}
}
protected function getLetter($note)
{
if (strpos($note, 'A')) $letterNote = 'A';
elseif (strpos($note, 'B')) $letterNote = 'B';
elseif (strpos($note, 'C')) $letterNote = 'C';
elseif (strpos($note, 'D')) $letterNote = 'D';
elseif (strpos($note, 'E')) $letterNote = 'E';
elseif (strpos($note, 'F')) $letterNote = 'F';
elseif (strpos($note, 'G')) $letterNote = 'G';
else
{
$letterNote = null;
die('error in getLetter method');
}
return $letterNote;
}
protected function thirdUp($letterNote)
{
switch ($letterNote) {
case 'A':
$nextNote = 'C';
break;
case 'B':
$nextNote = 'D';
break;
case 'C':
$nextNote = 'E';
break;
case 'D':
$nextNote = 'F';
break;
case 'E':
$nextNote = 'G';
break;
case 'F':
$nextNote = 'A';
break;
case 'G':
$nextNote = 'B';
break;
default:
die('Error in method thirdUp()');
}
return $nextNote;
}
}
?>
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.