Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@0: 
Chris@0: /*
Chris@52:     Sonic Visualiser
Chris@52:     An audio file viewer and annotation editor.
Chris@52:     Centre for Digital Music, Queen Mary, University of London.
Chris@52:     This file copyright 2006 Chris Cannam.
Chris@0:     
Chris@52:     This program is free software; you can redistribute it and/or
Chris@52:     modify it under the terms of the GNU General Public License as
Chris@52:     published by the Free Software Foundation; either version 2 of the
Chris@52:     License, or (at your option) any later version.  See the file
Chris@52:     COPYING included with this distribution for more information.
Chris@0: */
Chris@0: 
Chris@0: #ifndef _ZOOM_CONSTRAINT_H_
Chris@0: #define _ZOOM_CONSTRAINT_H_
Chris@0: 
Chris@0: #include <stdlib.h>
Chris@0: 
Chris@0: /**
Chris@0:  * ZoomConstraint is a simple interface that describes a limitation on
Chris@0:  * the available zoom sizes for a view, for example based on cache
Chris@0:  * strategy or a (processing) window-size limitation.
Chris@0:  *
Chris@12:  * The default ZoomConstraint imposes no actual constraint except for
Chris@12:  * a nominal maximum.
Chris@0:  */
Chris@0: 
Chris@0: class ZoomConstraint
Chris@0: {
Chris@0: public:
Chris@27:     virtual ~ZoomConstraint() { }
Chris@27: 
Chris@0:     enum RoundingDirection {
Chris@0: 	RoundDown,
Chris@0: 	RoundUp,
Chris@0: 	RoundNearest
Chris@0:     };
Chris@0: 
Chris@0:     /**
Chris@0:      * Given the "ideal" block size (frames per pixel) for a given
Chris@0:      * zoom level, return the nearest viable block size for this
Chris@0:      * constraint.
Chris@0:      *
Chris@0:      * For example, if a block size of 1523 frames per pixel is
Chris@0:      * requested but the underlying model only supports value
Chris@0:      * summaries at powers-of-two block sizes, return 1024 or 2048
Chris@0:      * depending on the rounding direction supplied.
Chris@0:      */
Chris@928:     virtual int getNearestBlockSize(int requestedBlockSize,
Chris@0: 				       RoundingDirection = RoundNearest)
Chris@0: 	const
Chris@0:     {
Chris@12: 	if (requestedBlockSize > getMaxZoomLevel()) return getMaxZoomLevel();
Chris@12: 	else return requestedBlockSize;
Chris@0:     }
Chris@12: 
Chris@160:     /**
Chris@160:      * Return the maximum zoom level within range for this constraint.
Chris@160:      */
Chris@928:     virtual int getMaxZoomLevel() const { return 262144; }
Chris@0: };
Chris@0: 
Chris@0: #endif
Chris@0: