【问题标题】:Getting MIDI byte array from a MIDI file从 MIDI 文件中获取 MIDI 字节数组
【发布时间】:2013-10-22 20:09:29
【问题描述】:

我只是从 C++ 开始,并且很难理解某些事情。我有一个 MIDI 文件,我想检索十六进制字符串,详细信息 here

如何从我读入 C++ 程序的 MIDI 文件中提取十六进制信息字符串?

【问题讨论】:

    标签: c++ hex midi


    【解决方案1】:

    字节数组是字节数组...据我所知,MIDI 数据没有特定的类型。不知道您正在使用什么操作系统,很难说出要使用哪些特定功能,但您只需分配一块内存,打开文件,将文件的数据读入该内存块,然后关闭文件。从那里,您可以以任何您喜欢的方式处理数据。

    【讨论】:

      【解决方案2】:
      main(){
      
      ifstream::pos_type size;
      char * memblock;
      
      ifstream file ("Dvorak_NewWorld.mid", ios::in|ios::binary|ios::ate);
      ofstream output;
      output.open("output.txt");
        if (file.is_open())
        {
          size = file.tellg();
          memblock = new char [size];
          file.seekg (0, ios::beg);
          file.read (memblock, size);
          file.close();
      
          cout << "the complete file content is in memory" << endl;
      
          std::string tohexed = toHex(std::string(memblock, size), true);
          output << tohexed << std::endl;
          output.close();
         }
      
        return 0;
      }
      
      string toHex(const string& s, bool upper_case)
      {
          ostringstream ret;
      
          for (string::size_type i = 0; i < s.length(); ++i)
              ret << std::hex << std::setfill('0') << std::setw(2) << (upper_case ? std::uppercase : std::nouppercase) << (int)s[i];
      
          return ret.str();
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-01
        相关资源
        最近更新 更多