00001 #include "AudioManager.hxx"
00002 #include "MIDIManager.hxx"
00003
00004 #include "ProcessingFactory.hxx"
00005 #include "MIDIKeyboard.hxx"
00006
00007
00008 namespace CLAM
00009 {
00010
00011 namespace Hidden
00012 {
00013 static const char * metadata[] = {
00014 "key", "MIDIKeyboard",
00015
00016
00017 0
00018 };
00019 static FactoryRegistrator<ProcessingFactory, MIDIKeyboard> reg = metadata;
00020 }
00021
00022 void MIDIKeyboardConfig::DefaultInit(void)
00023 {
00024 AddMidiDevice();
00025 UpdateData();
00026
00027 SetMidiDevice("alsa:hw:1,0");
00028 }
00029
00030 MIDIKeyboard::MIDIKeyboard()
00031 :
00032 mCurrentTime( 0.0 ),
00033 mCurrentTimeIncrement( 0 ),
00034 mNoteInControl( "NoteIn", this, false ),
00035 mVelocityInControl( "VelocityIn", this, false ),
00036 mPitchBendInControl( "PitchBendIn", this, false ),
00037 mModulationInControl( "ModulationIn", this, false ),
00038 mNoteOut( "NoteOut", this ),
00039 mVelocityOut( "VelocityOut", this ),
00040 mPitchBendOut( "PitchBendOut", this ),
00041 mModulationOut( "ModulationOut", this )
00042 {
00043 Configure( mConfig );
00044 }
00045
00046 MIDIKeyboard::MIDIKeyboard( ProcessingConfig& cfg )
00047 :
00048 mCurrentTime( 0.0 ),
00049 mCurrentTimeIncrement( 0 ),
00050 mNoteInControl( "NoteIn", this),
00051 mVelocityInControl( "VelocityIn", this, false ),
00052 mPitchBendInControl( "PitchBendIn", this, false ),
00053 mModulationInControl( "ModulationIn", this, false ),
00054 mNoteOut( "NoteOut", this ),
00055 mVelocityOut( "VelocityOut", this ),
00056 mPitchBendOut( "PitchBendOut", this ),
00057 mModulationOut( "ModulationOut", this )
00058 {
00059 Configure( cfg );
00060 }
00061
00062 bool MIDIKeyboard::ConcreteConfigure( const ProcessingConfig& cfg )
00063 {
00064 CopyAsConcreteConfig( mConfig, cfg );
00065
00066 mConfig.SetMidiDevice( "alsa:hw:1,0" );
00067
00068
00069
00070 mNoteInConfig.SetDevice( mConfig.GetMidiDevice() );
00071 mNoteInConfig.SetMessage( MIDI::eNoteOnOff );
00072 ConfigureAndCheck( mNoteIn, mNoteInConfig );
00073
00074 mPitchBendInConfig.SetDevice( mConfig.GetMidiDevice() );
00075 mPitchBendInConfig.SetMessage( MIDI::ePitchbend );
00076 ConfigureAndCheck( mPitchBendIn, mPitchBendInConfig );
00077
00078 mModulationConfig.SetDevice( mConfig.GetMidiDevice() );
00079 mModulationConfig.SetMessage(MIDI::eControlChange);
00080 mModulationConfig.SetFirstData( 0x01 );
00081 ConfigureAndCheck( mModulationIn, mModulationConfig );
00082
00083 OutControl& outNote = mNoteIn.GetOutControls().GetByNumber(1);
00084 OutControl& outVelocity = mNoteIn.GetOutControls().GetByNumber(2);
00085 OutControl& outPitchBend = mPitchBendIn.GetOutControls().GetByNumber(1);
00086 OutControl& outModulation = mModulationIn.GetOutControls().GetByNumber(1);
00087
00088 mNoteOut.PublishOutControl( outNote );
00089 mVelocityOut.PublishOutControl( outVelocity );
00090 mPitchBendOut.PublishOutControl( outPitchBend );
00091 mModulationOut.PublishOutControl( outModulation );
00092
00093 mNoteOut.AddLink( mNoteInControl );
00094 mVelocityOut.AddLink( mVelocityInControl );
00095 mPitchBendOut.AddLink( mPitchBendInControl );
00096 mModulationOut.AddLink( mModulationInControl );
00097
00098 mClockerConfig.SetDevice( mConfig.GetMidiDevice() );
00099 mClocker.Configure( mClockerConfig );
00100
00101 return true;
00102 }
00103
00104 bool MIDIKeyboard::Do()
00105 {
00106 TData buffersize = 512.0;
00107
00108 mCurrentTimeIncrement = buffersize * 1000.0 / CLAM::AudioManager::Current().SampleRate();
00109
00110 SendFloatToInControl(mClocker,0,mCurrentTime);
00111
00112 mNoteOut.SendControl( mNoteInControl.GetLastValue() );
00113 mVelocityOut.SendControl( mVelocityInControl.GetLastValue() );
00114 mPitchBendOut.SendControl( mPitchBendInControl.GetLastValue() );
00115 mModulationOut.SendControl( mModulationInControl.GetLastValue() );
00116
00117 mCurrentTime += mCurrentTimeIncrement;
00118
00119 CLAM::MIDIManager::Current().Check();
00120
00121 return true;
00122 }
00123
00124 bool MIDIKeyboard::ConfigureAndCheck( Processing& p, ProcessingConfig& cfg )
00125 {
00126 bool configurationOk = p.Configure(cfg);
00127 CLAM_ASSERT( configurationOk, p.GetConfigErrorMessage().c_str() );
00128
00129 return configurationOk;
00130 }
00131
00132
00133 }
00134