2010-09-19 21:01:53 -04:00
|
|
|
/*
|
2019-08-02 22:01:25 -04:00
|
|
|
* Copyright (C) 2010 Carl Hetherington <carl@carlh.net>
|
2023-05-18 15:02:22 -04:00
|
|
|
* Copyright (C) 2023 Robin Gareus <robin@gareus.org>
|
2019-08-02 22:01:25 -04:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2010-09-19 21:01:53 -04:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <iostream>
|
2023-05-18 15:02:22 -04:00
|
|
|
#include "pbd/progress.h"
|
2010-09-19 21:01:53 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2023-05-18 15:02:22 -04:00
|
|
|
PBD::Progress::Progress ()
|
2010-10-28 13:09:32 -04:00
|
|
|
: _cancelled (false)
|
2010-09-19 21:01:53 -04:00
|
|
|
{
|
|
|
|
descend (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Descend down one level in terms of progress reporting; e.g. if
|
|
|
|
* there is a task which is split up into N subtasks, each of which
|
|
|
|
* report their progress from 0 to 100%, call descend() before executing
|
|
|
|
* each subtask, and ascend() afterwards to ensure that overall progress
|
|
|
|
* is reported correctly.
|
|
|
|
*
|
|
|
|
* @param p Percentage (from 0 to 1) of the current task to allocate to the subtask.
|
|
|
|
*/
|
|
|
|
void
|
2023-05-18 15:02:22 -04:00
|
|
|
PBD::Progress::descend (float a)
|
2010-09-19 21:01:53 -04:00
|
|
|
{
|
|
|
|
_stack.push_back (Level (a));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-05-18 15:02:22 -04:00
|
|
|
PBD::Progress::ascend ()
|
2010-09-19 21:01:53 -04:00
|
|
|
{
|
|
|
|
assert (!_stack.empty ());
|
2010-10-28 13:02:29 -04:00
|
|
|
float const a = _stack.back().allocation;
|
2010-09-19 21:01:53 -04:00
|
|
|
_stack.pop_back ();
|
2010-10-28 13:02:29 -04:00
|
|
|
_stack.back().normalised += a;
|
2010-09-19 21:01:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Set the progress of the current task.
|
|
|
|
* @param p Progress (from 0 to 1)
|
|
|
|
*/
|
|
|
|
void
|
2023-05-18 15:02:22 -04:00
|
|
|
PBD::Progress::set_progress (float p)
|
2010-09-19 21:01:53 -04:00
|
|
|
{
|
|
|
|
assert (!_stack.empty ());
|
|
|
|
|
|
|
|
_stack.back().normalised = p;
|
|
|
|
|
|
|
|
float overall = 0;
|
|
|
|
float factor = 1;
|
|
|
|
for (list<Level>::iterator i = _stack.begin(); i != _stack.end(); ++i) {
|
|
|
|
factor *= i->allocation;
|
|
|
|
overall += i->normalised * factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_overall_progress (overall);
|
|
|
|
}
|
2010-10-28 13:09:32 -04:00
|
|
|
|
|
|
|
void
|
2023-05-18 15:02:22 -04:00
|
|
|
PBD::Progress::cancel ()
|
2010-10-28 13:09:32 -04:00
|
|
|
{
|
|
|
|
_cancelled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2023-05-18 15:02:22 -04:00
|
|
|
PBD::Progress::cancelled () const
|
2010-10-28 13:09:32 -04:00
|
|
|
{
|
|
|
|
return _cancelled;
|
|
|
|
}
|