To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / CollidoscopeApp / src / Config.cpp @ 18:f1ff1a81be20
History | View | Annotate | Download (2.35 KB)
| 1 |
/*
|
|---|---|
| 2 |
|
| 3 |
Copyright (C) 2016 Queen Mary University of London
|
| 4 |
Author: Fiore Martin
|
| 5 |
|
| 6 |
This file is part of Collidoscope.
|
| 7 |
|
| 8 |
Collidoscope is free software: you can redistribute it and/or modify
|
| 9 |
it under the terms of the GNU General Public License as published by
|
| 10 |
the Free Software Foundation, either version 3 of the License, or
|
| 11 |
(at your option) any later version.
|
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful,
|
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 16 |
GNU General Public License for more details.
|
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License
|
| 19 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 20 |
*/
|
| 21 |
|
| 22 |
#include "Config.h" |
| 23 |
|
| 24 |
|
| 25 |
#include "cinder/Exception.h" |
| 26 |
#include "boost/algorithm/string/trim.hpp" |
| 27 |
|
| 28 |
using ci::DataSourceRef;
|
| 29 |
using ci::XmlTree;
|
| 30 |
using ci::loadFile;
|
| 31 |
|
| 32 |
|
| 33 |
Config::Config() : |
| 34 |
mAudioInputDeviceKey( "" ),
|
| 35 |
mNumChunks(150),
|
| 36 |
mWaveLen(2.0) |
| 37 |
{
|
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
// uses Cinder api to parse configuration in XML file
|
| 42 |
void Config::loadFromFile( std::string&& path ) |
| 43 |
{
|
| 44 |
try {
|
| 45 |
XmlTree doc( loadFile( path ) ); |
| 46 |
|
| 47 |
XmlTree collidoscope = doc.getChild( "collidoscope" );
|
| 48 |
|
| 49 |
// audio input device
|
| 50 |
mAudioInputDeviceKey = collidoscope.getChild( "audioInputDeviceKey" ).getValue();
|
| 51 |
boost::trim( mAudioInputDeviceKey ); |
| 52 |
|
| 53 |
// wave len in seconds
|
| 54 |
std::string waveLenStr = collidoscope.getChild("wave_len").getValue(); |
| 55 |
boost::trim(waveLenStr); |
| 56 |
mWaveLen = ci::fromString<double>(waveLenStr);
|
| 57 |
|
| 58 |
// channel for each wave
|
| 59 |
XmlTree waves = collidoscope.getChild( "waves" );
|
| 60 |
|
| 61 |
for ( int i = 0; i < NUM_WAVES; i++ ){ |
| 62 |
for ( auto &wave : waves.getChildren() ){ |
| 63 |
int id = ci::fromString<int>( wave->getAttribute( "id" ) ); |
| 64 |
if ( id == i ){
|
| 65 |
parseWave( *wave, id ); |
| 66 |
break;
|
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
} |
| 72 |
catch ( std::exception &e ) {
|
| 73 |
throw ci::Exception( e.what() );
|
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
// thows exception captured in loadFromFile
|
| 81 |
void Config::parseWave( const XmlTree &wave, int id ) |
| 82 |
{
|
| 83 |
// midi channel
|
| 84 |
std::string midiChannelStr = wave.getChild( "midiChannel" ).getValue(); |
| 85 |
boost::trim( midiChannelStr ); |
| 86 |
|
| 87 |
mMidiChannels[id] = ci::fromString<size_t>( midiChannelStr ); |
| 88 |
|
| 89 |
} |