No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

167 líneas
3.3 KiB

  1. /*
  2. * cuebreakpoints.c -- print track break points
  3. *
  4. * Copyright (C) 2004, 2005 Svend Sorensen
  5. * For license terms, see the file COPYING in this distribution.
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <getopt.h>
  11. #include "cuefile.h"
  12. #include "time.h"
  13. char *progname;
  14. /* pregap correction modes
  15. * APPEND - append pregap to previous track (except for first track)
  16. * PREPEND - prefix pregap to current track
  17. * SPLIT - print breakpoints for beginning and end of pregap
  18. */
  19. enum GapMode {APPEND, PREPEND, SPLIT};
  20. void usage (int status)
  21. {
  22. if (0 == status) {
  23. fprintf(stdout, "%s: usage: cuebreakpoints [option...] [file...]\n", progname);
  24. fputs("\
  25. \n\
  26. OPTIONS\n\
  27. -h, --help print usage\n\
  28. -i, --input-format cue|toc set format of file(s)\n\
  29. --append-gaps append pregaps to previous track (default)\n\
  30. --prepend-gaps prefix pregaps to track\n\
  31. --split-gaps split at beginning and end of pregaps\n\
  32. ", stdout);
  33. } else {
  34. fprintf(stderr, "run `%s --help' for usage\n", progname);
  35. }
  36. exit (status);
  37. }
  38. void print_m_ss_ff (long frame)
  39. {
  40. int m, s, f;
  41. time_frame_to_msf(frame, &m, &s, &f);
  42. printf ("%d:%02d.%02d\n", m, s, f);
  43. }
  44. void print_breakpoint (long b)
  45. {
  46. /* do not print zero breakpoints */
  47. if (0 != b) {
  48. print_m_ss_ff(b);
  49. }
  50. }
  51. void print_breaks (Cd *cd, int gaps)
  52. {
  53. int i;
  54. long b;
  55. Track *track;
  56. for (i = 1; i <= cd_get_ntrack(cd); i++) {
  57. track = cd_get_track(cd, i);
  58. /* when breakpoint is at:
  59. * index 0: gap is prepended to track
  60. * index 1: gap is appended to previous track
  61. */
  62. b = track_get_start(track);
  63. if (gaps == PREPEND || gaps == SPLIT) {
  64. print_breakpoint(b);
  65. }
  66. if (gaps == APPEND || gaps == SPLIT) {
  67. /* there is no previous track to append the first tracks pregap to */
  68. /* TODO: should first track's pregap be split when appending?
  69. * this could be a suprising default
  70. */
  71. if (1 < i) {
  72. b += track_get_index(track, 1) - track_get_zero_pre(track);
  73. print_breakpoint(b);
  74. }
  75. }
  76. }
  77. }
  78. int breaks (char *name, int format, int gaps)
  79. {
  80. Cd *cd = NULL;
  81. if (NULL == (cd = cf_parse(name, &format))) {
  82. fprintf(stderr, "%s: input file error\n", name);
  83. return -1;
  84. }
  85. print_breaks(cd, gaps);
  86. return 0;
  87. }
  88. int main (int argc, char **argv)
  89. {
  90. int format = UNKNOWN;
  91. int gaps = APPEND;
  92. /* option variables */
  93. char c;
  94. /* getopt_long() variables */
  95. extern char *optarg;
  96. extern int optind;
  97. static struct option longopts[] = {
  98. {"help", no_argument, NULL, 'h'},
  99. {"input-format", required_argument, NULL, 'i'},
  100. {"append-gaps", no_argument, NULL, 'a'},
  101. {"prepend-gaps", no_argument, NULL, 'p'},
  102. {"split-gaps", no_argument, NULL, 's'},
  103. {NULL, 0, NULL, 0}
  104. };
  105. progname = *argv;
  106. while (-1 != (c = getopt_long(argc, argv, "hi:", longopts, NULL))) {
  107. switch (c) {
  108. case 'h':
  109. usage(0);
  110. break;
  111. case 'i':
  112. if (0 == strcmp("cue", optarg)) {
  113. format = CUE;
  114. } else if (0 == strcmp("toc", optarg)) {
  115. format = TOC;
  116. } else {
  117. fprintf(stderr, "%s: illegal format `%s'\n", progname, optarg);
  118. usage(1);
  119. }
  120. break;
  121. case 'a':
  122. gaps = APPEND;
  123. break;
  124. case 'p':
  125. gaps = PREPEND;
  126. break;
  127. case 's':
  128. gaps = SPLIT;
  129. break;
  130. default:
  131. usage(1);
  132. break;
  133. }
  134. }
  135. if (optind == argc) {
  136. breaks("-", format, gaps);
  137. } else {
  138. for (; optind < argc; optind++) {
  139. breaks(argv[optind], format, gaps);
  140. }
  141. }
  142. return 0;
  143. }