Reenable the correct sort column and type when redisplaying regions
[ardour.git] / gtk2_ardour / ardour_ui_engine.cc
1 /*
2  * Copyright (C) 2005-2007 Doug McLain <doug@nostar.net>
3  * Copyright (C) 2005-2017 Tim Mayberry <mojofunk@gmail.com>
4  * Copyright (C) 2005-2019 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
6  * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
7  * Copyright (C) 2006-2015 David Robillard <d@drobilla.net>
8  * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
9  * Copyright (C) 2008-2010 Sakari Bergen <sakari.bergen@beatwaves.net>
10  * Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
11  * Copyright (C) 2013-2015 Colin Fletcher <colin.m.fletcher@googlemail.com>
12  * Copyright (C) 2013-2016 John Emmas <john@creativepost.co.uk>
13  * Copyright (C) 2013-2016 Nick Mainsbridge <mainsbridge@gmail.com>
14  * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
15  * Copyright (C) 2015 AndrĂ© Nusser <andre.nusser@googlemail.com>
16  * Copyright (C) 2016-2018 Len Ovens <len@ovenwerks.net>
17  * Copyright (C) 2017 Johannes Mueller <github@johannes-mueller.org>
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 2 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License along
30  * with this program; if not, write to the Free Software Foundation, Inc.,
31  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32  */
33
34 #ifdef WAF_BUILD
35 #include "gtk2ardour-config.h"
36 #include "gtk2ardour-version.h"
37 #endif
38
39 #include "pbd/openuri.h"
40
41 #include "ardour/audioengine.h"
42
43 #include "ardour_message.h"
44 #include "ardour_ui.h"
45 #include "engine_dialog.h"
46 #include "gui_thread.h"
47
48 #include "pbd/i18n.h"
49
50 using namespace ARDOUR;
51 using namespace PBD;
52 using namespace Gtkmm2ext;
53 using namespace ArdourWidgets;
54 using namespace Gtk;
55 using namespace std;
56
57 void
58 ARDOUR_UI::audioengine_became_silent ()
59 {
60         ArdourMessageDialog msg (string_compose (_("This is a free/demo copy of %1. It has just switched to silent mode."), PROGRAM_NAME),
61                                  true,
62                                  Gtk::MESSAGE_WARNING,
63                                  Gtk::BUTTONS_NONE,
64                                  true);
65
66         msg.set_title (string_compose (_("%1 is now silent"), PROGRAM_NAME));
67
68         Gtk::Label pay_label (string_compose (_("Please consider paying for a copy of %1 - you can pay whatever you want."), PROGRAM_NAME));
69         Gtk::Label subscribe_label (_("Better yet become a subscriber - subscriptions start at US$1 per month."));
70         Gtk::Button pay_button (_("Pay for a copy (via the web)"));
71         Gtk::Button subscribe_button (_("Become a subscriber (via the web)"));
72         Gtk::HBox pay_button_box;
73         Gtk::HBox subscribe_button_box;
74
75         pay_button_box.pack_start (pay_button, true, false);
76         subscribe_button_box.pack_start (subscribe_button, true, false);
77
78         bool (*openuri)(const char*) = PBD::open_uri; /* this forces selection of the const char* variant of PBD::open_uri(), which we need to avoid ambiguity below */
79
80         pay_button.signal_clicked().connect (sigc::hide_return (sigc::bind (sigc::ptr_fun (openuri), (const char*) "https://ardour.org/download")));
81         subscribe_button.signal_clicked().connect (sigc::hide_return (sigc::bind (sigc::ptr_fun (openuri), (const char*) "https://community.ardour.org/s/subscribe")));
82
83         msg.get_vbox()->pack_start (pay_label);
84         msg.get_vbox()->pack_start (pay_button_box);
85         msg.get_vbox()->pack_start (subscribe_label);
86         msg.get_vbox()->pack_start (subscribe_button_box);
87
88         msg.get_vbox()->show_all ();
89
90         msg.add_button (_("Remain silent"), Gtk::RESPONSE_CANCEL);
91         msg.add_button (_("Save and quit"), Gtk::RESPONSE_NO);
92         msg.add_button (_("Give me more time"), Gtk::RESPONSE_YES);
93
94         int r = msg.run ();
95
96         switch (r) {
97         case Gtk::RESPONSE_YES:
98                 AudioEngine::instance()->reset_silence_countdown ();
99                 break;
100
101         case Gtk::RESPONSE_NO:
102                 /* save and quit */
103                 save_state_canfail ("");
104                 exit (EXIT_SUCCESS);
105                 break;
106
107         case Gtk::RESPONSE_CANCEL:
108         default:
109                 /* don't reset, save session and exit */
110                 break;
111         }
112 }
113
114 void
115 ARDOUR_UI::create_xrun_marker (samplepos_t where)
116 {
117         if (_session) {
118                 Location *location = new Location (*_session, where, where, _("xrun"), Location::IsMark, 0);
119                 _session->locations()->add (location);
120         }
121 }
122
123 void
124 ARDOUR_UI::halt_on_xrun_message ()
125 {
126         cerr << "HALT on xrun\n";
127         ArdourMessageDialog msg (_main_window, _("Recording was stopped because your system could not keep up."));
128         msg.run ();
129 }
130
131 void
132 ARDOUR_UI::xrun_handler (samplepos_t where)
133 {
134         if (!_session) {
135                 return;
136         }
137
138         ENSURE_GUI_THREAD (*this, &ARDOUR_UI::xrun_handler, where)
139
140         if (_session && Config->get_create_xrun_marker() && _session->actively_recording()) {
141                 create_xrun_marker(where);
142         }
143
144         if (_session && Config->get_stop_recording_on_xrun() && _session->actively_recording()) {
145                 halt_on_xrun_message ();
146         }
147 }
148
149 bool
150 ARDOUR_UI::check_audioengine (Gtk::Window& parent)
151 {
152         if (!AudioEngine::instance()->running()) {
153                 ArdourMessageDialog msg (parent, string_compose (
154                                                  _("%1 is not connected to any audio backend.\n"
155                                                  "You cannot open or close sessions in this condition"),
156                                                  PROGRAM_NAME));
157                 msg.run ();
158                 return false;
159         }
160         return true;
161 }