Wednesday, August 22, 2007

Convert MusicXML to Power Tabs

Here's a source snippet that will allow you to convert "P1" of a MusicXML score to a power tab file. This is just an example of what you can do with the php power tab classes. Keep in mind, you must have the latest version of the PHP ptparser for this to work.

The score will look funny when you open it. Run the score polisher. This will make it readable.

Hopefully this will inspire someone to make a complete converter.




<?

require_once "powertabdocument.php";


$ptb = new PowerTabDocument ();


$durArr = array('64th'=>64, '32nd'=>32, '16th'=>16,'eighth'=>8, 'quarter'=>4, 'half'=>2, 'whole'=>1);

$ptb->Load ("BlankPowerTabFile.ptb");
$guitarScore = &$ptb->GetGuitarScore();

$sxe = simplexml_load_file("music.xml");

$s = -1;
$measureCt = 3;

foreach ($sxe->part->measure as $measure) {

if ($measureCt > 1) {
$guitarScore->m_systemArray[++$s] = new System;
$measureCt = 1;
$p=0;
}

$firstStaff = &$guitarScore->GetSystem($s)->GetStaff(0);


foreach ($measure->note as $note) {

$string = $note->notations->technical->string;
$fret = $note->notations->technical->fret;
$tied = $note->notations->tied["type"];

$dur = $durArr[(string) $note->type];

if ( isset($string,$fret) ) {

if (!$note->chord) {
$thePosition = &$firstStaff->m_positionArray[0][$p];
$thePosition = new Position ();

$thePosition->SetDurationType($dur);

//$thePosition->SetPreviousBeamDurationType($prevDur);

$prevDur = $dur;

++$p;
}

array_push($thePosition->m_noteArray,new Note($string-1, $fret) );

if ($tied=="stop")
$thePosition->m_noteArray[count($thePosition->m_noteArray) - 1]->SetTied();
}


}

$barLines = &$guitarScore->GetSystem($s)->m_barlineArray;

array_push($barLines,new Barline($p) );


++$measureCt;


}

$ptb->Save ("ConvertedFileName.ptb");

?>

Thursday, August 09, 2007

PHP Power Tab Parser


We have just Written and Released a PHP Power Tab Parser. It is in beta, so please leave comments and report any bugs you may have.


This parser is a translation of Brad Larson's "ptparser." You must have PHP v5 or better. This package will only read and write power tab v1.7 files. See the sample script below to get your feet wet. This will load a power tab file and watermark it with a line of text at the top of the guitar score. This script is great if you are serving up power tab file, and you don't want someone stealing your power tabs, and redistributing them.




<?

require_once "powertabdocument.php";


$ptb = new PowerTabDocument ();

$ptb->Load ("powertabfile.ptb"); // Open and Load Power Tab

/* Water Mark File */

$guitarScore = &$ptb->GetGuitarScore(); // get the guitar score

$lastIndex = $guitarScore->GetFloatingTextCount(); // get the position of the last floating text element

$waterMark = &$guitarScore->m_floatingTextArray[$lastIndex];

$waterMark = new FloatingText ();

$rect = array (50,3,230,17); // create a new coordinate element

$waterMark->SetRect($rect);
$waterMark->SetText('File Downloaded @ AllPowerTabs.com');

/* Done Water Marking File */


$ptb->Save ("powertabfile.ptb"); // Save Power Tab File

?>



We have a lot planned for the feature, so keep checking the blog.

Music Headlines

Loading...