Shuffle order of items in status bar; change behavior per oofus on irc.
[ardour.git] / gtk2_ardour / dsp_load_gauge.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_gauge.h"
21
22 #include "ardour/audioengine.h"
23
24 #include "pbd/i18n.h"
25
26 #define PADDING 3
27
28 DspLoadGauge::DspLoadGauge ()
29         : ArdourGauge ("00.0%")
30         , _dsp_load (0)
31         , _xrun_count (0)
32         , _xrun_while_recording (false)
33 {
34 }
35
36 void
37 DspLoadGauge::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 DspLoadGauge::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         if (_xrun_count > 0) {
56                 snprintf (buf, sizeof (buf), "DSP: %.1f%% (%d)", _dsp_load, _xrun_count);
57         } else {
58                 snprintf (buf, sizeof (buf), "DSP: %.1f%%", _dsp_load);
59         }
60         update (std::string (buf));
61 }
62
63 float
64 DspLoadGauge::level () const {
65         return (_dsp_load / 100.f);
66 }
67
68 bool
69 DspLoadGauge::alert () const
70 {
71         bool ret = false;
72         
73         //xrun while recording
74         ret |= _xrun_while_recording;
75
76         //engine OFF
77         ret |= !ARDOUR::AudioEngine::instance()->running();
78         
79         return ret;
80 }
81
82 ArdourGauge::Status
83 DspLoadGauge::indicator () const
84 {
85         if (_dsp_load > 90) {
86                 return ArdourGauge::Level_CRIT;
87         } else if (_dsp_load > 75) {
88                 return ArdourGauge::Level_WARN;
89         } else {
90                 return ArdourGauge::Level_OK;
91         }
92 }
93
94 std::string
95 DspLoadGauge::tooltip_text ()
96 {
97         char buf[64];
98
99         //xruns
100         if (_xrun_count == UINT_MAX) {
101                 snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: ?\nClick to clear xruns."), _dsp_load);
102         } else if (_xrun_count > 9999) {
103                 snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: >10k\nClick to clear xruns."), _dsp_load);
104         } else {
105                 snprintf (buf, sizeof (buf), _("DSP: %.1f%% X: %u\nClick to clear xruns."), _dsp_load, _xrun_count);
106         }
107
108         return buf;
109 }
110
111 bool
112 DspLoadGauge::on_button_release_event (GdkEventButton *ev)
113 {
114         ARDOUR::Session* s = ARDOUR_UI::instance ()->the_session ();
115         if (s) {
116                 s->reset_xrun_count ();
117                 _xrun_while_recording = false;
118                 queue_draw();
119         }
120         return true;
121 }