SHARE
TWEET

randsho(2).cpp

HertzDevil Aug 1st, 2013 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // http://www.mediafire.com/?s1w45hdijht7026
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5. #include <cstdlib>
  6. #include <ctime>
  7.  
  8. using namespace std;
  9.  
  10. int main(int argc, char** argv){
  11.     if (argc < 2){
  12.         cout << "random .sho generator (HertzDevil made this)\n";
  13.         cout << "generates mario paint song file randomly\n";
  14.         cout << "usage: randsho [filename] ([size])\n";
  15.         cout << "[filename]: valid filename\n";
  16.         cout << "[size]: length of the song in quarter notes. maximum is 2880, default is 96\n";
  17.         exit(0);}
  18.  
  19.     srand(time(0));
  20.     fstream sho(argv[1], ios::out | ios::binary);
  21.     int songSize = argc >= 3 ? atoi(argv[2]) : 96;
  22.  
  23.     if (songSize < 1 || songSize > 2880){
  24.         cout << "INVALID SONG LENGTH!\n";
  25.         exit(0);}
  26.  
  27.     // .sho header
  28.     sho.put('s');
  29.     sho.put('h');
  30.     sho.put('r');
  31.     sho.put('o');
  32.     sho.put(argc >= 3 ? 3 : 2);
  33.     sho.put(0);
  34.     sho.put(0);
  35.  
  36.     // random title and author. (only 31 chars long, 2 unused bytes)
  37.     for (int i = 0; i < 64; i++){
  38.         sho.put(32 + rand() % 95);}
  39.  
  40.     // ignored currently
  41.     const char* inst = "default.shi";
  42.     sho.write(inst, 11);
  43.     for (int i = 0; i < 21; i++){
  44.         sho.put(0);}
  45.  
  46.     // long .sho inserts header here
  47.     if (songSize > 96){
  48.         // end of loop
  49.         sho.write(reinterpret_cast<char*>(&songSize), 2);
  50.         // loop, boolean
  51.         sho.put(rand() % 2);
  52.         // time signature, 0 for 3/4, 1 for 4/4
  53.         sho.put(rand() % 2);
  54.         // tempo
  55.         sho.put(rand() % 0xA0);}
  56.  
  57.     // song data
  58.     for (int i = 0; i < (songSize > 96 ? songSize : 96)*3; i++){
  59.         // each note is 4 times as common as no note
  60.         int note = rand() % 53;
  61.         // the note
  62.         sho.put(note == 52 ? 0xFF : note % 13 + 1);
  63.         // the instrument
  64.         sho.put(note == 52 ? 0xDF : rand() % 15);}
  65.  
  66.     // short .sho inserts header here
  67.     if (songSize <= 96){
  68.         // tempo
  69.         sho.put(rand() % 0xA0);
  70.         // end of loop
  71.         sho.put(songSize);
  72.         // loop, boolean
  73.         sho.put(rand() % 2);
  74.         // time signature, 0 for 3/4, 1 for 4/4
  75.         sho.put(rand() % 2);}
  76.  
  77.     // fucking done
  78.     sho.close();
  79.     return 0;}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top