PhpTabs
, (*1)
PhpTabs is a PHP library for reading and writing scores and MIDI files.
It provides direct methods to read a song name, get a list of instruments or whatever be your needs., (*2)
PhpTabs currently supports the following file formats:, (*3)
- Guitar Pro 3 (.gp3)
- Guitar Pro 4 (.gp4)
- Guitar Pro 5 (.gp5)
- MIDI (.mid, .midi)
Any questions?, (*4)
Table of contents
The documentation below contains only basic examples. If you want to
see more examples and the complete API behind the library, read the
PhpTabs Manual., (*5)
Before version 1.0.0, the old manual PhpTabs Manual, (*6)
Requirements
PhpTabs requires PHP 7.4+ and 8.0+., (*7)
Until PhpTabs 1.0.5, it was maintained for PHP versions 7.2 and 7.3., (*8)
Until PhpTabs 0.6.1, it was maintained for PHP versions 7.0 and 7.1., (*9)
Until PhpTabs 0.6.0, it was maintained for PHP versions 5.4, 5.5, 5.6
and HHVM., (*10)
Installation
Composer
composer require stdtabs/phptabs
Alternative
Download and extract an archive from https://github.com/stdtabs/phptabs/releases, (*11)
Then add this PHP line before usage:, (*12)
// Use standalone bootstrap
require_once 'src/PhpTabs/bootstrap.php';
Testing
To run tests, you should install PHPUnit first., (*13)
composer require phpunit/phpunit
Then run the test suite with:, (*14)
vendor/bin/phpunit
Basic Usage
require_once 'src/PhpTabs/bootstrap.php';
use PhpTabs\PhpTabs;
// Instanciates a tablature
$tablature = new PhpTabs("mytabs.gp3");
// Reads information
echo $tablature->getName();
Methods
getName()
Type string, (*15)
The name of the song., (*16)
Example, (*17)
$tablature->getName();
getArtist()
Type string, (*18)
The interpreter of the song., (*19)
Example, (*20)
$tablature->getArtist();
getAlbum()
Type string, (*21)
The name of the album., (*22)
Example, (*23)
$tablature->getAlbum();
getAuthor()
Type string, (*24)
The author of the song., (*25)
Example, (*26)
$tablature->getAuthor();
getCopyright()
Type string, (*27)
The copyright of the song., (*28)
Example, (*29)
$tablature->getCopyright();
getWriter()
Type string, (*30)
The songwriter., (*31)
Example, (*32)
$tablature->getWriter();
Type string, (*33)
The tablature comments. They are compounded of several lines
separated by a line break (PHP_EOL
)., (*34)
Example, (*35)
$tablature->getComments();
getTranscriber()
Type string, (*36)
Person who has transcribed tablature, (*37)
Support, (*38)
Guitar Pro >= 4, (*39)
Example, (*40)
$tablature->getTranscriber();
getDate()
Type string, (*41)
Date when tablature has been transcribed, (*42)
Support, (*43)
Guitar Pro >= 4, (*44)
Example, (*45)
$tablature->getDate();
Accessing tracks
countTracks()
Type integer, (*46)
The number of tracks, (*47)
Example, (*48)
$tablature->countTracks();
getTracks()
Type array, (*49)
An array of Track objects, (*50)
There is one track object for each instrument of the song., (*51)
Example, (*52)
$tablature->getTracks();
getTrack($index)
Type object, (*53)
Parameter integer $index, (*54)
The music sheet for one instrument., (*55)
Example, (*56)
// Get the first track
$tablature->getTrack(0);
Accessing channels
countChannels()
Type integer, (*57)
The number of channels, (*58)
Example, (*59)
$tablature->countChannels();
getChannels()
Type array, (*60)
An array of Channel objects, (*61)
There is one channel object for each track of the song., (*62)
Example, (*63)
$tablature->getChannels();
getChannel($index)
Type object, (*64)
Parameter integer $index, (*65)
The instrument and sound parameters for one track., (*66)
Example, (*67)
// Get the first channel
$tablature->getChannel(0);
Accessing instruments
countInstruments()
Type integer, (*68)
The number of instruments, (*69)
Example, (*70)
$tablature->countInstruments();
getInstruments()
Type array, (*71)
A list of instrument arrays, (*72)
array(
'id' => <integer InstrumentId>,
'name' => <string InstrumentName>
)
Example, (*73)
$tablature->getInstruments();
getInstrument($index)
Type array, (*74)
Parameter integer $index, (*75)
An instrument array, (*76)
array(
'id' => <integer InstrumentId>,
'name' => <string InstrumentName>
)
Example, (*77)
// Get the first instrument
$tablature->getInstrument(0);
Type integer, (*78)
The number of measure headers, (*79)
Example, (*80)
$tablature->countMeasureHeaders();
Type array, (*81)
An array of MeasureHeader objects, (*82)
Example, (*83)
$tablature->getMeasureHeaders();
Type object, (*84)
Parameter integer $index, (*85)
Measure header contains global informations about the measure., (*86)
Example, (*87)
// Get the first measure header
$tablature->getMeasureHeader(0);
Saving data
save($filename)
Type bool, (*88)
Parameter string $filename, (*89)
This method records data as binary to the disk or buffer.
It implicitly converts filetype if the specified file extension is
different from the original (see examples below)., (*90)
Following parameters are allowed:, (*91)
Parameter |
Type |
Description |
filename.ext |
bool |
A file_put_contents() return |
Example, (*92)
// Instanciate a GP3 tab
$tab = new PhpTabs('mytab.gp3');
// Save as GP3
$tab->save('newfile.gp3');
// Convert and save as GP5
$tab->save('newfile.gp5');
convert($type)
Type string, (*93)
Parameter string $type, (*94)
This method returns data as a binary string into a specified format., (*95)
Following formats are allowed:, (*96)
Parameter |
Type |
Description |
null |
string |
A binary string, original format |
gp3 |
string |
A binary string, GP3 formatted |
gp4 |
string |
A binary string, GP4 formatted |
gp5 |
string |
A binary string, GP5 formatted |
mid |
string |
A binary string, MIDI formatted |
midi |
string |
A binary string, MIDI formatted |
Example, (*97)
// Instanciate a GP3 tab
$tab = new PhpTabs('mytab.gp3');
// Convert as GP3
echo $tab->convert('gp3');
// Convert as GP5
echo $tab->convert('gp5');
// Convert as MIDI
echo $tab->convert('mid');
// Render as original format
// Should be equal as file_get_contents('mytab.gp3')
echo $tab->convert();
A lot more examples on PhpTabs Manual., (*98)