Move panner bypass state up to the PannerShell so that it is preserved even when...
[ardour2.git] / libs / ardour / progress.cc
blob0822b8e616c56130441f555f5dbfc860cc66db34
1 /*
2 Copyright (C) 2010 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <cassert>
21 #include <iostream>
22 #include "ardour/progress.h"
24 using namespace std;
26 ARDOUR::Progress::Progress ()
27 : _cancelled (false)
29 descend (1);
32 /** Descend down one level in terms of progress reporting; e.g. if
33 * there is a task which is split up into N subtasks, each of which
34 * report their progress from 0 to 100%, call descend() before executing
35 * each subtask, and ascend() afterwards to ensure that overall progress
36 * is reported correctly.
38 * @param p Percentage (from 0 to 1) of the current task to allocate to the subtask.
40 void
41 ARDOUR::Progress::descend (float a)
43 _stack.push_back (Level (a));
46 void
47 ARDOUR::Progress::ascend ()
49 assert (!_stack.empty ());
50 float const a = _stack.back().allocation;
51 _stack.pop_back ();
52 _stack.back().normalised += a;
55 /** Set the progress of the current task.
56 * @param p Progress (from 0 to 1)
58 void
59 ARDOUR::Progress::set_progress (float p)
61 assert (!_stack.empty ());
63 _stack.back().normalised = p;
65 float overall = 0;
66 float factor = 1;
67 for (list<Level>::iterator i = _stack.begin(); i != _stack.end(); ++i) {
68 factor *= i->allocation;
69 overall += i->normalised * factor;
72 set_overall_progress (overall);
75 void
76 ARDOUR::Progress::cancel ()
78 _cancelled = true;
81 bool
82 ARDOUR::Progress::cancelled () const
84 return _cancelled;