chaloman/tonal-php
Composer 安装命令:
composer require chaloman/tonal-php
包简介
PHP port of Tonal.js - A music theory library for notes, intervals, chords, scales, and more
README 文档
README
A PHP port of Tonal.js - a music theory library for working with notes, intervals, chords, scales, modes, keys, and more.
Requirements
- PHP 8.3 or higher
Installation
composer require chaloman/tonal-php
Usage
Notes
use Chaloman\Tonal\Note; // Get note properties $note = Note::get('C#4'); $note->name; // "C#4" $note->pc; // "C#" (pitch class) $note->letter; // "C" $note->acc; // "#" $note->octave; // 4 $note->midi; // 61 $note->freq; // 277.18... // Transpose notes Note::transpose('C4', '3M'); // "E4" Note::transpose('D4', '-2M'); // "C4" // Get enharmonic equivalents Note::enharmonic('C#'); // "Db" Note::enharmonic('Db'); // "C#" // Simplify notes Note::simplify('E##'); // "F#"
Intervals
use Chaloman\Tonal\Interval; // Get interval properties $interval = Interval::get('3M'); $interval->name; // "3M" $interval->semitones; // 4 $interval->quality; // "M" $interval->num; // 3 // Calculate distance between notes Interval::distance('C4', 'E4'); // "3M" // Add intervals Interval::add('3M', '3m'); // "5P" // Simplify compound intervals Interval::simplify('9M'); // "2M" // Invert intervals Interval::invert('3M'); // "6m"
Chords
use Chaloman\Tonal\Chord; // Get chord properties $chord = Chord::get('Cmaj7'); $chord->name; // "C major seventh" $chord->symbol; // "Cmaj7" $chord->tonic; // "C" $chord->type; // "major seventh" $chord->notes; // ["C", "E", "G", "B"] $chord->intervals; // ["1P", "3M", "5P", "7M"] // Get chord notes with octave Chord::get('Dm7/F')->notes; // ["F", "A", "C", "D"] // Transpose chords Chord::transpose('Cmaj7', '5P'); // "Gmaj7" // Detect chords from notes use Chaloman\Tonal\ChordDetect; ChordDetect::detect(['C', 'E', 'G']); // ["CM", "Em#5/C", ...] ChordDetect::detect(['D', 'F', 'A', 'C']); // ["Dm7", ...]
Scales
use Chaloman\Tonal\Scale; // Get scale properties $scale = Scale::get('C major'); $scale->name; // "C major" $scale->tonic; // "C" $scale->type; // "major" $scale->notes; // ["C", "D", "E", "F", "G", "A", "B"] $scale->intervals; // ["1P", "2M", "3M", "4P", "5P", "6M", "7M"] // Get scale notes Scale::get('D dorian')->notes; // ["D", "E", "F", "G", "A", "B", "C"] // Detect scales from notes Scale::detect(['C', 'D', 'E', 'F', 'G', 'A', 'B']); // ["C major", "C ionian", ...] // Find chords in a scale Scale::chords('C major'); // ["C", "Dm", "Em", "F", "G", "Am", "Bdim"]
Keys
use Chaloman\Tonal\Key; // Major keys $key = Key::majorKey('C'); $key->tonic; // "C" $key->type; // "major" $key->scale; // ["C", "D", "E", "F", "G", "A", "B"] $key->chords; // ["C", "Dm", "Em", "F", "G", "Am", "Bdim"] // Minor keys $key = Key::minorKey('A'); $key->natural->scale; // ["A", "B", "C", "D", "E", "F", "G"] $key->harmonic->scale; // ["A", "B", "C", "D", "E", "F", "G#"] $key->melodic->scale; // ["A", "B", "C", "D", "E", "F#", "G#"]
Modes
use Chaloman\Tonal\Mode; // Get mode properties $mode = Mode::get('dorian'); $mode->name; // "dorian" $mode->intervals; // ["1P", "2M", "3m", "4P", "5P", "6M", "7m"] $mode->triad; // "m" $mode->seventh; // "m7" // Get notes of a mode Mode::notes('dorian', 'D'); // ["D", "E", "F", "G", "A", "B", "C"] // Get all mode names Mode::names(); // ["ionian", "dorian", "phrygian", ...]
Progressions
use Chaloman\Tonal\Progression; // Convert roman numerals to chords Progression::fromRomanNumerals('C', ['I', 'IV', 'V', 'I']); // ["C", "F", "G", "C"] // Convert chords to roman numerals Progression::toRomanNumerals('C', ['C', 'Dm', 'G', 'C']); // ["I", "IIm", "V", "I"]
MIDI
use Chaloman\Tonal\Midi; // Convert between MIDI and notes Midi::toMidi('C4'); // 60 Midi::midiToNoteName(60); // "C4" // Convert between MIDI and frequency Midi::midiToFreq(69); // 440.0 Midi::freqToMidi(440); // 69
Roman Numerals
use Chaloman\Tonal\RomanNumeral; $rn = RomanNumeral::get('bVII'); $rn->name; // "bVII" $rn->roman; // "VII" $rn->interval; // "7m" $rn->acc; // "b" $rn->major; // true
Available Modules
- Note - Note operations (transpose, enharmonic, simplify)
- Interval - Interval calculations (add, subtract, invert)
- Chord - Chord properties and operations
- ChordType - Chord type dictionary
- ChordDetect - Chord detection from notes
- Scale - Scale properties and operations
- ScaleType - Scale type dictionary
- Key - Major and minor key information
- Mode - Musical modes
- Pcset - Pitch class set operations
- Progression - Roman numeral progressions
- RomanNumeral - Roman numeral analysis
- Midi - MIDI utilities
- Range - Note range generation
- Collection - Array utilities
- AbcNotation - ABC notation conversion
- DurationValue - Note duration values
- TimeSignature - Time signature parsing
- Voicing - Chord voicing utilities
- VoicingDictionary - Voicing patterns
- VoiceLeading - Voice leading algorithms
- RhythmPattern - Rhythm pattern generation
Credits
This library is a PHP port of Tonal.js by danigb.
License
The MIT License (MIT). Please see License File for more information.
chaloman/tonal-php 适用场景与选型建议
chaloman/tonal-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「music」 「theory」 「chords」 「keys」 「midi」 「notes」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chaloman/tonal-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chaloman/tonal-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chaloman/tonal-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
FormalTheory is a library that allows for manipulation and conversion of NFAs, DFAs and Regular Expressions.
PHP wrapper for command-line fingerprint generator - fpcalc
Library that obtains VK tokens that work for VK audio API. Библиотека для получения токена VK, подходящего для Audio API.
PHP-ML - Machine Learning library for PHP
A functional programming library that brings Haskell and Scala Cats like features to PHP.
FormalTheory is a library that allows for manipulation and conversion of NFAs, DFAs and Regular Expressions.
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-12