00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "MetaGenericEvent.h"
00024
00025 #include "Defines.h"
00026
00027 #include <iostream>
00028 #include <iomanip>
00029 using namespace std;
00030
00031 namespace MIDI
00032 {
00033 MetaGenericEvent::MetaGenericEvent()
00034 : MetaEvent(),_data(0),_dataLength(0)
00035 { }
00036
00037 MetaGenericEvent::MetaGenericEvent(const MetaGenericEvent& o)
00038 : MetaEvent(o),_data(0),_dataLength(o._dataLength)
00039 {
00040 _data=new byte[_dataLength];
00041 for(int i=0;i<_dataLength;i++)
00042 {
00043 _data[i]=o._data[i];
00044 }
00045 }
00046
00047 MetaGenericEvent::MetaGenericEvent(dword deltaTime,byte metaType,byte data[],int dataLength)
00048 : MetaEvent(deltaTime,metaType),_data(0),_dataLength(dataLength)
00049 {
00050 _data=new byte[_dataLength];
00051 for(int i=0;i<_dataLength;i++)
00052 {
00053 _data[i]=data[i];
00054 }
00055 }
00056
00057 MetaGenericEvent::MetaGenericEvent(dword deltaTime,byte metaType,int dataLength)
00058 : MetaEvent(deltaTime,metaType),_data(0),_dataLength(dataLength)
00059 {
00060 _data=new byte[_dataLength];
00061 for(int i=0;i<_dataLength;i++)
00062 {
00063 _data[i]='\0';
00064 }
00065 }
00066
00067 int MetaGenericEvent::dataLength()
00068 {
00069 return _dataLength;
00070 }
00071
00072 int MetaGenericEvent::paramInt(unsigned int id)
00073 {
00074 return (int)_data[id];
00075 }
00076
00077 unsigned int MetaGenericEvent::paramUInt(unsigned int id)
00078 {
00079 return char2num((char)_data[id]);
00080 }
00081
00082 void MetaGenericEvent::setParam(unsigned int id,byte value)
00083 {
00084 _data[id]=value;
00085 }
00086
00087 DataBuffer MetaGenericEvent::data()
00088 {
00089 DataBuffer data=MetaEvent::data();
00090
00091 data.writeVariableLength(_dataLength);
00092 for(int i=0;i<_dataLength;i++)
00093 {
00094 data.write(_data[i]);
00095 }
00096
00097 return data;
00098 }
00099
00100 void MetaGenericEvent::debug()
00101 {
00102 switch(metaType())
00103 {
00104 case MIDI_METAEVENT_PORT:
00105 cout << "\tMIDI Port" << endl;
00106 cout << "\t\tPort: " << paramUInt(0) << endl;
00107 break;
00108 case MIDI_METAEVENT_TIMESIGNATURE:
00109 cout << "\tTime Signature" << endl;
00110 cout << "\t\tNumerator: " << paramUInt(0) << endl;
00111 cout << "\t\tDenominator: " << paramUInt(1) << endl;
00112 cout << "\t\tMetronome: " << paramUInt(2) << endl;
00113 cout << "\t\t32nds: " << paramUInt(3) << endl;
00114 break;
00115 case MIDI_METAEVENT_KEYSIGNATURE:
00116 cout << "\tKey Signature" << endl;
00117 cout << "\t\tKey: " << paramInt(0) << endl;
00118 cout << "\t\tScale: " << paramUInt(1) << endl;
00119 break;
00120 case MIDI_METAEVENT_ENDOFTRACK:
00121 cout << "\tEnd of Track" << endl;
00122 break;
00123 default:
00124 cout << "\tGeneric Meta Event 0x" << setbase(16) << (unsigned int)metaType() << endl;
00125 for(int i=0;i<_dataLength;i++)
00126 {
00127 cout << "\t\t0x" << setbase(16) << paramInt(i) << endl;
00128 }
00129 break;
00130 }
00131 }
00132 }