waf: display warning if GUI frontend will not be built
[ladish.git] / gui / studio.c
blobecbd5310ee3ba0dcf4dc7e724ebbb3f2567389b0
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains the studio handling code
9 **************************************************************************
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "internal.h"
28 #include "studio.h"
29 #include "menu.h"
30 #include "../proxies/studio_proxy.h"
31 #include "statusbar.h"
32 #include "pixbuf.h"
33 #include "ask_dialog.h"
34 #include "jack.h"
36 /* File names */
37 #define STATUS_ICON_DOWN "status_down.png" /* temporary down during service restart */
38 #define STATUS_ICON_UNLOADED "status_unloaded.png"
39 #define STATUS_ICON_STARTED "status_started.png"
40 #define STATUS_ICON_STOPPED "status_stopped.png"
41 #define STATUS_ICON_WARNING "status_warning.png" /* xruns */
42 #define STATUS_ICON_ERROR "status_error.png" /* bad error */
44 static unsigned int g_studio_state = STUDIO_STATE_UNKNOWN;
45 static graph_view_handle g_studio_view = NULL;
47 unsigned int get_studio_state(void)
49 return g_studio_state;
52 void set_studio_state(unsigned int state)
54 g_studio_state = state;
57 bool studio_loaded(void)
59 return g_studio_view != NULL;
62 void create_studio_view(const char * name)
64 ASSERT(!studio_loaded());
66 if (!create_view(name, SERVICE_NAME, STUDIO_OBJECT_PATH, true, true, false, &g_studio_view))
68 log_error("create_view() failed for studio");
72 void destroy_studio_view(void)
74 ASSERT(studio_loaded());
76 destroy_view(g_studio_view);
77 g_studio_view = NULL;
80 bool studio_state_changed(char ** name_ptr_ptr)
82 const char * status;
83 const char * name;
84 char * buffer;
85 const char * status_image_path;
86 const char * tooltip;
87 GdkPixbuf * pixbuf;
89 menu_studio_state_changed(g_studio_state);
91 tooltip = NULL;
92 status_image_path = NULL;
94 switch (get_jack_state())
96 case JACK_STATE_NA:
97 tooltip = status = "JACK is sick";
98 status_image_path = STATUS_ICON_ERROR;
99 break;
100 case JACK_STATE_STOPPED:
101 status = "Stopped";
102 break;
103 case JACK_STATE_STARTED:
104 status = "xruns";
105 break;
106 default:
107 status = "???";
108 tooltip = "Internal error - unknown jack state";
109 status_image_path = STATUS_ICON_ERROR;
112 buffer = NULL;
114 switch (g_studio_state)
116 case STUDIO_STATE_NA:
117 name = "ladishd is down";
118 status_image_path = STATUS_ICON_DOWN;
119 break;
120 case STUDIO_STATE_SICK:
121 case STUDIO_STATE_UNKNOWN:
122 tooltip = name = "ladishd is sick";
123 status_image_path = STATUS_ICON_ERROR;
124 break;
125 case STUDIO_STATE_UNLOADED:
126 name = "No studio loaded";
127 status_image_path = STATUS_ICON_UNLOADED;
128 break;
129 case STUDIO_STATE_CRASHED:
130 status = "Crashed";
131 tooltip = "Crashed studio, save your work if you can and unload the studio";
132 status_image_path = STATUS_ICON_ERROR;
133 /* fall through */
134 case STUDIO_STATE_STOPPED:
135 case STUDIO_STATE_STARTED:
136 if (!studio_proxy_get_name(&buffer))
138 tooltip = "failed to get studio name";
139 log_error("%s", tooltip);
140 status_image_path = STATUS_ICON_ERROR;
142 else
144 name = buffer;
145 switch (g_studio_state)
147 case STUDIO_STATE_STARTED:
148 status_image_path = jack_xruns() ? STATUS_ICON_WARNING : STATUS_ICON_STARTED;
149 tooltip = "Studio is started";
150 break;
151 case STUDIO_STATE_STOPPED:
152 status_image_path = STATUS_ICON_STOPPED;
153 tooltip = "Studio is stopped";
154 break;
156 break;
158 default:
159 name = "???";
160 tooltip = "Internal error - unknown studio state";
161 status_image_path = STATUS_ICON_ERROR;
164 set_xrun_progress_bar_text(status);
166 set_studio_status_text(name);
168 if (status_image_path == NULL || (pixbuf = load_pixbuf(status_image_path)) == NULL)
170 gtk_image_set_from_stock(get_status_image(), GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_SMALL_TOOLBAR);
172 else
174 gtk_image_set_from_pixbuf(get_status_image(), pixbuf);
175 g_object_unref(pixbuf);
178 //gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(g_status_tool_item), tooltip);
180 if (get_jack_state() == JACK_STATE_STARTED)
182 update_jack_sample_rate();
184 else
186 clear_sample_rate_text();
187 clear_latency_text();
188 clear_dsp_load_text();
189 clear_xruns_text();
192 if (buffer == NULL)
194 return false;
197 if (name_ptr_ptr != NULL)
199 *name_ptr_ptr = buffer;
201 else
203 free(buffer);
206 return true;
209 void on_studio_started(void)
211 g_studio_state = STUDIO_STATE_STARTED;
212 studio_state_changed(NULL);
215 void on_studio_stopped(void)
217 g_studio_state = STUDIO_STATE_STOPPED;
218 studio_state_changed(NULL);
221 void on_studio_crashed(void)
223 g_studio_state = STUDIO_STATE_CRASHED;
224 studio_state_changed(NULL);
225 error_message_box("JACK crashed or stopped unexpectedly. Save your work, then unload and reload the studio.");
228 static void on_studio_renamed(const char * new_studio_name)
230 if (studio_loaded())
232 set_view_name(g_studio_view, new_studio_name);
233 set_studio_status_text(new_studio_name);
237 void menu_request_save_studio(void)
239 log_info("save studio request");
240 if (!studio_proxy_save())
242 error_message_box("Studio save failed, please inspect logs.");
246 void menu_request_save_as_studio(void)
248 char * new_name;
250 log_info("save as studio request");
252 if (name_dialog("Save studio as", "Studio name", "", &new_name))
254 if (!studio_proxy_save_as(new_name))
256 error_message_box("Saving of studio failed, please inspect logs.");
259 free(new_name);
263 void menu_request_start_studio(void)
265 log_info("start studio request");
266 if (!studio_proxy_start())
268 error_message_box("Studio start failed, please inspect logs.");
272 void menu_request_stop_studio(void)
274 log_info("stop studio request");
275 if (!studio_proxy_stop())
277 error_message_box("Studio stop failed, please inspect logs.");
281 void menu_request_unload_studio(void)
283 log_info("unload studio request");
284 if (!studio_proxy_unload())
286 error_message_box("Studio unload failed, please inspect logs.");
290 void menu_request_rename_studio(void)
292 char * new_name;
294 if (name_dialog("Rename studio", "Studio name", get_view_name(g_studio_view), &new_name))
296 if (!studio_proxy_rename(new_name))
298 error_message_box("Studio rename failed, please inspect logs.");
301 free(new_name);
305 void set_studio_callbacks(void)
307 studio_proxy_set_startstop_callbacks(on_studio_started, on_studio_stopped, on_studio_crashed);
308 studio_proxy_set_renamed_callback(on_studio_renamed);