f@0: #include "Config.h" f@0: f@0: f@0: #include "cinder/Exception.h" f@0: #include "boost/algorithm/string/trim.hpp" f@0: f@0: using ci::DataSourceRef; f@0: using ci::XmlTree; f@0: using ci::loadFile; f@0: f@0: f@0: Config::Config() : f@0: mAudioInputDeviceKey( "" ), f@0: mNumChunks(150), f@0: mWaveLen(2.0) f@0: { f@0: f@0: } f@0: f@0: f@0: void Config::loadFromFile( std::string&& path ) f@0: { f@0: try { f@0: XmlTree doc( loadFile( path ) ); f@0: f@0: XmlTree collidoscope = doc.getChild( "collidoscope" ); f@0: f@0: // audio input device f@0: mAudioInputDeviceKey = collidoscope.getChild( "audioInputDeviceKey" ).getValue(); f@0: boost::trim( mAudioInputDeviceKey ); f@0: f@0: // wave len in seconds f@0: std::string waveLenStr = collidoscope.getChild("wave_len").getValue(); f@0: boost::trim(waveLenStr); f@0: mWaveLen = ci::fromString(waveLenStr); f@0: f@0: // channel for each wave f@0: XmlTree waves = collidoscope.getChild( "waves" ); f@0: f@0: for ( int i = 0; i < NUM_WAVES; i++ ){ f@0: for ( auto &wave : waves.getChildren() ){ f@0: int id = ci::fromString( wave->getAttribute( "id" ) ); f@0: if ( id == i ){ f@0: parseWave( *wave, id ); f@0: break; f@0: } f@0: } f@0: } f@0: f@0: } f@0: catch ( std::exception &e ) { f@0: throw ci::Exception( e.what() ); f@0: } f@0: f@0: f@0: f@0: } f@0: f@0: // thows exception captured in loadFromFile f@0: void Config::parseWave( const XmlTree &wave, int id ) f@0: { f@0: // midi channel f@0: std::string midiChannelStr = wave.getChild( "midiChannel" ).getValue(); f@0: boost::trim( midiChannelStr ); f@0: f@0: mMidiChannels[id] = ci::fromString( midiChannelStr ); f@0: f@0: }