Giter VIP home page Giter VIP logo

Comments (1)

craigsapp avatar craigsapp commented on July 17, 2024

Finally fixed(!) with commit a48a2cb

I must have been thinking to use sprintf, but used printf by mistake... Obviously I have never used the save-to-file version of MidiFile::writeHex.

Here is a test program for creating a hex bytecode MIDI file:

//
// Programmer: Craig Stuart Sapp <[email protected]>
// Creation Date: Sun Apr 15 12:11:36 PDT 2018
// Last Modified: Sun Apr 15 12:11:40 PDT 2018
// Filename: midifile/src-programs/readstatus.cpp
// Syntax: C++11
//
// Description: Convert a binary standard MIDI file (or binasc MIDI file,
// or hex-byte MIDI file) into a hex byte-code MIDI file.
//
#include "MidiFile.h"
#include "Options.h"
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
Options options;
options.define("o|output=s", "output file name");
options.define("w|width=i:25", "hex bytes per text line");
options.process(argc, argv);
MidiFile midifile;
if (options.getArgCount() == 0) {
midifile.read(cin);
} else if (options.getArgCount() == 1) {
} else {
cerr << "Only one file input allowed" << endl;
exit(1);
}
string filename = options.getString("output");
if (filename.empty()) {
midifile.writeHex(cout, options.getInteger("width"));
} else {
midifile.writeHex(filename, options.getInteger("width"));
}
return 0;
}

test input file:

"MThd"
4'6
2'0
2'1
2'100

"MTRk"
4'13
v0   90 '60 '80
v200 90 '60 '80
v0   FF 2F 00

(a binary MIDI file also works as input).

output:

$ bin/midi2hex input.txt
4d 54 68 64 00 00 00 06 00 00 00 01 00 78 4d 54 72 6b 00 00 00 04 00 ff 2f
00

And using the -o option will save to a file without the accidental re-routing of the bytes to standard output:

$ bin/mid2hex -o output.hex input.txt

contents of output.hex:

4d 54 68 64 00 00 00 06 00 00 00 01 00 78 4d 54 72 6b 00 00 00 04 00 ff 2f
00

Such a great library! Thank you very much for sharing it, and the Options class is the best I've used.

Thanks! Yes, I cannot live without the Options class when writing command-line programs in C++.

from midifile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.