comparison src/cue/cuesheet.c @ 901:08643d5994fe trunk

[svn] - now do_setpos() takes relative position as the argument and works even if cuesheets are included in large playlist. may close #869. - improve handling of end of cue. - suppress warnings.
author yaz
date Mon, 26 Mar 2007 14:44:46 -0700
parents 59a876be8550
children a5752784d87b
comparison
equal deleted inserted replaced
900:d985f0dcdeb0 901:08643d5994fe
222 return get_tuple_uri(uri); 222 return get_tuple_uri(uri);
223 } 223 }
224 224
225 static TitleInput *get_tuple_uri(gchar *uri) 225 static TitleInput *get_tuple_uri(gchar *uri)
226 { 226 {
227 gchar *path2 = g_strdup(uri + 6); 227 gchar *path2 = g_strdup(uri + 6);
228 gchar *_path = strchr(path2, '?'); 228 gchar *_path = strchr(path2, '?');
229 gint track = 0; 229 gint track = 0;
230 gint file_length = 0;
231 230
232 InputPlugin *dec; 231 InputPlugin *dec;
233 TitleInput *phys_tuple, *out; 232 TitleInput *phys_tuple, *out;
234 233
235 if (_path != NULL && *_path == '?') 234 if (_path != NULL && *_path == '?')
336 #ifdef DEBUG 335 #ifdef DEBUG
337 g_print("e: stop\n"); 336 g_print("e: stop\n");
338 #endif 337 #endif
339 } 338 }
340 339
340 // not publicly available functions.
341 extern void playback_stop(void);
342 extern void mainwin_clear_song_info(void);
343
341 static gpointer do_stop(gpointer data) 344 static gpointer do_stop(gpointer data)
342 { 345 {
343 InputPlayback *playback = (InputPlayback *)data; 346 // InputPlayback *playback = (InputPlayback *)data;
344 Playlist *playlist = playlist_get_active(); 347 Playlist *playlist = playlist_get_active();
345 #ifdef DEBUG 348 #ifdef DEBUG
346 g_print("f: do_stop\n"); 349 g_print("f: do_stop\n");
347 #endif 350 #endif
348 ip_data.stop = TRUE; 351 ip_data.stop = TRUE;
357 360
358 #ifdef DEBUG 361 #ifdef DEBUG
359 g_print("e: do_stop\n"); 362 g_print("e: do_stop\n");
360 #endif 363 #endif
361 g_thread_exit(NULL); 364 g_thread_exit(NULL);
365 return NULL; //dummy
362 } 366 }
363 367
364 static gpointer do_setpos(gpointer data) 368 static gpointer do_setpos(gpointer data)
365 { 369 {
366 Playlist *playlist = playlist_get_active(); 370 Playlist *playlist = playlist_get_active();
367 #ifdef DEBUG 371 gint pos = playlist_get_position_nolock(playlist);
368 g_print("do_setpos: %d\n\n", *(guint *)data); 372 gint incr = *(gint *)data;
369 #endif 373
370 playlist_set_position(playlist, *(guint *)data); 374 pos = pos + incr;
375 if(pos < 0)
376 pos = 0;
377
378 #ifdef DEBUG
379 g_print("do_setpos: pos = %d\n\n", pos);
380 #endif
381 playlist_set_position(playlist, (guint)pos);
371 g_thread_exit(NULL); 382 g_thread_exit(NULL);
383 return NULL; //dummy
372 } 384 }
373 385
374 static void cue_pause(InputPlayback * data, short p) 386 static void cue_pause(InputPlayback * data, short p)
375 { 387 {
376 if (real_ip != NULL) 388 if (real_ip != NULL)
503 */ 515 */
504 static gpointer watchdog_func(gpointer data) 516 static gpointer watchdog_func(gpointer data)
505 { 517 {
506 gint time = 0; 518 gint time = 0;
507 Playlist *playlist = NULL; 519 Playlist *playlist = NULL;
508 GTimeVal sleep_time, startup_time; 520 GTimeVal sleep_time;
509 521
510 #ifdef DEBUG 522 #ifdef DEBUG
511 g_print("f: watchdog\n"); 523 g_print("f: watchdog\n");
512 #endif 524 #endif
513 525
556 continue; 568 continue;
557 569
558 // prev track 570 // prev track
559 if (time < cue_tracks[cur_cue_track].index) 571 if (time < cue_tracks[cur_cue_track].index)
560 { 572 {
561 guint pos; 573 gint incr;
574 gint oldpos = cur_cue_track;
562 #ifdef DEBUG 575 #ifdef DEBUG
563 g_print("i: watchdog prev\n"); 576 g_print("i: watchdog prev\n");
564 g_print("time = %d cur = %d cidx = %d nidx = %d\n", time, cur_cue_track, 577 g_print("time = %d cur = %d cidx = %d nidx = %d\n", time, cur_cue_track,
565 cue_tracks[cur_cue_track].index, 578 cue_tracks[cur_cue_track].index,
566 cue_tracks[cur_cue_track+1].index); 579 cue_tracks[cur_cue_track+1].index);
567 #endif 580 #endif
568 while(time < cue_tracks[cur_cue_track].index) { 581 while(time < cue_tracks[cur_cue_track].index) {
569 cur_cue_track--; 582 cur_cue_track--;
570 pos = cur_cue_track; 583 incr = cur_cue_track - oldpos; // relative position
571 if (time >= cue_tracks[cur_cue_track].index) 584 if (time >= cue_tracks[cur_cue_track].index)
572 finetune_seek = time; 585 finetune_seek = time;
573 } 586 }
574 587
575 exec_thread = g_thread_create(do_setpos, &pos, FALSE, NULL); 588 exec_thread = g_thread_create(do_setpos, &incr, FALSE, NULL);
576 g_usleep(TRANSITION_GUARD_TIME); 589 g_usleep(TRANSITION_GUARD_TIME);
577 } 590 }
578 591
579 // next track 592 // next track
580 if (cur_cue_track + 1 < last_cue_track && time > cue_tracks[cur_cue_track + 1].index) 593 if (cur_cue_track + 1 < last_cue_track && time > cue_tracks[cur_cue_track + 1].index)
581 { 594 {
582 guint pos; 595 gint incr;
596 gint oldpos = cur_cue_track;
583 #ifdef DEBUG 597 #ifdef DEBUG
584 g_print("i: watchdog next\n"); 598 g_print("i: watchdog next\n");
585 g_print("time = %d cur = %d cidx = %d nidx = %d last = %d lidx = %d\n", time, cur_cue_track, 599 g_print("time = %d cur = %d cidx = %d nidx = %d last = %d lidx = %d\n", time, cur_cue_track,
586 cue_tracks[cur_cue_track].index, 600 cue_tracks[cur_cue_track].index,
587 cue_tracks[cur_cue_track+1].index, 601 cue_tracks[cur_cue_track+1].index,
588 last_cue_track, cue_tracks[last_cue_track].index); 602 last_cue_track, cue_tracks[last_cue_track].index);
589 #endif 603 #endif
590 while(time > cue_tracks[cur_cue_track + 1].index) { 604 while(time > cue_tracks[cur_cue_track + 1].index) {
591 cur_cue_track++; 605 cur_cue_track++;
592 pos = cur_cue_track; 606 incr = cur_cue_track - oldpos; // relative position
593 if (time <= cue_tracks[cur_cue_track].index) 607 if (time <= cue_tracks[cur_cue_track].index)
594 finetune_seek = time; 608 finetune_seek = time;
595 } 609 }
596 610
597 if(cfg.stopaftersong) { 611 if(cfg.stopaftersong) {
598 exec_thread = g_thread_create(do_stop, (void *)real_ip, FALSE, NULL); 612 exec_thread = g_thread_create(do_stop, (void *)real_ip, FALSE, NULL);
599 } 613 }
600 else { 614 else {
601 exec_thread = g_thread_create(do_setpos, &pos, FALSE, NULL); 615 exec_thread = g_thread_create(do_setpos, &incr, FALSE, NULL);
602 g_usleep(TRANSITION_GUARD_TIME); 616 g_usleep(TRANSITION_GUARD_TIME);
603 } 617 }
604 } 618 }
605 619
606 // last track 620 // last track
607 if (cur_cue_track + 1 == last_cue_track && 621 if (cur_cue_track + 1 == last_cue_track &&
608 (cue_tracks[last_cue_track].index - time < 500 || 622 (cue_tracks[last_cue_track].index - time < 500 ||
609 time > cue_tracks[last_cue_track].index) ){ // may not happen. for safety. 623 time > cue_tracks[last_cue_track].index) ){ // may not happen. for safety.
610 if(!real_ip->output->buffer_playing()) { 624 if(!real_ip->output->buffer_playing()) {
611 #ifdef DEBUG 625 gint pos = playlist_get_position(playlist);
612 g_print("i: watchdog eof reached\n"); 626 if (pos + 1 == playlist_get_length_nolock(playlist)) {
613 #endif 627 #ifdef DEBUG
614 if(cfg.repeat) { 628 g_print("i: watchdog eof reached\n\n");
615 guint pos = 0; 629 #endif
616 exec_thread = g_thread_create(do_setpos, &pos, FALSE, NULL); 630
631 if(cfg.repeat) {
632 gint incr = -pos;
633 exec_thread = g_thread_create(do_setpos, &incr, FALSE, NULL);
634 g_usleep(TRANSITION_GUARD_TIME);
635 }
636 else {
637 exec_thread = g_thread_create(do_stop, (void *)real_ip, FALSE, NULL);
638 g_usleep(TRANSITION_GUARD_TIME);
639 }
617 } 640 }
618 else { 641 else {
619 exec_thread = g_thread_create(do_stop, (void *)real_ip, FALSE, NULL); 642 #ifdef DEBUG
643 g_print("i: watchdog end of cue, advance in playlist\n\n");
644 #endif
645 gint incr = 1;
646 exec_thread = g_thread_create(do_setpos, &incr, FALSE, NULL);
647 g_usleep(TRANSITION_GUARD_TIME);
620 } 648 }
621 } 649 }
622 } 650 }
623 } 651 }
624 #ifdef DEBUG 652 #ifdef DEBUG