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.
PhpTabs currently supports the following file formats:
- Guitar Pro 3 (.gp3)
- Guitar Pro 4 (.gp4)
- Guitar Pro 5 (.gp5)
- MIDI (.mid, .midi)
Any questions?
- Read the PhpTabs Manual
- Open an issue on github
- Contribute code
- Contribute documentation in the /docs
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.
Before version 1.0.0, the old manual PhpTabs Manual
- Requirements
- Installation
- Testing
- Basic Usage
- Methods
PhpTabs requires PHP 7.4+ and 8.0+.
Until PhpTabs 1.0.5, it was maintained for PHP versions 7.2 and 7.3.
Until PhpTabs 0.6.1, it was maintained for PHP versions 7.0 and 7.1.
Until PhpTabs 0.6.0, it was maintained for PHP versions 5.4, 5.5, 5.6 and HHVM.
composer require stdtabs/phptabsDownload and extract an archive from https://github.com/stdtabs/phptabs/releases
Then add this PHP line before usage:
// Use standalone bootstraprequire_once'src/PhpTabs/bootstrap.php';To run tests, you should install PHPUnit first.
composer require phpunit/phpunitThen run the test suite with:
vendor/bin/phpunitrequire_once'src/PhpTabs/bootstrap.php';
usePhpTabs\PhpTabs;
// Instanciates a tablature$tablature = newPhpTabs("mytabs.gp3");
// Reads informationecho$tablature->getName();Typestring
The name of the song.
Example
$tablature->getName();Typestring
The interpreter of the song.
Example
$tablature->getArtist();Typestring
The name of the album.
Example
$tablature->getAlbum();Typestring
The author of the song.
Example
$tablature->getAuthor();Typestring
The copyright of the song.
Example
$tablature->getCopyright();Typestring
The songwriter.
Example
$tablature->getWriter();Typestring
The tablature comments. They are compounded of several lines
separated by a line break (PHP_EOL).
Example
$tablature->getComments();Typestring
Person who has transcribed tablature
Support
Guitar Pro >= 4
Example
$tablature->getTranscriber();Typestring
Date when tablature has been transcribed
Support
Guitar Pro >= 4
Example
$tablature->getDate();Typeinteger
The number of tracks
Example
$tablature->countTracks();Typearray
An array of Track objects
There is one track object for each instrument of the song.
Example
$tablature->getTracks();Typeobject
Parameterinteger $index
The music sheet for one instrument.
Example
// Get the first track$tablature->getTrack(0);Typeinteger
The number of channels
Example
$tablature->countChannels();Typearray
An array of Channel objects
There is one channel object for each track of the song.
Example
$tablature->getChannels();Typeobject
Parameterinteger $index
The instrument and sound parameters for one track.
Example
// Get the first channel$tablature->getChannel(0);Typeinteger
The number of instruments
Example
$tablature->countInstruments();Typearray
A list of instrument arrays
array(
'id' => <integer InstrumentId>,
'name' => <string InstrumentName>
)Example
$tablature->getInstruments();Typearray
Parameterinteger $index
An instrument array
array(
'id' => <integer InstrumentId>,
'name' => <string InstrumentName>
)Example
// Get the first instrument$tablature->getInstrument(0);Typeinteger
The number of measure headers
Example
$tablature->countMeasureHeaders();Typearray
An array of MeasureHeader objects
Example
$tablature->getMeasureHeaders();Typeobject
Parameterinteger $index
Measure header contains global informations about the measure.
Example
// Get the first measure header$tablature->getMeasureHeader(0);Typebool
Parameterstring $filename
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).
Following parameters are allowed:
| Parameter | Type | Description |
|---|---|---|
| filename.ext | bool | A file_put_contents() return |
Example
// Instanciate a GP3 tab$tab = newPhpTabs('mytab.gp3');
// Save as GP3$tab->save('newfile.gp3');
// Convert and save as GP5$tab->save('newfile.gp5');Typestring
Parameterstring $type
This method returns data as a binary string into a specified format.
Following formats are allowed:
| 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
// Instanciate a GP3 tab$tab = newPhpTabs('mytab.gp3');
// Convert as GP3echo$tab->convert('gp3');
// Convert as GP5echo$tab->convert('gp5');
// Convert as MIDIecho$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.