| 1 | /* |
|---|
| 2 | * libjdkmidi-2004 C++ Class Library for MIDI |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2004 J.D. Koftinoff Software, Ltd. |
|---|
| 5 | * www.jdkoftinoff.com |
|---|
| 6 | * jeffk@jdkoftinoff.com |
|---|
| 7 | * |
|---|
| 8 | * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 *** |
|---|
| 9 | * |
|---|
| 10 | * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | * it under the terms of the GNU General Public License as published by |
|---|
| 12 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 13 | * (at your option) any later version. |
|---|
| 14 | * |
|---|
| 15 | * This program is distributed in the hope that it will be useful, |
|---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 18 | * GNU General Public License for more details. |
|---|
| 19 | * |
|---|
| 20 | * You should have received a copy of the GNU General Public License |
|---|
| 21 | * along with this program; if not, write to the Free Software |
|---|
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 23 | */ |
|---|
| 24 | /* |
|---|
| 25 | ** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd. |
|---|
| 26 | ** |
|---|
| 27 | ** All rights reserved. |
|---|
| 28 | ** |
|---|
| 29 | ** No one may duplicate this source code in any form for any reason |
|---|
| 30 | ** without the written permission given by J.D. Koftinoff Software, Ltd. |
|---|
| 31 | ** |
|---|
| 32 | */ |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | #ifndef JDKMIDI_FILE_H |
|---|
| 36 | #define JDKMIDI_FILE_H |
|---|
| 37 | |
|---|
| 38 | #include "jdkmidi/midi.h" |
|---|
| 39 | #include "jdkmidi/msg.h" |
|---|
| 40 | #include "jdkmidi/sysex.h" |
|---|
| 41 | #include "jdkmidi/tempo.h" |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | namespace jdkmidi |
|---|
| 45 | { |
|---|
| 46 | |
|---|
| 47 | // |
|---|
| 48 | // The MIDIFile class contains definitions and utilities to deal with |
|---|
| 49 | // reading and writing midi files. |
|---|
| 50 | // |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | const unsigned long _MThd=OSTYPE ( 'M','T','h','d' ); |
|---|
| 54 | const unsigned long _MTrk=OSTYPE ( 'M','T','r','k' ); |
|---|
| 55 | |
|---|
| 56 | class MIDIFile |
|---|
| 57 | { |
|---|
| 58 | public: |
|---|
| 59 | |
|---|
| 60 | MIDIFile(); |
|---|
| 61 | virtual ~MIDIFile(); |
|---|
| 62 | |
|---|
| 63 | struct MIDIFileChunk |
|---|
| 64 | { |
|---|
| 65 | unsigned long id; |
|---|
| 66 | unsigned long length; |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | struct MIDIFileHeader |
|---|
| 70 | { |
|---|
| 71 | short format; |
|---|
| 72 | short ntrks; |
|---|
| 73 | short division; |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | // |
|---|
| 77 | // define all the different meta event message types. |
|---|
| 78 | // |
|---|
| 79 | |
|---|
| 80 | enum |
|---|
| 81 | { |
|---|
| 82 | MF_SEQUENCE_NUMBER =0, |
|---|
| 83 | MF_TEXT_EVENT =1, |
|---|
| 84 | MF_COPYRIGHT =2, |
|---|
| 85 | MF_TRACK_NAME =3, |
|---|
| 86 | MF_INSTRUMENT_NAME =4, |
|---|
| 87 | MF_LYRIC =5, |
|---|
| 88 | MF_MARKER =6, |
|---|
| 89 | MF_CUE_POINT =7, |
|---|
| 90 | MF_GENERIC_TEXT_8 =8, |
|---|
| 91 | MF_GENERIC_TEXT_9 =9, |
|---|
| 92 | MF_GENERIC_TEXT_A =0xA, |
|---|
| 93 | MF_GENERIC_TEXT_B =0xB, |
|---|
| 94 | MF_GENERIC_TEXT_C =0xC, |
|---|
| 95 | MF_GENERIC_TEXT_D =0xD, |
|---|
| 96 | MF_GENERIC_TEXT_E =0xE, |
|---|
| 97 | MF_GENERIC_TEXT_F =0xF, |
|---|
| 98 | |
|---|
| 99 | MF_OUTPUT_CABLE =0x21, |
|---|
| 100 | MF_TRACK_LOOP =0x2E, |
|---|
| 101 | MF_END_OF_TRACK =0x2F, |
|---|
| 102 | MF_TEMPO =0x51, |
|---|
| 103 | MF_SMPTE =0x54, |
|---|
| 104 | MF_TIMESIG =0x58, |
|---|
| 105 | MF_KEYSIG =0x59, |
|---|
| 106 | MF_SEQUENCER_SPECIFIC =0x7F |
|---|
| 107 | }; |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | // |
|---|
| 111 | // ConvertTempoToFreq() returns the frequency of the required |
|---|
| 112 | // tempo clock |
|---|
| 113 | // |
|---|
| 114 | |
|---|
| 115 | static unsigned long ConvertTempoToFreq ( |
|---|
| 116 | short division, |
|---|
| 117 | MIDITempo &tempo |
|---|
| 118 | ); |
|---|
| 119 | |
|---|
| 120 | // |
|---|
| 121 | // Convert a four byte number to an unsigned long. |
|---|
| 122 | // |
|---|
| 123 | |
|---|
| 124 | static unsigned long To32Bit ( unsigned char a, unsigned char b, unsigned char c, unsigned char d ) |
|---|
| 125 | { |
|---|
| 126 | return ( ( unsigned long ) a << 24 ) |
|---|
| 127 | + ( ( unsigned long ) b << 16 ) |
|---|
| 128 | + ( ( unsigned long ) c << 8 ) |
|---|
| 129 | + ( ( unsigned long ) d << 0 ); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | // |
|---|
| 134 | // Convert a two byte number to an unsigned short |
|---|
| 135 | // |
|---|
| 136 | |
|---|
| 137 | static unsigned short To16Bit ( unsigned char a, unsigned char b ) |
|---|
| 138 | { |
|---|
| 139 | return ( unsigned short ) ( ( ( unsigned short ) a << 8 ) |
|---|
| 140 | + ( ( unsigned short ) b << 0 ) ); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | static unsigned long ReadVariableLengthNumber ( unsigned char **in ); |
|---|
| 144 | |
|---|
| 145 | static unsigned char * WriteVariableLengthNumber ( unsigned long num, unsigned char *out ); |
|---|
| 146 | |
|---|
| 147 | }; |
|---|
| 148 | |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | #endif |
|---|