nicolaswurtz/chordpro-php
Composer 安装命令:
composer require nicolaswurtz/chordpro-php
包简介
Parse, transpose and format (html,json,plaintext) ChordPro format for songs lyrics with chords.
README 文档
README
A simple tool to parse, transpose & format ChordPro songs with lyrics & chords.
It currently supports the following output formats :
- HTML (verses contain blocks with embricated
spanfor alignement of chords with lyrics) - JSON (verses are array of arrays of chords and lyrics for alignement purpose)
- Plain text (chords are aligned with monospace text thanks to whitespaces)
And provides some extra functionnalities :
- Tranpose chords (can be very clever if original key is known)
- Display french chords
- Guess tonality key of a song
I'm french, so there's probably a lot of mistakes, my english is not always accurate — je fais ce que je peux hein :P
Install
Via composer :
$ composer require nicolaswurtz/chordpro-php
Usage
See web/example.php for demo with CSS styling.
<?php require __DIR__ . '/vendor/autoload.php'; $txt = "{t:ChordpropPHP Song} {st:Nicolas Wurtz} {c:GPL3 2019 Nicolas Wurtz} {key:C} [C]This is the [Dm]beautiful [Em]song I [Dm]wroted in [F/G]Chordpro for[C]mat [Dm/F] Let's singing a[C/E]long [Bb] It's ea[Dm]sy to do [F]that [C] {soc} [F] [G] [C]This is the refrain [F] [G] [C]We could sing it twice {eoc} {c:Final} [Em/D]This is the [Bb]end."; $parser = new ChordPro\Parser(); // Choose one (or all !) of those formatters following your needs $html_formatter = new ChordPro\HtmlFormatter(); $monospace_formatter = new ChordPro\MonospaceFormatter(); $json_formatter = new ChordPro\JSONFormatter(); // Create song object after parsing txt $song = $parser->parse($txt); // You can tranpose your song, put how many semitones you want to transpose in second argument OR desired key (only if metadata "key" is defined) $transposer = new ChordPro\Transposer(); $transposer->transpose($song,-5); // Simple transpose, but could produce some musical errors (sharp instead of flat) //$transposer->transpose($song,'Abm'); // Some options are mandatory, you could use en empty array if none $options = array( 'french' => true, 'no_chords' => true ); // Render ! $html = $html_formatter->format($song,$options); $plaintext = $monospace_formatter->format($song,$options); $json = $json_formatter->format($song,$options);
Formatting options
Simply give an array with values at true or false for each key/option.
array( 'french' => true, // to display french chords (Do, Ré, Mi, Fa, Sol, La, Si, Do), including Song Key. 'no_chords' => true // to only get text (it removes "block" system for chords alignements) );
Specific methods
Song
$song->getKey([])to obtain key of song, with transposition, you can alter langage english by default, or French$song->getKey(['french' => true]);, options array is mandatory, you could use en empty array if none$song->getOriginalKey()to obtain key of song, as defined in metadata's field "key"
Guess key of a song
This fonctionnality is experimental and not reliable (20% of mistakes, tested with ~1000 songs), but can be very useful. Usage is very simple (you have to parse a song before as described before):
$guess = new ChordPro\GuessKey(); $key = $guess->guessKey($song);
CSS Classes you can use with HTML Formatter
Verses
Verses are one line composed by blocks of text + chords, chord with class chordpro-chord and text with class chordpro-text.
A typical div will be like this :
<div class="chordpro-verse"> <span class="chordpro-elem"> <span class="chordpro-chord">C</span> <span class="chordpro-text">This is the </span> </span> <span class="chordpro-elem"> <span class="chordpro-chord">Dm</span> <span class="chordpro-text">beautiful song</span> </span> </div>
Chorus
The chorus (soc/start_of_chorus) will be contained inside <div class="chordpro-chorus"></div>.
Metadata
By default, all metadatas are placed inside <div class="chordpro-metadataname"></div>.
For example, the title will be
<div class="chordpro-title">It's a great title !</div>
ChordproPHP doesn't care about the metadata names, it just puts it after chordpro- :)
Metatada's names are always converted to their long form (
cwill be recorded ascomment) when using short names from official directives
nicolaswurtz/chordpro-php 适用场景与选型建议
nicolaswurtz/chordpro-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.63k 次下载、GitHub Stars 达 17, 最近一次更新时间为 2019 年 02 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nicolaswurtz/chordpro-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nicolaswurtz/chordpro-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2019-02-17