Skip to content

Commit e3ba7aa

Browse files
committed
Updated example programs for C++11.
1 parent 670d926 commit e3ba7aa

29 files changed

+334
-446
lines changed

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
##
2828

2929
# targets which don't actually refer to files
30-
.PHONY : all info library examples programs bin options clean
30+
.PHONY : all info library examples programs bin options clean lib
3131

3232

33-
all: info library programs
33+
all: info library programs lib
3434

3535

3636
info:
@@ -49,6 +49,7 @@ info:
4949
@echo ""
5050

5151

52+
lib: library
5253
library:
5354
$(MAKE) -f Makefile.library
5455

Makefile.library

+4-6
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,16 @@ OBJS = $(notdir $(patsubst %.cpp,%.o,$(wildcard $(SRCDIR)/*.cpp)))
103103

104104

105105
all: makedirs $(OBJS)
106-
ifeq ($(OSTYPE),LINUX)
107-
@echo "Creating midifile library file for linux ..."
106+
ifeq ($(OSTYPE),OSX)
107+
@echo "Creating midifile library file for OSX (Intel)..."
108108
-rm -f $(LIBDIR)/$(LIBFILE)
109109
$(AR) r $(LIBDIR)/$(LIBFILE) $(OBJDIR)/*.o
110110
$(RANLIB) $(LIBDIR)/$(LIBFILE)
111-
else ifeq ($(OSTYPE),OSXPC)
112-
@echo "Creating midifile library file for OSX (Intel)..."
111+
else
112+
@echo "Creating midifile library file for linux ..."
113113
-rm -f $(LIBDIR)/$(LIBFILE)
114114
$(AR) r $(LIBDIR)/$(LIBFILE) $(OBJDIR)/*.o
115115
$(RANLIB) $(LIBDIR)/$(LIBFILE)
116-
else
117-
echo "Unkown operating system type."
118116
endif
119117

120118

Makefile.programs

+6-37
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ info:
127127

128128
bin:
129129
ifeq ($(wildcard $(TARGDIR)),)
130-
-mkdir -p $(TARGDIR)
130+
@-mkdir -p $(TARGDIR)
131131
endif
132132

133133

@@ -137,43 +137,12 @@ $(TARGDIR)/mid2hum:
137137
-echo Skipping mid2hum.cpp since it needs external library.
138138
$(TARGDIR)/peep2midi:
139139
-echo Skipping peep2midi.cpp since it needs external library.
140+
$(TARGDIR)/midiexcerpt:
141+
@echo Skipping $@ until PerlRegularExpressions class is added.
140142

141143
$(TARGDIR)/binasc:
142144
@echo Skipping $@ until it is updated to C++11 + STL.
143-
$(TARGDIR)/createmidifile:
144-
@echo Skipping $@ until it is updated to C++11 + STL.
145-
$(TARGDIR)/drumtab:
146-
@echo Skipping $@ until it is updated to C++11 + STL.
147-
$(TARGDIR)/mid2mat:
148-
@echo Skipping $@ until it is updated to C++11 + STL.
149-
$(TARGDIR)/midi2melody:
150-
@echo Skipping $@ until it is updated to C++11 + STL.
151-
$(TARGDIR)/midi2notes:
152-
@echo Skipping $@ until it is updated to C++11 + STL.
153-
$(TARGDIR)/midi2skini:
154-
@echo Skipping $@ until it is updated to C++11 + STL.
155-
$(TARGDIR)/midi2text:
156-
@echo Skipping $@ until it is updated to C++11 + STL.
157-
$(TARGDIR)/midicat:
158-
@echo Skipping $@ until it is updated to C++11 + STL.
159-
$(TARGDIR)/midiexcerpt:
160-
@echo Skipping $@ until it is updated to C++11 + STL.
161-
$(TARGDIR)/midimixup:
162-
@echo Skipping $@ until it is updated to C++11 + STL.
163-
$(TARGDIR)/miditime:
164-
@echo Skipping $@ until it is updated to C++11 + STL.
165-
$(TARGDIR)/perfid:
166-
@echo Skipping $@ until it is updated to C++11 + STL.
167-
$(TARGDIR)/text2midi:
168-
@echo Skipping $@ until it is updated to C++11 + STL.
169-
$(TARGDIR)/textmidi:
170-
@echo Skipping $@ until it is updated to C++11 + STL.
171-
$(TARGDIR)/tobin:
172-
@echo Skipping $@ until it is updated to C++11 + STL.
173-
$(TARGDIR)/todec:
174-
@echo Skipping $@ until it is updated to C++11 + STL.
175-
$(TARGDIR)/tohex:
176-
@echo Skipping $@ until it is updated to C++11 + STL.
145+
177146

178147

179148

@@ -184,7 +153,7 @@ $(TARGDIR)/tohex:
184153

185154
$(TARGDIR)/% : $(notdir %.cpp)
186155
ifeq ($(wildcard $(TARGDIR)),)
187-
-mkdir -p $(TARGDIR)
156+
@-mkdir -p $(TARGDIR)
188157
endif
189158
ifeq ($(wildcard $(LIBDIR)),)
190159
$(MAKE) -f Makefile.library
@@ -196,7 +165,7 @@ endif
196165

197166
% : $(notdir %.cpp)
198167
ifeq ($(wildcard $(TARGDIR)),)
199-
-mkdir -p $(TARGDIR)
168+
@-mkdir -p $(TARGDIR)
200169
endif
201170
ifeq ($(wildcard $(LIBDIR)),)
202171
$(MAKE) -f Makefile.library

include/MidiFile.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
#ifndef _MIDIfILE_H_INCLUDED
2727
#define _MIDIfILE_H_INCLUDED
2828

29-
using namespace std;
30-
3129
#include <vector>
3230
#include <istream>
3331
#include <fstream>
3432

33+
using namespace std;
34+
3535
typedef unsigned char uchar;
3636
typedef unsigned short ushort;
3737
typedef unsigned long ulong;

src-library/MidiFile.cpp

+11-12
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ int MidiFile::addTrack(int count) {
802802
}
803803

804804

805+
805806
//////////////////////////////
806807
//
807808
// MidiFile::allocateEvents --
@@ -810,8 +811,7 @@ int MidiFile::addTrack(int count) {
810811
void MidiFile::allocateEvents(int track, int aSize) {
811812
int oldsize = events[track]->size();
812813
if (oldsize < aSize) {
813-
events[track]->resize(aSize);
814-
events[track]->resize(oldsize);
814+
events[track]->reserve(aSize);
815815
}
816816
}
817817

@@ -1090,7 +1090,7 @@ int MidiFile::read(const string& filename) {
10901090
setFilename(filename);
10911091

10921092
fstream input;
1093-
input.open(filename, ios::binary | ios::in);
1093+
input.open(filename.data(), ios::binary | ios::in);
10941094

10951095
if (!input.is_open()) {
10961096
return 0;
@@ -1110,7 +1110,6 @@ int MidiFile::read(istream& input) {
11101110
int character;
11111111
// uchar buffer[123456] = {0};
11121112
ulong longdata;
1113-
uchar chardata;
11141113
ushort shortdata;
11151114

11161115

@@ -1125,7 +1124,7 @@ int MidiFile::read(istream& input) {
11251124
} else if (character != 'M') {
11261125
cout << "File " << filename << " is not a MIDI file" << endl;
11271126
cout << "Expecting 'M' at first byte but got '"
1128-
<< chardata << "'" << endl;
1127+
<< character << "'" << endl;
11291128
return 0;
11301129
}
11311130

@@ -1137,7 +1136,7 @@ int MidiFile::read(istream& input) {
11371136
} else if (character != 'T') {
11381137
cout << "File " << filename << " is not a MIDI file" << endl;
11391138
cout << "Expecting 'T' at first byte but got '"
1140-
<< chardata << "'" << endl;
1139+
<< character << "'" << endl;
11411140
return 0;
11421141
}
11431142

@@ -1149,7 +1148,7 @@ int MidiFile::read(istream& input) {
11491148
} else if (character != 'h') {
11501149
cout << "File " << filename << " is not a MIDI file" << endl;
11511150
cout << "Expecting 'h' at first byte but got '"
1152-
<< chardata << "'" << endl;
1151+
<< character << "'" << endl;
11531152
return 0;
11541153
}
11551154

@@ -1161,7 +1160,7 @@ int MidiFile::read(istream& input) {
11611160
} else if (character != 'd') {
11621161
cout << "File " << filename << " is not a MIDI file" << endl;
11631162
cout << "Expecting 'd' at first byte but got '"
1164-
<< chardata << "'" << endl;
1163+
<< character << "'" << endl;
11651164
return 0;
11661165
}
11671166

@@ -1264,7 +1263,7 @@ int MidiFile::read(istream& input) {
12641263
} else if (character != 'M') {
12651264
cout << "File " << filename << " is not a MIDI file" << endl;
12661265
cout << "Expecting 'M' at first byte in track but got '"
1267-
<< chardata << "'" << endl;
1266+
<< character << "'" << endl;
12681267
return 0;
12691268
}
12701269

@@ -1277,7 +1276,7 @@ int MidiFile::read(istream& input) {
12771276
} else if (character != 'T') {
12781277
cout << "File " << filename << " is not a MIDI file" << endl;
12791278
cout << "Expecting 'T' at first byte in track but got '"
1280-
<< chardata << "'" << endl;
1279+
<< character << "'" << endl;
12811280
return 0;
12821281
}
12831282

@@ -1290,7 +1289,7 @@ int MidiFile::read(istream& input) {
12901289
} else if (character != 'r') {
12911290
cout << "File " << filename << " is not a MIDI file" << endl;
12921291
cout << "Expecting 'r' at first byte in track but got '"
1293-
<< chardata << "'" << endl;
1292+
<< character << "'" << endl;
12941293
return 0;
12951294
}
12961295

@@ -1303,7 +1302,7 @@ int MidiFile::read(istream& input) {
13031302
} else if (character != 'k') {
13041303
cout << "File " << filename << " is not a MIDI file" << endl;
13051304
cout << "Expecting 'k' at first byte in track but got '"
1306-
<< chardata << "'" << endl;
1305+
<< character << "'" << endl;
13071306
return 0;
13081307
}
13091308

src-programs/80off.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
33
// Creation Date: Mon Feb 9 16:51:58 PST 2015
4-
// Last Modified: Mon Feb 9 16:52:00 PST 2015
4+
// Last Modified: Mon Feb 9 21:26:32 PST 2015 Updated for C++11.
55
// Filename: midifile/src-programs/80off.cpp
66
// Website: http://midifile.sapp.org
77
// Syntax: C++11
@@ -12,9 +12,9 @@
1212

1313
#include "Options.h"
1414
#include "MidiFile.h"
15+
#include <iostream>
1516

1617
using namespace std;
17-
#include <iostream>
1818

1919
// Global variables for command-line options.
2020
Options options; // for command-line processing

src-programs/binasc.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <iostream>
1414
#include <fstream>
1515
#include <iomanip>
16+
1617
using namespace std;
1718

1819
typedef unsigned char uchar;

src-programs/createmidifile.cpp

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
//
22
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
33
// Creation Date: Tue Jan 8 10:08:15 PST 2002
4-
// Last Modified: Tue Jan 8 10:31:08 PST 2002
4+
// Last Modified: Mon Feb 9 21:24:41 PST 2015 Updated for C++11.
55
// Filename: ...sig/doc/examples/all/createmidifile/createmidifile.cpp
66
// Syntax: C++
77
//
88
// Description: Demonstration of how to create a Multi-track MIDI file.
99
//
1010

1111
#include "MidiFile.h"
12+
#include <iostream>
1213

13-
#ifndef OLDCPP
14-
#include <iostream>
15-
using namespace std;
16-
#else
17-
#include <iostream.h>
18-
#endif
19-
14+
using namespace std;
2015

2116
typedef unsigned char uchar;
2217

@@ -27,8 +22,8 @@ int main(int argc, char** argv) {
2722
outputfile.absoluteTime(); // time information stored as absolute time
2823
// (will be coverted to delta time when written)
2924
outputfile.addTrack(2); // Add another two tracks to the MIDI file
30-
Array<uchar> midievent; // temporary storage for MIDI events
31-
midievent.setSize(3); // set the size of the array to 3 bytes
25+
vector<uchar> midievent; // temporary storage for MIDI events
26+
midievent.resize(3); // set the size of the array to 3 bytes
3227
int tpq = 120; // default value in MIDI file is 48
3328
outputfile.setTicksPerQuarterNote(tpq);
3429

@@ -80,7 +75,7 @@ int main(int argc, char** argv) {
8075
8176
void absoluteTime(void);
8277
Set the time information to absolute time.
83-
int addEvent(int aTrack, int aTime, Array<uchar>& midiData);
78+
int addEvent(int aTrack, int aTime, vector<uchar>& midiData);
8479
Add an event to the end of a MIDI track.
8580
int addTrack(void);
8681
Add an empty track to the MIDI file.
@@ -92,7 +87,7 @@ void deleteTrack(int aTrack);
9287
remove a track from the MIDI file.
9388
void erase(void);
9489
Empty the contents of the MIDI file, leaving one track with no data.
95-
_MFEvent& getEvent(int aTrack, int anIndex);
90+
MFEvent& getEvent(int aTrack, int anIndex);
9691
Return a MIDI event from the Track.
9792
int getTimeState(void);
9893
Indicates if the timestate is TIME_STATE_ABSOLUTE or TIME_STATE_DELTA.
@@ -117,13 +112,12 @@ int read(char* aFile);
117112
Read the contents of a MIDI file into the MidiFile class data structure
118113
void setTicksPerQuarterNote (int ticks);
119114
Set the MIDI file's ticks per quarter note information
120-
void sortTrack(Collection<_MFEvent>& trackData);
115+
void sortTrack(vector<MFEvent>& trackData);
121116
If in absolute time, sort particular track into correct time order.
122117
void sortTracks(void);
123118
If in absolute time, sort tracks into correct time order.
124119
125120
*/
126121

127122

128-
129123
// md5sum: 89b83de0fbe279cccd183ef8c1583f62 createmidifile.cpp [20100703]

src-programs/drumtab.cpp

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
33
// Creation Date: Sat May 17 19:34:13 PDT 2003
4-
// Last Modified: Sat May 17 19:34:15 PDT 2003
4+
// Last Modified: Mon Feb 9 21:23:13 PST 2015 Updated for C++11.
55
// Filename: ...sig/doc/examples/all/drumtab/drumtab.cpp
66
// Syntax: C++
77
//
@@ -11,14 +11,9 @@
1111
//
1212

1313
#include "MidiFile.h"
14+
#include <iostream>
1415

15-
#ifndef OLDCPP
16-
#include <iostream>
17-
using namespace std;
18-
#else
19-
#include <iostream.h>
20-
#endif
21-
16+
using namespace std;
2217

2318
#define HIGH_HAT 59
2419
#define SNARE 38
@@ -61,10 +56,10 @@ int main(int argc, char** argv) {
6156
//
6257

6358
void AddDrumTrack(MidiFile& midifile, int* data, int instrument, int ticks) {
64-
Array<uchar> midievent; // temporary storage for MIDI events
65-
midievent.setSize(3); // set the size of the array to 3 bytes
66-
midievent[2] = 64; // set the loudness to a constant value
67-
int notestate = 0; // 0 = off, 1 = on
59+
vector<uchar> midievent; // temporary storage for MIDI events
60+
midievent.resize(3); // set the size of the array to 3 bytes
61+
midievent[2] = 64; // set the loudness to a constant value
62+
int notestate = 0; // 0 = off, 1 = on
6863
int i = 0;
6964
int actiontime;
7065
int track = midifile.addTrack(); // Add a track to the MIDI file
@@ -111,4 +106,4 @@ void AddDrumTrack(MidiFile& midifile, int* data, int instrument, int ticks) {
111106
}
112107

113108

114-
// md5sum: 3c36ff696d281d9010f16e0ee50ae1ce drumtab.cpp [20050403]
109+

src-programs/henonfile.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
#include "Convert.h"
1717
#include "Options.h"
1818
#include "CircularBuffer.h"
19-
2019
#include <string.h>
2120
#include <stdio.h>
2221

22+
using namespace std;
23+
2324

2425
// function declarations:
2526
void checkOptions (Options& opts, int argc, char** argv);

0 commit comments

Comments
 (0)