Advertisement
EvilSupahFly

Convert MIDI to text, update GRUB2 with song

Apr 6th, 2024 (edited)
881
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | Source Code | 0 0
  1. # grub2_music_maker.cpp - takes a MIDI file as input, converts it to text notes, and writes it to GRUB_INIT_TUNE in /etc/default/grub -- V1.0
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5. #include <vector>
  6.  
  7. int main(int argc, char *argv[]) {
  8.     if (argc < 2) {
  9.         std::cout << "Usage: " << argv[0] << " <input MIDI file>" << std::endl;
  10.         return 1;
  11.     }
  12.  
  13.     std::ifstream midiFile(argv[1], std::ios::binary);
  14.     if (!midiFile.is_open()) {
  15.         std::cerr << "Error opening MIDI file" << std::endl;
  16.         return 1;
  17.     }
  18.  
  19.     // Read MIDI file and convert to plain text notes
  20.     std::vector<char> notes;
  21.     char note;
  22.     while (midiFile.read(&note, 1)) {
  23.         notes.push_back(note);
  24.     }
  25.  
  26.     // Save notes to the GRUB2 bootloader
  27.     std::ofstream grubFile("/etc/default/grub");
  28.     if (!grubFile.is_open()) {
  29.         std::cerr << "Error opening GRUB file" << std::endl;
  30.         return 1;
  31.     }
  32.  
  33.     grubFile << "GRUB_INIT_TUNE=\"";
  34.     for (const char& n : notes) {
  35.         grubFile << n;
  36.     }
  37.     grubFile << "\"" << std::endl;
  38.  
  39.     std::cout << "MIDI file converted to plain text notes and saved to GRUB2 bootloader" << std::endl;
  40.  
  41.     return 0;
  42. }
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement