You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

164 lines
3.3 KiB

  1. /*
  2. * cuebreakpoints.c -- print track break points
  3. *
  4. * Copyright (C) 2004 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. void print_breaks (Cd *cd, int gaps)
  51. {
  52. int i;
  53. long b;
  54. Track *track;
  55. for (i = 1; i <= cd_get_ntrack(cd); i++) {
  56. track = cd_get_track(cd, i);
  57. /* when breakpoint is at:
  58. * index 0: gap is prepended to track
  59. * index 1: gap is appended to previous track
  60. */
  61. b = track_get_start(track);
  62. if (gaps == PREPEND || gaps == SPLIT) {
  63. print_breakpoint(b);
  64. }
  65. if (gaps == APPEND || gaps == SPLIT) {
  66. /* there is no previous track to append the first tracks pregap to */
  67. /* TODO: should first track's pregap be split when appending?
  68. * this could be a suprising default
  69. */
  70. if (1 < i) {
  71. b += track_get_index(track, 1) - track_get_zero_pre(track);
  72. print_breakpoint(b);
  73. }
  74. }
  75. }
  76. }
  77. int breaks (char *name, int format, int gaps)
  78. {
  79. Cd *cd = NULL;
  80. if (NULL == (cd = cf_parse(name, &format))) {
  81. fprintf(stderr, "%s: input file error\n", name);
  82. return -1;
  83. }
  84. print_breaks(cd, gaps);
  85. return 0;
  86. }
  87. int main (int argc, char **argv)
  88. {
  89. int format = UNKNOWN;
  90. int gaps = APPEND;
  91. /* option variables */
  92. char c;
  93. /* getopt_long() variables */
  94. extern char *optarg;
  95. extern int optind;
  96. static struct option longopts[] = {
  97. {"help", no_argument, NULL, 'h'},
  98. {"input-format", required_argument, NULL, 'i'},
  99. {"append-gaps", no_argument, NULL, 'a'},
  100. {"prepend-gaps", no_argument, NULL, 'p'},
  101. {"split-gaps", no_argument, NULL, 's'},
  102. {NULL, 0, NULL, 0}
  103. };
  104. progname = *argv;
  105. while (-1 != (c = getopt_long(argc, argv, "hi:", longopts, NULL))) {
  106. switch (c) {
  107. case 'h':
  108. usage(0);
  109. break;
  110. case 'i':
  111. if (0 == strcmp("cue", optarg))
  112. format = CUE;
  113. else if (0 == strcmp("toc", optarg))
  114. format = TOC;
  115. else
  116. fprintf(stderr, "%s: illegal format `%s'\n", progname, optarg);
  117. usage(1);
  118. break;
  119. case 'a':
  120. gaps = APPEND;
  121. break;
  122. case 'p':
  123. gaps = PREPEND;
  124. break;
  125. case 's':
  126. gaps = SPLIT;
  127. break;
  128. default:
  129. usage(1);
  130. break;
  131. }
  132. }
  133. if (optind == argc) {
  134. breaks("-", format, gaps);
  135. } else {
  136. for (; optind < argc; optind++)
  137. breaks(argv[optind], format, gaps);
  138. }
  139. return 0;
  140. }