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);
|
tom@399
|
73 if (parameters->IsSet(sParamName)) {
|
tomwalters@398
|
74 if (strcmp(parameters->GetString(sParamName), "auto") == 0)
|
tomwalters@398
|
75 m_fMin = fMin;
|
tomwalters@398
|
76 else
|
tomwalters@398
|
77 m_fMin = parameters->GetFloat(sParamName);
|
tomwalters@398
|
78 }
|
tomwalters@397
|
79
|
tomwalters@398
|
80 //! - \c "<prefix>.max", the maximum value; a float or \c 'auto'
|
tomwalters@398
|
81 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
|
tomwalters@397
|
82 "%s.max",
|
tomwalters@397
|
83 sPrefix);
|
tom@399
|
84 if (parameters->IsSet(sParamName)) {
|
tomwalters@398
|
85 if (strcmp(parameters->GetString(sParamName), "auto")==0)
|
tomwalters@398
|
86 m_fMax = fMax;
|
tomwalters@398
|
87 else
|
tomwalters@398
|
88 m_fMax = parameters->GetFloat(sParamName);
|
tomwalters@398
|
89 }
|
tomwalters@397
|
90
|
tomwalters@398
|
91 // Make sure ranges are updated properly
|
tomwalters@398
|
92 SetDisplayRange(m_fMin, m_fMax);
|
tomwalters@397
|
93
|
tomwalters@398
|
94 //! - \c "<prefix>.scale", the scale; one of \c 'auto',
|
tomwalters@397
|
95 //! \c 'linear', \c 'erb' or \c 'log'
|
tomwalters@398
|
96 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
|
tomwalters@397
|
97 "%s.scale",
|
tomwalters@397
|
98 sPrefix);
|
tom@399
|
99 if (parameters->IsSet(sParamName)) {
|
tomwalters@398
|
100 // Scale change, we updated min/max values already so no need to
|
tomwalters@398
|
101 Scale::ScaleType iThisScale;
|
tomwalters@398
|
102 const char *sVal = parameters->GetString(sParamName);
|
tomwalters@398
|
103 if (strcmp(sVal, "auto")==0)
|
tomwalters@398
|
104 iThisScale = iScale;
|
tomwalters@398
|
105 else if (strcmp(sVal, "linear")==0)
|
tomwalters@398
|
106 iThisScale = Scale::SCALE_LINEAR;
|
tomwalters@398
|
107 else if (strcmp(sVal, "erb")==0)
|
tomwalters@398
|
108 iThisScale = Scale::SCALE_ERB;
|
tomwalters@398
|
109 else if (strcmp(sVal, "log")==0)
|
tomwalters@398
|
110 iThisScale = Scale::SCALE_LOG;
|
tomwalters@398
|
111 else {
|
tom@399
|
112 LOG_ERROR(_T("Unrecognized scale type in parameter '%s': '%s'"),
|
tomwalters@397
|
113 sParamName,
|
tomwalters@397
|
114 sVal);
|
tomwalters@398
|
115 return false;
|
tomwalters@398
|
116 }
|
tomwalters@398
|
117 SetDisplayScale(iThisScale);
|
tomwalters@398
|
118 }
|
tomwalters@397
|
119
|
tomwalters@398
|
120 //! - \c "<prefix>.label", the label; a string
|
tomwalters@398
|
121 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
|
tomwalters@397
|
122 "%s.label",
|
tomwalters@397
|
123 sPrefix);
|
tomwalters@398
|
124 if (parameters->IsSet(sParamName))
|
tomwalters@398
|
125 m_sLabel = parameters->GetString(sParamName); // Assumes strings remains valid
|
tomwalters@397
|
126
|
tomwalters@398
|
127 return true;
|
tomwalters@397
|
128 }
|
tom@399
|
129 } // namespace aimc
|