annotate CollidoscopeApp/src/Config.cpp @ 0:02467299402e

First import CollidoscopeApp for Raspberry Pi JackDevice Teensy code for Collidoscope
author Fiore Martin <f.martin@qmul.ac.uk>
date Thu, 30 Jun 2016 14:50:06 +0200
parents
children dd889fff8423
rev   line source
f@0 1 #include "Config.h"
f@0 2
f@0 3
f@0 4 #include "cinder/Exception.h"
f@0 5 #include "boost/algorithm/string/trim.hpp"
f@0 6
f@0 7 using ci::DataSourceRef;
f@0 8 using ci::XmlTree;
f@0 9 using ci::loadFile;
f@0 10
f@0 11
f@0 12 Config::Config() :
f@0 13 mAudioInputDeviceKey( "" ),
f@0 14 mNumChunks(150),
f@0 15 mWaveLen(2.0)
f@0 16 {
f@0 17
f@0 18 }
f@0 19
f@0 20
f@0 21 void Config::loadFromFile( std::string&& path )
f@0 22 {
f@0 23 try {
f@0 24 XmlTree doc( loadFile( path ) );
f@0 25
f@0 26 XmlTree collidoscope = doc.getChild( "collidoscope" );
f@0 27
f@0 28 // audio input device
f@0 29 mAudioInputDeviceKey = collidoscope.getChild( "audioInputDeviceKey" ).getValue();
f@0 30 boost::trim( mAudioInputDeviceKey );
f@0 31
f@0 32 // wave len in seconds
f@0 33 std::string waveLenStr = collidoscope.getChild("wave_len").getValue();
f@0 34 boost::trim(waveLenStr);
f@0 35 mWaveLen = ci::fromString<double>(waveLenStr);
f@0 36
f@0 37 // channel for each wave
f@0 38 XmlTree waves = collidoscope.getChild( "waves" );
f@0 39
f@0 40 for ( int i = 0; i < NUM_WAVES; i++ ){
f@0 41 for ( auto &wave : waves.getChildren() ){
f@0 42 int id = ci::fromString<int>( wave->getAttribute( "id" ) );
f@0 43 if ( id == i ){
f@0 44 parseWave( *wave, id );
f@0 45 break;
f@0 46 }
f@0 47 }
f@0 48 }
f@0 49
f@0 50 }
f@0 51 catch ( std::exception &e ) {
f@0 52 throw ci::Exception( e.what() );
f@0 53 }
f@0 54
f@0 55
f@0 56
f@0 57 }
f@0 58
f@0 59 // thows exception captured in loadFromFile
f@0 60 void Config::parseWave( const XmlTree &wave, int id )
f@0 61 {
f@0 62 // midi channel
f@0 63 std::string midiChannelStr = wave.getChild( "midiChannel" ).getValue();
f@0 64 boost::trim( midiChannelStr );
f@0 65
f@0 66 mMidiChannels[id] = ci::fromString<size_t>( midiChannelStr );
f@0 67
f@0 68 }