PHP code example of iammordaty / key-tools
1. Go to this page and download the library: Download iammordaty/key-tools library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iammordaty / key-tools example snippets
use KeyTools\KeyTools;
$keyTools = new KeyTools();
echo $keyTools->calculateKey('3A'); // "3A"
echo $keyTools->calculateKey('3A', 1); // "4A"
echo $keyTools->calculateKey('3A', 2); // "5A"
echo $keyTools->calculateKey('3A', -1); // "2A"
echo $keyTools->calculateKey('3A', 0, true); // "3B"
use KeyTools\KeyTools;
$keyTools = new KeyTools([
'leading_zero' => true,
'notation' => KeyTools::NOTATION_CAMELOT_KEY,
]);
echo $keyTools->calculateKey('3A'); // "03A"
echo $keyTools->calculateKey('3A', 1); // "04A"
echo $keyTools->calculateKey('3A', 2); // "05A"
echo $keyTools->calculateKey('3A', -1); // "02A"
echo $keyTools->calculateKey('3A', 0, true); // "03B"
echo $keyTools->noChange('3A'); // "3A"
echo $keyTools->perfectFifth('3A'); // "4A"
echo $keyTools->wholeStep('3A'); // "5A"
echo $keyTools->perfectFourth('3A'); // "2A"
echo $keyTools->relativeMinorToMajor('3A'); // "3B"
echo $keyTools->convertKeyToNotation('Fmin', KeyTools::NOTATION_CAMELOT_KEY); // "4A"
echo $keyTools->convertKeyToNotation('Fmin', KeyTools::NOTATION_OPEN_KEY); // "9M"
echo $keyTools->convertKeyToNotation('Fmin', KeyTools::NOTATION_MUSICAL); // = "Fm"
$key = 'Fmin';
$notation = KeyTools::NOTATION_CAMELOT_KEY;
$keyTools = new KeyTools();
if (!$keyTools->isValidKey($key)) {
exit('Invalid key');
}
if (!$keyTools->isSupportedNotation($notation)) {
exit('Unsupported notation');
}
echo $keyTools->convertKeyToNotation($key, $notation); // "4A"
use KeyTools\Exception\InvalidKeyException;
use KeyTools\Exception\UnsupportedNotationException;
$key = 'Fmin';
$notation = KeyTools::NOTATION_CAMELOT_KEY;
try {
$keyTools = new KeyTools();
echo $keyTools->convertKeyToNotation($key, $notation); // "4A"
} catch (InvalidKeyException | UnsupportedNotationException $e) {
echo $e->getMessage();
}