Hey soiaf
I tried your suggestion, it didn't want to work with extern or without, so I had to add ALL The wavpack src as "Resource Files" and set them to compile without /clr (I don't know why) but after that it actually compiled. I changed the _s (safe methods back) so hopefully it might work on your compiler as is. Here is the current code
lyric.h
#ifndef LYRIC_H
#define LYRIC_H
extern "C" {
#include "include\wavpack.h"
}
#include <string>
#include <fstream>
#include <iostream>
//#include <stdio.h>
#include <time.h>
//#include <sys/types.h>
#include <sys/stat.h>
using namespace std;
class lyric
{
public:
lyric(int lid, string stime, string ftime, string lines);
lyric();
//gets
int Lid() { return lid; }
string Stime() { return stime; }
string Ftime() { return ftime; }
string Lines() { return lines; }
int stm() { return st; }
int ftm() { return ft; }
int Duration() { return duration; }
friend ostream& operator<< (ostream &out, lyric &clyric);
private:
int lid;
string stime;
string ftime;
string lines;
int st; //start time in milliseconds
int ft; //finished time in milliseconds
int duration; //in milliseconds
};
#endif
lyrics.cpp
#include "lyric.h"
lyric::lyric(int lid, string stime, string ftime, string lines)
{
char *str1,*str2, *token1,*token2, *next_token1, *next_token2;
char seps[] = " :,";
this->lid = lid;
this->stime = stime;
this->ftime = ftime;
this->lines = lines;
st = 0;
ft = 0;
str1 = new char[stime.size()+1];
strcpy(str1,stime.c_str());
str2 = new char[ftime.size()+1];
strcpy(str2,ftime.c_str());
token1 = strtok(str1, seps);
st += atoi(token1)*3600000; //hours
if (token1 != NULL)
{
token1 = strtok( NULL, seps);
st += atoi(token1)*60000; //minutes
}
if (token1 != NULL)
{
token1 = strtok ( NULL, seps);
st += atoi(token1)*1000; //seconds
}
if (token1 != NULL)
{
token1 = strtok ( NULL, seps);
st += atoi(token1); //milliseconds
}
token2 = strtok ( str2, seps);
ft += atoi(token2)*3600000; //hours
if (token2 != NULL)
{
token2 = strtok (NULL, seps);
ft += atoi(token2)*60000; //minutes
}
if (token2 != NULL)
{
token2 = strtok (NULL, seps);
ft += atoi(token2)*1000; //seconds
}
if (token2 != NULL)
{
token2 = strtok (NULL, seps);
ft += atoi(token2); //milliseconds
}
//IF st > ft throw exception @ lyric number 'lid' exit(1)
this->duration = ft - st;
}
lyric::lyric()
{
}
ostream& operator<< (ostream &out, lyric &clyric)
{
out << "(" << clyric.lid << ", Start time: " <<
clyric.st <<", Finish time: " << clyric.ft << ")";
return out;
}
srtreader.cpp
#include "lyric.h"
void wait ( int ms );
static int32_t read_bytes (void *id, void *data, int32_t bcount) {
return (int32_t) fread (data, 1, bcount, (FILE*) id);
}
static uint32_t get_pos (void *id) {
return ftell ((FILE*) id);
}
static int set_pos_abs (void *id, uint32_t pos) {
return fseek ((FILE *)id, pos, SEEK_SET);
}
static int set_pos_rel (void *id, int32_t delta, int mode) {
return fseek ((FILE *)id, delta, mode);
}
static int push_back_byte (void *id, int c) {
return ungetc (c, (FILE *)id);
}
static uint32_t get_length (void *id) {
FILE *file = (FILE *)id;
struct stat statbuf;
if (!file || fstat (fileno (file), &statbuf) || !(statbuf.st_mode & S_IFREG))
return 0;
return statbuf.st_size;
}
static int can_seek (void *id) {
FILE *file = (FILE *)id;
struct stat statbuf;
return file && !fstat (fileno (file), &statbuf) && (statbuf.st_mode & S_IFREG);
}
static int32_t write_bytes (void *id, void *data, int32_t bcount) {
return (int32_t) fwrite (data, 1, bcount, (FILE*) id);
}
static WavpackStreamReader freader = {
read_bytes, get_pos, set_pos_abs, set_pos_rel, push_back_byte, get_length, can_seek,
write_bytes
};
int main ()
{
WavpackContext *wpc;
int open_flags;
int srt_size;
int retval;
char errorBuff[128];
FILE *f = NULL;
int lid, max, ctime, error;
string line, line2, lyrics;
lyric* slyrics;
f = fopen("Love The Way You Lie.wv", "r");
if (!f)
{
cout << "Error! couldn't open wavpack file" << endl;
cin >> lid;
exit(1);
// something really bad has happened, you can't open the file, maybe time to quit
}
open_flags = OPEN_TAGS | OPEN_2CH_MAX | OPEN_NORMALIZE;
wpc = WavpackOpenFileInputEx (&freader, f, NULL, errorBuff, open_flags, 0);
if (wpc == NULL) //currently always true
{
cout << "Error! inside wavpack file" << endl;
cin >> lid;
exit(1);
}
/*
// work out if there is Lyrics data, this will return the size of the Lyrics tag or 0 if not there
srt_size = WavpackGetTagItem (wpc, "Lyrics", NULL, 0);
// this is rough code, remember you need to check that the malloc worked
char *srtdata = (char*)malloc(srt_size);
retval = WavpackGetTagItem (wpc, "Lyrics", srtdata, srt_size);
if (retval == 0)
{
cout << "Error! .srt incorrectly formatted" << endl;
cin >> lid;
exit(1);
}
wpc = WavpackCloseFile(wpc); // tidies up after us*/
// Lyrics data is now is srtdata, process this as you like.....
// don't forget to free the memory you grabbed after you've processed the SRT data
ifstream myfile("Lyrics.srt", ifstream::in); //open lyrics !needs to be changed to read from wavpack tag marked with extention *.srt
if (myfile.is_open())
{
error = 0;
while (! myfile.eof() ) //counts the number of lyrics
{
error++;
getline(myfile, line);
lid = atoi(line.c_str()); //lyric id !Throw 'not correct format' "exception at this line x =" exit(1)
if (lid == 0)
{
cout << "Error! at line " << error << ", .srt incorrectly formatted" << endl;
exit(1);
}
while (myfile.eof() == 0 && line.length() != 0) //lyrics
{
getline(myfile,line);
lyrics += line;
}
}
max = lid; //last lyric ID is the max number of lyrics
myfile.clear();
myfile.seekg(0);
slyrics = new lyric[max];
for (int i=0;! myfile.eof();i++ )
{
getline(myfile, line);
lid = atoi(line.c_str()); //lyric id //exception taken care of from the last while loop
getline(myfile,line2); //<start time> --> <end time> !IF line2.size() != 29 Throw 'not correct format' "exception at this line x =" exit(1)
lyrics.clear();
while (myfile.eof() != 1 && line.length() != 0) //find all the lyric lines and add dynamically
{
getline(myfile,line); //lyrics
lyrics += (line + '\n');
}
while (lyrics.find_last_of('\n') == (lyrics.length()-1)) //trim function
{
lyrics = lyrics.substr(0,lyrics.length()-1);
}
slyrics[i] = lyric(lid,line2.substr(0,12),line2.substr(17,29),lyrics);
}
myfile.close();
ctime = 0;
for (int i=0;i < max;++i) //print lyric objects
{
if (slyrics[i].stm()-ctime > 10)
{
wait(slyrics[i].stm()-ctime);
}
cout << slyrics[i].Lines() << endl;
wait(slyrics[i].Duration() - 50); //-50 this offset is just a guess, wait isn't accurate, well for me anyway
system( "cls" );
ctime = slyrics[i].ftm();
}
}
else
{
cout << "Unable to open file";
}
cin >> line;
//free(srtdata);
return 0;
}
void wait ( int ms )
{
clock_t endwait;
endwait = clock () + ms;
while (clock() < endwait) {}
}
currently it's clearly having problems reading the wavpack file (I've tried 2 different files, so I hope I'm right)
if (wpc == NULL) //currently always true
{
cout << "Error! inside wavpack file" << endl;
cin >> lid;
exit(1);
}
directly after the lines I was having trouble with before
open_flags = OPEN_TAGS | OPEN_2CH_MAX | OPEN_NORMALIZE;
wpc = WavpackOpenFileInputEx (&freader, f, NULL, errorBuff, open_flags, 0);
thanks in advance RJ.
I've also been looking for foobar coding of any kind and it looks like it's on another level, I'm going to look at winamp to see if their coding is any easier to understand...