00001 /* 00002 Copyright (C) 2010 Karol Krizka <kkrizka@gmail.com> 00003 00004 URL: http://www.krizka.net/projects/libmidi/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 $Id$ 00021 */ 00022 00023 #include "MetaTextEvent.h" 00024 00025 #include "Defines.h" 00026 00027 #include <iostream> 00028 #include <iomanip> 00029 using namespace std; 00030 00031 namespace MIDI 00032 { 00033 MetaTextEvent::MetaTextEvent() 00034 : MetaEvent() 00035 { } 00036 00037 MetaTextEvent::MetaTextEvent(const MetaTextEvent& o) 00038 : MetaEvent(o),_text(o._text) 00039 { } 00040 00041 MetaTextEvent::MetaTextEvent(dword deltaTime,byte metaType,byte data[],dword length) 00042 : MetaEvent(deltaTime,metaType) 00043 { 00044 _text=""; 00045 for(int i=0;i<length;i++) 00046 { 00047 _text+=((char)data[i]); 00048 } 00049 } 00050 00051 string MetaTextEvent::text() 00052 { 00053 return _text; 00054 } 00055 00056 DataBuffer MetaTextEvent::data() 00057 { 00058 DataBuffer data=MetaEvent::data(); 00059 00060 data.writeVariableLength(_text.length()); 00061 for(int i=0;i<_text.length();i++) 00062 { 00063 data.write(_text[i]); 00064 } 00065 00066 return data; 00067 } 00068 00069 void MetaTextEvent::debug() 00070 { 00071 switch(metaType()) 00072 { 00073 case MIDI_METAEVENT_TEXT: 00074 cout << "\tText" << endl; 00075 cout << "\t\t" << _text; 00076 break; 00077 case MIDI_METAEVENT_COPYRIGHT: 00078 cout << "\tCopyright" << endl; 00079 cout << "\t\t" << _text << endl; 00080 break; 00081 case MIDI_METAEVENT_TRACKNAME: 00082 cout << "\tTrack Name: " << _text << endl; 00083 break; 00084 case MIDI_METAEVENT_MAKER: 00085 cout << "\tMaker: " << _text << endl; 00086 break; 00087 default: 00088 cout << "\tUnknown Meta Text Event 0x" << setbase(16) << (unsigned int)metaType() << endl; 00089 cout << "\t\t" << _text; 00090 break; 00091 } 00092 } 00093 }