summaryrefslogtreecommitdiff
path: root/gtk2_ardour/disk_space_gauge.cc
blob: acc2525b7f0f707f936b7b2ca59192fb20863535 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
 *
 * 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.
 */

#include "ardour_ui.h"
#include "dsp_load_gauge.h"

#include "pbd/i18n.h"

#define PADDING 3

DiskSpaceGauge::DiskSpaceGauge ()
	: ArdourGauge (" ")
	, _sec (12*60*60)
{
}

void
DiskSpaceGauge::set_available_disk_sec (float sec)
{
	if (_sec == sec) {
		return;
	}
	_sec = sec;

	if (sec < 0) {
		update (_("N/A"));
		return;
	}

	char buf[64];
	if (_sec > 86400) {
		update (_("Rec: >24h"));
		return;
	} else if (_sec > 32400 /* 9 hours */) {
		snprintf (buf, sizeof (buf), "Rec: %.0fh", _sec / 3600.f);
	} else if (_sec > 5940 /* 99 mins */) {
		snprintf (buf, sizeof (buf), "Rec: %.1fh", _sec / 3600.f);
	} else {
		snprintf (buf, sizeof (buf), "Rec: %.0fm", _sec / 60.f);
	}
	update (std::string (buf));
}

float
DiskSpaceGauge::level () const {
	static const float six_hours = 6.f * 3600.f;
	if (_sec < 0) return 0.0;
	if (_sec > six_hours) return 0.0;
	return (1.0 - (_sec / six_hours));
}

bool
DiskSpaceGauge::alert () const
{
	return _sec >=0 && _sec < 60.f * 10.f;
}

ArdourGauge::Status
DiskSpaceGauge::indicator () const
{
	if (_sec > 3600.f) {
		return ArdourGauge::Level_OK;
	} else if (_sec > 1800.f) {
		return ArdourGauge::Level_WARN;
	}
	return ArdourGauge::Level_CRIT;
}

std::string
DiskSpaceGauge::tooltip_text ()
{
	if (_sec < 0) {
		return _("Unkown");
	}

	int sec = floor (_sec);
	char buf[64];
	int hrs  = sec / 3600;
	int mins = (sec / 60) % 60;
	int secs = sec % 60;

	snprintf (buf, sizeof(buf), _("%02dh:%02dm:%02ds"), hrs, mins, secs);
	return _("Available capture disk-space: ") + std::string (buf);
}