CLAM-Development  1.4.0
Fund2MIDI.cxx
Go to the documentation of this file.
1 /*
2  *
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19 
20 #include "Fund2MIDI.hxx"
21 #include "ProcessingFactory.hxx"
22 
23 namespace CLAM
24 {
25 namespace Hidden
26 {
27  static const char * metadata[] = {
28  "key", "Fund2MIDI",
29  "category", "MIDI",
30  "description", "Fund2MIDI",
31  0
32  };
33  static FactoryRegistrator<ProcessingFactory, Fund2MIDI> reg = metadata;
34 }
35 
36 bool Fund2MIDI::Do( const Fundamental& inFund )
37 {
38  TControlData fund_note = Round( 69. + log(inFund.GetFreq(0)/440.)*17.31234 );
39 
40  //FIXME clipping if necessary (testing), check inFund.GetFreq(0)
41  if (fund_note > 127 || fund_note < 0 )
42  {
43  std::cout << "value clipped! - old fund_note: " << fund_note ;
44  fund_note = CLAM_min( CLAM_max(fund_note,(TControlData)0), (TControlData)127 );
45  std::cout << " - new fund_note: " << fund_note << std::endl;
46  }
47  CLAM_DEBUG_ASSERT( fund_note>=0 & fund_note<128, "Fundamental MIDI note should be betweeen 0..127");
48 
49  mFreqControlOut.SendControl( fund_note );
50 
51  if (fund_note!=_previousNote)
52  {
53  MIDI::Message tmpMessage1(128, _previousNote, 90, 0); //128 NoteOff, note, velocity (fixed in 90)
54  mOutputMIDIMessage.SendControl(tmpMessage1);
55 
56  MIDI::Message tmpMessage2(144, fund_note, 90, 0); //144 NoteOn, note, velocity (fixed in 90)
57  mOutputMIDIMessage.SendControl(tmpMessage2);
58  _previousNote = fund_note;
59  }
60 
61  return true;
62 }
63 
64 
65 }
66