Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://www.mediafire.com/?s1w45hdijht7026
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main(int argc, char** argv){
- if (argc < 2){
- cout << "random .sho generator (HertzDevil made this)\n";
- cout << "generates mario paint song file randomly\n";
- cout << "usage: randsho [filename] ([size])\n";
- cout << "[filename]: valid filename\n";
- cout << "[size]: length of the song in quarter notes. maximum is 2880, default is 96\n";
- exit(0);}
- srand(time(0));
- fstream sho(argv[1], ios::out | ios::binary);
- int songSize = argc >= 3 ? atoi(argv[2]) : 96;
- if (songSize < 1 || songSize > 2880){
- cout << "INVALID SONG LENGTH!\n";
- exit(0);}
- // .sho header
- sho.put('s');
- sho.put('h');
- sho.put('r');
- sho.put('o');
- sho.put(argc >= 3 ? 3 : 2);
- sho.put(0);
- sho.put(0);
- // random title and author. (only 31 chars long, 2 unused bytes)
- for (int i = 0; i < 64; i++){
- sho.put(32 + rand() % 95);}
- // ignored currently
- const char* inst = "default.shi";
- sho.write(inst, 11);
- for (int i = 0; i < 21; i++){
- sho.put(0);}
- // long .sho inserts header here
- if (songSize > 96){
- // end of loop
- sho.write(reinterpret_cast<char*>(&songSize), 2);
- // loop, boolean
- sho.put(rand() % 2);
- // time signature, 0 for 3/4, 1 for 4/4
- sho.put(rand() % 2);
- // tempo
- sho.put(rand() % 0xA0);}
- // song data
- for (int i = 0; i < (songSize > 96 ? songSize : 96)*3; i++){
- // each note is 4 times as common as no note
- int note = rand() % 53;
- // the note
- sho.put(note == 52 ? 0xFF : note % 13 + 1);
- // the instrument
- sho.put(note == 52 ? 0xDF : rand() % 15);}
- // short .sho inserts header here
- if (songSize <= 96){
- // tempo
- sho.put(rand() % 0xA0);
- // end of loop
- sho.put(songSize);
- // loop, boolean
- sho.put(rand() % 2);
- // time signature, 0 for 3/4, 1 for 4/4
- sho.put(rand() % 2);}
- // fucking done
- sho.close();
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement