summaryrefslogtreecommitdiff
path: root/scripts/gdparams.pm
blob: 35aa3193678c54eadea26109de66a7d87bb58b95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
##################################################
#
# GiantDisc mp3 Jukebox
# 
# © 2000, Rolf Brugger
#
##################################################

package gdparams;

#use lib '/usr/local/bin';
use strict;
use Getopt::Long;

my @mp3dirs;

############################################################
### Global variables (accessible from anywhere)

# IMPORTANT ERROR!  all modules refer to gdparms::varname instead
# of gdparams::varname
# ... however, it works ... I just don't know why  :-/


#my ($dbhost, $shutdowncmd, $extmp3player, $defrecbitrate,
#    $systemonline);


### Global constants
my $minfreehdspace = 1000;	# minimal space required for a directory, 
				# that it can be used to record and 
				# compress a cd (in MB)


############################################################
###

sub get_configfile_params{
  ### Parameters: Call-by-reference

  my ($dbhost, 
    $commmode,
    $serialdevice, $serialspeed,
    $tcpiphost, $tcpipport,
    $playerhost, $playertype, $snddevice, 
    $playerapp, $mp3playerparams, $oggplayerparams, $ptlogger, 
    $mp3encoder, $logtarget, $shutdowncmd,
    $extmp3player, $defrecbitrate, $systemonline
    ) 		= @_;

  
  ### Read configuration file im home directory
  open (CONF, "< ".gdbase()."/.gdconfig")
    or die "Error: could not open configuration file .gdconfig\n";
    
  my $line;
  while(<CONF>){
    $line = $_;
    chop $line;
    $line =~ tr/\r/ /;
	# \w word-char
	# \w non-word-char
	# \s whitespace-char
	# \S non-whitespace-char

    if($line =~ m/^dbhost.*=\s*(\S+)/i ){
      $$dbhost = $1;
    }

    if($line =~ m/^commmode.*=\s*([0-9]+)/i ){
      $$commmode = $1;
    }

    if($line =~ m/^serialdevice.*=\s*([\w\/]+)/i ){
      $$serialdevice = $1;
    }

    if($line =~ m/^serialspeed.*=\s*([0-9]+)/i ){
      $$serialspeed = $1;
    }

    if($line =~ m/^tcpiphost.*=\s*(\S+)/i ){
      $$tcpiphost = $1;
    }

    if($line =~ m/^tcpipport.*=\s*([0-9]+)/i ){
      $$tcpipport = $1;
    }

    if($line =~ m/^playerhost.*=\s*(\S+)/i ){
      $$playerhost = $1;
    }

    if($line =~ m/^playertype.*=\s*([0-9]+)/i ){
      $$playertype = $1;
    }

    if($line =~ m/^playerapp.*=\s*(\S+)/i ){
      $$playerapp = $1;
    }

    if($line =~ m/^playerparams.*=\s*(.*)$/i ){ # match anything to end of line
      print "\nWARNING: as of v1.20 the option 'playerparams' has been replaced by\n";
      print "         'mp3playerparams' and 'oggplayerparams'. Update .gdconfig accordingly\n\n";
      #$$playerparams = $1;
    }
    if($line =~ m/^mp3playerparams.*=\s*(.*)$/i ){ # match anything to end of line
      $$mp3playerparams = $1;
    }
    if($line =~ m/^oggplayerparams.*=\s*(.*)$/i ){ # match anything to end of line
      $$oggplayerparams = $1;
    }

    if($line =~ m/^shutdowncmd.*=\s*(.*)$/i ){ # match anything to end of line
      $$shutdowncmd = $1;
    }

    if($line =~ m/^extmp3player.*=\s*(.*)$/i ){ # match anything to end of line
      $$extmp3player = $1;
    }

    if($line =~ m/^sounddevice.*=\s*(\S+)/i ){
      $$snddevice = $1;
    }

    if($line =~ m/^mp3encoder.*=\s*(\w+)/i ){
      $$mp3encoder = $1;
    }

    if($line =~ m/^logtarget.*=\s*(\w+)/i ){
      if ($1 eq "stdout" || $1 eq "logfile" || $1 eq "devnull"){
        $$logtarget = $1;
      }
    }

    if($line =~ m/^ptlogger.*=\s*(\S+)/i ){
      $$ptlogger = $1;
    }

    if($line =~ m/^defrecbitrate.*=\s*(.+)/i ){ # match anything to end of line
      $$defrecbitrate = $1;
    }

    if($line =~ m/^systemonline.*=\s*([0-9])/i ){
      $$systemonline = $1;
    }

  }

  close (CONF);
}


############################################################
###

sub get_otherclients_params{
  ### Parameters: Call-by-reference

  my ($keymap  # type: reference to an empty hash
    )= @_;

  
  ### Read configuration file im home directory
  open (CONF, "< ".gdbase()."/.gdconfig")
    or die "Error: could not open configuration file .gdconfig\n";
    
  my $line;
  while(<CONF>){
    $line = $_;
    chop $line;
    $line =~ tr/\r/ /;
	# \w word-char
	# \w non-word-char
	# \s whitespace-char
	# \S non-whitespace-char

    if($line =~ m/^keymap.*=\s*(\S+)\s*-\s*(\S+)\s*$/i ){
      print ("keymap: key: $1, val: $2\n");
      $$keymap{$1} = $2;
    }


  }

  close (CONF);
}


############################################################
### translate logtarget string to integer
sub logtarget_to_int{
  my ($logtargetstr) = @_;
  if ($logtargetstr eq "devnull") {return 0;}
  if ($logtargetstr eq "logfile") {return 1;}
  if ($logtargetstr eq "stdout" ) {return 2;}
  return 2; # default
}


############################################################
###

sub get_commandline_params{

  my ($dbhost, 
    $commmode,
    $serialdevice, $serialspeed,
    $tcpiphost, $tcpipport,
    $playerhost, $playertype, $snddevice, 
    $playerapp, 
    $mp3playerparams, $oggplayerparams, 
    $ptlogger, 
    $mp3encoder, $logtarget) 		= @_;
	# ARGV passed implicitly


  my $help;
  $Getopt::Long::autoabbrev=1;
  GetOptions(
	"help" 		 => \$help, 
	"dbhost:s" 	 => $dbhost,	# $dbhost is already a reference
	"commmode:i"     => $commmode,
	"serialdevice:s" => $serialdevice,
	"serialspeed:i"  => $serialspeed,
	"tcpiphost:s"    => $tcpiphost,
	"tcpipport:i"    => $tcpipport,
	"playertype:i"   => $playertype,
	"playerhost:s"   => $playerhost,
	"sounddevice:s"  => $snddevice,
	"mp3playerparams=s" => $mp3playerparams,
	"oggplayerparams=s" => $oggplayerparams,
	"ptlogger:s"	 => $ptlogger,
	"mp3encoder:s"	 => $mp3encoder,
	"logtarget:s"	 => $logtarget
	);

  if ($help){
  print <<EOF;
gdd.pl: GiantDisc Server Script
Option         possible values  

--dbhost (string)          address or hostname of mysql database server
                           Default value: localhost    

--commmode (number)        Communication mode between Palm and server.
                           1: serial line RS232
                           2: generic TCP/IP (server - accepts incoming connections)
                           3: generic TCP/IP (client - connects to server)
                           Default value: 1

--serialdevice (string)    Device, where Palm is connected to. 
                           Only used if --commmode 1
                           Default value: /dev/ttyS0

--serialspeed  (number)    Communication speed over serial line in
                           Bits per second.
                           Only used if --commmode 1
                           Default value: 19200

--tcpiphost (string)       Host, that accepts socket connections.
                           Only used if --commmode 2 or 3
                           Default value: localhost
                                  
--tcpipport  (number)      Port used for TCP/IP communication mode.
                           Only used if --commmode 2 or 3
                           Default value: 26468

--playertype (number)      main audio out device type
                           0:  soundcard (first audio channel)
                           20: network attached audio streaming device
                           Default value: 0

--playerhost (string)      address or hostname where the audio stream
                           is sent to.
                           playertype 0:  host of soundcard (not used)
                           playertype 20: audio stream decoder host
                           Default value: localhost

--sounddevice  (string)    Device where audio stream is sent to.
                           playertype 0:  soundcard device (not used)
                           playertype 20: port number of TCP stream
                           Default value: 2020

--mp3playerparams (string) Optional parameters to the mp3 or ogg 
--oggplayerparams (string) decoder. Example: "--buffer 1024" to 
                           increase the audio output buffer size of
                           "mpg123".
                           Default value: 

--ptlogger     (string)    The application that updates at least
                           once per second the playtime of the
                           currently played track (needed by Palm
                           to display the playtime).
                           Default value: gdplatimefilter

--mp3encoder   lame,       Application to be used to encode ripped
               notlame,    wav files into mp3 format.
               l3enc       Default value: lame

--logtarget    stdout,     Target, where log-messages of the 
               logfile,    server script should be sent to. 
               or devnull  'stdout' sends to standard out, 'logfile'
                           sends to a log file in ~music/tmp and
                           devnull supresses all logging.
                           Default value: stdout

EOF
  exit 0;
  }
}


############################################################
###

sub gdbase{ # returns base path of gd files 
	    # The path must not end with a slash!
  return "/home/music";
}

sub mp3dirs{	# returns list of mp3 directories
		# Scans the music directory for 2-digit directories

  opendir MUSICDIR, gdbase() or die "ERROR: can't scan music directory\n";
  @mp3dirs = grep /^[0-9][0-9]$/ , readdir MUSICDIR;
  closedir MUSICDIR;
  #print "MP3dirs: ",@mp3dirs, "\n";
  return ( @mp3dirs );
}




1;
#