| 1 |
/* Playing a sound file |
| 2 |
|
| 3 |
* Copyright (C) 1998 J.A. Bezemer |
| 4 |
* |
| 5 |
* Licensed under the terms of the GNU General Public License. |
| 6 |
* ABSOLUTELY NO WARRANTY. |
| 7 |
* See the file `COPYING' in this directory. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "playwav.h" |
| 11 |
#include "scrollmenu.h" |
| 12 |
#include "stringinput.h" |
| 13 |
#include "buttons.h" |
| 14 |
#include "boxes.h" |
| 15 |
#include "dirfilemenu.h" |
| 16 |
#include "errorwindow.h" |
| 17 |
#include "textwindow.h" |
| 18 |
#include "checkfile.h" |
| 19 |
#include "yesnowindow.h" |
| 20 |
#include "helpline.h" |
| 21 |
#include "clrscr.h" |
| 22 |
#include "secshms.h" |
| 23 |
#include "fmtheaders.h" |
| 24 |
#include "signpr_main.h" |
| 25 |
|
| 26 |
#include <stdlib.h> |
| 27 |
#include <sys/stat.h> |
| 28 |
#include <string.h> |
| 29 |
#ifndef OLD_CURSES |
| 30 |
#include <ncurses.h> |
| 31 |
#else |
| 32 |
#include <curses.h> |
| 33 |
#endif |
| 34 |
|
| 35 |
|
| 36 |
void |
| 37 |
playwav_playit (char *filename, int usebeginendtime, double begintime, |
| 38 |
double endtime) |
| 39 |
{ |
| 40 |
char shellcmd[500]; |
| 41 |
|
| 42 |
switch (checkfile (filename)) |
| 43 |
{ |
| 44 |
case FILE_EXISTS: |
| 45 |
|
| 46 |
if (usebeginendtime) |
| 47 |
sprintf (shellcmd, "bplay_gramo -S -s 44100 -b 16 -J %ld -T %ld %s", |
| 48 |
(long) (begintime * 44100), |
| 49 |
(long) ((endtime - begintime) * 44100), filename); |
| 50 |
else |
| 51 |
sprintf (shellcmd, "bplay_gramo -S -s 44100 -b 16 %s", filename); |
| 52 |
/* defaults for raw files (but no -r, so .wav's supply their own |
| 53 |
parameters) - you can even listen to executables in CD quality (: */ |
| 54 |
|
| 55 |
def_prog_mode (); /* save terminal state */ |
| 56 |
|
| 57 |
system (shellcmd); |
| 58 |
|
| 59 |
reset_prog_mode (); /* reset terminal state */ |
| 60 |
clear (); |
| 61 |
|
| 62 |
break; |
| 63 |
|
| 64 |
case DIR_EXISTS: |
| 65 |
error_window ("The specified name is of a directory. A \ |
| 66 |
file name must be specified."); |
| 67 |
break; |
| 68 |
|
| 69 |
case DIR_OK_NEW_FILE: |
| 70 |
case DIR_WRONG: |
| 71 |
error_window ("The specified file does not exist."); |
| 72 |
break; |
| 73 |
|
| 74 |
default: |
| 75 |
error_window ("Fell out of switch, playwav #2"); |
| 76 |
break; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
#define PLAY_TRACK 1 |
| 81 |
#define PLAY_BEGINNING 2 |
| 82 |
#define PLAY_END 3 |
| 83 |
#define PLAY_BEFORE 4 |
| 84 |
#define PLAY_AFTER 5 |
| 85 |
|
| 86 |
/* These may be fractional, like 5.2, if you like that better. */ |
| 87 |
#define BEGINNING_SECS 5 |
| 88 |
#define END_SECS 4 |
| 89 |
#define BEFORE_SECS 3 |
| 90 |
#define AFTER_SECS 3 |
| 91 |
|
| 92 |
void |
| 93 |
playwav_track (char *filename, int track, int action) |
| 94 |
{ |
| 95 |
beginendsample_t tracktimes[100]; |
| 96 |
int number_of_tracks; |
| 97 |
double begintime, endtime; |
| 98 |
char helpstring[200]; |
| 99 |
|
| 100 |
if (!load_track_times (filename, tracktimes, &number_of_tracks)) |
| 101 |
return; |
| 102 |
|
| 103 |
if (track > number_of_tracks || track < 1) |
| 104 |
{ |
| 105 |
sprintf (helpstring, "There are only %d tracks.", number_of_tracks); |
| 106 |
error_window (helpstring); |
| 107 |
return; |
| 108 |
} |
| 109 |
|
| 110 |
switch (action) |
| 111 |
{ |
| 112 |
case PLAY_TRACK: |
| 113 |
begintime = tracktimes[track].begin; |
| 114 |
endtime = tracktimes[track].end; |
| 115 |
/* use samples here, convert to seconds after switch */ |
| 116 |
break; |
| 117 |
|
| 118 |
case PLAY_BEGINNING: |
| 119 |
begintime = tracktimes[track].begin; |
| 120 |
endtime = tracktimes[track].begin + BEGINNING_SECS * 44100; |
| 121 |
break; |
| 122 |
|
| 123 |
case PLAY_END: |
| 124 |
begintime = tracktimes[track].end - END_SECS * 44100; |
| 125 |
endtime = tracktimes[track].end; |
| 126 |
break; |
| 127 |
|
| 128 |
case PLAY_BEFORE: |
| 129 |
begintime = tracktimes[track].begin - BEFORE_SECS * 44100; |
| 130 |
endtime = tracktimes[track].begin; |
| 131 |
break; |
| 132 |
|
| 133 |
case PLAY_AFTER: |
| 134 |
begintime = tracktimes[track].end; |
| 135 |
endtime = tracktimes[track].end + AFTER_SECS * 44100; |
| 136 |
break; |
| 137 |
|
| 138 |
default: |
| 139 |
error_window ("Fell out of switch, playwav #3"); |
| 140 |
return; |
| 141 |
} |
| 142 |
|
| 143 |
if (begintime < 0) |
| 144 |
begintime = 0; |
| 145 |
if (endtime < 0) |
| 146 |
endtime = 0; |
| 147 |
if (begintime >= endtime) |
| 148 |
return; |
| 149 |
|
| 150 |
/* samples -> seconds here */ |
| 151 |
playwav_playit (filename, 1, begintime / 44100, endtime / 44100); |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
int |
| 156 |
playwav_select_file (char *startdir, char *selectedfile, |
| 157 |
int *usebeginendtime, double *begintime, |
| 158 |
double *endtime) |
| 159 |
/* Returns 0: canceled, 1: OK */ |
| 160 |
{ |
| 161 |
scrollmenu_t dirfilelist; |
| 162 |
stringinput_t string; |
| 163 |
button_t ok_button, cancel_button; |
| 164 |
int dont_stop = TRUE; |
| 165 |
int returnval = 0; |
| 166 |
int focus; |
| 167 |
int in_ch; |
| 168 |
int i; |
| 169 |
char helpstring[500]; |
| 170 |
char *charpointer; |
| 171 |
struct stat filestats; |
| 172 |
int oldselected; |
| 173 |
double tempdouble = 0; |
| 174 |
long templong; |
| 175 |
char tempstring[250]; |
| 176 |
stringinput_t trackstring, begintimestring, endtimestring; |
| 177 |
button_t beginend_check; |
| 178 |
struct stat buf; |
| 179 |
|
| 180 |
char *helplines[8] = |
| 181 |
{ |
| 182 |
" Select name of sound file to be played. TAB: Next field", |
| 183 |
" Enter: Play track B/E: Beginning/End F/A: beFore/After +/-: Prev/Next", |
| 184 |
" Play only a part of the sound file. TAB: Next field", |
| 185 |
" Enter begin time of part to be played. TAB: Next field", |
| 186 |
" Enter end time of part to be played. TAB: Next field", |
| 187 |
" Enter name of sound file to be played. TAB: Next field", |
| 188 |
" Back to main menu. TAB: Next field", |
| 189 |
" Play the specified (part of the) sound file. TAB: Next field"}; |
| 190 |
|
| 191 |
dirfilelist.y = 3; |
| 192 |
dirfilelist.x = 5; |
| 193 |
dirfilelist.h = 12; |
| 194 |
dirfilelist.w = 32; |
| 195 |
dirfilelist.firstonscreen = 0; |
| 196 |
dirfilemenu (startdir, &dirfilelist); |
| 197 |
dirfilelist.selected = dirfilelist.last_of_1st_part + 1; |
| 198 |
|
| 199 |
string.maxlen = 500; |
| 200 |
string.string = (char *) malloc (string.maxlen * sizeof (char)); |
| 201 |
if (selectedfile[0] == '\0') |
| 202 |
strcpy (string.string, startdir); |
| 203 |
else |
| 204 |
strcpy (string.string, selectedfile); |
| 205 |
string.y = 17; |
| 206 |
string.x = 5; |
| 207 |
string.w = 70; |
| 208 |
string.cursorpos = strlen (string.string); |
| 209 |
string.firstcharonscreen = strlen (string.string) - string.w + 2; |
| 210 |
if (string.firstcharonscreen < 0) |
| 211 |
string.firstcharonscreen = 0; |
| 212 |
|
| 213 |
ok_button.text = " Play "; |
| 214 |
ok_button.y = 20; |
| 215 |
ok_button.x = 69; |
| 216 |
ok_button.selected = FALSE; |
| 217 |
|
| 218 |
cancel_button.text = " Cancel "; |
| 219 |
cancel_button.y = 20; |
| 220 |
cancel_button.x = 5; |
| 221 |
cancel_button.selected = FALSE; |
| 222 |
|
| 223 |
trackstring.maxlen = 500; |
| 224 |
trackstring.string = (char *) malloc ( |
| 225 |
trackstring.maxlen * sizeof (char)); |
| 226 |
strcpy (trackstring.string, "1"); |
| 227 |
trackstring.y = 11; |
| 228 |
trackstring.x = 54; |
| 229 |
trackstring.w = 10; |
| 230 |
trackstring.cursorpos = strlen (trackstring.string); |
| 231 |
trackstring.firstcharonscreen = 0; |
| 232 |
|
| 233 |
begintimestring.maxlen = 500; |
| 234 |
begintimestring.string = (char *) malloc ( |
| 235 |
begintimestring.maxlen * sizeof (char)); |
| 236 |
fsec2hmsf (*begintime, begintimestring.string); |
| 237 |
begintimestring.y = 14; |
| 238 |
begintimestring.x = 59; |
| 239 |
begintimestring.w = 18; |
| 240 |
begintimestring.cursorpos = strlen (begintimestring.string); |
| 241 |
begintimestring.firstcharonscreen = 0; |
| 242 |
|
| 243 |
endtimestring.maxlen = 500; |
| 244 |
endtimestring.string = (char *) malloc ( |
| 245 |
endtimestring.maxlen * sizeof (char)); |
| 246 |
fsec2hmsf (*endtime, endtimestring.string); |
| 247 |
endtimestring.y = 15; |
| 248 |
endtimestring.x = 59; |
| 249 |
endtimestring.w = 18; |
| 250 |
endtimestring.cursorpos = strlen (endtimestring.string); |
| 251 |
endtimestring.firstcharonscreen = 0; |
| 252 |
|
| 253 |
beginend_check.text = ""; /* see below */ |
| 254 |
beginend_check.y = 13; |
| 255 |
beginend_check.x = 42; |
| 256 |
beginend_check.selected = FALSE; |
| 257 |
|
| 258 |
clearscreen (PLAYWAV_HEADERTEXT); |
| 259 |
|
| 260 |
if (selectedfile[0] == '\0') |
| 261 |
focus = 0; |
| 262 |
else |
| 263 |
focus = 5; |
| 264 |
|
| 265 |
do |
| 266 |
{ |
| 267 |
if (*usebeginendtime) |
| 268 |
beginend_check.text = "[X] Use begin and end times"; |
| 269 |
else |
| 270 |
beginend_check.text = "[ ] Use begin and end times"; |
| 271 |
|
| 272 |
if (focus == 2) |
| 273 |
beginend_check.selected = TRUE; |
| 274 |
else |
| 275 |
beginend_check.selected = FALSE; |
| 276 |
|
| 277 |
if (focus == 6) |
| 278 |
cancel_button.selected = TRUE; |
| 279 |
else |
| 280 |
cancel_button.selected = FALSE; |
| 281 |
|
| 282 |
if (focus == 7) |
| 283 |
ok_button.selected = TRUE; |
| 284 |
else |
| 285 |
ok_button.selected = FALSE; |
| 286 |
|
| 287 |
dirfilelist.hasfocus = (focus == 0); |
| 288 |
|
| 289 |
scrollmenu_display (&dirfilelist); |
| 290 |
mybox (dirfilelist.y - 1, dirfilelist.x - 1, |
| 291 |
dirfilelist.h + 2, dirfilelist.w + 2); |
| 292 |
mvprintw (dirfilelist.y - 1, dirfilelist.x + 1, |
| 293 |
"Files and directories:"); |
| 294 |
|
| 295 |
button_display (&beginend_check); |
| 296 |
|
| 297 |
stringinput_display (&trackstring); |
| 298 |
mvprintw (trackstring.y, trackstring.x - 7, |
| 299 |
"Track:"); |
| 300 |
|
| 301 |
stringinput_display (&begintimestring); |
| 302 |
mvprintw (begintimestring.y, begintimestring.x - 12, |
| 303 |
"Begin time:"); |
| 304 |
|
| 305 |
stringinput_display (&endtimestring); |
| 306 |
mvprintw (endtimestring.y, endtimestring.x - 12, |
| 307 |
"End time :"); |
| 308 |
|
| 309 |
stringinput_display (&string); |
| 310 |
mybox (string.y - 1, string.x - 1, 3, string.w + 2); |
| 311 |
mvprintw (string.y - 1, string.x + 1, "File name:"); |
| 312 |
|
| 313 |
button_display (&cancel_button); |
| 314 |
mybox (cancel_button.y - 1, cancel_button.x - 1, |
| 315 |
3, strlen (cancel_button.text) + 2); |
| 316 |
button_display (&ok_button); |
| 317 |
mybox (ok_button.y - 1, ok_button.x - 1, |
| 318 |
3, strlen (ok_button.text) + 2); |
| 319 |
|
| 320 |
header (PLAYWAV_HEADERTEXT); |
| 321 |
helpline (helplines[focus]); |
| 322 |
|
| 323 |
/* this really should be a switch... */ |
| 324 |
if (focus == 1) |
| 325 |
stringinput_display (&trackstring); |
| 326 |
else if (focus == 3) |
| 327 |
stringinput_display (&begintimestring); |
| 328 |
else if (focus == 4) |
| 329 |
stringinput_display (&endtimestring); |
| 330 |
else if (focus == 5) |
| 331 |
stringinput_display (&string); |
| 332 |
else |
| 333 |
move (0, 79); |
| 334 |
|
| 335 |
refresh (); |
| 336 |
|
| 337 |
in_ch = getch (); |
| 338 |
|
| 339 |
switch (focus) |
| 340 |
{ |
| 341 |
case 0: /* dirfilelist */ |
| 342 |
if (scrollmenu_stdkeys (in_ch, &dirfilelist) >= 0) |
| 343 |
{ |
| 344 |
oldselected = dirfilelist.selected; |
| 345 |
i = dirfilemenu_process_select (&dirfilelist, |
| 346 |
helpstring); |
| 347 |
if (i == 0) /* filename in helpstring */ |
| 348 |
{ |
| 349 |
strcpy (string.string, helpstring); |
| 350 |
focus = 7; |
| 351 |
string.cursorpos = strlen (string.string); |
| 352 |
string.firstcharonscreen = 0; |
| 353 |
|
| 354 |
if (!stat (helpstring, &buf)) |
| 355 |
{ |
| 356 |
*begintime = 0; |
| 357 |
if (buf.st_size < sizeof (wavhead)) |
| 358 |
*endtime = 0; |
| 359 |
else |
| 360 |
*endtime = (buf.st_size - sizeof (wavhead)) |
| 361 |
/ (2 * 2 * 44100.); |
| 362 |
|
| 363 |
fsec2hmsf (*begintime, begintimestring.string); |
| 364 |
begintimestring.cursorpos = |
| 365 |
strlen (begintimestring.string); |
| 366 |
begintimestring.firstcharonscreen = 0; |
| 367 |
|
| 368 |
fsec2hmsf (*endtime, endtimestring.string); |
| 369 |
endtimestring.cursorpos = strlen (endtimestring.string); |
| 370 |
endtimestring.firstcharonscreen = 0; |
| 371 |
} |
| 372 |
} |
| 373 |
else |
| 374 |
/* dir in helpstring */ |
| 375 |
{ |
| 376 |
scrollmenu_delete_menu (&dirfilelist); |
| 377 |
dirfilemenu (helpstring, &dirfilelist); |
| 378 |
if (dirfilelist.number == 0) |
| 379 |
{ |
| 380 |
error_window ( |
| 381 |
"No permission to read this directory."); |
| 382 |
scrollmenu_delete_menu (&dirfilelist); |
| 383 |
dirfilemenu (startdir, &dirfilelist); |
| 384 |
dirfilelist.selected = oldselected; |
| 385 |
} |
| 386 |
else |
| 387 |
{ |
| 388 |
strcpy (startdir, helpstring); |
| 389 |
dirfilelist.firstonscreen = 0; |
| 390 |
|
| 391 |
charpointer = strrchr (string.string, '/'); |
| 392 |
if (charpointer != NULL) |
| 393 |
strcat (helpstring, charpointer + 1); |
| 394 |
else |
| 395 |
strcat (helpstring, string.string); |
| 396 |
strcpy (string.string, helpstring); |
| 397 |
} |
| 398 |
} |
| 399 |
} |
| 400 |
else |
| 401 |
switch (in_ch) |
| 402 |
{ |
| 403 |
case KEY_LEFT: |
| 404 |
focus--; |
| 405 |
break; |
| 406 |
case KEY_RIGHT: |
| 407 |
focus++; |
| 408 |
break; |
| 409 |
} |
| 410 |
break; |
| 411 |
|
| 412 |
case 1: /* tracks */ |
| 413 |
/* exclude keys like b,e,f,a,+,- */ |
| 414 |
if ((in_ch >= '0' && in_ch <= '9') || in_ch > 127) |
| 415 |
stringinput_stdkeys (in_ch, &trackstring); |
| 416 |
|
| 417 |
templong = atol (trackstring.string); |
| 418 |
|
| 419 |
switch (in_ch) |
| 420 |
{ |
| 421 |
case KEY_ENTER: |
| 422 |
case 13: |
| 423 |
playwav_track (string.string, templong, PLAY_TRACK); |
| 424 |
break; |
| 425 |
|
| 426 |
case 'b': |
| 427 |
case 'B': |
| 428 |
playwav_track (string.string, templong, PLAY_BEGINNING); |
| 429 |
break; |
| 430 |
|
| 431 |
case 'e': |
| 432 |
case 'E': |
| 433 |
playwav_track (string.string, templong, PLAY_END); |
| 434 |
break; |
| 435 |
|
| 436 |
case 'f': |
| 437 |
case 'F': |
| 438 |
playwav_track (string.string, templong, PLAY_BEFORE); |
| 439 |
break; |
| 440 |
|
| 441 |
case 'a': |
| 442 |
case 'A': |
| 443 |
playwav_track (string.string, templong, PLAY_AFTER); |
| 444 |
break; |
| 445 |
|
| 446 |
case '+': |
| 447 |
case '=': |
| 448 |
if (templong < 99) |
| 449 |
templong++; |
| 450 |
sprintf (trackstring.string, "%ld", templong); |
| 451 |
trackstring.cursorpos = strlen (trackstring.string); |
| 452 |
trackstring.firstcharonscreen = 0; |
| 453 |
break; |
| 454 |
|
| 455 |
case '-': |
| 456 |
case '_': |
| 457 |
if (templong > 1) |
| 458 |
templong--; |
| 459 |
sprintf (trackstring.string, "%ld", templong); |
| 460 |
trackstring.cursorpos = strlen (trackstring.string); |
| 461 |
trackstring.firstcharonscreen = 0; |
| 462 |
break; |
| 463 |
|
| 464 |
case KEY_UP: |
| 465 |
focus--; |
| 466 |
break; |
| 467 |
case KEY_DOWN: |
| 468 |
focus++; |
| 469 |
break; |
| 470 |
} |
| 471 |
|
| 472 |
break; |
| 473 |
|
| 474 |
case 2: /* Use begin/end times */ |
| 475 |
switch (in_ch) |
| 476 |
{ |
| 477 |
case KEY_ENTER: |
| 478 |
case 13: |
| 479 |
case ' ': |
| 480 |
case 'x': |
| 481 |
case 'X': |
| 482 |
*usebeginendtime = 1 - *usebeginendtime; |
| 483 |
break; |
| 484 |
|
| 485 |
case KEY_LEFT: |
| 486 |
case KEY_UP: |
| 487 |
focus--; |
| 488 |
break; |
| 489 |
case KEY_RIGHT: |
| 490 |
case KEY_DOWN: |
| 491 |
focus++; |
| 492 |
break; |
| 493 |
} |
| 494 |
break; |
| 495 |
|
| 496 |
case 3: /* begin time */ |
| 497 |
stringinput_stdkeys (in_ch, &begintimestring); |
| 498 |
switch (in_ch) |
| 499 |
{ |
| 500 |
case KEY_ENTER: |
| 501 |
case 13: |
| 502 |
strcpy (tempstring, begintimestring.string); |
| 503 |
if (!hmsf2fsec (tempstring, &tempdouble)) |
| 504 |
{ |
| 505 |
error_window ("Enter the time in the format hours:\ |
| 506 |
minutes:seconds.fractions, for example 0:04:26.740"); |
| 507 |
begintimestring.cursorpos = |
| 508 |
strlen (begintimestring.string); |
| 509 |
} |
| 510 |
else |
| 511 |
{ |
| 512 |
*begintime = tempdouble; |
| 513 |
fsec2hmsf (tempdouble, begintimestring.string); |
| 514 |
begintimestring.cursorpos = |
| 515 |
strlen (begintimestring.string); |
| 516 |
focus++; |
| 517 |
} |
| 518 |
break; |
| 519 |
|
| 520 |
case KEY_UP: |
| 521 |
focus--; |
| 522 |
break; |
| 523 |
case KEY_DOWN: |
| 524 |
focus++; |
| 525 |
break; |
| 526 |
} |
| 527 |
break; |
| 528 |
|
| 529 |
case 4: /* end time */ |
| 530 |
stringinput_stdkeys (in_ch, &endtimestring); |
| 531 |
switch (in_ch) |
| 532 |
{ |
| 533 |
case KEY_ENTER: |
| 534 |
case 13: |
| 535 |
strcpy (tempstring, endtimestring.string); |
| 536 |
if (!hmsf2fsec (tempstring, &tempdouble)) |
| 537 |
{ |
| 538 |
error_window ("Enter the time in the format hours:\ |
| 539 |
minutes:seconds.fractions, for example 0:04:26.740"); |
| 540 |
endtimestring.cursorpos = |
| 541 |
strlen (endtimestring.string); |
| 542 |
} |
| 543 |
else |
| 544 |
{ |
| 545 |
*endtime = tempdouble; |
| 546 |
fsec2hmsf (tempdouble, endtimestring.string); |
| 547 |
endtimestring.cursorpos = |
| 548 |
strlen (endtimestring.string); |
| 549 |
focus = 5; |
| 550 |
} |
| 551 |
break; |
| 552 |
|
| 553 |
case KEY_UP: |
| 554 |
focus--; |
| 555 |
break; |
| 556 |
case KEY_DOWN: |
| 557 |
focus++; |
| 558 |
break; |
| 559 |
} |
| 560 |
break; |
| 561 |
|
| 562 |
|
| 563 |
case 5: /* string */ |
| 564 |
stringinput_stdkeys (in_ch, &string); |
| 565 |
if (in_ch == KEY_ENTER || in_ch == 13) |
| 566 |
{ |
| 567 |
strcpy (helpstring, string.string); |
| 568 |
|
| 569 |
/* cut away last '/'-s */ |
| 570 |
while (strlen (helpstring) > 0 && |
| 571 |
helpstring[strlen (helpstring) - 1] == '/') |
| 572 |
helpstring[strlen (helpstring) - 1] = '\0'; |
| 573 |
|
| 574 |
strcat (helpstring, "/"); |
| 575 |
|
| 576 |
if (!stat (helpstring, &filestats) && |
| 577 |
S_ISDIR (filestats.st_mode)) |
| 578 |
{ |
| 579 |
strcpy (startdir, helpstring); |
| 580 |
scrollmenu_delete_menu (&dirfilelist); |
| 581 |
dirfilemenu (startdir, &dirfilelist); |
| 582 |
dirfilelist.firstonscreen = 0; |
| 583 |
dirfilelist.selected = |
| 584 |
dirfilelist.last_of_1st_part + 1; |
| 585 |
strcpy (string.string, startdir); |
| 586 |
string.cursorpos = strlen (string.string); |
| 587 |
focus = 0; |
| 588 |
} |
| 589 |
else |
| 590 |
/* it's a file */ |
| 591 |
{ |
| 592 |
focus = 7; |
| 593 |
|
| 594 |
if (!stat (string.string, &buf)) |
| 595 |
{ |
| 596 |
*begintime = 0; |
| 597 |
if (buf.st_size < sizeof (wavhead)) |
| 598 |
*endtime = 0; |
| 599 |
else |
| 600 |
*endtime = (buf.st_size - sizeof (wavhead)) |
| 601 |
/ (2 * 2 * 44100.); |
| 602 |
|
| 603 |
fsec2hmsf (*begintime, begintimestring.string); |
| 604 |
begintimestring.cursorpos = |
| 605 |
strlen (begintimestring.string); |
| 606 |
begintimestring.firstcharonscreen = 0; |
| 607 |
|
| 608 |
fsec2hmsf (*endtime, endtimestring.string); |
| 609 |
endtimestring.cursorpos = strlen (endtimestring.string); |
| 610 |
endtimestring.firstcharonscreen = 0; |
| 611 |
} |
| 612 |
} |
| 613 |
} |
| 614 |
else |
| 615 |
switch (in_ch) |
| 616 |
{ |
| 617 |
case KEY_UP: |
| 618 |
focus--; |
| 619 |
break; |
| 620 |
case KEY_DOWN: |
| 621 |
focus++; |
| 622 |
break; |
| 623 |
} |
| 624 |
break; |
| 625 |
|
| 626 |
case 6: /* Cancel */ |
| 627 |
if (in_ch == KEY_ENTER || in_ch == 13) |
| 628 |
{ |
| 629 |
returnval = 0; |
| 630 |
dont_stop = FALSE; |
| 631 |
} |
| 632 |
else |
| 633 |
switch (in_ch) |
| 634 |
{ |
| 635 |
case KEY_LEFT: |
| 636 |
case KEY_UP: |
| 637 |
focus--; |
| 638 |
break; |
| 639 |
case KEY_RIGHT: |
| 640 |
case KEY_DOWN: |
| 641 |
focus++; |
| 642 |
break; |
| 643 |
} |
| 644 |
break; |
| 645 |
|
| 646 |
case 7: /* OK */ |
| 647 |
if (in_ch == KEY_ENTER || in_ch == 13) |
| 648 |
{ |
| 649 |
strcpy (tempstring, begintimestring.string); |
| 650 |
if (!hmsf2fsec (tempstring, &tempdouble)) |
| 651 |
{ |
| 652 |
error_window ("Enter the begin time in the format hours:\ |
| 653 |
minutes:seconds.fractions, for example 0:04:26.740"); |
| 654 |
begintimestring.cursorpos = |
| 655 |
strlen (begintimestring.string); |
| 656 |
focus = 3; |
| 657 |
break; |
| 658 |
} |
| 659 |
|
| 660 |
*begintime = tempdouble; |
| 661 |
|
| 662 |
strcpy (tempstring, endtimestring.string); |
| 663 |
if (!hmsf2fsec (tempstring, &tempdouble)) |
| 664 |
{ |
| 665 |
error_window ("Enter the end time in the format hours:\ |
| 666 |
minutes:seconds.fractions, for example 0:04:26.740"); |
| 667 |
endtimestring.cursorpos = |
| 668 |
strlen (endtimestring.string); |
| 669 |
focus = 4; |
| 670 |
break; |
| 671 |
} |
| 672 |
|
| 673 |
*endtime = tempdouble; |
| 674 |
|
| 675 |
if (*begintime > *endtime) |
| 676 |
{ |
| 677 |
error_window ("The begin time is larger than the end time."); |
| 678 |
fsec2hmsf (*begintime, begintimestring.string); |
| 679 |
begintimestring.cursorpos = |
| 680 |
strlen (begintimestring.string); |
| 681 |
fsec2hmsf (*endtime, endtimestring.string); |
| 682 |
endtimestring.cursorpos = |
| 683 |
strlen (endtimestring.string); |
| 684 |
focus = 3; |
| 685 |
break; |
| 686 |
} |
| 687 |
|
| 688 |
switch (checkfile (string.string)) |
| 689 |
{ |
| 690 |
case FILE_EXISTS: |
| 691 |
/* strcpy (selectedfile, string.string); |
| 692 |
returnval = 1; |
| 693 |
dont_stop = FALSE; */ |
| 694 |
|
| 695 |
playwav_playit (string.string, *usebeginendtime, *begintime, |
| 696 |
*endtime); |
| 697 |
break; |
| 698 |
|
| 699 |
case DIR_EXISTS: |
| 700 |
error_window ("The specified name is of a directory. A \ |
| 701 |
file name must be specified."); |
| 702 |
string.cursorpos = strlen (string.string); |
| 703 |
focus = 5; |
| 704 |
break; |
| 705 |
|
| 706 |
case DIR_OK_NEW_FILE: |
| 707 |
case DIR_WRONG: |
| 708 |
error_window ("The specified file does not exist."); |
| 709 |
string.cursorpos = strlen (string.string); |
| 710 |
focus = 5; |
| 711 |
break; |
| 712 |
|
| 713 |
default: |
| 714 |
error_window ("Fell out of switch, playwav #1"); |
| 715 |
break; |
| 716 |
} |
| 717 |
|
| 718 |
} /* if ENTER */ |
| 719 |
else |
| 720 |
switch (in_ch) |
| 721 |
{ |
| 722 |
case KEY_LEFT: |
| 723 |
case KEY_UP: |
| 724 |
focus--; |
| 725 |
break; |
| 726 |
case KEY_RIGHT: |
| 727 |
case KEY_DOWN: |
| 728 |
focus++; |
| 729 |
break; |
| 730 |
} |
| 731 |
break; |
| 732 |
} |
| 733 |
|
| 734 |
if (in_ch == 9) /* TAB */ |
| 735 |
focus++; |
| 736 |
|
| 737 |
if (in_ch == 27) |
| 738 |
dont_stop = FALSE; |
| 739 |
|
| 740 |
if (focus > 7) |
| 741 |
focus = 0; |
| 742 |
if (focus < 0) |
| 743 |
focus = 7; |
| 744 |
} |
| 745 |
while (dont_stop); |
| 746 |
|
| 747 |
scrollmenu_delete_menu (&dirfilelist); |
| 748 |
free (string.string); |
| 749 |
|
| 750 |
return returnval; |
| 751 |
} |
| 752 |
|
| 753 |
void |
| 754 |
playwav_main (char *startdir) |
| 755 |
{ |
| 756 |
char filename[250]; |
| 757 |
/* char shellcmd[500]; */ |
| 758 |
int usebeginendtime = 0; |
| 759 |
double begintime = 0, endtime = 0; |
| 760 |
|
| 761 |
filename[0] = '\0'; |
| 762 |
|
| 763 |
while (1) |
| 764 |
{ |
| 765 |
if (!playwav_select_file (startdir, filename, &usebeginendtime, |
| 766 |
&begintime, &endtime)) |
| 767 |
return; |
| 768 |
|
| 769 |
#if 0 |
| 770 |
/* not used any more - integrated in select_file */ |
| 771 |
def_prog_mode (); /* save terminal state */ |
| 772 |
|
| 773 |
if (usebeginendtime) |
| 774 |
sprintf (shellcmd, "bplay_gramo -S -s 44100 -b 16 -J %ld -T %ld %s", |
| 775 |
(long) (begintime * 44100), |
| 776 |
(long) ((endtime - begintime) * 44100), filename); |
| 777 |
else |
| 778 |
sprintf (shellcmd, "bplay_gramo -S -s 44100 -b 16 %s", filename); |
| 779 |
/* defaults for raw files (but no -r, so .wav's supply their own |
| 780 |
parameters */ |
| 781 |
|
| 782 |
system (shellcmd); |
| 783 |
|
| 784 |
reset_prog_mode (); /* reset terminal state */ |
| 785 |
#endif /* 0 */ |
| 786 |
|
| 787 |
} |
| 788 |
} |