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