// // Programmer: Craig Stuart Sapp // Creation Date: Sat Apr 25 21:19:21 PDT 1998 // Last Modified: Sat Apr 25 21:19:24 PDT 1998 // Filename: ...sig/doc/examples/sig/sigfile/sndcomment/sndcomment.cpp // Syntax: C++; sig // // Description: extracts or replaces a comment in a soundfile. // #include "sigAudio.h" #include #ifndef OLDCPP #include using namespace std; #else #include #endif void checkOptions(Options& opts); void example(void); void usage(const char* command); char* getcomment(const char* filename); /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { Options options(argc, argv); checkOptions(options); SoundHeader header(options.getArg(1)); char* comment; if (strlen(options.getString("comment-file")) != 0) { comment = getcomment(options.getString("comment-file")); } else { comment = new char[strlen(options.getString("comment")) + 1]; strcpy(comment, options.getString("comment")); } header.setComment(comment); int numSamples = header.getSamples() * header.getChannels(); // Elements: SoundFileIn insound(options.getArg(1)); SoundFileOut outsound(options.getArg(2), header); // Connections: for (int i=0; i 2) { cout << "Error: too many arguments. Given " << opts.getArgCount() << " but need only 2." << endl; usage(opts.getCommand()); exit(1); } } ////////////////////////////// // // example -- gives example calls to the dcblock program. // void example(void) { cout << "# sndcomment examples: \n" " sndcomment -c \"This is a comment\" in.snd out.snd \n" << endl; } ////////////////////////////// // // usage -- how to run the osc program on the command line. // void usage(const char* command) { cout << " \n" "Sets a comment in the soundfile header. Doesn't work with \n" " \n" "Usage: " << command << " [-c comment][-f file][-e] insound outsound \n" " \n" "Options: \n" " -c = comment string \n" " -f = comment file. overrides the -c option \n" " -e = extracts the comment from the input soundfile \n" " --options = list of all options, aliases and defaults \n" << endl; } ////////////////////////////// // // getcomment -- gets a comment from a text file. // char* getcomment(const char* filename) { #ifndef OLDCPP fstream infile(filename, ios::in); #else fstream infile(filename, ios::nocreate | ios::in); #endif // figure out how many bytes in file: infile.seekg(0, ios::end); int size = infile.tellg(); infile.seekg(0, ios::beg); char* output = new char[size + 1]; output[size] = '\0'; infile.read(output, sizeof(char) * size); return output; } // md5sum: 8a8e7d1b16e40c1658c739f6012c7f26 sndcomment.cpp [20050403]