midiFileToRomData.h (1274B)
1 #pragma once 2 3 #include <cstdint> 4 #include <string> 5 #include <vector> 6 7 namespace virusLib 8 { 9 class MidiFileToRomData 10 { 11 public: 12 using Packet = std::vector<uint8_t>; 13 14 MidiFileToRomData(const uint8_t _expectedFirstSector = 0xff) : m_expectedSector(_expectedFirstSector) 15 { 16 } 17 18 bool load(const std::string& _filename); 19 bool load(const std::vector<uint8_t>& _fileData, bool _isMidiFileData = false); 20 21 bool add(const std::vector<Packet>& _packets); 22 bool add(const Packet& _packet); 23 24 bool isValid() const { return m_valid; } 25 bool isComplete() const { return isValid() && m_complete; } 26 27 const std::vector<uint8_t>& getData() const { return m_data; } 28 29 size_t getPacketCount() const { return m_packets.size(); } 30 31 uint8_t getFirstSector() const { return m_firstSector; } 32 33 private: 34 void addPacket(const Packet& _packet) 35 { 36 m_packets.push_back(_packet); 37 } 38 bool setCompleted(); 39 40 bool processPacket(const Packet& _packet, uint8_t _msb, uint8_t _lsb); 41 42 bool toBinary(std::vector<uint8_t>& _binary) const; 43 44 std::vector<Packet> m_packets; 45 std::vector<uint8_t> m_data; 46 47 bool m_valid = true; 48 bool m_complete = false; 49 50 uint8_t m_expectedMSB = 127; 51 uint8_t m_expectedLSB = 8; 52 uint8_t m_expectedSector; 53 uint8_t m_firstSector = 0xff; 54 }; 55 }