PHPackages                             iammordaty/key-tools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. iammordaty/key-tools

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

iammordaty/key-tools
====================

KeyTools is a library that allows you to convert musical keys between notations. In addition, KeyTools allows you to calculate matching keys for harmonic mixing.

0.8.2(6y ago)34401MITPHPPHP &gt;=7.1CI failing

Since Oct 2Pushed 6y ago4 watchersCompare

[ Source](https://github.com/iammordaty/key-tools)[ Packagist](https://packagist.org/packages/iammordaty/key-tools)[ RSS](/packages/iammordaty-key-tools/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (10)Used By (0)

iammordaty/key-tools
====================

[](#iammordatykey-tools)

KeyTools is a library that allows you to convert musical keys between notations. In addition, KeyTools allows you to calculate matching keys for harmonic mixing.

Supported notations:

- Camelot Key
- Open Key
- Musical
- Musical used by Beatport
- Musical used by Essentia streaming extractor

KeyTools is based on the code written by [@mossspence](https://github.com/mossspence), which can be found [here](https://github.com/mossspence/trakofflive/blob/master/appsrc/moss/musicapp/finder/keyTools.php).

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Requirements](#requirements)
- [Usage](#usage)
- [Tests](#tests)
- [Further information](#further-information)
- [License](#license)

Installation
------------

[](#installation)

The easiest way to install this library is via [composer](https://getcomposer.org):

```
$ composer require iammordaty/key-tools
```

Requirements
------------

[](#requirements)

- PHP 7.1 and higher

Usage
-----

[](#usage)

The following example shows how to calculate a new key.

```
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"
```

KeyTools can return keys with a leading zero – just set the parameter `leading_zero` to `true`, as in the following example. Please note that, this setting applies only to Camelot Key and Open Key notations.

```
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"
```

To calculate new key, you can also use shorthand methods:

```
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"
```

Also, conversion of keys between notations is easy:

```
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"
```

KeyTools allows key and notation validation by suitable methods...

```
$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"
```

... or by throwing appropriate exceptions:

```
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();
}
```

Tests
-----

[](#tests)

Copy `phpunit.xml.dist` file to `phpunit.xml` and use [PHPUnit](https://phpunit.de) to run tests:

```
$ ./vendor/bin/phpunit
```

Further information
-------------------

[](#further-information)

- [Harmonic mixing overview and how-to](http://www.harmonic-mixing.com/HowTo.aspx)
- ["What Is Harmonic Mixing?" – tutorial by DJ Endo](http://blog.dubspot.com/harmonic-mixing-w-dj-endo-part-1/)
- ["Digital DJing: harmonic mixing" – tutorial by Radley Marx](https://radleymarx.com/djs/digital-djing-harmonic-mixing/)
- [Open Key notation](https://beatunes.com/en/open-key-notation.html)
- [Camelot wheel (image)](https://forums.pioneerdj.com/hc/user_images/yBXP1v0OnnB8wIrg3_mbpw.jpeg)
- [More possibilities for harmonic mixing (image)](https://imgur.com/KYw9IBE)
- [Essentia – C++ library for audio and music analysis, description and synthesis](https://github.com/MTG/essentia)
- [Essentia streaming extractor music command-line tool](https://essentia.upf.edu/streaming_extractor_music.html)

License
-------

[](#license)

iammordaty/key-tools is licensed under the MIT License.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~17 days

Total

9

Last Release

2259d ago

PHP version history (2 changes)0.1PHP ~7.1

0.3PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13261799?v=4)[iammordaty](/maintainers/iammordaty)[@iammordaty](https://github.com/iammordaty)

---

Top Contributors

[![iammordaty](https://avatars.githubusercontent.com/u/13261799?v=4)](https://github.com/iammordaty "iammordaty (21 commits)")

---

Tags

automationbeatportcamelot-wheeldjharmonic-mixingmusic-libraryrekordboxtraktorautomationkeybeatportdjTraktorharmonic-mixingcamelot-wheelrekordbox

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/iammordaty-key-tools/health.svg)

```
[![Health](https://phpackages.com/badges/iammordaty-key-tools/health.svg)](https://phpackages.com/packages/iammordaty-key-tools)
```

###  Alternatives

[jakubkulhan/chrome-devtools-protocol

Chrome Devtools Protocol client for PHP

183967.6k3](/packages/jakubkulhan-chrome-devtools-protocol)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)[gladcodes/keygen

A fluent PHP random key generator.

119668.9k2](/packages/gladcodes-keygen)[sulu/automation-bundle

The Sulu Bundle which provides automation functionality

18289.1k8](/packages/sulu-automation-bundle)[andrewcarteruk/cryptokey

A command line tool for generating keys using a CSPRNG.

6124.2k](/packages/andrewcarteruk-cryptokey)[hiqdev/hidev

Automation tool mixed with code generator for easier continuous development

3229.4k28](/packages/hiqdev-hidev)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
