Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: track_info.c
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- --- track_info.c (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
- +++ track_info.c (revision )
- @@ -44,6 +44,16 @@
- free(ti);
- }
- +int getTime(char buffer[], unsigned int start, unsigned int end) {
- + int length = end - start;
- + char timeChar[length];
- + memcpy(timeChar, buffer + start, end);
- + int temp1;
- + sscanf(timeChar, "%d", &temp1);
- +
- + return temp1;
- +}
- +
- struct track_info *track_info_new(const char *filename)
- {
- struct track_info *ti;
- @@ -54,6 +64,80 @@
- ti->comments = NULL;
- ti->codec = NULL;
- ti->codec_profile = NULL;
- +
- + // Find SRT
- + int filename_length = strlen(filename);
- + int position_extension;
- +
- + //Find begin of extension
- + for (position_extension = filename_length; position_extension >= 0; position_extension--) {
- + if (filename[position_extension - 1] == '.')
- + break;
- + }
- +
- + if (position_extension <= 0)
- + return ti;
- +
- + //Creating name of lyrics
- + char filename_str[position_extension + 4];
- + memcpy(filename_str, filename, sizeof(char) * position_extension);
- + memcpy(filename_str + position_extension, "srt", sizeof(char) * 4);
- +
- + // Read SRT
- + ti->count_total_lyrics = 0;
- + if (access(filename_str, F_OK) != -1) {
- + ti->showTextLyric = noneLyric;
- + ti->lastLyric = 0;
- +
- + int tempStrFileSize = 30;
- + ti->lyric = malloc(sizeof(struct sLyric) * tempStrFileSize);
- +
- + FILE *fp;
- + fp = fopen(filename_str, "r");
- +
- + enum {lCounter, lTime, lText, lBlank} currentTypeLine = lCounter;
- +
- + char buffer[256];
- + int bufferCount = 0;
- + while ((buffer[bufferCount] = getc(fp)) != EOF) {
- + if (buffer[bufferCount] == '\n') {
- + buffer[bufferCount - 1] = '\0';
- + if (currentTypeLine == lCounter) {
- + if (ti->count_total_lyrics == tempStrFileSize) {
- + tempStrFileSize += 5;
- + ti->lyric = realloc(ti->lyric, sizeof(struct sLyric) * tempStrFileSize);
- + }
- + } else if (currentTypeLine == lTime) {
- + int startHour = getTime(buffer, 0, 1);
- + int startMinutes = getTime(buffer, 3, 4);
- + int startSeconds = getTime(buffer, 6, 7);
- + int startHundredths = getTime(buffer, 9, 11);
- + ti->lyric[ti->count_total_lyrics].timeStart = (startHour * 3600) + (startMinutes * 60) + (startSeconds) + ((double) startHundredths / 1000);
- +
- + int endHour = getTime(buffer, 17, 18);
- + int endMinutes = getTime(buffer, 20, 21);
- + int endSeconds = getTime(buffer, 23, 24);
- + int endHundredths = getTime(buffer, 26, 28);
- + ti->lyric[ti->count_total_lyrics].timeEnd = (endHour * 3600) + (endMinutes * 60) + (endSeconds) + ((double) endHundredths / 1000);
- + } else if (currentTypeLine == lText) {
- + strcpy(ti->lyric[ti->count_total_lyrics].messageText, buffer);
- + ti->count_total_lyrics++;
- + }
- +
- + if (currentTypeLine == lBlank) {
- + currentTypeLine = lCounter;
- + } else {
- + currentTypeLine++;
- + }
- +
- + bufferCount = 0;
- + buffer[bufferCount] = '\0';
- + } else {
- + bufferCount++;
- + }
- + }
- + }
- +
- return ti;
- }
- Index: options.c
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- --- options.c (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
- +++ options.c (revision )
- @@ -225,6 +225,7 @@
- " %{status} %{?show_playback_position?%{position} %{?duration?/ %{duration} }?%{?duration?%{duration} }}"
- "- %{total} "
- "%{?volume>=0?vol: %{?lvolume!=rvolume?%{lvolume},%{rvolume} ?%{volume} }}"
- + " | %{lyrics} | "
- "%{?stream?buf: %{buffer} }"
- "%{?show_current_bitrate & bitrate>=0? %{bitrate} kbps }"
- "%="
- Index: track_info.h
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- --- track_info.h (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
- +++ track_info.h (revision )
- @@ -22,6 +22,14 @@
- #include <time.h>
- #include <stddef.h>
- +enum states_lyric {noneLyric, newLyric, oldLyric};
- +
- +struct sLyric {
- + double timeStart;
- + double timeEnd;
- + char messageText[100];
- +};
- +
- struct track_info {
- struct keyval *comments;
- @@ -64,6 +72,12 @@
- unsigned int play_count;
- int is_va_compilation : 1;
- +
- + int count_total_lyrics;
- + struct sLyric *lyric;
- + int lastLyric;
- + enum states_lyric showTextLyric;
- + char *currentTextLyric;
- };
- typedef size_t sort_key_t;
- Index: ui_curses.c
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- --- ui_curses.c (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
- +++ ui_curses.c (revision )
- @@ -289,6 +289,7 @@
- TF_VOLUME,
- TF_LVOLUME,
- TF_RVOLUME,
- + TF_LYRICS,
- TF_BUFFER,
- TF_REPEAT,
- TF_CONTINUE,
- @@ -345,6 +346,7 @@
- DEF_FO_INT('\0', "volume", 1),
- DEF_FO_INT('\0', "lvolume", 1),
- DEF_FO_INT('\0', "rvolume", 1),
- + DEF_FO_STR('\0', "lyrics", 0),
- DEF_FO_INT('\0', "buffer", 1),
- DEF_FO_STR('\0', "repeat", 0),
- DEF_FO_STR('\0', "continue", 0),
- @@ -653,8 +655,17 @@
- fopt_set_str(&track_fopts[TF_SHUFFLE], shuffle_strs[shuffle]);
- fopt_set_str(&track_fopts[TF_PLAYLISTMODE], aaa_mode_names[aaa_mode]);
- - if (player_info.ti)
- + if (player_info.ti) {
- duration = player_info.ti->duration;
- +
- + if (player_info.ti->count_total_lyrics && player_info.ti->showTextLyric == newLyric) {
- + fopt_set_str(&track_fopts[TF_LYRICS], player_info.ti->currentTextLyric);
- + player_info.ti->showTextLyric = oldLyric;
- + refresh();
- + } else if (player_info.ti->showTextLyric == noneLyric) {
- + fopt_set_str(&track_fopts[TF_LYRICS], "");
- + }
- + }
- vol_left = vol_right = vol = -1;
- if (soft_vol) {
- Index: player.c
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- --- player.c (revision 35ca936eb33e206ff2b083a5fc7a4f32e682b82d)
- +++ player.c (revision )
- @@ -26,6 +26,7 @@
- #include "debug.h"
- #include "compiler.h"
- #include "options.h"
- +#include "track_info.h"
- #include <stdio.h>
- #include <stdlib.h>
- @@ -521,17 +522,29 @@
- */
- static void _consumer_position_update(void)
- {
- - static unsigned int old_pos = -1;
- - unsigned int pos = 0;
- + static double old_pos = -1;
- + double pos = 0;
- long bitrate;
- if (consumer_status == CS_PLAYING || consumer_status == CS_PAUSED)
- - pos = consumer_pos / buffer_second_size();
- + pos = (double) consumer_pos / (double) buffer_second_size();
- +
- if (pos != old_pos) {
- old_pos = pos;
- player_info_lock();
- - player_info.pos = pos;
- + player_info.pos = (int) pos;
- +
- + if (player_info.ti->count_total_lyrics && player_info.ti->lastLyric <= player_info.ti->count_total_lyrics) {
- + if (player_info.ti->lastLyric > 0 && player_info.ti->lyric[player_info.ti->lastLyric - 1].timeEnd <= pos)
- + player_info.ti->showTextLyric = noneLyric;
- +
- + if (player_info.ti->lyric[player_info.ti->lastLyric].timeStart <= pos) {
- + player_info.ti->currentTextLyric = player_info.ti->lyric[player_info.ti->lastLyric].messageText;
- + player_info.ti->lastLyric++;
- + player_info.ti->showTextLyric = newLyric;
- + }
- + }
- if (show_current_bitrate) {
- bitrate = ip_current_bitrate(ip);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement