annotate base/ZoomConstraint.h @ 1543:1f72a44f5638 zoom

More sensible limit
author Chris Cannam
date Fri, 28 Sep 2018 18:08:00 +0100
parents 5360f7aba189
children 05c3fbaec8ea
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@52 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@52 9 This program is free software; you can redistribute it and/or
Chris@52 10 modify it under the terms of the GNU General Public License as
Chris@52 11 published by the Free Software Foundation; either version 2 of the
Chris@52 12 License, or (at your option) any later version. See the file
Chris@52 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@1528 16 #ifndef SV_ZOOM_CONSTRAINT_H
Chris@1528 17 #define SV_ZOOM_CONSTRAINT_H
Chris@0 18
Chris@0 19 #include <stdlib.h>
Chris@0 20
Chris@1532 21 #include "ZoomLevel.h"
Chris@1324 22
Chris@0 23 /**
Chris@0 24 * ZoomConstraint is a simple interface that describes a limitation on
Chris@0 25 * the available zoom sizes for a view, for example based on cache
Chris@0 26 * strategy or a (processing) window-size limitation.
Chris@0 27 *
Chris@12 28 * The default ZoomConstraint imposes no actual constraint except for
Chris@12 29 * a nominal maximum.
Chris@0 30 */
Chris@0 31
Chris@0 32 class ZoomConstraint
Chris@0 33 {
Chris@0 34 public:
Chris@27 35 virtual ~ZoomConstraint() { }
Chris@27 36
Chris@0 37 enum RoundingDirection {
Chris@1429 38 RoundDown,
Chris@1429 39 RoundUp,
Chris@1429 40 RoundNearest
Chris@0 41 };
Chris@0 42
Chris@0 43 /**
Chris@1324 44 * Given an "ideal" zoom level (frames per pixel or pixels per
Chris@1324 45 * frame) for a given zoom level, return the nearest viable block
Chris@1324 46 * size for this constraint.
Chris@0 47 *
Chris@0 48 * For example, if a block size of 1523 frames per pixel is
Chris@0 49 * requested but the underlying model only supports value
Chris@0 50 * summaries at powers-of-two block sizes, return 1024 or 2048
Chris@0 51 * depending on the rounding direction supplied.
Chris@0 52 */
Chris@1324 53 virtual ZoomLevel getNearestZoomLevel(ZoomLevel requestedZoomLevel,
Chris@1324 54 RoundingDirection = RoundNearest)
Chris@1429 55 const
Chris@0 56 {
Chris@1324 57 if (getMaxZoomLevel() < requestedZoomLevel) return getMaxZoomLevel();
Chris@1324 58 else return requestedZoomLevel;
Chris@0 59 }
Chris@12 60
Chris@160 61 /**
Chris@1324 62 * Return the minimum zoom level within range for this constraint.
Chris@1324 63 * Individual views will probably want to limit this, for example
Chris@1324 64 * in order to ensure that at least one or two samples fit in the
Chris@1324 65 * current window size, or in order to save on interpolation cost.
Chris@1324 66 */
Chris@1324 67 virtual ZoomLevel getMinZoomLevel() const {
Chris@1543 68 return { ZoomLevel::PixelsPerFrame, 512 };
Chris@1324 69 }
Chris@1324 70
Chris@1324 71 /**
Chris@160 72 * Return the maximum zoom level within range for this constraint.
Chris@1102 73 * This is quite large -- individual views will probably want to
Chris@1102 74 * limit how far a user might reasonably zoom out based on other
Chris@1102 75 * factors such as the duration of the file.
Chris@160 76 */
Chris@1324 77 virtual ZoomLevel getMaxZoomLevel() const {
Chris@1324 78 return { ZoomLevel::FramesPerPixel, 4194304 }; // 2^22, arbitrarily
Chris@1324 79 }
Chris@0 80 };
Chris@0 81
Chris@0 82 #endif
Chris@0 83