CLAM-Development  1.4.0
MIDIKeyboard.cxx
Go to the documentation of this file.
1 #include "AudioManager.hxx"
2 #include "MIDIManager.hxx"
3 
4 #include "ProcessingFactory.hxx"
5 #include "MIDIKeyboard.hxx"
6 #include "DataTypes.hxx"
7 
8 
9 namespace CLAM
10 {
11 
12 namespace Hidden
13 {
14  static const char * metadata[] = {
15  "key", "MIDIKeyboard",
16  // "category", "MIDI",
17  // "description", "MIDIKeyboard",
18  0
19  };
20  static FactoryRegistrator<ProcessingFactory, MIDIKeyboard> reg = metadata;
21 }
22 
23 void MIDIKeyboardConfig::DefaultInit(void)
24 {
25  AddMidiDevice();
26  UpdateData();
27 
28  SetMidiDevice("alsa:hw:1,0");
29 }
30 
32  : mCurrentTime( 0.0 )
33  , mCurrentTimeIncrement( 0 )
34  , mNoteInControl( "NoteIn", this)
35  , mVelocityInControl( "VelocityIn") // TODO: Check why this should not be published
36  , mPitchBendInControl( "PitchBendIn") // TODO: Check why this should not be published
37  , mModulationInControl( "ModulationIn") // TODO: Check why this should not be published
38  , mNoteOut( "NoteOut", this )
39  , mVelocityOut( "VelocityOut", this )
40  , mPitchBendOut( "PitchBendOut", this )
41  , mModulationOut( "ModulationOut", this )
42 {
43  Configure( cfg );
44 }
45 
47 {
48  CopyAsConcreteConfig( mConfig, cfg );
49 
50  mConfig.SetMidiDevice( "alsa:hw:1,0" );
51 
52 // mConfig.SetMidiDevice( "file:test.mid" );
53 
54  mNoteInConfig.SetDevice( mConfig.GetMidiDevice() );
55  mNoteInConfig.SetMessage( MIDI::eNoteOnOff );
56  ConfigureAndCheck( mNoteIn, mNoteInConfig );
57 
58  mPitchBendInConfig.SetDevice( mConfig.GetMidiDevice() );
59  mPitchBendInConfig.SetMessage( MIDI::ePitchbend );
60  ConfigureAndCheck( mPitchBendIn, mPitchBendInConfig );
61 
62  mModulationConfig.SetDevice( mConfig.GetMidiDevice() );
63  mModulationConfig.SetMessage(MIDI::eControlChange);
64  mModulationConfig.SetFirstData( 0x01 ); // modulation
65  ConfigureAndCheck( mModulationIn, mModulationConfig );
66 
67  FloatOutControl& outNote = (FloatOutControl&) mNoteIn.GetOutControl(1);
68  FloatOutControl& outVelocity = (FloatOutControl&) mNoteIn.GetOutControl(2);
69  FloatOutControl& outPitchBend = (FloatOutControl&) mPitchBendIn.GetOutControl(1);
70  FloatOutControl& outModulation = (FloatOutControl&) mModulationIn.GetOutControl(1);
71 
72  mNoteOut.PublishOutControl( outNote );
73  mVelocityOut.PublishOutControl( outVelocity );
74  mPitchBendOut.PublishOutControl( outPitchBend );
75  mModulationOut.PublishOutControl( outModulation );
76 
77  mNoteOut.AddLink( mNoteInControl );
78  mVelocityOut.AddLink( mVelocityInControl );
79  mPitchBendOut.AddLink( mPitchBendInControl );
80  mModulationOut.AddLink( mModulationInControl );
81 
82  mClockerConfig.SetDevice( mConfig.GetMidiDevice() );
83  mClocker.Configure( mClockerConfig );
84 
85  return true;
86 }
87 
89 {
90  TData buffersize = 512.0;
91 
92  mCurrentTimeIncrement = buffersize * 1000.0 / CLAM::AudioManager::Current().SampleRate();
93 
94  SendFloatToInControl(mClocker,0,mCurrentTime);
95 
96  mNoteOut.SendControl( mNoteInControl.GetLastValue() );
97  mVelocityOut.SendControl( mVelocityInControl.GetLastValue() );
98  mPitchBendOut.SendControl( mPitchBendInControl.GetLastValue() );
99  mModulationOut.SendControl( mModulationInControl.GetLastValue() );
100 
101  mCurrentTime += mCurrentTimeIncrement;
102 
104 
105  return true;
106 }
107 
108 bool MIDIKeyboard::ConfigureAndCheck( Processing& p, ProcessingConfig& cfg )
109 {
110  bool configurationOk = p.Configure(cfg);
111  CLAM_ASSERT( configurationOk, p.GetConfigErrorMessage().c_str() );
112 
113  return configurationOk;
114 }
115 
116 
117 } // namespace CLAM
118