clip2code.php
<?
include("_renoisefunctions.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<style>
HTML,BODY{
background-color : #fef1e7;
height:100%;
padding:5px;
margin:0px;
font-family:arial;
}
TEXTAREA{
width:100%;
font-size:0.8em;
border:10px solid #6b0e10;
margin:0px;
}
H1{
border-top:5px solid black;
color:#fcffcc;
background-color:maroon;
margin:0px;
padding:5px;
font-size:95%;
}
H1 a{
font-size:85%;
color:#999999;
margin-left:100px;
}
H1 a:hover{
font-size:85%;
color:yellow;
margin-left:100px;
}
H2{
border-top:5px solid black;
color:white;
background-color:maroon;
margin:0px;
padding:5px;
font-size:90%;
}
.error{
margin-top:10px;
padding:0px;
background-color:#f0d1ad;
color:#d03025;
border: 1px solid black;
width:100%;
height:190px;
}
.error .header{
font-size:1.1em;
background-color:#d03025;
color:white;
padding:5px;
}
.error b{
padding:10px;
display:block;
}
.error img{
margin:10px;
text-decoration:none;
float:left;
border:1px solid black;
}
code{
white-space: nowrap;
}
form{
margin:0px;
}
.codeoutput{
background-color:#333333;
color:#dddddd;
border:10px solid #6b0e10;
padding:10px;
white-space: nowrap;
overflow: scroll;
}
</style>
<script language="JavaScript">
function initall(){
ta_onload();
}
function ta_onload(){
var taObj=document.getElementById("xmldata");
ta_init_val=taObj.value;
}
function ta_onfocus(taObj){
if(taObj.value==ta_init_val){
taObj.value="";
taObj.style.color='black';
}
}
</script>
<title>Renoise Clip2Code</title>
</head>
<body OnLoad="initall()">
<h1><img src="rnlogo.gif" align="centre" width="84" height="32"> Clip2Code Utility by Mick Rippon <a href='clip2code_source.php'>view source</a></h1>
<form action="<?echo $_SERVER["REQUEST_URI"];?>" method="post" name="cliptocode" id="cliptocode">
<textarea id="xmldata" cols="0" rows="20" name="xmldata" <?if(!$_POST[xmldata])echo "OnFocus=\"ta_onfocus(this)\"";?>>
<?
if($_POST[xmldata]){
echo stripslashes($_POST[xmldata]);
}else{
echo "Paste Renoise Clipboard XML in Here";
}
?>
</textarea>
<input type="submit" value="Convert to Code">
</form>
<?
if($_POST[xmldata]){
$renoise=new renoiseUtil();
$cliparray=$renoise->PatternClipToArray($_POST[xmldata]);
echo "<h2>Output</h2>";
foreach($cliparray[data] as $track_id=>$track_data){
if($track_data[NoteColumns]){
foreach($track_data[NoteColumns] as $col_id=>$col_data){
for($x=0; $x<=$cliparray[maxlines]; $x++){
if(!$col_data[$x][Note])$col_data[$x][Note]="---";
if(!$col_data[$x][Instrument])$col_data[$x][Instrument]=" ";
if(!$col_data[$x][Volume])$col_data[$x][Volume]="..";
if($cliparray[panmode]){
if(!$col_data[$x][Panning])$col_data[$x][Panning]=" .."; else $col_data[$x][Panning]=" ".$col_data[$x][Panning];
}else{
$col_data[$x][Panning]="";
}
$output[$x].=$col_data[$x][Note].$col_data[$x][Instrument].$col_data[$x][Volume].$col_data[$x][Panning]." ";
}
}
}
if($track_data[EffectColumns]){
foreach($track_data[EffectColumns] as $col_id=>$col_data){
for($x=0; $x<=$cliparray[maxlines]; $x++){
if(!$col_data[$x][Number])$col_data[$x][Number]="--";
if(!$col_data[$x][Value])$col_data[$x][Value]="--";
$output[$x].=$col_data[$x][Number].$col_data[$x][Value]." ";
}
}
}else{
for($x=0; $x<=$cliparray[maxlines]; $x++){
if(!$col_data[$x][Number])$col_data[$x][Number]="--";
if(!$col_data[$x][Value])$col_data[$x][Value]="--";
$output[$x].=$col_data[$x][Number].$col_data[$x][Value]." ";
}
}
for($x=0; $x<=$cliparray[maxlines]; $x++){
$output[$x].=" | ";
}
}
if(!$output)echo "we have a problem. :("; else{
echo "<div class='codeoutput'>";
echo "<code>\n";
foreach($output as $row_id=>$row_data){
$row_id=str_pad($row_id,3, "0", STR_PAD_LEFT);
echo "$row_id | $row_data<br>\n";
}
echo "</code>\n</div>\n";
}
}
?>
</body>
</html>
_renoisefunctions.php
<?
class renoiseUtil{
function PatternClipToArray($clipdata){
$maxLines=0;
$doc = new DOMDocument();
@$doc->loadXML(stripslashes($clipdata));
$items=$doc->getElementsByTagName("TrackColumns")->item(0);
if(!$items)$this->death("No Track Columns Found<br>XML struct appears to be fucked.");
$TrackColumns=$this->getChildrenOf($items);
if(!$TrackColumns)$this->death("No Track Columns Found");
foreach($TrackColumns as $track_id=>$track_obj){
$Track_subcols=$this->getChildrenOf($track_obj);
foreach($Track_subcols as $subcol_id=>$subcol_obj){
$subcol_info=$this->getChildrenOf($subcol_obj);
foreach($subcol_info as $trackEntity_obj){
$tagName=$trackEntity_obj->tagName;
if($tagName=="Lines"){
$lineData=$this->getChildrenOf($trackEntity_obj);
foreach($lineData as $rowdata){
$rowIndex=$rowdata->attributes->getNamedItem('index')->value;
if($rowIndex>$maxLines)$maxLines=$rowIndex;
$cellData=$this->getChildrenOf($rowdata);
if($cellData){
foreach($cellData as $cellinfo){
if($cellinfo->tagName=="NoteColumns"){
$noteData=$this->getChildrenOf($cellinfo); $noteData=$noteData[0];
$noteData=$this->getChildrenOf($noteData);
foreach($noteData as $noteAttribs){
$build[$track_id][NoteColumns][$subcol_id][$rowIndex][$noteAttribs->tagName]=$noteAttribs->nodeValue;
if($noteAttribs->tagName=="Panning")$panmode=TRUE;
}
}
if($cellinfo->tagName=="EffectColumns"){
$noteData=$this->getChildrenOf($cellinfo); $noteData=$noteData[0];
$noteData=$this->getChildrenOf($noteData);
foreach($noteData as $noteAttribs){
$build[$track_id][EffectColumns][$subcol_id][$rowIndex][$noteAttribs->tagName]=$noteAttribs->nodeValue;
}
}
}
}
}
}
}
}
}
return array("data"=>$build, "maxlines"=>$maxLines, "panmode"=>$panmode);
}
function getChildrenOf($obj){
$itemList=$obj->childNodes;
if(!$itemList)return FALSE;
foreach($itemList as $k=>$thiselementObj){
if($thiselementObj->nodeType==XML_ELEMENT_NODE){
$ret[]=$thiselementObj;
}
}
return $ret;
}
function death($err){
echo "<div class='error'>";
echo "<div class='header'>Error</div>";
echo "<img src=\"cry.jpg\">";
echo "<b>$err</b>";
echo "</div>";
exit();
}
}
?>