MIDIInControl.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "MIDIInControl.hxx"
00023 #include "OutControl.hxx"
00024 #include <string>
00025 #include "ProcessingFactory.hxx"
00026 #include <cstdio>
00027
00028 namespace CLAM
00029 {
00030
00031 namespace Hidden
00032 {
00033 static const char * metadata[] = {
00034 "key", "MIDIInControl",
00035
00036
00037 0
00038 };
00039 static FactoryRegistrator<ProcessingFactory, MIDIInControl> reg = metadata;
00040 }
00041
00042 MIDIInControl::MIDIInControl():MIDIIn(false)
00043 {
00044 mpDevice = 0;
00045 mMessageSize = mControllingBytes = 0;
00046 mMsgByteIdToControlId = 0;
00047 Configure(MIDIIOConfig());
00048 }
00049
00050 MIDIInControl::MIDIInControl(const MIDIIOConfig &c):MIDIIn(false)
00051 {
00052 mpDevice = 0;
00053 mMessageSize = mControllingBytes = 0;
00054 mMsgByteIdToControlId = 0;
00055 Configure(c);
00056 }
00057
00058
00059 bool MIDIInControl::ConcreteConfigure(const ProcessingConfig& c)
00060 throw(ErrProcessingObj)
00061 {
00062 bool ret = MIDIIn::ConcreteConfigure(c);
00063 if (ret==false) return false;
00064
00065 MIDI::Message m = MIDI::Message(mConfig.GetMessage());
00066
00067 int mMessageSize = MIDI::GetMessageInfo(m).length;
00068
00069
00070
00071 mControllingBytes = mMessageSize;
00072
00073 if (mConfig.GetChannel()!=0) mControllingBytes--;
00074
00075
00076 if (mConfig.GetFirstData()!=128) mControllingBytes--;
00077
00078 if (mMsgByteIdToControlId) delete mMsgByteIdToControlId;
00079 mMsgByteIdToControlId = new unsigned char[mControllingBytes];
00080
00081 int ctrlid = 0;
00082
00083 bool singlePitchBendValue = false;
00084
00085
00086 for (int i=0;i<mMessageSize;i++)
00087 {
00088 const char* fieldname = 0;
00089
00090
00091 switch (i)
00092 {
00093 case 0:
00094 if (mConfig.GetMessage()==MIDI::eSystem)
00095 {
00096 if (mConfig.GetChannel()==0)
00097 fprintf(stderr,"ERROR: sysex in not yet implemented\n");
00098 else
00099
00100 fieldname = MIDI::GetMessageInfo(m).field[i];
00101 }else{
00102 if (mConfig.GetChannel()==0)
00103
00104 fieldname = MIDI::GetMessageInfo(m).field[i];
00105 }
00106 break;
00107 case 1:
00108 if (mConfig.GetFirstData()==128)
00109 {
00110
00111 fieldname = MIDI::GetMessageInfo(m).field[i];
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121 if (mConfig.GetMessage()==MIDI::ePitchbend)
00122 {
00123 fieldname = "Value";
00124 singlePitchBendValue = true;
00125 }
00126
00127 break;
00128 default:
00129
00130 if (!singlePitchBendValue)
00131 {
00132 fieldname = MIDI::GetMessageInfo(m).field[i];
00133 }
00134 break;
00135 }
00136 if (fieldname)
00137 {
00138 std::string tmp = std::string() + MIDI::GetMessageInfo(m).name + ":" + fieldname;
00139
00140
00141 mMsgByteIdToControlId[i] = ctrlid++;
00142 mMyOutControls.AddElem(new OutControl(tmp.c_str(),this));
00143 }else{
00144 mMsgByteIdToControlId[i] = 0xFF;
00145 }
00146 }
00147
00148 return true;
00149 }
00150
00151 void MIDIInControl::Handle(unsigned char* msg,int size)
00152 {
00153
00154
00155
00156 for (int i=size-1;i>=0;i--)
00157 {
00158 if (i==0 && (msg[0]&0xF0) == 0xF0)
00159 {
00160
00161
00162
00163 SendFloatToOutControl(*this,0,1);
00164 }
00165 else
00166 {
00167 if (mMsgByteIdToControlId[i] == 0xFF) continue;
00168
00169 if (i==1 && (msg[0]&0xF0)==0xE0)
00170 {
00171
00172
00173
00174
00175 SendFloatToOutControl(*this,mMsgByteIdToControlId[1],msg[1] + (msg[2]<<7));
00176 }
00177 else
00178 if (i==0)
00179 {
00180 SendFloatToOutControl(*this,mMsgByteIdToControlId[0],(msg[0]&0x0F)+1);
00181 }
00182 else
00183 {
00184 SendFloatToOutControl(*this,mMsgByteIdToControlId[i],msg[i]);
00185 }
00186 }
00187 }
00188 }
00189
00190
00191 }
00192