root/trunk/extra/serverTools/hydrogen.php

Revision 122, 4.2 kB (checked in by smoors, 9 months ago)

added a php-script which could be used to generate xml-files for the SoundLibrary?

Line 
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 informations ( 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 informations 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     }
71
72     $author = "";
73     $info = "";
74
75     /* Start of xml-document */
76
77     print "<?xml version='1.0' encoding='UTF-8'?>\n";
78     print "<drumkit_list>\n";
79
80
81     /* Start of song listing */
82     
83
84     $dir = "./";
85     if ($dh = opendir( $dir )) {
86             while (( $file = readdir($dh) ) !== false) {
87             $extension = array_pop( explode(".", $file) );
88             if( $extension == "h2song" ) {
89                 print "\t<song>\n";
90                 $content = file( $dir.$file );
91                 $xml = join( " ",$content );
92                 print "\t\t<name>" . getTag( $xml , "<name>" ) . "</name>\n";
93                 print "\t\t<url>" . $url.$file ."</url>\n";
94                 print "\t\t<author>" . getTag( $xml , "<author>" ) . "</author>\n";
95                 print "\t\t<info>" . getTag( $xml , "<info>" ) . "</info>\n";
96                 print "\t</song>\n";
97             }
98             }
99             closedir( $dh );
100         }
101     /* End of song listing */
102
103
104
105     /* Start of pattern listing */
106     $dir = "./";
107     if ($dh = opendir( $dir )) {
108             while ( ( $file = readdir( $dh ) ) !== false ) {
109             $extension = array_pop(explode( ".", $file ));
110             if( $extension == "h2pattern" ) {
111                 $content = file( $dir.$file );
112                 $xml = join( " " , $content );
113                 print "\t<pattern>\n";
114                 print "\t\t<name>" . getTag( $xml , "<name>" ) . "</name>\n";
115                 print "\t\t<url>" . $url.$file ."</url>\n";
116                 print "\t</pattern>\n";
117             }
118             }
119             closedir( $dh );
120         }   
121     /* End of pattern listing */
122
123
124     /* Start of drumkit listing */
125     $dir = "./";
126     if ($dh = opendir( $dir ) ) {
127             while ( ( $file = readdir( $dh ) ) !== false) {
128             $extension = array_pop( explode( ".", $file ) );
129             if( $extension == "h2drumkit" ) {
130                 $content = file( $dir.$file );
131                 $xml = join( " " , $content );
132                 print "\t<drumkit>\n";
133             
134                 //name: filename without extension
135                 $name = basename( $file,".h2drumkit" );
136
137                 If( ISSET( $drumkit_list[ $name ]) ){
138                     $author = $drumkit_list[ $name ][ "author" ];
139                     $info = $drumkit_list[ $name ][ "info" ];
140                 }
141
142                 print "\t\t<name> $name </name>\n";
143                 print "\t\t<url>" . $url.$file ."</url>\n";
144                 print "\t\t<author>$author</author>\n";
145                 print "\t\t<info>$info</info>\n";
146                 print "\t</drumkit>\n";
147             }
148             }
149             closedir( $dh );
150         }   
151     /* End of pattern listing */
152
153
154     print "</drumkit_list>\n";
155         
156
157 ?>
158
Note: See TracBrowser for help on using the browser.