Chris@224: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@224: 
Chris@224: /*
Chris@224:     Sonic Visualiser
Chris@224:     An audio file viewer and annotation editor.
Chris@224:     Centre for Digital Music, Queen Mary, University of London.
Chris@224:     This file copyright 2006 Chris Cannam.
Chris@224:     
Chris@224:     This program is free software; you can redistribute it and/or
Chris@224:     modify it under the terms of the GNU General Public License as
Chris@224:     published by the Free Software Foundation; either version 2 of the
Chris@224:     License, or (at your option) any later version.  See the file
Chris@224:     COPYING included with this distribution for more information.
Chris@224: */
Chris@224: 
Chris@224: #ifndef _LOG_RANGE_H_
Chris@224: #define _LOG_RANGE_H_
Chris@224: 
Chris@478: #include <vector>
Chris@687: #include "Debug.h"
Chris@478: 
Chris@224: class LogRange
Chris@224: {
Chris@224: public:
Chris@224:     /**
Chris@224:      * Map a linear range onto a logarithmic range.  min and max are
Chris@224:      * passed as the extents of the linear range and returned as the
Chris@224:      * extents of the logarithmic range.  thresh is the minimum value
Chris@224:      * for the log range, to be used if the linear range spans zero.
Chris@224:      */
Chris@224:     static void mapRange(float &min, float &max, float thresh = -10);
Chris@224: 
Chris@224:     /**
Chris@224:      * Map a value onto a logarithmic range.  This just means taking
Chris@224:      * the base-10 log of the absolute value, or using the threshold
Chris@224:      * value if the absolute value is zero.
Chris@224:      */
Chris@224:     static float map(float value, float thresh = -10);
Chris@266: 
Chris@266:     /**
Chris@266:      * Map a value from the logarithmic range back again.  This just
Chris@266:      * means taking the value'th power of ten.
Chris@266:      */
Chris@266:     static float unmap(float value);
Chris@478: 
Chris@478:     /**
Chris@478:      * Estimate whether a set of values would be more properly shown
Chris@478:      * using a logarithmic than a linear scale.  This is only ever
Chris@478:      * going to be a rough guess.
Chris@478:      */
Chris@478:     static bool useLogScale(std::vector<float> values);
Chris@478: 
Chris@224: };
Chris@224: 
Chris@224: #endif