tomwalters@116: // Copyright 2006, Willem van Engen tomwalters@116: // tomwalters@116: // AIM-C: A C++ implementation of the Auditory Image Model tomwalters@116: // http://www.acousticscale.org/AIMC tomwalters@116: // tomwalters@116: // Licensed under the Apache License, Version 2.0 (the "License"); tomwalters@116: // you may not use this file except in compliance with the License. tomwalters@116: // You may obtain a copy of the License at tomwalters@116: // tomwalters@116: // http://www.apache.org/licenses/LICENSE-2.0 tomwalters@116: // tomwalters@116: // Unless required by applicable law or agreed to in writing, software tomwalters@116: // distributed under the License is distributed on an "AS IS" BASIS, tomwalters@116: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tomwalters@116: // See the License for the specific language governing permissions and tomwalters@116: // limitations under the License. tomwalters@116: tomwalters@116: #include "Support/Common.h" tomwalters@116: #include tomwalters@116: #include tomwalters@116: tomwalters@116: #include "Modules/Output/Graphics/GraphAxisSpec.h" tomwalters@116: tom@118: namespace aimc { tom@118: tomwalters@116: GraphAxisSpec::GraphAxisSpec(float fMin, float fMax, Scale::ScaleType iScale) { tomwalters@117: m_pScale = NULL; tomwalters@117: m_sLabel = NULL; tomwalters@117: SetDisplayRange(fMin, fMax); tomwalters@117: SetDisplayScale(iScale); tomwalters@116: } tomwalters@116: tomwalters@116: GraphAxisSpec::GraphAxisSpec() { tomwalters@117: m_pScale = NULL; tomwalters@117: m_sLabel = NULL; tomwalters@117: m_fMin = 0; tomwalters@117: m_fMax = 0; tomwalters@116: } tomwalters@116: tomwalters@116: GraphAxisSpec::~GraphAxisSpec() { tomwalters@117: DELETE_IF_NONNULL(m_pScale); tomwalters@116: } tomwalters@116: tomwalters@116: void GraphAxisSpec::SetDisplayRange(float fMin, float fMax) { tomwalters@117: AIM_ASSERT(fMin <= fMax); tomwalters@117: m_fMin = fMin; tomwalters@117: m_fMax = fMax; tomwalters@117: if (m_pScale) tomwalters@117: m_pScale->FromLinearScaledExtrema(m_fMin, m_fMax); tomwalters@116: } tomwalters@116: tomwalters@116: void GraphAxisSpec::SetDisplayScale(Scale::ScaleType iScale) { tomwalters@117: DELETE_IF_NONNULL(m_pScale); tomwalters@117: m_pScale = Scale::Create(iScale); tom@118: AIM_ASSERT(m_pScale); tomwalters@117: m_pScale->FromLinearScaledExtrema(m_fMin, m_fMax); tomwalters@116: } tomwalters@116: tomwalters@116: bool GraphAxisSpec::Initialize(Parameters *parameters, tomwalters@116: const char *sPrefix, tomwalters@116: float fMin, tomwalters@116: float fMax, tomwalters@116: Scale::ScaleType iScale) { tom@118: AIM_ASSERT(parameters); tomwalters@117: AIM_ASSERT(sPrefix && sPrefix[0]!='\0'); tomwalters@117: char sParamName[Parameters::MaxParamNameLength]; tomwalters@116: tomwalters@117: //! The following parameters are recognized for each axis: tomwalters@117: //! - \c ".min", the minimum value; a float or \c 'auto' tomwalters@117: snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]), tomwalters@116: "%s.min", tomwalters@116: sPrefix); tom@118: if (parameters->IsSet(sParamName)) { tomwalters@117: if (strcmp(parameters->GetString(sParamName), "auto") == 0) tomwalters@117: m_fMin = fMin; tomwalters@117: else tomwalters@117: m_fMin = parameters->GetFloat(sParamName); tomwalters@117: } tomwalters@116: tomwalters@117: //! - \c ".max", the maximum value; a float or \c 'auto' tomwalters@117: snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]), tomwalters@116: "%s.max", tomwalters@116: sPrefix); tom@118: if (parameters->IsSet(sParamName)) { tomwalters@117: if (strcmp(parameters->GetString(sParamName), "auto")==0) tomwalters@117: m_fMax = fMax; tomwalters@117: else tomwalters@117: m_fMax = parameters->GetFloat(sParamName); tomwalters@117: } tomwalters@116: tomwalters@117: // Make sure ranges are updated properly tomwalters@117: SetDisplayRange(m_fMin, m_fMax); tomwalters@116: tomwalters@117: //! - \c ".scale", the scale; one of \c 'auto', tomwalters@116: //! \c 'linear', \c 'erb' or \c 'log' tomwalters@117: snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]), tomwalters@116: "%s.scale", tomwalters@116: sPrefix); tom@118: if (parameters->IsSet(sParamName)) { tomwalters@117: // Scale change, we updated min/max values already so no need to tomwalters@117: Scale::ScaleType iThisScale; tomwalters@117: const char *sVal = parameters->GetString(sParamName); tomwalters@117: if (strcmp(sVal, "auto")==0) tomwalters@117: iThisScale = iScale; tomwalters@117: else if (strcmp(sVal, "linear")==0) tomwalters@117: iThisScale = Scale::SCALE_LINEAR; tomwalters@117: else if (strcmp(sVal, "erb")==0) tomwalters@117: iThisScale = Scale::SCALE_ERB; tomwalters@117: else if (strcmp(sVal, "log")==0) tomwalters@117: iThisScale = Scale::SCALE_LOG; tomwalters@117: else { tom@118: LOG_ERROR(_T("Unrecognized scale type in parameter '%s': '%s'"), tomwalters@116: sParamName, tomwalters@116: sVal); tomwalters@117: return false; tomwalters@117: } tomwalters@117: SetDisplayScale(iThisScale); tomwalters@117: } tomwalters@116: tomwalters@117: //! - \c ".label", the label; a string tomwalters@117: snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]), tomwalters@116: "%s.label", tomwalters@116: sPrefix); tomwalters@117: if (parameters->IsSet(sParamName)) tomwalters@117: m_sLabel = parameters->GetString(sParamName); // Assumes strings remains valid tomwalters@116: tomwalters@117: return true; tomwalters@116: } tom@118: } // namespace aimc