PhpTabs Documentation Build Status

Parse and write GuitarPro and MIDI files

Home Manual GitHub

Render as an ASCII tablature

ASCII tablature is a must-have feature, PhpTabs (>= 0.6.0) can render a whole tablature or a single track as an ASCII string.

Quick Usage

The following code prints all tabstaves of the first track.

include 'vendor/autoload.php';

use PhpTabs\PhpTabs;

$tab = new PhpTabs('mytab.gp4');

// Render first track
echo $tab
  ->getRenderer('ascii')
  ->render(0);

The render() method takes a track index as parameter. It starts from 0 for the first track.

This example will ouput something like:

E|------------------------|-10-----10-----------------------------------------------------|
B|--------------------X---|-------------13------------------------------------------------|
G|-%-------%------11------|------------------12---12--10------------10----------%---------|
D|-%-------%--------------|-------------------------------12--12--------12--10--%---12----|
A|------------------------|---------------------------------------------------------------|
E|------------------------|---------------------------------------------------------------|


Customize ASCII options

Some options can be passed to customize tabstaves.

Track informations can be printed with trackHeader option.

include 'vendor/autoload.php';

use PhpTabs\PhpTabs;

$tab = new PhpTabs('mytab.gp4');

// Render first track with track number and name
echo $tab
  ->getRenderer('ascii')
  ->setOptions(['trackHeader' => true])
  ->render(0);

It will output something like:

Track 1: Guitar
E|------------------------|-10-----10-----------------------------------------------------|
B|--------------------X---|-------------13------------------------------------------------|
G|-%-------%------11------|------------------12---12--10------------10----------%---------|
D|-%-------%--------------|-------------------------------12--12--------12--10--%---12----|
A|------------------------|---------------------------------------------------------------|
E|------------------------|---------------------------------------------------------------|

Song informations can be printed with songHeader option.

include 'vendor/autoload.php';

use PhpTabs\PhpTabs;

$tab = new PhpTabs('mytab.gp4');

// Render first track with song meta data
echo $tab
  ->getRenderer('ascii')
  ->setOptions(['songHeader'  => true])
  ->render(0);

It will output something like:

Title: Testing name
Album: Testing album
Artist: Testing artist
Author: Testing author


E|------------------------|-10-----10-----------------------------------------------------|
B|--------------------X---|-------------13------------------------------------------------|
G|-%-------%------11------|------------------12---12--10------------10----------%---------|
D|-%-------%--------------|-------------------------------12--12--------12--10--%---12----|
A|------------------------|---------------------------------------------------------------|
E|------------------------|---------------------------------------------------------------|

Song informations and track informations can be combined.

include 'vendor/autoload.php';

use PhpTabs\PhpTabs;

$tab = new PhpTabs('mytab.gp4');

// Render first track with song meta data and track informations
echo $tab
  ->getRenderer('ascii')
  ->setOptions(['songHeader'  => true, 'trackHeader' => true])
  ->render(0);

It will output something like:

Title: Testing name
Album: Testing album
Artist: Testing artist
Author: Testing author


Track 1: Guitar
E|------------------------|-10-----10-----------------------------------------------------|
B|--------------------X---|-------------13------------------------------------------------|
G|-%-------%------11------|------------------12---12--10------------10----------%---------|
D|-%-------%--------------|-------------------------------12--12--------12--10--%---12----|
A|------------------------|---------------------------------------------------------------|
E|------------------------|---------------------------------------------------------------|

include 'vendor/autoload.php';

use PhpTabs\PhpTabs;

$tab = new PhpTabs('mytab.gp4');

// Render a limited number of characters.
echo $tab
  ->getRenderer('ascii')
  ->setOptions(['maxLineLength' => 10])
  ->render(0);

It will output something like:

E|------------------------|
B|--------------------X---|
G|-%-------%------11------|
D|-%-------%--------------|
A|------------------------|
E|------------------------|


E|-10-----10-----------------------------------------------------|
B|-------------13------------------------------------------------|
G|------------------12---12--10------------10----------%---------|
D|-------------------------------12--12--------12--10--%---12----|
A|---------------------------------------------------------------|
E|---------------------------------------------------------------|

include 'vendor/autoload.php';

use PhpTabs\PhpTabs;

$tab = new PhpTabs('mytab.gp4');

// Render all song with song and track informations
echo $tab
  ->getRenderer('ascii')
  ->setOptions(['songHeader'  => true, 'trackHeader' => true])
  ->render();

It will output something like:

Title: Testing name
Album: Testing album
Artist: Testing artist
Author: Testing author


Track 1: Guitar
E|------------------------|-10-----10-----------------------------------------------------|
B|--------------------X---|-------------13------------------------------------------------|
G|-%-------%------11------|------------------12---12--10------------10----------%---------|
D|-%-------%--------------|-------------------------------12--12--------12--10--%---12----|
A|------------------------|---------------------------------------------------------------|
E|------------------------|---------------------------------------------------------------|


Track 2: Voice
E|-------------------------------------|-0-----------3-----------------------|
B|-5-----5-----5-----5-----5-----5-----|-5-----5-----5-----5-----5-----5-----|
G|-------------------------------------|-------------5-----------------------|
D|-------------------------------------|-------------5-----------------------|
A|-------------------------------------|-------------3-----------------------|
E|-------------------------------------|-------------3-----------------------|


Edit this document on GitHub