コード例 #1
0
// ----------------------------------------------------------------------------
//
bool IniFile::read( )
{
    FILE* fp;

    errno_t err = fopen_s( &fp, m_ini_filename, "r" );
    if ( err || !fp )   // Assume it does not exist
        return false;
        
    SimpleJsonParser parser;

    try {
        parser.parse( fp );

        fclose( fp );
    }
    catch ( std::exception& e ) {
        fclose( fp );
        throw e;
    }
    
    m_dmx_required = parser.get<bool>( "dmx_required", true );
    m_debug = parser.get<bool>( "debug", false );
    m_venue_filename = parser.get<CString>( "venue_filename", "" );
    m_venue_container = parser.get<CString>( "venue_container", "" );

    if ( parser.has_key( "remote" ) ) {
        JsonNode remote = parser.get<JsonNode>( "remote" );
        m_http_port = parser.get<unsigned>( "http_port", 80 );
        m_http_enabled = parser.get<bool>( "enable", true );
    }

    if ( parser.has_key( "whiteout_slow" ) ) {
        JsonNode whiteout_slow = parser.get<JsonNode>( "whiteout_slow" );
        m_whiteout_strobe_slow.m_on_ms = whiteout_slow.get<unsigned>( "on_ms" );
        m_whiteout_strobe_slow.m_off_ms = whiteout_slow.get<unsigned>( "off_ms" );
    }

    if ( parser.has_key( "whiteout_fast" ) ) {
        JsonNode whiteout_fast = parser.get<JsonNode>( "whiteout_fast" );
        m_whiteout_strobe_fast.m_on_ms = whiteout_fast.get<unsigned>( "on_ms" );
        m_whiteout_strobe_fast.m_off_ms = whiteout_fast.get<unsigned>( "off_ms" );
    }

    if ( parser.has_key( "music_player" ) ) {
        JsonNode music_player = parser.get<JsonNode>( "music_player" );
        m_music_player_ddl = music_player.get<CString>( "library" );
        m_music_player_username = music_player.get<CString>( "username" );

        m_music_player_enabled = true;
    }

    return true;
}
コード例 #2
0
ファイル: HttpRestVenue.cpp プロジェクト: desantir/DMXStudio
// ----------------------------------------------------------------------------
//
void HttpRestServices::control_venue_whiteout_palette( Venue* venue, DMXHttpSession* session, CString& response, LPCSTR data, DWORD size, LPCSTR content_type )
{
    SimpleJsonParser parser;

    try {
        parser.parse( data );

        RGBWAArray palette_colors = parser.getArrayAsVector<RGBWA>( "palette" );
        ColorWeights palette_weights;

        if ( parser.has_key( "weights" ) )
            palette_weights = parser.getArrayAsVector<double>( "weights" );

        UINT duration = parser.get<UINT>( "duration_ms" );

        venue->setVideoPalette( palette_colors, palette_weights );

        venue->setWhiteoutColor( SYSTEM_PALETTE_4 );
        venue->setWhiteoutStrobeMS( duration, 0 );
        venue->setWhiteout( WhiteoutMode::WHITEOUT_ON );
    }
    catch ( std::exception& e ) {
        throw RestServiceException( "JSON parser error (%s) data (%s)", e.what(), data );
    }
}
コード例 #3
0
ファイル: IniFile.cpp プロジェクト: desantir/DMXStudio
// ----------------------------------------------------------------------------
//
bool IniFile::read( LPCSTR filename )
{
    FILE* fp;

    errno_t err = fopen_s( &fp, filename, "r" );
    if ( err || !fp )   // Assume it does not exist
        return false;
        
    SimpleJsonParser parser;

    try {
        parser.parse( fp );

        fclose( fp );
    }
    catch ( std::exception& e ) {
        fclose( fp );
        throw e;
    }
    
    m_dmx_required = parser.get<bool>( "dmx_required", true );
    m_debug = parser.get<bool>( "debug", false );
    m_venue_filename = parser.get<CString>( "venue_filename", "" );
    m_venue_container = parser.get<CString>( "venue_container", "" );
    m_google_api_key = parser.get<CString>( "google_api_key", "" );

    if ( parser.has_key( "remote" ) ) {
        JsonNode remote = parser.get<JsonNode>( "remote" );
        m_http_port = remote.get<unsigned>( "http_port", 80 );
        m_http_enabled = remote.get<bool>( "enable", true );
     }

    if ( parser.has_key( "videos" ) ) {
        JsonNode videos = parser.get<JsonNode>( "videos" );
        m_videos_per_track = videos.get<unsigned>( "videos_per_track", 12 );
        m_video_palette_size = videos.get<unsigned>( "video_palette_size", 12 );
    }

    if ( parser.has_key( "whiteout_slow" ) ) {
        JsonNode whiteout_slow = parser.get<JsonNode>( "whiteout_slow" );
        m_whiteout_strobe_slow.setOnMS( whiteout_slow.get<unsigned>( "on_ms" ) );
        m_whiteout_strobe_slow.setOffMS( whiteout_slow.get<unsigned>( "off_ms" ) );
        m_whiteout_strobe_slow.setFadeInMS( whiteout_slow.get<unsigned>( "fade_in_ms", 0 ) );
        m_whiteout_strobe_slow.setFadeOutMS( whiteout_slow.get<unsigned>( "fade_out_ms", 0 ) );
		m_whiteout_strobe_slow.setFlashes( whiteout_slow.get<unsigned>( "flashes", 1 ) );
    }

    if ( parser.has_key( "whiteout_fast" ) ) {
        JsonNode whiteout_fast = parser.get<JsonNode>( "whiteout_fast" );
        m_whiteout_strobe_fast.setOnMS( whiteout_fast.get<unsigned>( "on_ms" ) );
        m_whiteout_strobe_fast.setOffMS( whiteout_fast.get<unsigned>( "off_ms" ) );
        m_whiteout_strobe_fast.setFadeInMS( whiteout_fast.get<unsigned>( "fade_in_ms", 0 ) );
        m_whiteout_strobe_fast.setFadeOutMS( whiteout_fast.get<unsigned>( "fade_out_ms", 0 ) );
        m_whiteout_strobe_fast.setFlashes( whiteout_fast.get<unsigned>( "flashes", 1 ) );
    }

    if ( parser.has_key( "whiteout_manual" ) ) {
        JsonNode whiteout_manual = parser.get<JsonNode>( "whiteout_manual" );
        m_whiteout_strobe_manual.setOnMS( whiteout_manual.get<unsigned>( "on_ms" ) );
        m_whiteout_strobe_manual.setOffMS( 0 );
        m_whiteout_strobe_manual.setFadeInMS( whiteout_manual.get<unsigned>( "fade_in_ms", 0 ) );
        m_whiteout_strobe_manual.setFadeOutMS( whiteout_manual.get<unsigned>( "fade_out_ms", 0 ) );
        m_whiteout_strobe_manual.setFlashes( whiteout_manual.get<unsigned>( "flashes", 1 ) );
    }

    if ( parser.has_key( "music_player" ) ) {
        JsonNode music_player = parser.get<JsonNode>( "music_player" );
        m_music_player_ddl = music_player.get<CString>( "library" );
        m_music_player_username = music_player.get<CString>( "username" );

        m_music_player_enabled = true;
    }

    if ( parser.has_key( "hue" ) ) {
        JsonNode hue = parser.get<JsonNode>( "hue" );
        m_hue_bridge_ip = hue.get<CString>( "bridge_ip", "" );
        m_hue_auto_setup = hue.get<bool>( "auto_setup", true );

        if ( hue.has_key( "ignored_lights" ) ) {
            for ( UINT light_number : hue.getArrayAsVector<UINT>( "ignored_lights" ) ) {
                m_hue_ignored_lights.insert( light_number );
            }
        }

        if ( hue.has_key( "allowed_groups" ) ) {
            for ( CString& group_name : hue.getArrayAsVector<CString>( "allowed_groups" ) ) {
                m_hue_allowed_groups.insert( group_name );
            }
        }
    }

    return true;
}