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@1324: #ifndef SV_ZOOM_CONSTRAINT_H Chris@1324: #define SV_ZOOM_CONSTRAINT_H Chris@0: Chris@0: #include Chris@0: Chris@1324: #include "BaseTypes.h" Chris@1324: 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@1429: RoundDown, Chris@1429: RoundUp, Chris@1429: RoundNearest Chris@0: }; Chris@0: Chris@0: /** Chris@1324: * Given an "ideal" zoom level (frames per pixel or pixels per Chris@1324: * frame) for a given zoom level, return the nearest viable block Chris@1324: * size for this 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@1324: virtual ZoomLevel getNearestZoomLevel(ZoomLevel requestedZoomLevel, Chris@1324: RoundingDirection = RoundNearest) Chris@1429: const Chris@0: { Chris@1324: if (getMaxZoomLevel() < requestedZoomLevel) return getMaxZoomLevel(); Chris@1324: else return requestedZoomLevel; Chris@0: } Chris@12: Chris@160: /** Chris@1324: * Return the minimum zoom level within range for this constraint. Chris@1324: * Individual views will probably want to limit this, for example Chris@1324: * in order to ensure that at least one or two samples fit in the Chris@1324: * current window size, or in order to save on interpolation cost. Chris@1324: */ Chris@1324: virtual ZoomLevel getMinZoomLevel() const { Chris@1324: return { ZoomLevel::PixelsPerFrame, 16384 }; Chris@1324: } Chris@1324: Chris@1324: /** Chris@160: * Return the maximum zoom level within range for this constraint. Chris@1102: * This is quite large -- individual views will probably want to Chris@1102: * limit how far a user might reasonably zoom out based on other Chris@1102: * factors such as the duration of the file. Chris@160: */ Chris@1324: virtual ZoomLevel getMaxZoomLevel() const { Chris@1324: return { ZoomLevel::FramesPerPixel, 4194304 }; // 2^22, arbitrarily Chris@1324: } Chris@0: }; Chris@0: Chris@0: #endif Chris@0: