Mercurial > audlegacy-plugins
comparison src/madplug/plugin.c @ 1428:4993976d7ed0
madplug: tuple API changes
| author | William Pitcock <nenolod@atheme-project.org> |
|---|---|
| date | Fri, 10 Aug 2007 07:45:29 -0500 |
| parents | fe0a9cf95642 |
| children | 195b5657303e |
comparison
equal
deleted
inserted
replaced
| 1424:230661b01dc7 | 1428:4993976d7ed0 |
|---|---|
| 513 #endif | 513 #endif |
| 514 return; | 514 return; |
| 515 } | 515 } |
| 516 | 516 |
| 517 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) { | 517 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) { |
| 518 if(myinfo.tuple->track_name) | 518 if(tuple_get_string(myinfo.tuple, "track-name")) |
| 519 *title = strdup(myinfo.tuple->track_name); | 519 *title = g_strdup(tuple_get_string(myinfo.tuple, "track-name")); |
| 520 else | 520 else |
| 521 *title = strdup(url); | 521 *title = g_strdup(url); |
| 522 if(myinfo.tuple->length == -1) | 522 if(tuple_get_int(myinfo.tuple, "length") == -1) |
| 523 *length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS); | 523 *length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS); |
| 524 else | 524 else |
| 525 *length = myinfo.tuple->length; | 525 *length = tuple_get_int(myinfo.tuple, "length"); |
| 526 } | 526 } |
| 527 else { | 527 else { |
| 528 *title = strdup(url); | 528 *title = g_strdup(url); |
| 529 *length = -1; | 529 *length = -1; |
| 530 } | 530 } |
| 531 input_term(&myinfo); | 531 input_term(&myinfo); |
| 532 #ifdef DEBUG | 532 #ifdef DEBUG |
| 533 g_message("e: audmad_get_song_info"); | 533 g_message("e: audmad_get_song_info"); |
| 550 #endif | 550 #endif |
| 551 return; | 551 return; |
| 552 } | 552 } |
| 553 | 553 |
| 554 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) { | 554 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) { |
| 555 if(myinfo.tuple->length == -1) | 555 if(tuple_get_int(myinfo.tuple, "length") == -1) |
| 556 *length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS); | 556 *length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS); |
| 557 else | 557 else |
| 558 *length = myinfo.tuple->length; | 558 *length = tuple_get_int(myinfo.tuple, "length"); |
| 559 } | 559 } |
| 560 else { | 560 else { |
| 561 *length = -1; | 561 *length = -1; |
| 562 } | 562 } |
| 563 input_term(&myinfo); | 563 input_term(&myinfo); |
| 626 } | 626 } |
| 627 | 627 |
| 628 extern void audmad_get_file_info(char *filename); | 628 extern void audmad_get_file_info(char *filename); |
| 629 extern void audmad_configure(); | 629 extern void audmad_configure(); |
| 630 | 630 |
| 631 static void __set_and_free(Tuple *tuple, gchar *name, gchar *value) | |
| 632 { | |
| 633 tuple_associate_string(tuple, name, value); | |
| 634 g_free(value); | |
| 635 } | |
| 631 | 636 |
| 632 // tuple stuff | 637 // tuple stuff |
| 633 static TitleInput *__audmad_get_song_tuple(char *filename, VFSFile *fd) | 638 static Tuple *__audmad_get_song_tuple(char *filename, VFSFile *fd) |
| 634 { | 639 { |
| 635 TitleInput *tuple = NULL; | 640 Tuple *tuple = NULL; |
| 636 gchar *string = NULL; | 641 gchar *string = NULL; |
| 637 gchar *realfn = NULL; | 642 gchar *realfn = NULL; |
| 638 | 643 |
| 639 struct id3_file *id3file = NULL; | 644 struct id3_file *id3file = NULL; |
| 640 struct id3_tag *tag = NULL; | 645 struct id3_tag *tag = NULL; |
| 649 #endif | 654 #endif |
| 650 | 655 |
| 651 if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) <= 0){ | 656 if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) <= 0){ |
| 652 if((fd && vfs_is_streaming(fd)) || (info.playback && info.playback->playing)) { | 657 if((fd && vfs_is_streaming(fd)) || (info.playback && info.playback->playing)) { |
| 653 gchar *tmp = NULL; | 658 gchar *tmp = NULL; |
| 654 tuple = bmp_title_input_new(); | 659 tuple = tuple_new(); |
| 655 | 660 |
| 656 #ifdef DEBUG | 661 #ifdef DEBUG |
| 657 if(info.playback) | 662 if(info.playback) |
| 658 g_message("info.playback->playing = %d",info.playback->playing); | 663 g_message("info.playback->playing = %d",info.playback->playing); |
| 659 #endif | 664 #endif |
| 660 tmp = vfs_get_metadata(info.infile ? info.infile : fd, "track-name"); | 665 tmp = vfs_get_metadata(info.infile ? info.infile : fd, "track-name"); |
| 661 if(tmp){ | 666 if(tmp){ |
| 662 tuple->track_name = str_to_utf8(tmp); | 667 gchar *scratch; |
| 668 | |
| 669 scratch = str_to_utf8(tmp); | |
| 670 tuple_associate_string(tuple, "title", scratch); | |
| 663 g_free(tmp); | 671 g_free(tmp); |
| 672 g_free(scratch); | |
| 673 | |
| 664 tmp = NULL; | 674 tmp = NULL; |
| 665 } | 675 } |
| 666 tmp = vfs_get_metadata(info.infile ? info.infile : fd, "stream-name"); | 676 tmp = vfs_get_metadata(info.infile ? info.infile : fd, "stream-name"); |
| 667 if(tmp){ | 677 if(tmp){ |
| 668 tuple->album_name = str_to_utf8(tmp); | 678 gchar *scratch; |
| 679 | |
| 680 scratch = str_to_utf8(tmp); | |
| 681 tuple_associate_string(tuple, "title", scratch); | |
| 669 g_free(tmp); | 682 g_free(tmp); |
| 683 g_free(scratch); | |
| 684 | |
| 670 tmp = NULL; | 685 tmp = NULL; |
| 671 } | 686 } |
| 672 | 687 |
| 673 #ifdef DEBUG | 688 #ifdef DEBUG |
| 674 g_message("audmad_get_song_tuple: track_name = %s", tuple->track_name); | 689 g_message("audmad_get_song_tuple: track_name = %s", tuple->track_name); |
| 675 g_message("audmad_get_song_tuple: stream_name = %s", tuple->album_name); | 690 g_message("audmad_get_song_tuple: stream_name = %s", tuple->album_name); |
| 676 #endif | 691 #endif |
| 677 realfn = g_filename_from_uri(filename, NULL, NULL); | 692 realfn = g_filename_from_uri(filename, NULL, NULL); |
| 678 tuple->file_name = g_path_get_basename(realfn ? realfn : filename); | 693 __set_and_free(tuple, "file-name", g_path_get_basename(realfn ? realfn : filename)); |
| 679 tuple->file_path = g_path_get_dirname(realfn ? realfn : filename); | 694 __set_and_free(tuple, "file-path", g_path_get_dirname(realfn ? realfn : filename)); |
| 680 tuple->file_ext = extname(realfn ? realfn : filename); | 695 tuple_associate_string(tuple, "file-ext", extname(realfn ? realfn : filename)); |
| 681 g_free(realfn); realfn = NULL; | 696 g_free(realfn); realfn = NULL; |
| 682 | 697 |
| 683 tuple->length = -1; | 698 tuple_associate_int(tuple, "length", -1); |
| 684 tuple->mtime = 0; // this indicates streaming | 699 tuple_associate_int(tuple, "mtime", 0); // this indicates streaming |
| 685 #ifdef DEBUG | 700 #ifdef DEBUG |
| 686 g_message("get_song_tuple: remote: tuple"); | 701 g_message("get_song_tuple: remote: tuple"); |
| 687 #endif | 702 #endif |
| 688 return tuple; | 703 return tuple; |
| 689 } | 704 } |
| 690 #ifdef DEBUG | 705 #ifdef DEBUG |
| 691 g_message("get_song_tuple: remote: NULL"); | 706 g_message("get_song_tuple: remote: NULL"); |
| 692 #endif | 707 #endif |
| 693 return NULL; | 708 return NULL; |
| 694 } /* info.remote */ | 709 } /* info.remote */ |
| 695 | |
| 696 tuple = bmp_title_input_new(); | |
| 697 | 710 |
| 698 // if !fd, pre-open the file with vfs_fopen() and reuse fd. | 711 // if !fd, pre-open the file with vfs_fopen() and reuse fd. |
| 699 if(!fd) { | 712 if(!fd) { |
| 700 fd = vfs_fopen(filename, "rb"); | 713 fd = vfs_fopen(filename, "rb"); |
| 701 if(!fd) | 714 if(!fd) |
| 702 return NULL; | 715 return NULL; |
| 703 local_fd = TRUE; | 716 local_fd = TRUE; |
| 704 } | 717 } |
| 705 | 718 |
| 719 tuple = tuple_new(); | |
| 720 tuple_associate_int(tuple, "length", -1); | |
| 721 | |
| 706 id3file = id3_file_vfsopen(fd, ID3_FILE_MODE_READONLY); | 722 id3file = id3_file_vfsopen(fd, ID3_FILE_MODE_READONLY); |
| 707 | 723 |
| 708 if (id3file) { | 724 if (id3file) { |
| 709 | 725 |
| 710 tag = id3_file_tag(id3file); | 726 tag = id3_file_tag(id3file); |
| 711 if (tag) { | 727 if (tag) { |
| 712 tuple->performer = | 728 __set_and_free(tuple, "artist", input_id3_get_string(tag, ID3_FRAME_ARTIST)); |
| 713 input_id3_get_string(tag, ID3_FRAME_ARTIST); | 729 __set_and_free(tuple, "album", input_id3_get_string(tag, ID3_FRAME_ALBUM)); |
| 714 tuple->album_name = | 730 __set_and_free(tuple, "title", input_id3_get_string(tag, ID3_FRAME_TITLE)); |
| 715 input_id3_get_string(tag, ID3_FRAME_ALBUM); | |
| 716 tuple->track_name = | |
| 717 input_id3_get_string(tag, ID3_FRAME_TITLE); | |
| 718 | 731 |
| 719 // year | 732 // year |
| 720 string = NULL; | 733 string = NULL; |
| 721 string = input_id3_get_string(tag, ID3_FRAME_YEAR); //TDRC | 734 string = input_id3_get_string(tag, ID3_FRAME_YEAR); //TDRC |
| 722 if (!string) | 735 if (!string) |
| 723 string = input_id3_get_string(tag, "TYER"); | 736 string = input_id3_get_string(tag, "TYER"); |
| 724 | 737 |
| 725 if (string) { | 738 if (string) { |
| 726 tuple->year = atoi(string); | 739 tuple_associate_int(tuple, "year", atoi(string)); |
| 727 g_free(string); | 740 g_free(string); |
| 728 string = NULL; | 741 string = NULL; |
| 729 } | 742 } |
| 730 realfn = g_filename_from_uri(filename, NULL, NULL); | 743 realfn = g_filename_from_uri(filename, NULL, NULL); |
| 731 tuple->file_name = g_path_get_basename(realfn ? realfn : filename); | 744 __set_and_free(tuple, "file-name", g_path_get_basename(realfn ? realfn : filename)); |
| 732 tuple->file_path = g_path_get_dirname(realfn ? realfn : filename); | 745 __set_and_free(tuple, "file-path", g_path_get_dirname(realfn ? realfn : filename)); |
| 733 tuple->file_ext = extname(realfn ? realfn : filename); | 746 tuple_associate_string(tuple, "file-ext", extname(realfn ? realfn : filename)); |
| 734 g_free(realfn); realfn = NULL; | 747 g_free(realfn); realfn = NULL; |
| 735 | 748 |
| 736 // length | 749 // length |
| 737 tuple->length = -1; | |
| 738 string = input_id3_get_string(tag, "TLEN"); | 750 string = input_id3_get_string(tag, "TLEN"); |
| 739 if (string) { | 751 if (string) { |
| 740 tuple->length = atoi(string); | 752 tuple_associate_int(tuple, "length", atoi(string)); |
| 741 #ifdef DEBUG | 753 #ifdef DEBUG |
| 742 g_message("get_song_tuple: TLEN = %d", tuple->length); | 754 g_message("get_song_tuple: TLEN = %d", tuple_get_int(tuple, "length")); |
| 743 #endif | 755 #endif |
| 744 g_free(string); | 756 g_free(string); |
| 745 string = NULL; | 757 string = NULL; |
| 746 } | 758 } |
| 747 else { | 759 else { |
| 748 char *dummy = NULL; | 760 char *dummy = NULL; |
| 749 int length = 0; | 761 int length = 0; |
| 750 audmad_get_song_length(filename, &length, fd); | 762 audmad_get_song_length(filename, &length, fd); |
| 751 tuple->length = length; | 763 tuple_associate_int(tuple, "length", length); |
| 752 g_free(dummy); | 764 g_free(dummy); |
| 753 } | 765 } |
| 754 | 766 |
| 755 // track number | 767 // track number |
| 756 string = input_id3_get_string(tag, ID3_FRAME_TRACK); | 768 string = input_id3_get_string(tag, ID3_FRAME_TRACK); |
| 757 if (string) { | 769 if (string) { |
| 758 tuple->track_number = atoi(string); | 770 tuple_associate_int(tuple, "track-number", atoi(string)); |
| 759 g_free(string); | 771 g_free(string); |
| 760 string = NULL; | 772 string = NULL; |
| 761 } | 773 } |
| 762 // genre | 774 // genre |
| 763 tuple->genre = input_id3_get_string(tag, ID3_FRAME_GENRE); | 775 __set_and_free(tuple, "genre", input_id3_get_string(tag, ID3_FRAME_GENRE)); |
| 776 __set_and_free(tuple, "comment", input_id3_get_string(tag, ID3_FRAME_COMMENT)); | |
| 764 #ifdef DEBUG | 777 #ifdef DEBUG |
| 765 g_message("genre = %s", tuple->genre); | 778 g_message("genre = %s", tuple->genre); |
| 766 #endif | 779 #endif |
| 767 // comment | |
| 768 tuple->comment = | |
| 769 input_id3_get_string(tag, ID3_FRAME_COMMENT); | |
| 770 | |
| 771 } | 780 } |
| 772 id3_file_close(id3file); | 781 id3_file_close(id3file); |
| 773 } // id3file | 782 } // id3file |
| 774 else { // no id3tag | 783 else { // no id3tag |
| 775 realfn = g_filename_from_uri(filename, NULL, NULL); | 784 realfn = g_filename_from_uri(filename, NULL, NULL); |
| 776 tuple->file_name = g_path_get_basename(realfn ? realfn : filename); | 785 __set_and_free(tuple, "file-name", g_path_get_basename(realfn ? realfn : filename)); |
| 777 tuple->file_path = g_path_get_dirname(realfn ? realfn : filename); | 786 __set_and_free(tuple, "file-path", g_path_get_dirname(realfn ? realfn : filename)); |
| 778 tuple->file_ext = extname(realfn ? realfn : filename); | 787 tuple_associate_string(tuple, "file-ext", extname(realfn ? realfn : filename)); |
| 779 g_free(realfn); realfn = NULL; | 788 g_free(realfn); realfn = NULL; |
| 780 // length | 789 // length |
| 781 { | 790 { |
| 782 char *dummy = NULL; | 791 char *dummy = NULL; |
| 783 int length = 0; | 792 int length = 0; |
| 784 if(tuple->length == -1) { | 793 if(tuple_get_int(tuple, "length") == -1) { |
| 785 audmad_get_song_length(filename, &length, fd); | 794 audmad_get_song_length(filename, &length, fd); |
| 786 tuple->length = length; | 795 tuple_associate_int(tuple, "length", length); |
| 787 } | 796 } |
| 788 g_free(dummy); | 797 g_free(dummy); |
| 789 } | 798 } |
| 790 } | 799 } |
| 791 | 800 |
| 801 tuple_associate_string(tuple, "quality", "lossy"); | |
| 802 tuple_associate_string(tuple, "codec", "MPEG Audio (MP3)"); | |
| 803 | |
| 792 if(local_fd) | 804 if(local_fd) |
| 793 vfs_fclose(fd); | 805 vfs_fclose(fd); |
| 794 | 806 |
| 795 #ifdef DEBUG | 807 #ifdef DEBUG |
| 796 g_message("e: mad: audmad_get_song_tuple"); | 808 g_message("e: mad: audmad_get_song_tuple"); |
| 797 #endif | 809 #endif |
| 798 return tuple; | 810 return tuple; |
| 799 } | 811 } |
| 800 | 812 |
| 801 static TitleInput *audmad_get_song_tuple(char *filename) | 813 static Tuple *audmad_get_song_tuple(char *filename) |
| 802 { | 814 { |
| 803 return __audmad_get_song_tuple(filename, NULL); | 815 return __audmad_get_song_tuple(filename, NULL); |
| 804 } | 816 } |
| 805 | 817 |
| 806 static TitleInput *audmad_probe_for_tuple(char *filename, VFSFile *fd) | 818 static Tuple *audmad_probe_for_tuple(char *filename, VFSFile *fd) |
| 807 { | 819 { |
| 808 if (!audmad_is_our_fd(filename, fd)) | 820 if (!audmad_is_our_fd(filename, fd)) |
| 809 return NULL; | 821 return NULL; |
| 810 | 822 |
| 811 vfs_rewind(fd); | 823 vfs_rewind(fd); |
