As the Song object is the root node of PhpTabs, it has no parent container.
You can access its methods by 2 ways:
$tab = new PhpTabs('mytabs.gp4');
// Directly
$tab->method();
// Getting the Song object
$tab->getSong()->method();
This method returns the number of measures contained by each track.
integer
$tab = new PhpTabs('mytabs.gp4');
// Count the number of measures
echo $tab->countMeasureHeaders();
// Will print a number between 0 and n-1
This method returns a MeasureHeader resource.
$tab = new PhpTabs('mytabs.gp4');
// Get the fourth measure header
$header = $tab->getMeasureHeader(3);
if ($header !== null) {
echo $header->getNumber();
} else {
echo "header number 4 / index 3 is not defined';
}
If the measure header number 4 exists, $header is containing a MeasureHeader. Otherwise, it’s a null value.
This method returns an array of MeasureHeader resources.
These are all measure headers.
[]\PhpTabs\Music\MeasureHeader
$tab = new PhpTabs('mytabs.gp4');
// Get all measure headers
$headers = $tab->getMeasureHeaders();
// Print number and index for all measure headers
foreach ($headers as $index => $header) {
echo sprintf(
"\nHeader number=%d, index=%d",
$header->getNumber(),
$index
);
}
will ouput something like:
Header number=1, index=0
Header number=2, index=1
Header number=3, index=2
Header number=4, index=3
This method returns the number of channels contained by the Song resource.
integer
$tab = new PhpTabs('mytabs.gp4');
// Count channels
echo $tab->countChannels();
// Print something like 4 if there is four types of instruments
This method returns a Channel resource.
$tab = new PhpTabs('mytabs.gp4');
// Get the second channel
$channel = $tab->getChannel(1);
if ($channel !== null) {
echo $channel->getChannelId();
} else {
echo "Channel at index 1 is not defined';
}
This method returns a Channel resource.
$tab = new PhpTabs('mytabs.gp4');
// Is there any channel using a Piano?
$channel = $tab->getChannelById(0);
if ($channel !== null) {
echo "Yes";
} else {
echo "No;
}
This method returns an array of Channel resources.
These are all channels.
$tab = new PhpTabs('mytabs.gp4');
// Get all channels
$channels = $tab->getChannels();
// Print channelId and volume for all channels
foreach ($channels as $index => $channel) {
echo sprintf(
"\nChannel index=%d, id=%d, volume=%d",
$index,
$channel->getChannelId(),
$channel->getVolume()
);
}
will ouput something like:
Channel index=0, id=28, volume=127
Channel index=1, id=0, volume=65
This method returns the number of tracks contained by the Song resource.
integer
$tab = new PhpTabs('mytabs.gp4');
// Count tracks
echo $tab->countTracks();
// Print something like 2 if there is 2 tracks
This method returns a Track resource.
$tab = new PhpTabs('mytabs.gp4');
// Is the first track using a Piano channel?
$track = $tab->getTrack(0);
if ($track->getChannelId() == 0) {
echo "Yes";
} else {
echo "No;
}
This method returns an array of tracks contained by the Song resource.
Let’s print the channel id for all tracks
$tab = new PhpTabs('mytabs.gp4');
foreach($tab->getTracks() as $track) {
echo sprintf(
"\nTrack %d, channel %d",
$track->getNumber(),
$track->getChannelId()
);
}
will ouput something like:
Track 1, channel 28
Track 2, channel 0
This method returns the name of the song.
string
$tab = new PhpTabs('mytabs.gp4');
echo $tab->getName();
// Will output "My song name"
This method returns the album of the song.
string
$tab = new PhpTabs('mytabs.gp4');
echo $tab->getAlbum();
// Will output "My song album name"
This method returns the author of the song.
string
$tab = new PhpTabs('mytabs.gp4');
echo $tab->getAuthor();
// Will output "Author name"
This method returns the artist of the song.
string
$tab = new PhpTabs('mytabs.gp4');
echo $tab->getArtist();
// Will output "Artist name"
This method returns the date of the song.
string
$tab = new PhpTabs('mytabs.gp4');
echo $tab->getDate();
// Will output "12/12/2012"
This method returns the copyright of the song.
string
$tab = new PhpTabs('mytabs.gp4');
echo $tab->getCopyright();
// Will output a string which represents licensing conditions
This method returns the writer of the song.
string
$tab = new PhpTabs('mytabs.gp4');
echo $tab->getWriter();
// Will output "Writer name"
This method returns the transcriber of the song.
string
$tab = new PhpTabs('mytabs.gp4');
echo $tab->getTranscriber();
// Will output "Transcriber name"
This method returns comments (multiple lines).
string
$tab = new PhpTabs('mytabs.gp4');
echo $tab->getComments();
// Will output "Comment line 1\nComment line 2"
This method returns true if the song has not any measure header or tracks.
Otherwise, it returns false.
boolean
$tab = new PhpTabs('mytabs.gp4');
if ($tab->isEmpty()) {
echo "Empty song";
} else {
echo "Song has at least one measure header and one track";
}
This method adds a new Track at the end of the stack.
use PhpTabs\Music\TabString;
use PhpTabs\Music\Track;
$tab = new PhpTabs('mytabs.gp4');
$track = new Track();
// Attach a song
$track->setSong($tab->getSong());
// Set at the end
$track->setNumber($tab->countTracks() + 1);
// Set a name
$track->setName('My track name');
// Prepare a one-string instrument
$string = new TabString();
$string->setNumber(1);
$string->setValue(34);
$track->addString($string);
// Add the new track
$tab->addTrack($track);
This method moves a Track from its last position to the given index.
In this example, the first track will be put at the last position.
$tab = new PhpTabs('mytabs.gp4');
$track = $tab->getTrack(0);
$index = $tab->countTracks() - 1;
$tab->moveTrack($index, $track);
This method removes and clears the given Track.
In this example, all tracks will be removed.
$tab = new PhpTabs('mytabs.gp4');
foreach ($tab->getTracks() as $track) {
$tab->removeTrack($track);
}
This method adds a new Channel at the end of the stack.
In this example, a new channel will be added with default configuration.
use Phptabs\Music\Channel;
$tab = new PhpTabs('mytabs.gp4');
$channel = new Channel();
$channel->setChannelId(
$tab->countChannels() + 1
);
$tab->addChannel($channel);
This method moves Channel to an index position.
In this example, the last channel will be moved to the first position.
$tab = new PhpTabs('mytabs.gp4');
// Get the last defined channel
$channel = $tab->getChannel(
$tab->countChannels() - 1
);
// Set at the first position
$tab->moveChannel(0, $channel);
This method removes a Channel.
In this example, the first channel will be removed.
$tab = new PhpTabs('mytabs.gp4');
// Get a channel
$channel = $tab->getChannel(0);
// Remove it
$tab->removeChannel($channel);
This method adds a new measure header at the end of the stack.
$tab = new PhpTabs('mytabs.gp4');
$measureHeader = new MeasureHeader();
$measureHeader->setNumber(
$tab->countMeasureHeaders()
);
// Add the new header
$tab->addMeasureHeader($measureHeader);
This method removes a MeasureHeader at given index.
In this example, the first measure header will be removed.
$tab = new PhpTabs('mytabs.gp4');
$tab->removeMeasureHeader(0);
This method sets the name attribute.
$tab = new PhpTabs('mytabs.gp4');
$tab->setName('My new song title');
This method sets the album attribute.
$tab = new PhpTabs('mytabs.gp4');
$tab->setAlbum('My new album title');
This method sets the author attribute.
$tab = new PhpTabs('mytabs.gp4');
$tab->setAuthor('My new author name');
This method sets the artist attribute.
$tab = new PhpTabs('mytabs.gp4');
$tab->setArtist('My new artist name');
This method sets the date attribute.
$tab = new PhpTabs('mytabs.gp4');
$tab->setDate('12/12/2012');
This method sets the copyright attribute.
$tab = new PhpTabs('mytabs.gp4');
$tab->setCopyright('License LGPL2.1+');
This method sets the writer attribute.
$tab = new PhpTabs('mytabs.gp4');
$tab->setWriter('Writer name');
This method sets the transcriber attribute.
$tab = new PhpTabs('mytabs.gp4');
$tab->setTranscriber('Transcriber name');
This method sets the comments attribute.
$tab = new PhpTabs('mytabs.gp4');
$tab->setComments('Comment line 1
Comment line 2
Etc...');
This method clears all channels, measure headers and tracks.
$tab = new PhpTabs('mytabs.gp4');
$tab->clear();
This method converts all data of a given song into internal data.
In this example, an empty song will replace actual data.
$tab = new PhpTabs('mytabs.gp4');
$tab->copyFrom(new Song());