Giter Club home page Giter Club logo

phptabs's Introduction

PhpTabs

Latest Stable Version Build Status License

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?

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.

Before version 1.0.0, the old manual PhpTabs Manual


Requirements

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.


Installation

Composer

composer require stdtabs/phptabs

Alternative

Download and extract an archive from https://github.com/stdtabs/phptabs/releases

Then add this PHP line before usage:

// Use standalone bootstrap
require_once 'src/PhpTabs/bootstrap.php';

Testing

To run tests, you should install PHPUnit first.

composer require phpunit/phpunit

Then run the test suite with:

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

Accessing metadata


getName()

Type string

The name of the song.

Example

$tablature->getName();

getArtist()

Type string

The interpreter of the song.

Example

$tablature->getArtist();

getAlbum()

Type string

The name of the album.

Example

$tablature->getAlbum();

getAuthor()

Type string

The author of the song.

Example

$tablature->getAuthor();

getCopyright()

Type string

The copyright of the song.

Example

$tablature->getCopyright();

getWriter()

Type string

The songwriter.

Example

$tablature->getWriter();

getComments()

Type string

The tablature comments. They are compounded of several lines separated by a line break (PHP_EOL).

Example

$tablature->getComments();

getTranscriber()

Type string

Person who has transcribed tablature

Support

Guitar Pro >= 4

Example

$tablature->getTranscriber();

getDate()

Type string

Date when tablature has been transcribed

Support

Guitar Pro >= 4

Example

$tablature->getDate();

Accessing tracks


countTracks()

Type integer

The number of tracks

Example

$tablature->countTracks();

getTracks()

Type array

An array of Track objects

There is one track object for each instrument of the song.

Example

$tablature->getTracks();

getTrack($index)

Type object

Parameter integer $index

The music sheet for one instrument.

Example

// Get the first track
$tablature->getTrack(0);

Accessing channels


countChannels()

Type integer

The number of channels

Example

$tablature->countChannels();

getChannels()

Type array

An array of Channel objects

There is one channel object for each track of the song.

Example

$tablature->getChannels();

getChannel($index)

Type object

Parameter integer $index

The instrument and sound parameters for one track.

Example

// Get the first channel
$tablature->getChannel(0);

Accessing instruments


countInstruments()

Type integer

The number of instruments

Example

$tablature->countInstruments();

getInstruments()

Type array

A list of instrument arrays

array(
  'id' => <integer InstrumentId>,
  'name' => <string InstrumentName>
)

Example

$tablature->getInstruments();

getInstrument($index)

Type array

Parameter integer $index

An instrument array

array(
  'id' => <integer InstrumentId>,
  'name' => <string InstrumentName>
)

Example

// Get the first instrument
$tablature->getInstrument(0);

Accessing measure headers


countMeasureHeaders()

Type integer

The number of measure headers

Example

$tablature->countMeasureHeaders();

getMeasureHeaders()

Type array

An array of MeasureHeader objects

Example

$tablature->getMeasureHeaders();

getMeasureHeader($index)

Type object

Parameter integer $index

Measure header contains global informations about the measure.

Example

// Get the first measure header
$tablature->getMeasureHeader(0);

Saving data


save($filename)

Type bool

Parameter string $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 = new PhpTabs('mytab.gp3');

// Save as GP3
$tab->save('newfile.gp3');

// Convert and save as GP5
$tab->save('newfile.gp5');

convert($type)


Type string

Parameter string $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 = 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.

phptabs's People

Contributors

landrok avatar motniemtin avatar peter279k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

phptabs's Issues

phptabs itterating tru partiture

Hi, Looking at the phptabs, lot's of work on this project, and well coded and done.

I am looking at the methods, and I cannot figure it out how do I walk trough a partiture, I am trying to generate guitar tabs, eventually vextab file to be played in vextab player.
Thank you.

can't change instrument tuning

when i try the following, it just changes the strings

$filename = '/GuitDaEMOns/CIID-Heaven&Hell-BibleBlack-Full2exp.mid';

$tab = new PhpTabs($filename);

foreach ($tab->getTracks() as $itrack => $track) {
    if ($track->getStrings()[0]->getValue() !== 0)
    {
        $tuning = [36,41,46,51,55,60,65];
        $count = $track->countStrings();
        $diff = $count - count($tuning) + 1;
        $j = 0;
        for ($i = $count - 1; $i >= 0; $i--)
         {
            $tabString = $track->getStrings()[$j];
            $tabString->setValue($tuning[$i]);
            $j++;
         }
    }
}
file_put_contents($filename.'.gp5', $tab->getTablature()->toGuitarPro5());
echo $tab->getTablature()->toAscii();

the strings change tuning but the notes don't change, the frets stay the same

Reading Midi Files

Hi, I'm trying to update the names for some midi files as when I import them into my DAW, they show a standard name and it's tough to know what is what.

I'm doing this:

<?php

require_once 'vendor/autoload.php';

use PhpTabs\PhpTabs;

$file = $argv[1];
$mid = new PhpTabs($file);
echo $mid->getName() . PHP_EOL;

--

Each time the getName() is blank. If I use a gp* file, it seems to work fine (for example: https://gprotab.net/en/tabs/the-eagles/hotel-california works).

Here's an example of it not working for a Midi file: https://www.midiworld.com/download/3290 (Enter Sandman).

Thanks,
Hans

Class 'PhpTabs\Reader\Midi\TabString' not found

Hi, i get the above error when trying to parse Midi file via
$tab = new PhpTabs(public_path("midi/".$filename));
error is at
stdtabs\phptabs\src\PhpTabs\Reader\Midi\MidiReader.php

  • Create percussion strings
    *

    • @param int $stringCount
    • @return array
      */
      private function createPercussionStrings($stringCount)
      {
      $strings = array();

    for ($i = 1; $i <= $stringCount; $i++) {
    $strings[] = new TabString($i, 0);
    }

    return $strings;
    }

may i know what exactly is TabString? thank you

I have problem to convert measure length to seconds. please help!

  {
    "header": {
      "number": 1,
      "start": 960,
      "length": 3840,
      "timeSignature": {
        "numerator": 4,
        "denominator": {
          "value": 4,
          "dotted": false,
          "doubleDotted": false,
          "divisionType": {
            "enters": 1,
            "times": 1
          }
        }
      },
      "tempo": 120,
      "marker": null,
      "repeatOpen": false,
      "repeatAlternative": 0,
      "repeatClose": 0,
      "tripletFeel": 1
    }
  }

What time spend for this measure ?, how to calculate ?

Check Tab parsed successfully

Hi Landrok,
let me wish you a happy new year first! May it be as productive as the last one. :)

Quick question from my side:
I'm updating my website to use the current version 1.0.4 of PhpTabs. In former versions it was possible to check if an gp5-file has been parsed successfully by checking:

$tablature = new PhpTabs("file.gp5");
if ($tablature->hasError()) { ... }

In the current version this method does not exist anymore. Which way is intended to check if a file has been parsed succussfully?

Best regards,
MrChros

Error when convert gp5 to midi

Fatal error: Uncaught TypeError: Argument 1 passed to PhpTabs\Writer\Midi\MidiWriter::__construct() must be an instance of PhpTabs\Model\Song, instance of PhpTabs\Music\Song given, called in /src/PhpTabs/Component/Writer.php on line 60 and defined in /src/PhpTabs/Writer/Midi/MidiWriter.php:37 Stack trace: #0 /src/PhpTabs/Component/Writer.php(60): PhpTabs\Writer\Midi\MidiWriter->__construct(Object(PhpTabs\Music\Song)) #1 /src/PhpTabs/Component/Tablature.php(212): PhpTabs\Component\Writer->build('midi') #2 /src/PhpTabs/PhpTabs.php(138): PhpTabs\Component\Tablature->convert('midi') #3 /index.php(8): PhpTabs\PhpTabs->__call('conver in /src/PhpTabs/Writer/Midi/MidiWriter.php on line 37

New error when convert to midi file, and i can't open your midi when success in some files(on Windows Media)

Fatal error: Uncaught TypeError: Argument 1 passed to PhpTabs\Writer\Midi\MidiSequenceParser::applyStaticDuration() must be an instance of PhpTabs\Music\Tempo, string given, called in /phptabs-master/src/PhpTabs/Writer/Midi/MidiSequenceParser.php on line 598 and defined in /phptabs-master/src/PhpTabs/Writer/Midi/MidiSequenceParser.php:616 Stack trace: #0 /phptabs-master/src/PhpTabs/Writer/Midi/MidiSequenceParser.php(598): PhpTabs\Writer\Midi\MidiSequenceParser->applyStaticDuration('tempo', 60, 480) #1 /phptabs-master/src/PhpTabs/Writer/Midi/MidiSequenceParser.php(562): PhpTabs\Writer\Midi\MidiSequenceParser->applyDurationEffects(Object(PhpTabs\Music\Note), Object(PhpTabs\Music\Tempo), 480) #2 /phptabs-master/src/PhpTabs/Writer/Midi/MidiSequenceParser.php(262): PhpTabs\Writer\Midi\MidiSequenceParser->getRealNoteDuration(Object(PhpTabs\Writer\Midi\Midi in /phptabs-master/src/PhpTabs/Writer/Midi/MidiSequenceParser.php on line 616

Tab from scratch

First of all, thank you for your Library! Very nice job, mate!!

I'm working on a proprietary tablature format and I'd like to convert it to phptabs format, in order to export to midi and gp5. I already mapped some of the structures like Channel, Note, Voice, Measure but the save function is still throwing errors. I'm probably missing something. So I'd like to ask if you have a minimal example of a tablature written from scratch. That would be very useful!

Thanks again.

Regards,
Chrystian.

Render option for single measures only

I have recently tried the render function to ASCII format. It work very well, but I did not see an option to render only a single measure or a range of measures of a single track.

In order to enable such a feature I wrote an external function:

function PhpTabs_Render_Single_Measure(\PhpTabs\PhpTabs $tab_source, $track_number, $measure_number)
{
	// Create new Tablature, Track and copy Track name
	$tablature 	= new PhpTabs();
	$track 		= new Track();
	$track->setName($tab_source->getTrack($track_number)->getName());
	$tablature->addTrack($track);

	// Copy Strings
	$strings = $tab_source->getTrack($track_number)->getStrings();
	for($i=0;$i<count($strings);$i++) {
		$s = new TabString();
		$s->copyFrom($strings[$i]);
		$track->addString($s);
	}

	// Copy Measure Header according to $measure_number
	$mh = new MeasureHeader();
	$mh->copyFrom($tab_source->getMeasureHeader($measure_number));
	$mh->setNumber(1);
	$tablature->addMeasureHeader($mh);

	// Copy Measure according to $measure_number
	$m = new Measure($mh);
	$m->copyFrom($tab_source->getTrack($track_number)->getMeasure($measure_number));
	$track->addMeasure($m);

	
	$render_output = $tablature->getRenderer('ascii')->render(0);
	while($render_output[0] == chr(13) || $render_output[0] == chr(10))
	{
		$render_output = ltrim($render_output, chr(10));
		$render_output = ltrim($render_output, chr(13));
	}

	$output = "Measure " . ($measure_number + 1);
	$output.= " (" . $mh->getTimeSignature()->getNumerator() . "/" . $mh->getTimeSignature()->getDenominator()->getValue() . "):";
	$output.= "\n";
	$output.= $render_output;

	return $output;
}

I"m sure there is a better/easier way to do that. But for the time being, this function works and could easily be extended to render a range of measures.

For future version, I suggest to add this feature to the renderer. :)

Best,

MrChros

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.