Fund2MIDI.cxx

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  */
00019 
00020 #include "Fund2MIDI.hxx"
00021 #include "ProcessingFactory.hxx"
00022 
00023 namespace CLAM
00024 {
00025 namespace Hidden
00026 {
00027         static const char * metadata[] = {
00028                 "key", "Fund2MIDI",
00029                 "category", "MIDI",
00030                 "description", "Fund2MIDI",
00031                 0
00032         };
00033         static FactoryRegistrator<ProcessingFactory, Fund2MIDI> reg = metadata;
00034 }
00035 
00036 bool Fund2MIDI::Do( const Fundamental& inFund ) 
00037 {
00038         TControlData fund_note = Round( 69. + log(inFund.GetFreq(0)/440.)*17.31234 );
00039 
00040         //FIXME clipping if necessary (testing), check inFund.GetFreq(0)
00041         if (fund_note > 127 || fund_note < 0 )
00042         {
00043                 std::cout << "value clipped! - old fund_note: " << fund_note ;
00044                 fund_note = CLAM_min( CLAM_max(fund_note,(TControlData)0), (TControlData)127 );
00045                 std::cout << " - new fund_note: " << fund_note << std::endl;
00046         }
00047         CLAM_DEBUG_ASSERT( fund_note>=0 & fund_note<128, "Fundamental MIDI note should be betweeen 0..127");
00048 
00049         mFreqControlOut.SendControl( fund_note );
00050 
00051         if (fund_note!=_previousNote)
00052         {
00053                 MIDI::Message tmpMessage1(128, _previousNote, 90, 0); //128 NoteOff, note, velocity (fixed in 90)
00054                 mOutputMIDIMessage.SendControl(tmpMessage1);
00055 
00056                 MIDI::Message tmpMessage2(144, fund_note, 90, 0); //144 NoteOn, note, velocity (fixed in 90)
00057                 mOutputMIDIMessage.SendControl(tmpMessage2);
00058                 _previousNote = fund_note;
00059         }
00060 
00061         return true;
00062 }
00063 
00064 
00065 }
00066 
Generated by  doxygen 1.6.3