MIDI2Melody.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 "MIDI2Melody.hxx"
00023
00024 namespace CLAM {
00025
00026 MIDI2Melody::MIDI2Melody()
00027 : mOutput("Output",this),
00028 mTime("time",this)
00029 {
00030 ConcreteConfigure(Control2DataConfig());
00031 }
00032
00033 bool MIDI2Melody::GenerateOutputData(int id, TControlData val)
00034 {
00035 switch(id)
00036 {
00037 case 0:
00038 {
00039
00040 int index,velocity,beginTime,endTime;
00041 index=FindNote(int(val));
00042 if(index==-1) break;
00043 velocity=(int) mVelocities[index];
00044 beginTime=(int) mBeginTimes[index];
00045 endTime=(int) mTime.GetLastValue();
00046 DeleteNoteFromIndex(index);
00047
00048 MIDINote newNote;
00049 newNote.SetKey(int(val));
00050 newNote.SetVelocity(velocity);
00051 MediaTime time;
00052 time.AddBegin();
00053 time.AddEnd();
00054 time.RemoveDuration();
00055 time.UpdateData();
00056 time.SetBegin(beginTime);
00057 time.SetEnd(endTime);
00058 newNote.SetTime(time);
00059 mOutput.GetData().GetNoteArray().AddElem(newNote);
00060
00061 break;
00062 }
00063 case 1:
00064 {
00065
00066 break;
00067 }
00068 case 2:
00069 {
00070
00071 AddNote(int(val),0,int(mTime.GetLastValue()));
00072 mLastKey=int(val);
00073 break;
00074 }
00075 case 3:
00076 {
00077
00078 ModifyVelocity(mLastKey,int(val));
00079 break;
00080 }
00081 default:
00082 {
00083 CLAM_ASSERT(false,"Not a valid MIDI control");
00084 }
00085 }
00086 return true;
00087 }
00088
00089
00090 bool MIDI2Melody::ConcreteConfigure(const ProcessingConfig& c)
00091 {
00092
00093 Control2DataConfig &tmp=const_cast<Control2DataConfig&>(dynamic_cast<const Control2DataConfig&>(c));
00094
00095 tmp.SetNumControls(4);
00096 Control2Data::ConcreteConfigure(tmp);
00097 return true;
00098 }
00099
00100 int MIDI2Melody::FindNote(int key)
00101 {
00102 int index=-1;
00103 int i;
00104 for(i=0;i<mKeys.Size();i++)
00105 {
00106 if (mKeys[i]==key){
00107 index=i;
00108 break;
00109 }
00110 }
00111 return index;
00112 }
00113
00114 void MIDI2Melody::AddNote(int key, int velocity,int time)
00115 {
00116 mKeys.AddElem(key);
00117 mVelocities.AddElem(velocity);
00118 mBeginTimes.AddElem(time);
00119 }
00120
00121 void MIDI2Melody::DeleteNote(int key)
00122 {
00123 DeleteNoteFromIndex(FindNote(key));
00124 }
00125
00126 void MIDI2Melody::DeleteNoteFromIndex(int index)
00127 {
00128 mKeys.DeleteElem(index);
00129 mVelocities.DeleteElem(index);
00130 mBeginTimes.DeleteElem(index);
00131 }
00132
00133 void MIDI2Melody::ModifyVelocity(int key,int newVelocity)
00134 {
00135 int index=FindNote(key);
00136 mVelocities[index]=newVelocity;
00137 }
00138
00139 }
00140