// // Programmer: Craig Stuart Sapp // Creation Date: Sat Jul 1 02:48:55 PDT 2006 // Last Modified: Mon Mar 17 23:19:09 PST 2008 // Filename: ...sig/examples/all/plotcurve.cpp // Web Address: http://sig.sapp.org/examples/museinfo/plotcurve/plotcurve.cpp // Syntax: C++; museinfo // // Description: Plot a stream of numbers. // #include "HumdrumFile.h" #include "Array.h" #include "Options.h" #include "PixelColor.h" #include #include #ifndef OLDCPP using namespace std; #include #include #else #include #include #endif // function declarations: void checkOptions (Options& opts, int argc, char** argv); void example (void); void usage (const char* command); void printDataPlot (Array& a, Array& b, int height, int gridlines); // User interface variables: Options options; int column = 0; // used with -n option (for averaging) int flipq = 0; // flip the data from tempo to duration int maxheight = -1; // used with --height option int gradientq = 0; // used with -G option double smooth = 0.0; // used with -S option int hline = 0; // used with -H option int plotq = 0; // used with -P option int unsmoothq = 0; // used with -U option int bifeature = 0; // used with -b option int bgval = 80; // no interface to user yet ////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { // process the command-line options checkOptions(options, argc, argv); HumdrumFile infile; string filename = ""; if (options.getArgCount() <= 0) { infile.read(cin); } else { filename = options.getArg(1); infile.read(filename.c_str()); } Array a; //Array b; // loadData(infile, a); // printDataPlot(a); return 0; } ////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // printDataPlot -- print an input data plot underneath the scape. // void printDataPlot(Array& a, Array& b, int height, int gridlines) { PixelColor pc; pc.setColor(255,0,0); int i, j; int rows = height; int cols = a.getSize() * 2; Array > plotregion; plotregion.setSize(rows); plotregion.allowGrowth(0); for (i=0; i 0: if (gridlines > 0) { for (j=0; j maxx) { maxx = a[i]; } } double i1; double i2; int x1; int x2; int k; int xlow; int xhi; for (j=0; j= rows) { i = rows-1; } plotregion[i][2*j].setColor(0,0,255); if (j < a.getSize()-1) { i2 = (a[j+1] - minn)/(maxx - minn) * rows; x1 = rows - int(i1) - 1; x2 = rows - int(i2) - 1; if (x1 < 0) { x1 = 0; } if (x1 >= rows) { x1 = rows-1; } if (x2 < 0) { x2 = 0; } if (x2 >= rows) { x2 = rows-1; } if (x1 < x2) { xlow = x1; xhi = x2; } else { xlow = x2; xhi = x1; } for (k=xlow+1; k 1) { column = 1; } // dataq = opts.getBoolean("data"); // correlq = opts.getBoolean("correlation"); // if (opts.getBoolean("hue")) { // colortype = COLOR_HUE; // } // if ((rampq || archq) && opts.getBoolean("gradient")) { // gradientq = 1; // } // if (opts.getBoolean("rectangle")) { // plotshape = SHAPE_RECTANGLE; // } } ////////////////////////////// // // example -- // void example(void) { } ////////////////////////////// // // usage -- // void usage(const char* command) { } // md5sum: c4281aea8a410d05fb2463edc64e7e20 curveplot.cpp [20160320]