annotate src/Modules/Output/Graphics/GraphAxisSpec.cc @ 263:07dc1f7047f5

Debug output for audio_example and added a write function for aimc_data
author hamel.phil
date Thu, 06 Jan 2011 20:11:41 +0000
parents af02b6addf7a
children
rev   line source
tomwalters@116 1 // Copyright 2006, Willem van Engen
tomwalters@116 2 //
tomwalters@116 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@116 4 // http://www.acousticscale.org/AIMC
tomwalters@116 5 //
tomwalters@116 6 // Licensed under the Apache License, Version 2.0 (the "License");
tomwalters@116 7 // you may not use this file except in compliance with the License.
tomwalters@116 8 // You may obtain a copy of the License at
tomwalters@116 9 //
tomwalters@116 10 // http://www.apache.org/licenses/LICENSE-2.0
tomwalters@116 11 //
tomwalters@116 12 // Unless required by applicable law or agreed to in writing, software
tomwalters@116 13 // distributed under the License is distributed on an "AS IS" BASIS,
tomwalters@116 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tomwalters@116 15 // See the License for the specific language governing permissions and
tomwalters@116 16 // limitations under the License.
tomwalters@116 17
tomwalters@116 18 #include "Support/Common.h"
tomwalters@116 19 #include <string.h>
tomwalters@116 20 #include <stdio.h>
tomwalters@116 21
tomwalters@116 22 #include "Modules/Output/Graphics/GraphAxisSpec.h"
tomwalters@116 23
tom@229 24 namespace aimc {
tom@229 25
tomwalters@116 26 GraphAxisSpec::GraphAxisSpec(float fMin, float fMax, Scale::ScaleType iScale) {
tomwalters@228 27 m_pScale = NULL;
tomwalters@228 28 m_sLabel = NULL;
tomwalters@228 29 SetDisplayRange(fMin, fMax);
tomwalters@228 30 SetDisplayScale(iScale);
tomwalters@116 31 }
tomwalters@116 32
tomwalters@116 33 GraphAxisSpec::GraphAxisSpec() {
tomwalters@228 34 m_pScale = NULL;
tomwalters@228 35 m_sLabel = NULL;
tomwalters@228 36 m_fMin = 0;
tomwalters@228 37 m_fMax = 0;
tomwalters@116 38 }
tomwalters@116 39
tomwalters@116 40 GraphAxisSpec::~GraphAxisSpec() {
tomwalters@228 41 DELETE_IF_NONNULL(m_pScale);
tomwalters@116 42 }
tomwalters@116 43
tomwalters@116 44 void GraphAxisSpec::SetDisplayRange(float fMin, float fMax) {
tomwalters@228 45 AIM_ASSERT(fMin <= fMax);
tomwalters@228 46 m_fMin = fMin;
tomwalters@228 47 m_fMax = fMax;
tomwalters@228 48 if (m_pScale)
tomwalters@228 49 m_pScale->FromLinearScaledExtrema(m_fMin, m_fMax);
tomwalters@116 50 }
tomwalters@116 51
tomwalters@116 52 void GraphAxisSpec::SetDisplayScale(Scale::ScaleType iScale) {
tomwalters@228 53 DELETE_IF_NONNULL(m_pScale);
tomwalters@228 54 m_pScale = Scale::Create(iScale);
tom@229 55 AIM_ASSERT(m_pScale);
tomwalters@228 56 m_pScale->FromLinearScaledExtrema(m_fMin, m_fMax);
tomwalters@116 57 }
tomwalters@116 58
tomwalters@116 59 bool GraphAxisSpec::Initialize(Parameters *parameters,
tomwalters@116 60 const char *sPrefix,
tomwalters@116 61 float fMin,
tomwalters@116 62 float fMax,
tomwalters@116 63 Scale::ScaleType iScale) {
tom@229 64 AIM_ASSERT(parameters);
tomwalters@228 65 AIM_ASSERT(sPrefix && sPrefix[0]!='\0');
tomwalters@228 66 char sParamName[Parameters::MaxParamNameLength];
tomwalters@116 67
tomwalters@228 68 //! The following parameters are recognized for each axis:
tomwalters@228 69 //! - \c "<prefix>.min", the minimum value; a float or \c 'auto'
tomwalters@228 70 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
tomwalters@116 71 "%s.min",
tomwalters@116 72 sPrefix);
tomwalters@237 73 if (strcmp(parameters->DefaultString(sParamName, "auto"), "auto") == 0)
tomwalters@237 74 m_fMin = fMin;
tomwalters@237 75 else
tomwalters@237 76 m_fMin = parameters->GetFloat(sParamName);
tomwalters@237 77
tomwalters@116 78
tomwalters@228 79 //! - \c "<prefix>.max", the maximum value; a float or \c 'auto'
tomwalters@228 80 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
tomwalters@116 81 "%s.max",
tomwalters@116 82 sPrefix);
tomwalters@237 83 if (strcmp(parameters->DefaultString(sParamName, "auto"), "auto")==0)
tomwalters@237 84 m_fMax = fMax;
tomwalters@237 85 else
tomwalters@237 86 m_fMax = parameters->GetFloat(sParamName);
tomwalters@116 87
tomwalters@228 88 // Make sure ranges are updated properly
tomwalters@228 89 SetDisplayRange(m_fMin, m_fMax);
tomwalters@116 90
tomwalters@228 91 //! - \c "<prefix>.scale", the scale; one of \c 'auto',
tomwalters@116 92 //! \c 'linear', \c 'erb' or \c 'log'
tomwalters@228 93 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
tomwalters@116 94 "%s.scale",
tomwalters@116 95 sPrefix);
tomwalters@237 96 // Scale change, we updated min/max values already so no need to
tomwalters@237 97 Scale::ScaleType iThisScale;
tomwalters@237 98 const char *sVal = parameters->DefaultString(sParamName, "auto");
tomwalters@237 99 if (strcmp(sVal, "auto")==0)
tomwalters@237 100 iThisScale = iScale;
tomwalters@237 101 else if (strcmp(sVal, "linear")==0)
tomwalters@237 102 iThisScale = Scale::SCALE_LINEAR;
tomwalters@237 103 else if (strcmp(sVal, "erb")==0)
tomwalters@237 104 iThisScale = Scale::SCALE_ERB;
tomwalters@237 105 else if (strcmp(sVal, "log")==0)
tomwalters@237 106 iThisScale = Scale::SCALE_LOG;
tomwalters@237 107 else {
tomwalters@237 108 LOG_ERROR(_T("Unrecognized scale type in parameter '%s': '%s'"),
tomwalters@237 109 sParamName,
tomwalters@237 110 sVal);
tomwalters@237 111 return false;
tomwalters@228 112 }
tomwalters@237 113 SetDisplayScale(iThisScale);
tomwalters@237 114
tomwalters@126 115
tomwalters@228 116 //! - \c "<prefix>.label", the label; a string
tomwalters@228 117 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
tomwalters@116 118 "%s.label",
tomwalters@116 119 sPrefix);
tomwalters@237 120 m_sLabel = parameters->DefaultString(sParamName, ""); // Assumes strings remains valid
tomwalters@116 121
tomwalters@228 122 return true;
tomwalters@116 123 }
tom@229 124 } // namespace aimc