f@5: /* f@5: f@5: Copyright (C) 2016 Queen Mary University of London f@5: Author: Fiore Martin f@5: f@5: This file is part of Collidoscope. f@5: f@5: Collidoscope is free software: you can redistribute it and/or modify f@5: it under the terms of the GNU General Public License as published by f@5: the Free Software Foundation, either version 3 of the License, or f@5: (at your option) any later version. f@5: f@5: This program is distributed in the hope that it will be useful, f@5: but WITHOUT ANY WARRANTY; without even the implied warranty of f@5: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@5: GNU General Public License for more details. f@5: f@5: You should have received a copy of the GNU General Public License f@5: along with this program. If not, see . f@5: */ f@5: 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@2: // uses Cinder api to parse configuration in XML file 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: }