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
|
tomwalters@116
|
24 GraphAxisSpec::GraphAxisSpec(float fMin, float fMax, Scale::ScaleType iScale) {
|
tomwalters@228
|
25 m_pScale = NULL;
|
tomwalters@228
|
26 m_sLabel = NULL;
|
tomwalters@228
|
27 SetDisplayRange(fMin, fMax);
|
tomwalters@228
|
28 SetDisplayScale(iScale);
|
tomwalters@116
|
29 }
|
tomwalters@116
|
30
|
tomwalters@116
|
31 GraphAxisSpec::GraphAxisSpec() {
|
tomwalters@228
|
32 m_pScale = NULL;
|
tomwalters@228
|
33 m_sLabel = NULL;
|
tomwalters@228
|
34 m_fMin = 0;
|
tomwalters@228
|
35 m_fMax = 0;
|
tomwalters@116
|
36 }
|
tomwalters@116
|
37
|
tomwalters@116
|
38 GraphAxisSpec::~GraphAxisSpec() {
|
tomwalters@228
|
39 DELETE_IF_NONNULL(m_pScale);
|
tomwalters@116
|
40 }
|
tomwalters@116
|
41
|
tomwalters@116
|
42 void GraphAxisSpec::SetDisplayRange(float fMin, float fMax) {
|
tomwalters@228
|
43 AIM_ASSERT(fMin <= fMax);
|
tomwalters@228
|
44 m_fMin = fMin;
|
tomwalters@228
|
45 m_fMax = fMax;
|
tomwalters@228
|
46 if (m_pScale)
|
tomwalters@228
|
47 m_pScale->FromLinearScaledExtrema(m_fMin, m_fMax);
|
tomwalters@116
|
48 }
|
tomwalters@116
|
49
|
tomwalters@116
|
50 void GraphAxisSpec::SetDisplayScale(Scale::ScaleType iScale) {
|
tomwalters@228
|
51 DELETE_IF_NONNULL(m_pScale);
|
tomwalters@228
|
52 m_pScale = Scale::Create(iScale);
|
tomwalters@228
|
53 aimASSERT(m_pScale);
|
tomwalters@228
|
54 m_pScale->FromLinearScaledExtrema(m_fMin, m_fMax);
|
tomwalters@116
|
55 }
|
tomwalters@116
|
56
|
tomwalters@116
|
57 bool GraphAxisSpec::Initialize(Parameters *parameters,
|
tomwalters@116
|
58 const char *sPrefix,
|
tomwalters@116
|
59 float fMin,
|
tomwalters@116
|
60 float fMax,
|
tomwalters@116
|
61 Scale::ScaleType iScale) {
|
tomwalters@228
|
62 AIM_ASSERT(pParam);
|
tomwalters@228
|
63 AIM_ASSERT(sPrefix && sPrefix[0]!='\0');
|
tomwalters@228
|
64 char sParamName[Parameters::MaxParamNameLength];
|
tomwalters@116
|
65
|
tomwalters@228
|
66 //! The following parameters are recognized for each axis:
|
tomwalters@228
|
67 //! - \c "<prefix>.min", the minimum value; a float or \c 'auto'
|
tomwalters@228
|
68 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
|
tomwalters@116
|
69 "%s.min",
|
tomwalters@116
|
70 sPrefix);
|
tomwalters@228
|
71 if (pParam->IsSet(sParamName)) {
|
tomwalters@228
|
72 if (strcmp(parameters->GetString(sParamName), "auto") == 0)
|
tomwalters@228
|
73 m_fMin = fMin;
|
tomwalters@228
|
74 else
|
tomwalters@228
|
75 m_fMin = parameters->GetFloat(sParamName);
|
tomwalters@228
|
76 }
|
tomwalters@116
|
77
|
tomwalters@228
|
78 //! - \c "<prefix>.max", the maximum value; a float or \c 'auto'
|
tomwalters@228
|
79 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
|
tomwalters@116
|
80 "%s.max",
|
tomwalters@116
|
81 sPrefix);
|
tomwalters@228
|
82 if (pParam->IsSet(sParamName)) {
|
tomwalters@228
|
83 if (strcmp(parameters->GetString(sParamName), "auto")==0)
|
tomwalters@228
|
84 m_fMax = fMax;
|
tomwalters@228
|
85 else
|
tomwalters@228
|
86 m_fMax = parameters->GetFloat(sParamName);
|
tomwalters@228
|
87 }
|
tomwalters@116
|
88
|
tomwalters@228
|
89 // Make sure ranges are updated properly
|
tomwalters@228
|
90 SetDisplayRange(m_fMin, m_fMax);
|
tomwalters@116
|
91
|
tomwalters@228
|
92 //! - \c "<prefix>.scale", the scale; one of \c 'auto',
|
tomwalters@116
|
93 //! \c 'linear', \c 'erb' or \c 'log'
|
tomwalters@228
|
94 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
|
tomwalters@116
|
95 "%s.scale",
|
tomwalters@116
|
96 sPrefix);
|
tomwalters@228
|
97 if (pParam->IsSet(sParamName)) {
|
tomwalters@228
|
98 // Scale change, we updated min/max values already so no need to
|
tomwalters@228
|
99 Scale::ScaleType iThisScale;
|
tomwalters@228
|
100 const char *sVal = parameters->GetString(sParamName);
|
tomwalters@228
|
101 if (strcmp(sVal, "auto")==0)
|
tomwalters@228
|
102 iThisScale = iScale;
|
tomwalters@228
|
103 else if (strcmp(sVal, "linear")==0)
|
tomwalters@228
|
104 iThisScale = Scale::SCALE_LINEAR;
|
tomwalters@228
|
105 else if (strcmp(sVal, "erb")==0)
|
tomwalters@228
|
106 iThisScale = Scale::SCALE_ERB;
|
tomwalters@228
|
107 else if (strcmp(sVal, "log")==0)
|
tomwalters@228
|
108 iThisScale = Scale::SCALE_LOG;
|
tomwalters@228
|
109 else {
|
tomwalters@228
|
110 AIM_ERROR(_T("Unrecognized scale type in parameter '%s': '%s'"),
|
tomwalters@227
|
111 sParamName,
|
tomwalters@227
|
112 sVal);
|
tomwalters@228
|
113 return false;
|
tomwalters@228
|
114 }
|
tomwalters@228
|
115 SetDisplayScale(iThisScale);
|
tomwalters@228
|
116 }
|
tomwalters@126
|
117
|
tomwalters@228
|
118 //! - \c "<prefix>.label", the label; a string
|
tomwalters@228
|
119 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
|
tomwalters@116
|
120 "%s.label",
|
tomwalters@116
|
121 sPrefix);
|
tomwalters@228
|
122 if (parameters->IsSet(sParamName))
|
tomwalters@228
|
123 m_sLabel = parameters->GetString(sParamName); // Assumes strings remains valid
|
tomwalters@116
|
124
|
tomwalters@228
|
125 return true;
|
tomwalters@116
|
126 }
|