Skip to content

Commit c1b503b

Browse files
committed
Added freeBSD-style license and converted Binasc program to a class.
1 parent 4691228 commit c1b503b

File tree

6 files changed

+1948
-1029
lines changed

6 files changed

+1948
-1029
lines changed

LICENSE.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 1999-2015, Craig Stuart Sapp
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
and the following disclaimer in the documentation and/or other materials
11+
provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23+

include/Binasc.h

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//
2+
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
3+
// Creation Date: Mon Feb 16 12:26:32 PST 2015 Adapted from binasc program.
4+
// Last Modified: Wed Feb 18 14:48:21 PST 2015
5+
// Filename: midifile/include/Binasc.cpp
6+
// Syntax: C++11
7+
// vim: ts=3 expandtab
8+
//
9+
// description: Interface to convert bytes between binary and ASCII forms.
10+
//
11+
12+
#ifndef _BINASC_H_INCLUDED
13+
#define _BINASC_H_INCLUDED
14+
15+
#include <iostream>
16+
#include <fstream>
17+
18+
using namespace std;
19+
20+
typedef unsigned char uchar;
21+
typedef unsigned short ushort;
22+
typedef unsigned long ulong;
23+
24+
class Binasc {
25+
public:
26+
Binasc (void);
27+
~Binasc ();
28+
29+
// functions for setting options:
30+
int setLineLength (int length);
31+
int getLineLength (void);
32+
int setLineBytes (int length);
33+
int getLineBytes (void);
34+
void setComments (int state);
35+
void setCommentsOn (void);
36+
void setCommentsOff (void);
37+
void setBytes (int state);
38+
void setBytesOn (void);
39+
void setBytesOff (void);
40+
41+
// functions for converting into a binary file:
42+
void writeToBinary (const string& outfile, const string& infile);
43+
void writeToBinary (const string& outfile, istream& input);
44+
ostream& writeToBinary (ostream& out, const string& infile);
45+
ostream& writeToBinary (ostream& out, istream& input);
46+
47+
// functions for converting into an ASCII file with hex bytes:
48+
void readFromBinary (const string& outfile, const string& infile);
49+
void readFromBinary (const string& outfile, istream& input);
50+
ostream& readFromBinary (ostream& out, const string& infile);
51+
ostream& readFromBinary (ostream& out, istream& input);
52+
53+
ostream& outputStyleMidiFile(ostream& out, istream& input);
54+
int readMidiEvent (ostream& out, istream& infile, int& trackbytes,
55+
int& command);
56+
int getVLV (istream& infile, int& trackbytes);
57+
58+
// static functions for writing ordered bytes:
59+
static ostream& writeLittleEndianUShort (ostream& out, ushort value);
60+
static ostream& writeBigEndianUShort (ostream& out, ushort value);
61+
static ostream& writeLittleEndianShort (ostream& out, short value);
62+
static ostream& writeBigEndianShort (ostream& out, short value);
63+
static ostream& writeLittleEndianULong (ostream& out, ulong value);
64+
static ostream& writeBigEndianULong (ostream& out, ulong value);
65+
static ostream& writeLittleEndianLong (ostream& out, long value);
66+
static ostream& writeBigEndianLong (ostream& out, long value);
67+
static ostream& writeLittleEndianFloat (ostream& out, float value);
68+
static ostream& writeBigEndianFloat (ostream& out, float value);
69+
static ostream& writeLittleEndianDouble (ostream& out, double value);
70+
static ostream& writeBigEndianDouble (ostream& out, double value);
71+
72+
protected:
73+
// helper functions for reading ASCII content to conver to binary:
74+
ostream& processLine (ostream& out, char* word, int lineNum);
75+
ostream& processAsciiWord (ostream& out, const char* word, int lineNum);
76+
ostream& processBinaryWord (ostream& out, const char* word, int lineNum);
77+
ostream& processDecimalWord (ostream& out, const char* word, int lineNum);
78+
ostream& processHexWord (ostream& out, const char* word, int lineNum);
79+
ostream& processVlvWord (ostream& out, const char* word, int lineNum);
80+
ostream& processMidiPitchBendWord(ostream& out, const char* word,
81+
int lineNum);
82+
83+
// helper functions for reading binary content to convert to ASCII:
84+
ostream& outputStyleAscii (ostream& out, istream& input);
85+
ostream& outputStyleBinary (ostream& out, istream& input);
86+
ostream& outputStyleBoth (ostream& out, istream& input);
87+
88+
private:
89+
int bytesQ; // option for printing hex bytes in ASCII output.
90+
int commentsQ; // option for printing comments in ASCII output.
91+
int maxLineLength; // number of character in ASCII output on a line.
92+
int maxLineBytes; // number of hex bytes in ASCII output on a line.
93+
};
94+
95+
96+
#endif /* _BINASC_H_INCLUDED */
97+
98+
99+

include/MidiFile.h

+15-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,21 @@ class MidiFile {
109109
const char* getFilename (void);
110110

111111
// static functions:
112-
static uchar readByte (istream& input);
113-
static ushort readLittleEndian2Bytes(istream& input);
114-
static ulong readLittleEndian4Bytes(istream& input);
112+
static uchar readByte (istream& input);
113+
static ushort readLittleEndian2Bytes (istream& input);
114+
static ulong readLittleEndian4Bytes (istream& input);
115+
static ostream& writeLittleEndianUShort (ostream& out, ushort value);
116+
static ostream& writeBigEndianUShort (ostream& out, ushort value);
117+
static ostream& writeLittleEndianShort (ostream& out, short value);
118+
static ostream& writeBigEndianShort (ostream& out, short value);
119+
static ostream& writeLittleEndianULong (ostream& out, ulong value);
120+
static ostream& writeBigEndianULong (ostream& out, ulong value);
121+
static ostream& writeLittleEndianLong (ostream& out, long value);
122+
static ostream& writeBigEndianLong (ostream& out, long value);
123+
static ostream& writeLittleEndianFloat (ostream& out, float value);
124+
static ostream& writeBigEndianFloat (ostream& out, float value);
125+
static ostream& writeLittleEndianDouble (ostream& out, double value);
126+
static ostream& writeBigEndianDouble (ostream& out, double value);
115127

116128
protected:
117129
vector<MidiEventList*> events; // MIDI file events

0 commit comments

Comments
 (0)