00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "ChannelEvent.h"
00024
00025 #include "Defines.h"
00026
00027 #include <iostream>
00028 #include <iomanip>
00029 using namespace std;
00030
00031 namespace MIDI
00032 {
00033 ChannelEvent::ChannelEvent()
00034 : Event(0),_command(0),_channel(0),_param1(0),_param2(0)
00035 { }
00036
00037 ChannelEvent::ChannelEvent(const ChannelEvent& o)
00038 : Event(o),_command(o._command),_channel(o._channel),_param1(o._param1),_param2(o._param2)
00039 { }
00040
00041 ChannelEvent::ChannelEvent(dword timeDelta,byte command,int channel,int param1,int param2)
00042 : Event(timeDelta),_command(command),_channel(channel),_param1(param1),_param2(param2)
00043 { }
00044
00045 EventType ChannelEvent::type()
00046 {
00047 return MIDI_CHEVENT;
00048 }
00049
00050 byte ChannelEvent::command()
00051 {
00052 return _command;
00053 }
00054
00055 int ChannelEvent::channel()
00056 {
00057 return _channel;
00058 }
00059
00060 int ChannelEvent::param1()
00061 {
00062 return _param1;
00063 }
00064
00065 int ChannelEvent::param2()
00066 {
00067 return _param2;
00068 }
00069
00070 DataBuffer ChannelEvent::data(bool shorten)
00071 {
00072 DataBuffer data=Event::data();
00073
00074 if(!shorten)
00075 {
00076 byte typething=_command;
00077 typething=(typething<<4);
00078 typething+=_channel;
00079 data.write(typething);
00080 }
00081 data.write(_param1);
00082 data.write(_param2);
00083
00084 return data;
00085 }
00086
00087 void ChannelEvent::debug()
00088 {
00089 switch(_command)
00090 {
00091 case MIDI_CHEVENT_INVALID:
00092 cout << "\tInvalid MIDI Channel Event" << endl;
00093 break;
00094 case MIDI_CHEVENT_NOTEOFF:
00095 cout << "\tEnd Note " << setbase(10) << _param1 << endl;
00096 cout << "\t\tVelocity: " << setbase(10) << _param2 << endl;
00097 break;
00098 case MIDI_CHEVENT_NOTEON:
00099 cout << "\tStart Note " << setbase(10) << _param1 << endl;
00100 cout << "\t\tVelocity: " << setbase(10) << _param2 << endl;
00101 break;
00102 case MIDI_CHEVENT_NOTEAFTERTOUCH:
00103 cout << "\tNote Aftertouch" << setbase(10) << _param1 << endl;
00104 cout << "\t\tValue: " << setbase(10) << _param2 << endl;
00105 break;
00106 case MIDI_CHEVENT_CONTROLLER:
00107 cout << "\tController Event" << endl;
00108 cout << "\t\tChannel: " << setbase(10) << _channel << endl;
00109 cout << "\t\tType: 0x" << setbase(16) << _param1 << endl;
00110 cout << "\t\tValue: 0x" << setbase(16) << _param2 << endl;
00111 break;
00112 case MIDI_CHEVENT_PROGRAMCHANGE:
00113 cout << "\tProgram Change to " << setbase(10) << _param1 << endl;
00114 break;
00115 case MIDI_CHEVENT_CHANNELAFTERTOUCH:
00116 cout << "\tChannel Aftertouch" << endl;
00117 cout << "\t\tValue: " << setbase(10) << _param1 << endl;
00118 break;
00119 case MIDI_CHEVENT_PITCHBEND:
00120 cout << "\tPitch Bend" << endl;
00121 cout << "\t\tPitch Value (MSB): " << setbase(10) << _param1 << endl;
00122 cout << "\t\tPitch Value (LSB): " << setbase(10) << _param2 << endl;
00123 break;
00124 default:
00125 cout << "\tUnknown MIDI Channel Event" << endl;
00126 cout << "\t\tCommand: 0x" << setbase(16) << (unsigned int)_command << endl;
00127 cout << "\t\tChannel: " << setbase(10) << _channel << endl;
00128 cout << "\t\tParam 1: 0x" << setbase(16) << _param1 << endl;
00129 cout << "\t\tParam 2: 0x" << setbase(16) << _param2 << endl;
00130 break;
00131 }
00132 }
00133 }