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