To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (1.57 KB)

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