// // Programmer: Craig Stuart Sapp // Creation Date: Sun Apr 15 19:09:11 PDT 2018 // Last Modified: Sun Apr 15 19:09:22 PDT 2018 // Filename: tools/extractlyrics.cpp // URL: https://github.com/craigsapp/midifile/blob/master/tools/extractlyrics.cpp // Syntax: C++11 // vim: ts=3 // // Description: Demonstration of how to extract lyrics from a MIDI file. // Used the -s option to display the timestamp in seconds // that the lyric occurs at. // #include "MidiFile.h" #include "Options.h" #include using namespace std; using namespace smf; void extractLyrics(MidiFile& midifile, int seconds); /////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { Options options; options.define("s|seconds|timestamp=b", "display timestamp for lyrics"); options.process(argc, argv); MidiFile midifile; if (options.getArgCount() == 0) { midifile.read(cin); } else if (options.getArgCount() == 1) { midifile.read(options.getArg(1)); } else { cerr << "Too many filenames" << endl; exit(1); } extractLyrics(midifile, options.getBoolean("seconds")); return 0; } ////////////////////////////// // // extractLyrics -- Extract lyrics from MIDI file, one lyric per output line. // void extractLyrics(MidiFile& midifile, int seconds) { if (seconds) { midifile.doTimeAnalysis(); } for (int i=0; i