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