Changeset 394


Ignore:
Timestamp:
04/06/08 16:19:53 (16 years ago)
Author:
r2d
Message:

mpcchap supports cue/toc files through cuetools library (CMakeLists.txt has been change to look for cuetools, but untested).

Location:
libmpc/trunk/mpcchap
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libmpc/trunk/mpcchap/CMakeLists.txt

    r385 r394  
     1FIND_PATH(CUEFILE_INCLUDE_DIR src/lib/cuefile.h
     2        ${libmpc_SOURCE_DIR}/../cuetools-1.3.1
     3)
     4
     5FIND_LIBRARY(CUEFILE_LIBRARY NAMES cuefile_static PATHS
     6        ${CUEFILE_INCLUDE_DIR}/src/lib
     7)
     8
    19include_directories(${libmpc_SOURCE_DIR}/include)
     10include_directories(${CUEFILE_INCLUDE_DIR})
    211
    312link_directories(${libmpc_BINARY_DIR}/libmpcdec)
     
    817target_link_libraries(mpcchap mpcdec_static)
    918target_link_libraries(mpcchap mpcenc_static)
     19target_link_libraries(mpcchap ${CUEFILE_LIBRARY})
    1020
    1121if(NOT MSVC)
  • libmpc/trunk/mpcchap/Makefile.am

    r384 r394  
    33common_sources = ../common/tags.c
    44
    5 INCLUDES = -I$(top_srcdir)/include
     5INCLUDES = -I$(top_srcdir)/include -I/home/nico/src/cuetools-1.3.1/
    66METASOURCES = AUTO
    77mpcchap_SOURCES = dictionary.c iniparser.c mpcchap.c $(common_sources)
    88mpcchap_LDADD = $(top_builddir)/libmpcdec/libmpcdec.la \
    9         $(top_builddir)/libmpcenc/libmpcenc.a -lm
     9        $(top_builddir)/libmpcenc/libmpcenc.a /home/nico/src/cuetools-1.3.1/src/lib/libcuefile.a -lm
  • libmpc/trunk/mpcchap/mpcchap.c

    r388 r394  
    33  All rights reserved.
    44
    5   Redistribution and use in source and binary forms, with or without
    6   modification, are permitted provided that the following conditions are
    7   met:
    8 
    9   * Redistributions of source code must retain the above copyright
    10   notice, this list of conditions and the following disclaimer.
    11 
    12   * Redistributions in binary form must reproduce the above
    13   copyright notice, this list of conditions and the following
    14   disclaimer in the documentation and/or other materials provided
    15   with the distribution.
    16 
    17   * Neither the name of the The Musepack Development Team nor the
    18   names of its contributors may be used to endorse or promote
    19   products derived from this software without specific prior
    20   written permission.
    21 
    22   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    23   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    24   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    25   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    26   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    27   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    28   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    29   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    30   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    31   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    32   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     5  This program is free software; you can redistribute it and/or
     6  modify it under the terms of the GNU General Public License
     7  as published by the Free Software Foundation; either version 2
     8  of the License, or (at your option) any later version.
     9
     10  This program is distributed in the hope that it will be useful,
     11  but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  GNU General Public License for more details.
     14
     15  You should have received a copy of the GNU General Public License
     16  along with this program; if not, write to the Free Software
     17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    3318*/
    3419
     
    3924
    4025#include <sys/stat.h>
     26
     27#include <src/lib/cuefile.h>
    4128
    4229// tags.c
     
    5643{
    5744        printf(
    58                 "Usage: %s <infile.mpc> <chapterfile.ini>\n"
     45                "Usage: %s <infile.mpc> <chapterfile.ini / cuefile>\n"
    5946                "   if chapterfile.ini exists, chapter tags in infile.mpc will be\n"
    6047                "   replaced by those from chapterfile.ini, else chapters will be\n"
     
    6956}
    7057
    71 mpc_status add_chaps(char * mpc_file, char * chap_file, mpc_demux * demux, mpc_streaminfo * si)
     58mpc_status add_chaps_ini(char * mpc_file, char * chap_file, mpc_demux * demux, mpc_streaminfo * si)
    7259{
    7360        struct stat stbuf;
     
    126113}
    127114
     115mpc_status add_chaps_cue(char * mpc_file, char * chap_file, mpc_demux * demux, mpc_streaminfo * si)
     116{
     117        int Ptis[7] = { PTI_TITLE, PTI_PERFORMER, PTI_SONGWRITER, PTI_COMPOSER,
     118                        PTI_ARRANGER, PTI_MESSAGE, PTI_GENRE};
     119        char * APE_keys[7] = {"Title", "Artist", "Songwriter", "Composer",
     120                        "Arranger", "Comment", "Genre"};
     121
     122        Cd *cd = 0;
     123        int nchap, format = UNKNOWN;
     124        struct stat stbuf;
     125        FILE * in_file;
     126        int chap_pos, end_pos, chap_size, i;
     127
     128        if (0 == (cd = cf_parse(chap_file, &format))) {
     129                fprintf(stderr, "%s: input file error\n", chap_file);
     130                return !MPC_STATUS_OK;
     131        }
     132
     133        chap_pos = (demux->chap_pos >> 3) + si->header_position;
     134        end_pos = mpc_demux_pos(demux) >> 3;
     135        chap_size = end_pos - chap_pos;
     136
     137        stat(mpc_file, &stbuf);
     138        char * tmp_buff = malloc(stbuf.st_size - chap_pos - chap_size);
     139        in_file = fopen( mpc_file, "r+b" );
     140        fseek(in_file, chap_pos + chap_size, SEEK_SET);
     141        fread(tmp_buff, 1, stbuf.st_size - chap_pos - chap_size, in_file);
     142        fseek(in_file, chap_pos, SEEK_SET);
     143
     144        nchap = cd_get_ntrack(cd);
     145        for (i = 1; i <= nchap; i++) {
     146                int j, nitem = 0, tag_len = 0, key_len, item_len;
     147                Track * track;
     148                Cdtext *cdtext;
     149
     150                track = cd_get_track (cd, i);
     151                cdtext = track_get_cdtext(track);
     152
     153                // position du chapitre
     154                mpc_int64_t chap_pos = si->sample_freq * track_get_start (track) / 75;
     155
     156                if (chap_pos > si->samples - si->beg_silence)
     157                        fprintf(stderr, "warning : chapter %i starts @ %lli after the end of the stream (%lli)\n", i, chap_pos, si->samples - si->beg_silence);
     158
     159                Init_Tags();
     160
     161                char track_buf[16];
     162                sprintf(track_buf, "%i/%i", i, nchap);
     163                key_len = 5;
     164                item_len = strlen(track_buf);
     165                addtag("Track", key_len, track_buf, item_len, 0, 0);
     166                tag_len += key_len + item_len;
     167                nitem++;
     168
     169                for (j = 0; j < (sizeof(Ptis) / sizeof(*Ptis)); j++) {
     170                        char * item_key = APE_keys[j], * item_value;
     171                        item_value = cdtext_get (Ptis[j], cdtext);
     172                        if (item_value != 0) {
     173                                key_len = strlen(item_key);
     174                                item_len = strlen(item_value);
     175                                addtag(item_key, key_len, item_value, item_len, 0, 0);
     176                                tag_len += key_len + item_len;
     177                                nitem++;
     178                        }
     179                }
     180
     181                tag_len += 24 + nitem * 9;
     182                char block_header[12] = "CT";
     183                char sample_offset[10];
     184                int offset_size = encodeSize(chap_pos, sample_offset, MPC_FALSE);
     185                tag_len = encodeSize(tag_len + offset_size + 2, block_header + 2, MPC_TRUE);
     186                fwrite(block_header, 1, tag_len + 2, in_file);
     187                fwrite(sample_offset, 1, offset_size, in_file);
     188                FinalizeTags(in_file, TAG_VERSION, TAG_NO_FOOTER | TAG_NO_PREAMBLE);
     189        }
     190
     191        fwrite(tmp_buff, 1, stbuf.st_size - chap_pos - chap_size, in_file);
     192        ftruncate(fileno(in_file), ftell(in_file));
     193
     194        fclose(in_file);
     195        free(tmp_buff);
     196
     197        return MPC_STATUS_OK;
     198}
     199
    128200mpc_status dump_chaps(mpc_demux * demux, char * chap_file, int chap_nb)
    129201{
     
    194266                err = dump_chaps(demux, chap_file, chap_nb);
    195267        } else {
     268                int len;
    196269                fclose(test_file);
    197                 err = add_chaps(mpc_file, chap_file, demux, &si);
     270                len = strlen(chap_file);
     271                if (strcasecmp(chap_file + len - 4, ".cue") == 0 || strcasecmp(chap_file + len - 4, ".toc") == 0)
     272                        err = add_chaps_cue(mpc_file, chap_file, demux, &si);
     273                else if (strcasecmp(chap_file + len - 4, ".ini") == 0)
     274                        err = add_chaps_ini(mpc_file, chap_file, demux, &si);
     275                else
     276                        err = !MPC_STATUS_OK;
    198277        }
    199278
Note: See TracChangeset for help on using the changeset viewer.