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@0
|
16 #ifndef _ZOOM_CONSTRAINT_H_
|
Chris@0
|
17 #define _ZOOM_CONSTRAINT_H_
|
Chris@0
|
18
|
Chris@0
|
19 #include <stdlib.h>
|
Chris@0
|
20
|
Chris@0
|
21 /**
|
Chris@0
|
22 * ZoomConstraint is a simple interface that describes a limitation on
|
Chris@0
|
23 * the available zoom sizes for a view, for example based on cache
|
Chris@0
|
24 * strategy or a (processing) window-size limitation.
|
Chris@0
|
25 *
|
Chris@12
|
26 * The default ZoomConstraint imposes no actual constraint except for
|
Chris@12
|
27 * a nominal maximum.
|
Chris@0
|
28 */
|
Chris@0
|
29
|
Chris@0
|
30 class ZoomConstraint
|
Chris@0
|
31 {
|
Chris@0
|
32 public:
|
Chris@27
|
33 virtual ~ZoomConstraint() { }
|
Chris@27
|
34
|
Chris@0
|
35 enum RoundingDirection {
|
Chris@0
|
36 RoundDown,
|
Chris@0
|
37 RoundUp,
|
Chris@0
|
38 RoundNearest
|
Chris@0
|
39 };
|
Chris@0
|
40
|
Chris@0
|
41 /**
|
Chris@0
|
42 * Given the "ideal" block size (frames per pixel) for a given
|
Chris@0
|
43 * zoom level, return the nearest viable block size for this
|
Chris@0
|
44 * constraint.
|
Chris@0
|
45 *
|
Chris@0
|
46 * For example, if a block size of 1523 frames per pixel is
|
Chris@0
|
47 * requested but the underlying model only supports value
|
Chris@0
|
48 * summaries at powers-of-two block sizes, return 1024 or 2048
|
Chris@0
|
49 * depending on the rounding direction supplied.
|
Chris@0
|
50 */
|
Chris@0
|
51 virtual size_t getNearestBlockSize(size_t requestedBlockSize,
|
Chris@0
|
52 RoundingDirection = RoundNearest)
|
Chris@0
|
53 const
|
Chris@0
|
54 {
|
Chris@12
|
55 if (requestedBlockSize > getMaxZoomLevel()) return getMaxZoomLevel();
|
Chris@12
|
56 else return requestedBlockSize;
|
Chris@0
|
57 }
|
Chris@12
|
58
|
Chris@12
|
59 virtual size_t getMaxZoomLevel() const { return 262144; }
|
Chris@0
|
60 };
|
Chris@0
|
61
|
Chris@0
|
62 #endif
|
Chris@0
|
63
|