Mercurial > hg > svcore
annotate data/model/PowerOfTwoZoomConstraint.cpp @ 211:e2bbb58e6df6
Several changes related to referring to remote URLs for sessions and files:
* Pull file dialog wrapper functions out from MainWindow into FileFinder
* If a file referred to in a session is not found at its expected location,
try a few other alternatives (same location as the session file or same
location as the last audio file) before asking the user to locate it
* Allow user to give a URL when locating an audio file, not just locate on
the filesystem
* Make wave file models remember the "original" location (e.g. URL) of
the audio file, not just the actual location from which the data was
loaded (e.g. local copy of that URL) -- when saving a session, use the
original location so as not to refer to a temporary file
* Clean up incompletely-downloaded local copies of files
author | Chris Cannam |
---|---|
date | Thu, 11 Jan 2007 13:29:58 +0000 |
parents | 3a13b0d4934e |
children | 59e7fe1b1003 |
rev | line source |
---|---|
Chris@147 | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ |
Chris@147 | 2 |
Chris@147 | 3 /* |
Chris@147 | 4 Sonic Visualiser |
Chris@147 | 5 An audio file viewer and annotation editor. |
Chris@147 | 6 Centre for Digital Music, Queen Mary, University of London. |
Chris@147 | 7 This file copyright 2006 Chris Cannam. |
Chris@147 | 8 |
Chris@147 | 9 This program is free software; you can redistribute it and/or |
Chris@147 | 10 modify it under the terms of the GNU General Public License as |
Chris@147 | 11 published by the Free Software Foundation; either version 2 of the |
Chris@147 | 12 License, or (at your option) any later version. See the file |
Chris@147 | 13 COPYING included with this distribution for more information. |
Chris@147 | 14 */ |
Chris@147 | 15 |
Chris@147 | 16 #include "PowerOfTwoZoomConstraint.h" |
Chris@147 | 17 |
Chris@147 | 18 size_t |
Chris@147 | 19 PowerOfTwoZoomConstraint::getNearestBlockSize(size_t req, |
Chris@147 | 20 RoundingDirection dir) const |
Chris@147 | 21 { |
Chris@147 | 22 size_t result = 0; |
Chris@147 | 23 |
Chris@147 | 24 for (size_t bs = 1; ; bs *= 2) { |
Chris@147 | 25 if (bs >= req) { |
Chris@147 | 26 if (dir == RoundNearest) { |
Chris@147 | 27 if (bs - req < req - bs/2) { |
Chris@147 | 28 result = bs; |
Chris@147 | 29 break; |
Chris@147 | 30 } else { |
Chris@147 | 31 result = bs/2; |
Chris@147 | 32 break; |
Chris@147 | 33 } |
Chris@147 | 34 } else if (dir == RoundDown) { |
Chris@147 | 35 result = bs/2; |
Chris@147 | 36 break; |
Chris@147 | 37 } else { |
Chris@147 | 38 result = bs; |
Chris@147 | 39 break; |
Chris@147 | 40 } |
Chris@147 | 41 } |
Chris@147 | 42 } |
Chris@147 | 43 |
Chris@147 | 44 if (result > getMaxZoomLevel()) result = getMaxZoomLevel(); |
Chris@147 | 45 return result; |
Chris@147 | 46 } |
Chris@147 | 47 |