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 #ifndef _ControlPiano_ 00021 #define _ControlPiano_ 00022 00023 #include "Processing.hxx" 00024 #include "InControl.hxx" 00025 #include "OutControl.hxx" 00026 00027 #include "MIDIMessage.hxx" 00028 00029 namespace CLAM 00030 { 00031 00032 class ControlPiano : public Processing 00033 { 00034 public: 00035 const char *GetClassName() const { return "ControlPiano"; } 00036 00037 protected: 00039 InControl< MIDI::Message > mInputMIDIMessage; 00040 OutControl< MIDI::Message > mOutputMIDIMessage; 00041 00042 public: 00043 00044 ControlPiano(const Config & config=Config()) 00045 : 00046 mInputMIDIMessage("MIDI Message In", this, &ControlPiano::DoCallback), 00047 mOutputMIDIMessage("MIDI Message Out", this) 00048 { 00049 Configure( config ); 00050 00051 _notes.resize(12); // one octave 00052 for(unsigned int i=0;i<_notes.size();i++) { _notes[i]=false; } 00053 00054 _velocity = 90; // fixed velocity. TODO: add it as a processing configuration parameter. 00055 _octave = 4; // fixed octave (C4). TODO: add it as a processing configuration parameter. 00056 } 00057 00058 ~ControlPiano() 00059 { 00060 } 00061 00062 bool Do() { return true; } 00063 00064 void DoCallback(const MIDI::Message & inMessage) 00065 { 00066 MIDI::Message message = inMessage; 00067 00068 mOutputMIDIMessage.SendControl(message); //delivers the same input message to the output 00069 00070 MIDI::Message voidMessage; 00071 if (message==voidMessage) return; 00072 00073 if (message[1]>=21 && message[1]<=108) 00074 { 00075 if (message[0]==144) //note on 00076 { 00077 _notes[(message[1]-21)%12]=true; 00078 } 00079 else if (message[0]==128) //note off 00080 { 00081 _notes[(message[1]-21)%12]=false; 00082 } 00083 } 00084 }; 00085 00086 void SendMIDIMessage(MIDI::Message &msg) 00087 { 00088 mOutputMIDIMessage.SendControl(msg); 00089 } 00090 00091 void SetNoteStatus(TSize i, bool state) 00092 { 00093 _notes[i] = state; 00094 } 00095 00096 bool GetNoteStatus(TSize i) 00097 { 00098 return _notes[i]; 00099 } 00100 00101 TSize GetVelocity() 00102 { 00103 return _velocity; 00104 } 00105 00106 TSize GetOctave() 00107 { 00108 return _octave; 00109 } 00110 00111 protected: 00112 std::vector<bool> _notes; 00113 TSize _velocity; 00114 TSize _octave; 00115 }; 00116 00117 } 00118 00119 #endif