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