Reverse the drawing of DSP indicator to match other displays.
[ardour.git] / gtk2_ardour / dsp_load_indicator.cc
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
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.
13  *
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #include "ardour_ui.h"
20 #include "dsp_load_indicator.h"
21
22 #include "ardour/audioengine.h"
23
24 #include "pbd/i18n.h"
25
26 #define PADDING 3
27
28 DspLoadIndicator::DspLoadIndicator ()
29         : ArdourGauge ("00.0%")
30         , _dsp_load (0)
31         , _xrun_count (0)
32         , _xrun_while_recording (false)
33 {
34 }
35
36 void
37 DspLoadIndicator::set_xrun_count (const unsigned int xruns)
38 {
39         if (xruns == _xrun_count) {
40                 return;
41         }
42         _xrun_count = xruns;
43         update ();
44 }
45
46 void
47 DspLoadIndicator::set_dsp_load (const double load)
48 {
49         if (load == _dsp_load) {
50                 return;
51         }
52         _dsp_load = load;
53
54         char buf[64];
55         snprintf (buf, sizeof (buf), "DSP %.1f%%", _dsp_load);
56         update (std::string (buf));
57 }
58
59 float
60 DspLoadIndicator::level () const {
61         return (100.0-_dsp_load) / 100.f;
62 }
63
64 bool
65 DspLoadIndicator::alert () const
66 {
67         bool ret = false;
68         
69         //xrun while recording
70         ret |= _xrun_while_recording;
71
72         //engine OFF
73         ret |= !ARDOUR::AudioEngine::instance()->running();
74         
75         return ret;
76 }
77
78 ArdourGauge::Status
79 DspLoadIndicator::indicator () const
80 {
81         if (_dsp_load > 90) {
82                 return ArdourGauge::Level_CRIT;
83         } else if (_dsp_load > 80) {
84                 return ArdourGauge::Level_WARN;
85         } else {
86                 return ArdourGauge::Level_OK;
87         }
88 }
89
90 std::string
91 DspLoadIndicator::tooltip_text ()
92 {
93         char buf[64];
94
95         //xruns
96         if (_xrun_count == UINT_MAX) {
97                 snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: ?"), _dsp_load);
98         } else if (_xrun_count > 9999) {
99                 snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: >10k"), _dsp_load);
100         } else {
101                 snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: %u"), _dsp_load, _xrun_count);
102         }
103
104         return buf;
105 }
106
107 bool
108 DspLoadIndicator::on_button_release_event (GdkEventButton *ev)
109 {
110         ARDOUR::Session* s = ARDOUR_UI::instance ()->the_session ();
111         if (s) {
112                 s->reset_xrun_count ();
113                 _xrun_while_recording = false;
114         }
115         return true;
116 }