1<?php 2 /* 3 * Hydrogen Web Toolkit 4 * Copyright(c) 2008 by Sebastian Moors [mauser@smoors.de] 5 * 6 * http://www.hydrogen-music.org 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY, without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * 22 */ 23 24 25 /* 26 Use this script if you want to share your hydrogen songs,patterns and 27 drumkits with other people. It generates a xml-file which can be used 28 with the hydrogen soundlibrary. 29 30 Just place this script in one directory with all your drumkits, songs 31 and patterns and make it available via a webserver. 32 33 Songs and patterns could be parsed in place. Since drumkits are archives, 34 we cannot parse the files at runtime. Therefore, just the name and the url of the drumkit will be used. 35 If you want additional information ( such as author / info ) take a look 36 at the metaInfo.inc file (the file has to be in the same directory as this script). 37 38 */ 39 40 41 /* 42 metaInfo.inc holds meta information about the drumkits, namely: 43 44 - url 45 - author 46 - info 47 - name 48 49 If metaInfo.inc is not available, the script takes the filename as namely and guesses the url 50 */ 51 52 if ( is_file("metaInfo.inc") ) { 53 include("metaInfo.inc"); 54 } 55 56 57 function getTag( $xml , $tag ){ 58 preg_match( "/". $tag . "(.*)</" , $xml , $found ); 59 if( ISSET( $found[1] ) ) { 60 return $found[1]; 61 } 62 } 63 64 65 //$url should be defined in metaInfo.inc 66 if( ! ISSET( $url ) ){ 67 $url = $_SERVER [ 'SERVER_NAME' ] ; 68 $dir = dirname ( $_SERVER['PHP_SELF'] ) ; 69 $url = "http://$url$dir"; 70 $drumkitImageUrl = $url + '/' + $drumkitImageDir; 71 } 72 73 $author = ""; 74 $info = ""; 75 76 /* Start of xml-document */ 77 78 print "<?xml version='1.0' encoding='UTF-8'?>\n"; 79 print "<drumkit_list>\n"; 80 81 82 /* Start of song listing */ 83 84 85 $dir = "./"; 86 if ($dh = opendir( $dir )) { 87 while (( $file = readdir($dh) ) !== false) { 88 $extension = array_pop( explode(".", $file) ); 89 if( $extension == "h2song" ) { 90 print "\t<song>\n"; 91 $content = file( $dir.$file ); 92 $xml = join( " ",$content ); 93 print "\t\t<name>" . getTag( $xml , "<name>" ) . "</name>\n"; 94 print "\t\t<url>" . $url.$file ."</url>\n"; 95 print "\t\t<author>" . getTag( $xml , "<author>" ) . "</author>\n"; 96 print "\t\t<info>" . getTag( $xml , "<info>" ) . "</info>\n"; 97 print "\t</song>\n"; 98 } 99 } 100 closedir( $dh ); 101 } 102 /* End of song listing */ 103 104 105 106 /* Start of pattern listing */ 107 $dir = "./"; 108 if ($dh = opendir( $dir )) { 109 while ( ( $file = readdir( $dh ) ) !== false ) { 110 $extension = array_pop(explode( ".", $file )); 111 if( $extension == "h2pattern" ) { 112 $content = file( $dir.$file ); 113 $xml = join( " " , $content ); 114 print "\t<pattern>\n"; 115 print "\t\t<name>" . getTag( $xml , "<name>" ) . "</name>\n"; 116 print "\t\t<url>" . $url.$file ."</url>\n"; 117 print "\t</pattern>\n"; 118 } 119 } 120 closedir( $dh ); 121 } 122 /* End of pattern listing */ 123 124 125 /* Start of drumkit listing */ 126 $dir = "./"; 127 $hasImages = false; 128 if ($imageDirHandle = opendir( $drumkitImageDir ) ) { 129 $hasImages = true; 130 $imageFiles[] = array(); 131 while ( ( $f = readdir($imageDirHandle ) ) !== false ) { 132 $imageFiles[] = $file; 133 } 134 closedir($dh); 135 } 136 137 if ($dh = opendir( $dir ) ) { 138 while ( ( $file = readdir( $dh ) ) !== false) { 139 $extension = array_pop( explode( ".", $file ) ); 140 if( $extension == "h2drumkit" ) { 141 $content = file( $dir.$file ); 142 $xml = join( " " , $content ); 143 print "\t<drumkit>\n"; 144 145 //name: filename without extension 146 $name = basename( $file,".h2drumkit" ); 147 148 If( ISSET( $drumkit_list[ $name ]) ){ 149 $author = $drumkit_list[ $name ][ "author" ]; 150 $info = $drumkit_list[ $name ][ "info" ]; 151 } 152 153 print "\t\t<name> $name </name>\n"; 154 print "\t\t<url>" . $url.$file ."</url>\n"; 155 print "\t\t<author>$author</author>\n"; 156 print "\t\t<info>$info</info>\n"; 157 // Get image 158 // Possible method: Have image filename same as basename of drumkit file. 159 // ie: for DeathMetal.h2drumkit, image file would be DeathMetal.jpeg 160 // and allow for .png as well (non-case sensitive extension) 161 // The drumkit filenames need to be unique, and this would force the 162 // images to be unique names but be consistent. 163 // use regex like: /.*\.(?:jpeg|jpg|png)/i 164 // 165 // Go through all files in image directory named $basename.* and 166 // see if there's a regex match, if so use that image file 167 if ( $hasImages ) 168 { 169 // search $imageFiles array for basename that matches with extension that matches regex 170 $images = preg_grep( "/.*\.(?:jpeg|jpg|png)/i", $imageFiles ); 171 if ( count( $images ) ) { 172 // if there's more than one match we'll just use the first 173 print "\t\t<image>" . $drumkitImageUrl . "/" . $images[0] . "</image>"; 174 } 175 } 176 print "\t</drumkit>\n"; 177 } 178 } 179 closedir( $dh ); 180 } 181 /* End of pattern listing */ 182 183 184 print "</drumkit_list>\n"; 185 186 187?> 188