Advertisement
KeplerBR

[cmus] View SRT - beta 2

Jul 1st, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.48 KB | None | 0 0
  1. Index: track_info.c
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. --- track_info.c    (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
  7. +++ track_info.c    (revision )
  8. @@ -54,6 +54,131 @@
  9.     ti->comments = NULL;
  10.     ti->codec = NULL;
  11.     ti->codec_profile = NULL;
  12. +
  13. +   // Find SRT
  14. +   int filename_length = 0;
  15. +   int position_extension = 0;
  16. +   char c = filename[filename_length];
  17. +   for (; c != '\0'; ++filename_length) {
  18. +       c = filename[filename_length];
  19. +       if (c == '.')
  20. +           position_extension = filename_length + 1;
  21. +   }
  22. +   int filename_str_length;
  23. +   if (position_extension) {
  24. +       filename_str_length = filename_length - (filename_length - position_extension - 3);
  25. +   } else {
  26. +       filename_str_length = filename_length + 3;
  27. +   }
  28. +
  29. +   char filename_str[filename_str_length];
  30. +   memcpy(filename_str, filename, sizeof(char) * filename_str_length);
  31. +
  32. +   filename_str[position_extension + 0] = 's';
  33. +   filename_str[position_extension + 1] = 'r';
  34. +   filename_str[position_extension + 2] = 't';
  35. +
  36. +   // Read SRT
  37. +   ti->count_total_lyrics = 0;
  38. +   if (access(filename_str, F_OK) != -1) {
  39. +       ti->showTextLyric = 0;
  40. +       ti->lastLyric = 0;
  41. +
  42. +       int tempStrFileSize = 30;
  43. +       ti->lyric = malloc(sizeof(struct sLyric) * tempStrFileSize);
  44. +
  45. +       FILE *fp;
  46. +       fp = fopen(filename_str, "r");
  47. +
  48. +       enum {lCounter, lTime, lText, lBlank} currentTypeLine = lCounter;
  49. +
  50. +       char buffer[256];
  51. +       int bufferCount = 0;
  52. +       while ((buffer[bufferCount] = getc(fp)) != EOF) {
  53. +           if (buffer[bufferCount] == '\n') {
  54. +               buffer[bufferCount - 1] = '\0';
  55. +               if (currentTypeLine == lCounter) {
  56. +                   if (ti->count_total_lyrics == tempStrFileSize) {
  57. +                       tempStrFileSize += 5;
  58. +                       ti->lyric = realloc(ti->lyric, sizeof(struct sLyric) * tempStrFileSize);
  59. +                   }
  60. +               } else if (currentTypeLine == lTime) {
  61. +                   int temp1;
  62. +                   char start_hours[2];
  63. +                   start_hours[0] = buffer[0];
  64. +                   start_hours[1] = buffer[1];
  65. +                   sscanf(start_hours, "%d", &temp1);
  66. +
  67. +                   int temp2;
  68. +                   char start_minutes[2];
  69. +                   start_minutes[0] = buffer[3];
  70. +                   start_minutes[1] = buffer[4];
  71. +                   sscanf(start_minutes, "%d", &temp2);
  72. +
  73. +                   int temp3;
  74. +                   char start_seconds[2];
  75. +                   start_seconds[0] = buffer[6];
  76. +                   start_seconds[1] = buffer[7];
  77. +                   sscanf(start_seconds, "%d", &temp3);
  78. +
  79. +                   double tempD1;
  80. +                   char start_cents[5];
  81. +                   start_cents[0] = '0';
  82. +                   start_cents[1] = '.';
  83. +                   start_cents[2] = buffer[9];
  84. +                   start_cents[3] = buffer[10];
  85. +                   start_cents[4] = buffer[11];
  86. +                   sscanf(start_cents, "%lf", &tempD1);
  87. +
  88. +                   ti->lyric[ti->count_total_lyrics].timeStart = (double) (temp1 * 3600) + (temp2 * 60) + (temp3) + (tempD1);
  89. +
  90. +                   int temp4;
  91. +                   char end_hours[2];
  92. +                   end_hours[0] = buffer[17];
  93. +                   end_hours[1] = buffer[18];
  94. +                   sscanf(end_hours, "%d", &temp4);
  95. +
  96. +                   int temp5;
  97. +                   char end_minutes[2];
  98. +                   end_minutes[0] = buffer[20];
  99. +                   end_minutes[1] = buffer[21];
  100. +                   sscanf(end_minutes, "%d", &temp5);
  101. +
  102. +                   int temp6;
  103. +                   char end_seconds[2];
  104. +                   end_seconds[0] = buffer[23];
  105. +                   end_seconds[1] = buffer[24];
  106. +                   sscanf(end_seconds, "%d", &temp6);
  107. +
  108. +                   double tempD2;
  109. +                   char end_cents[5];
  110. +                   end_cents[0] = '0';
  111. +                   end_cents[1] = '.';
  112. +                   end_cents[2] = buffer[26];
  113. +                   end_cents[3] = buffer[27];
  114. +                   end_cents[4] = buffer[28];
  115. +                   sscanf(end_cents, "%lf", &tempD2);
  116. +
  117. +                   ti->lyric[ti->count_total_lyrics].timeEnd = (double) (temp4 * 3600) + (temp5 * 60) + (temp6) + (tempD2);
  118. +               } else if (currentTypeLine == lText) {
  119. +                   strcpy(ti->lyric[ti->count_total_lyrics].messageText, buffer);
  120. +                   ti->count_total_lyrics++;
  121. +               }
  122. +
  123. +               if (currentTypeLine == lBlank) {
  124. +                   currentTypeLine = lCounter;
  125. +               } else {
  126. +                   currentTypeLine++;
  127. +               }
  128. +
  129. +               bufferCount = 0;
  130. +               buffer[bufferCount] = '\0';
  131. +           } else {
  132. +               bufferCount++;
  133. +           }
  134. +       }
  135. +   }
  136. +
  137.     return ti;
  138.  }
  139.  
  140. Index: options.c
  141. IDEA additional info:
  142. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  143. <+>UTF-8
  144. ===================================================================
  145. --- options.c   (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
  146. +++ options.c   (revision )
  147. @@ -225,6 +225,7 @@
  148.         " %{status} %{?show_playback_position?%{position} %{?duration?/ %{duration} }?%{?duration?%{duration} }}"
  149.         "- %{total} "
  150.         "%{?volume>=0?vol: %{?lvolume!=rvolume?%{lvolume},%{rvolume} ?%{volume} }}"
  151. +       " | %{lyrics} | "
  152.         "%{?stream?buf: %{buffer} }"
  153.         "%{?show_current_bitrate & bitrate>=0? %{bitrate} kbps }"
  154.         "%="
  155. Index: track_info.h
  156. IDEA additional info:
  157. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  158. <+>UTF-8
  159. ===================================================================
  160. --- track_info.h    (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
  161. +++ track_info.h    (revision )
  162. @@ -22,6 +22,12 @@
  163.  #include <time.h>
  164.  #include <stddef.h>
  165.  
  166. +struct sLyric {
  167. +   double timeStart;
  168. +   double timeEnd;
  169. +   char messageText[100];
  170. +};
  171. +
  172.  struct track_info {
  173.     struct keyval *comments;
  174.  
  175. @@ -64,6 +70,12 @@
  176.     unsigned int play_count;
  177.  
  178.     int is_va_compilation : 1;
  179. +
  180. +   int count_total_lyrics;
  181. +   struct sLyric *lyric;
  182. +   int lastLyric;
  183. +   int showTextLyric;
  184. +   char *currentTextLyric;
  185.  };
  186.  
  187.  typedef size_t sort_key_t;
  188. Index: ui_curses.c
  189. IDEA additional info:
  190. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  191. <+>UTF-8
  192. ===================================================================
  193. --- ui_curses.c (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
  194. +++ ui_curses.c (revision )
  195. @@ -289,6 +289,7 @@
  196.     TF_VOLUME,
  197.     TF_LVOLUME,
  198.     TF_RVOLUME,
  199. +   TF_LYRICS,
  200.     TF_BUFFER,
  201.     TF_REPEAT,
  202.     TF_CONTINUE,
  203. @@ -345,6 +346,7 @@
  204.     DEF_FO_INT('\0', "volume", 1),
  205.     DEF_FO_INT('\0', "lvolume", 1),
  206.     DEF_FO_INT('\0', "rvolume", 1),
  207. +   DEF_FO_STR('\0', "lyrics", 0),
  208.     DEF_FO_INT('\0', "buffer", 1),
  209.     DEF_FO_STR('\0', "repeat", 0),
  210.     DEF_FO_STR('\0', "continue", 0),
  211. @@ -653,8 +655,15 @@
  212.     fopt_set_str(&track_fopts[TF_SHUFFLE], shuffle_strs[shuffle]);
  213.     fopt_set_str(&track_fopts[TF_PLAYLISTMODE], aaa_mode_names[aaa_mode]);
  214.  
  215. -   if (player_info.ti)
  216. +   if (player_info.ti) {
  217.         duration = player_info.ti->duration;
  218. +
  219. +       if (player_info.ti->count_total_lyrics && player_info.ti->showTextLyric) {
  220. +           fopt_set_str(&track_fopts[TF_LYRICS], player_info.ti->currentTextLyric);
  221. +       } else {
  222. +           fopt_set_str(&track_fopts[TF_LYRICS], "");
  223. +       }
  224. +   }
  225.  
  226.     vol_left = vol_right = vol = -1;
  227.     if (soft_vol) {
  228. Index: player.c
  229. IDEA additional info:
  230. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  231. <+>UTF-8
  232. ===================================================================
  233. --- player.c    (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
  234. +++ player.c    (revision )
  235. @@ -532,6 +532,18 @@
  236.  
  237.         player_info_lock();
  238.         player_info.pos = pos;
  239. +       double pos2 = (double)consumer_pos / (double)buffer_second_size();
  240. +
  241. +       if (player_info.ti->count_total_lyrics && player_info.ti->lastLyric <= player_info.ti->count_total_lyrics) {
  242. +           if (player_info.ti->lastLyric > 0 && player_info.ti->lyric[player_info.ti->lastLyric - 1].timeEnd <= pos2)
  243. +               player_info.ti->showTextLyric = 0;
  244. +
  245. +           if (player_info.ti->lyric[player_info.ti->lastLyric].timeStart <= pos2) {
  246. +               player_info.ti->currentTextLyric = player_info.ti->lyric[player_info.ti->lastLyric].messageText;
  247. +               player_info.ti->lastLyric++;
  248. +               player_info.ti->showTextLyric = 1;
  249. +           }
  250. +       }
  251.  
  252.         if (show_current_bitrate) {
  253.             bitrate = ip_current_bitrate(ip);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement