annotate base/ZoomConstraint.h @ 1886:f803d3c33f76 tip

Switch off copious debug in soft synth driving
author Chris Cannam
date Fri, 14 Aug 2020 10:44:44 +0100
parents 05c3fbaec8ea
children
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@1552 57 // canonicalise
Chris@1552 58 if (requestedZoomLevel.level == 1) {
Chris@1552 59 requestedZoomLevel.zone = ZoomLevel::FramesPerPixel;
Chris@1552 60 }
Chris@1324 61 if (getMaxZoomLevel() < requestedZoomLevel) return getMaxZoomLevel();
Chris@1324 62 else return requestedZoomLevel;
Chris@0 63 }
Chris@12 64
Chris@160 65 /**
Chris@1324 66 * Return the minimum zoom level within range for this constraint.
Chris@1324 67 * Individual views will probably want to limit this, for example
Chris@1324 68 * in order to ensure that at least one or two samples fit in the
Chris@1324 69 * current window size, or in order to save on interpolation cost.
Chris@1324 70 */
Chris@1324 71 virtual ZoomLevel getMinZoomLevel() const {
Chris@1543 72 return { ZoomLevel::PixelsPerFrame, 512 };
Chris@1324 73 }
Chris@1324 74
Chris@1324 75 /**
Chris@160 76 * Return the maximum zoom level within range for this constraint.
Chris@1102 77 * This is quite large -- individual views will probably want to
Chris@1102 78 * limit how far a user might reasonably zoom out based on other
Chris@1102 79 * factors such as the duration of the file.
Chris@160 80 */
Chris@1324 81 virtual ZoomLevel getMaxZoomLevel() const {
Chris@1324 82 return { ZoomLevel::FramesPerPixel, 4194304 }; // 2^22, arbitrarily
Chris@1324 83 }
Chris@0 84 };
Chris@0 85
Chris@0 86 #endif
Chris@0 87