// // Programmer: Craig Stuart Sapp // Creation Date: Thu Dec 2 12:45:43 PST 1999 // Last Modified: Fri Feb 20 20:34:39 PST 2015 // Filename: midimixup.cpp // Syntax: C++11 // // Description: Reads a standard MIDI file, move the pitches around // into a random order. // #include "MidiFile.h" #include "Options.h" #include #include #include #include using namespace std; // function declarations: void checkOptions (Options& opts); void example (void); void usage (const char* command); void randomizeNotes (vector& notes); void reverseNotes (vector& notes); void swapNotes (vector& notes, int index1, int index2); class pairing { public: int index; double value; }; // variables related to command-line options int reverseQ = 0; // used with -r option: reverse notes /////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { Options options(argc, argv); checkOptions(options); MidiFile midifile; if (options.getArgCount() == 2) { midifile.read(options.getArg(1)); } else if (options.getArgCount() == 1) { midifile.read(options.getArg(1)); } else { cerr << "Need one optional MIDI file (or standard input), "; cerr << "and one output" << endl; exit(1); } midifile.linkNotePairs(); vector notes; notes.reserve(123456); int track, event; for (track=0; track& notes) { int count = notes.size(); for (int i=0; i& notes) { random_device rd; mt19937 md(rd()); uniform_real_distribution dist(0, 100); int count = notes.size(); vector neworder; neworder.resize(notes.size()); int i; for (i=0; i<(int)neworder.size(); i++) { neworder[i].index = i; neworder[i].value = dist(md); } sort(neworder.begin(), neworder.end(), [](const pairing& a, const pairing& b) { return a.value > b.value; }); for (i=0; i& notes, int index1, int index2) { MidiEvent* noteon1 = notes[index1]; MidiEvent* noteon2 = notes[index2]; MidiEvent* noteoff1 = notes[index1]->getLinkedEvent(); MidiEvent* noteoff2 = notes[index2]->getLinkedEvent(); if (noteon1 == NULL) { return; } if (noteon2 == NULL) { return; } if (noteoff1 == NULL) { return; } if (noteoff2 == NULL) { return; } int pitch1 = noteon1->getKeyNumber(); int pitch2 = noteon2->getKeyNumber(); if (pitch1 == pitch2) { return; } if (pitch1 < 0) { return; } if (pitch2 < 0) { return; } noteon1->setKeyNumber(pitch2); noteoff1->setKeyNumber(pitch2); noteon2->setKeyNumber(pitch1); noteoff2->setKeyNumber(pitch1); } ////////////////////////////// // // checkOptions -- handle command-line options. // void checkOptions(Options& opts) { opts.define("r|reverse=b", "Reverse the order of notes"); opts.define("author=b", "Author of the program"); opts.define("version=b", "Print version of the program"); opts.define("example=b", "Display example use of the program"); opts.define("help=b", "Dispay help for the program"); opts.process(); if (opts.getBoolean("author")) { cout << "Written by Craig Stuart Sapp, " << "craig@ccrma.stanford.edu, 2 December 1999" << endl; exit(0); } if (opts.getBoolean("version")) { cout << "midimixup version 2.0" << endl; cout << "compiled: " << __DATE__ << endl; } if (opts.getBoolean("help")) { usage(opts.getCommand().data()); exit(0); } if (opts.getBoolean("example")) { example(); exit(0); } reverseQ = opts.getBoolean("reverse"); } ////////////////////////////// // // example -- gives example calls to the midiplay program. // void example(void) { cout << " \n" << endl; } ////////////////////////////// // // usage -- how to run the textmidi program on the command line. // void usage(const char* command) { cout << " \n" << endl; }