easylrc::Parser
Getting lyrics from text/audio files and processing for further operations.
This is detailed description of most methods of this part of the library, in a most-likely used order. Might be hard to understand how to use together, mostly for describing functions themselves, so you can look into Render's examples as it might give you more understanding how to use it in simpler way.
1. Loading / unloading lyrics
void load_lrc(const std::string& path)
Use this to read text (mostly, .lrc) file or audio file's lyrics tags (using libavformat) into memory to be able to work with it later.
Arguments
path- path to text/audio file for reading.
Example
#include <easylrc/parser.h>
int main(int argc, char* argv[]) {
easylrc::Parser parser; // create parser object
parser.load_lrc("/path/to/song.flac"); // load
// ...
return 0;
}
void clear()
Use this when you have finished working with one file and wish to close it (end of program or switching to another file).
Example
#include <easylrc/parser.h>
int main(int argc, char* argv[]) {
easylrc::Parser parser; // create parser object
parser.load_lrc("/path/to/song.flac"); // load
// do something
parser.clear() // unload when lyrics are not needed anymore
parser.load_lrc("/path/to/another-song.lrc"); // load another file
// do something
parser.clear() // unload
return 0;
}
2. Getting LRC type
lrc_type_t get_lrc_type(const std::string& path)
Use this to determine type of lyrics - is it STD or an EXT (LRC/eLRC respectively).
Returns easylrc::lrc_type_t::INVALID if is not an lyrics content.
Example
easylrc::lrc_type_t type = parser.get_lrc_type("/path/to/file.lrc");
switch (type) {
case easylrc::lrc_type_t::STD:
std::cout << "LRC" << std::endl;
break;
case easylrc::lrc_type_t::EXT:
std::cout << "eLRC" << std::endl;
break;
default:
std::cerr << "Error: Invalid LRC content" << std::endl;
break;
}
3. Getting lyrics' lines
std::vector<line_t> get() const
Use this to get raw lines data. Returns std::vector<line_t>.
See easylrc::line_t
std_line_t std_get_line_by_timestamp(unsigned int timestamp)
Use this to get one line from standart LRC on a specific timestamp, of a easylrc::std_line_t struct type. Works only for standart LRC. Recommended to firstly check type of lyrics to decide which method to use.
Arguments
timestamp- specifies at what time (in miliseconds) to get line from.
Example
// assuming we have already loaded lyrics using load_lrc()
easylrc::std_line_t line = parser.std_get_line_by_timestamp(5000);
ext_line_t ext_get_line_by_timestamp(unsigned int timestamp)
Use this to get one line from extended LRC on a specific timestamp, of a easylrc::ext_line_t struct type. Works only for extended LRC. Recommended to first check type of lrc to decide which method to use.
Arguments
timestamp- specifies at what time (in miliseconds) to get line from.
Example
// assuming we have already loaded lyrics using load_lrc()
easylrc::ext_line_t line = parser.ext_get_line_by_timestamp(5000);
ext_word_t ext_get_word_by_timestamp(unsigned int timestamp)
Use this to get one word from extended LRC on a specific timestamp, of a easylrc::ext_word_t struct type. Works only for extended LRC. Recommended to first check type of lrc to decide which method to use.
Arguments
timestamp- specifies at what time (in miliseconds) to get word from.
Example
// assuming we have already loaded lyrics using load_lrc()
easylrc::ext_word_t word = parser.ext_get_word_by_timestamp(5000);
Usage
Getting from file
To use easylrc::Parser module, you have to include <easylrc/parser.h>
#include <easylrc/parser.h>
#include <easylrc/render.h>
#include <string> // for std::string
#include <iostream> // for std::cout
// create out objects
easylrc::Parser parser;
easylrc::Render render;
// set path to file which we extract lyrics from
std::string path = "/path/to/file.flac";
// let's set out timestamp to 12000ms (12s) for example
unsigned int timestamp = 12000;
// load file
parser.load_lrc(path);
// parse it!
std::string parsed = render.render_json(parser.get(), timestamp);
// we can now clear parser's memory as we won't call it anymore
parser.clear();
// output it to console :P
std::cout << parsed << std::endl;