Table of Contents

preface xiii
acknowledgments xiv
author online xv
about the reader xvi
guide to the book xvii

1    MIDI and Windows 95 1
           What is MIDI, Anyway? 3
Simple Connections 4
Why Not Use the MCI Sequencer or Streams? 6
The Windows MIDI Connection 7
The MaxMidi ToolKit 11
Rolling Your Own 11

2    The Musical Instrument Digital Interface 12
Overview 13
Get the Spec 13
The MIDI Protocol 14
Channel Voice Messages 14
           Note On/Note Off 15, Aftertouch 16, Control Change 17, Program Change 17, Pitch Bend 17
Channel Mode Messages 18
System Messages 20
System Real-Time Messages 21
System Exclusive Messages 22
MIDI Time Code and SMPTE 23
General MIDI 26
The General MIDI Mode 26, General MIDI Requirements 27, The GM Sound Set 28, The Percussion Map 28
MIDI Evolution 30

3    Using MIDI in Windows 31
Organization of the ToolKit 32
Windows and DLLs 33
Windows 95 and the Win16Mutex 35
Timers and Windows 95 37
Low-Level MMSYSTEM MIDI Functions 38
MIDI Input Functions 40, MIDI Output Functions 42
Putting MIDI to Use 43

4    Sending MIDI 44
It's An Event 45
Devices and Drivers 46
Identifying Devices 46
Initializing the MaxMidi System 48
Opening the MIDI Output Device 49
Sending An Event 50
Closing the MIDI Output 52
Other Useful MIDI Output Functions 52
Inside MIDI Output 53
Callbacks and Fixed Code Segments 53, MIDI Output Data Flow 54

5    Receiving MIDI 58
Opening and Using MIDI Input 59
Opening in Greater Detail 62
Controlling MIDI Input 64
The Input Queue 65
Closing the MIDI Input 67
Inside MIDI Input 68
MIDI Input Data Flow 68

6    System Exclusive Messages 72
One Stream--Handling Short and Long Messages 73
Sending and Receiving Sysexes 74
Long Messages and Buffers 77
MIDI Headers and Buffers 79
MIDI Input Data Flow Changes 82
MIDI Output Data Flow Changes 85

7    Keeping Time 88
Timestamps 89
Of Ticks and Tempo 90
Resolution and Accuracy 92
Generating Ticks 93
Processing Timestamps 94
Inside the Tick Generator 94
MIDI Time Code Synchronization 97
Starting SMPTE/MTC Synchronization 98
Chasing SMPTE/MTC 99
MIDI Timing Clock Synchronization 100
Chasing MIDI Sync 103

8    MaxMidi Synchronization 105
Using the Sync Functions 109
Playing Back in Time 110
Recording 111
Sync Data Flow 112
MIDI Input Data Flow Changes 115,MIDI Output Data Flow Changes 117

9    I Want My C++ 120
Microsoft Visual C++ and the Microsoft Foundation Classes 122
Encapsulating the DLL in C++ Classes 124
The CMaxMidiIn Class 124
The CMaxMidiOut Class 126
The CMaxMidiSync Class 129
Attaching the Sync Device 131
Tempo and Resolution 132
Summary 134

10    Using the ToolKit with Microsoft Visual C++ 135
The Application Framework 136
Adding MIDI to MFC Applications 138
Compiler Configuration 139
Add the ToolKit Files 139
Use the ToolKit Classes 140
Receiving and Sending MIDI 143
Adding Device Menus 146

11    Handling Sysex Messages in C++ 150
Receiving Sysex Messages 151
Sending Sysex Messages 160
Loading and Saving Sysex Files 164

12    A Simple Sequencer 167
Tracks 168
Recording a Track 171
Playing Back the Track 178

13    Standard MIDI Files 186
SMFs Use Chunks 187
Variable-Length Values 188
Format 0 and Format 1 Files 189
The SMF Header Chunk 191
Track Chunks 192
Meta Events 193
Reading an SMF in C 194
Writing an SMF in C 198
Other MaxMidi SMF Functions 200
The CMaxMidiSMF Class 201
Inside the MaxMidi DLL SMF Routines 204

14    Enhancing the Sequencer 208
Playing Multiple Tracks 209
The Multitrack Sequencer Revealed 212
Writing a Standard MIDI File 218
Reading a Standard MIDI File 219

15    Go Forth and Write 223
Use the Source 224
Expanding the MIDI Horizon 225
Building An Even Better ToolKit 226

appendix A    The MIDI ToolKit APIs 227
MaxMidi Function Reference 228
MIDI Output Functions 228
MIDI Input Functions 232
Synchronization Functions 236
Standard MIDI File Functions 242
System Functions 249
Error Codes 250
MaxMidi Messages 250
MaxMidi Structures 252
MaxMidi C++ Classes 253
MIDI Input Class -- CMaxMidiIn 262
MIDI Sync Class -- CMaxMidiSync 269
MIDI Input Menu Class -- CMidiInDeviceMenu 277
MIDI Output Menu Class -- CMidiOutDeviceMenu 280
Track Class -- CMaxMidiTrack 284
Standard MIDI File Class-- CMaxMidiSMF 293

appendix B    MaxMidi DLL Source Code 301
MaxMidi Header Files 302
MaxMidi.h 302, MxDll.h 305
MxMidi16 DLL Source 308
MidiIn.c 308, MidiOut.c 318, Sync.c 328, MxMidi.def 338
MxMidi32 DLL Source 338
MxMidi32.c 338, SMF.c 342
Thunk Script 360

appendix C    MaxMidi C++ Classes Source Code362
CMaxMidiIn 363
CMaxMidiOut 367
CMaxMidiSync 375
CMaxMidiTrack 379
CMaxMidiSMF 385
CMidiInDeviceMenu 390
CMidiOutDeviceMenu 391

appendix D    MidiSpy, SxLib and MaxSeq Source Code 394
MidiSpy 395
MidiSpy App 395
MainFrm 397
MidiSpyDoc 398
MidiSpyView 400
MyMidiIn 403
SxLib 406
SxLib App 406
MainFrm 408
SxLibDoc 410
SxLibView 412
MyMidiIn 415
MyMidiOut 416
MaxSeq 417
MaxSeq App 417
MainFrm 419
MaxSeqDoc 422
MaxSeqView 426
MyMidiIn 430
MySync 431
NewTrackDialog 432
ResolutionDialog 433
TempoDialog 434
MaxMidi ToolKit License Agreement 435

glossary 436
index 446
guide to the CDROM 454