root/gui/studio.c @ e9ae6c1be87b932573169381bb665931d22bc379

Revision e9ae6c1be87b932573169381bb665931d22bc379, 7.4 KB (checked in by Nedko Arnaudov <nedko@…>, 21 months ago)

fix another compiler warning

../gui/studio.c:86:16: error: variable 'tooltip' set but not used [-Werror=unused-but-set-variable]

  • Property mode set to 100644
Line 
1/* -*- Mode: C ; c-basic-offset: 2 -*- */
2/*
3 * LADI Session Handler (ladish)
4 *
5 * Copyright (C) 2010, 2011 Nedko Arnaudov <nedko@arnaudov.name>
6 *
7 **************************************************************************
8 * This file contains the studio handling code
9 **************************************************************************
10 *
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.
15 *
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.
20 *
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.
25 */
26
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"
35
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 */
43
44static unsigned int g_studio_state = STUDIO_STATE_UNKNOWN;
45static graph_view_handle g_studio_view = NULL;
46
47unsigned int get_studio_state(void)
48{
49  return g_studio_state;
50}
51
52void set_studio_state(unsigned int state)
53{
54  g_studio_state = state;
55}
56
57bool studio_loaded(void)
58{
59  return g_studio_view != NULL;
60}
61
62void create_studio_view(const char * name)
63{
64  ASSERT(!studio_loaded());
65
66  if (!create_view(name, SERVICE_NAME, STUDIO_OBJECT_PATH, true, true, true, false, &g_studio_view))
67  {
68    log_error("create_view() failed for studio");
69  }
70}
71
72void destroy_studio_view(void)
73{
74  ASSERT(studio_loaded());
75
76  destroy_view(g_studio_view);
77  g_studio_view = NULL;
78}
79
80bool studio_state_changed(char ** name_ptr_ptr)
81{
82  const char * status;
83  const char * name;
84  char * buffer;
85  const char * status_image_path;
86  //const char * tooltip;
87  GdkPixbuf * pixbuf;
88
89  menu_studio_state_changed(g_studio_state);
90
91  //tooltip = NULL;
92  status_image_path = NULL;
93
94  switch (get_jack_state())
95  {
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;
110  }
111
112  buffer = NULL;
113
114  switch (g_studio_state)
115  {
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))
137    {
138      //tooltip = _("failed to get studio name");
139      log_error("failed to get studio name");
140      status_image_path = STATUS_ICON_ERROR;
141    }
142    else
143    {
144      name = buffer;
145      switch (g_studio_state)
146      {
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;
155      }
156      break;
157    }
158  default:
159    name = "???";
160    //tooltip = _("Internal error - unknown studio state");
161    status_image_path = STATUS_ICON_ERROR;
162  }
163
164  set_xrun_progress_bar_text(status);
165
166  set_studio_status_text(name);
167
168  if (status_image_path == NULL || (pixbuf = load_pixbuf(status_image_path)) == NULL)
169  {
170    gtk_image_set_from_stock(get_status_image(), GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_SMALL_TOOLBAR);
171  }
172  else
173  {
174    gtk_image_set_from_pixbuf(get_status_image(), pixbuf);
175    g_object_unref(pixbuf);
176  }
177
178  //gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(g_status_tool_item), tooltip);
179
180  if (get_jack_state() == JACK_STATE_STARTED)
181  {
182    update_jack_sample_rate();
183  }
184  else
185  {
186    clear_sample_rate_text();
187    clear_latency_text();
188    clear_dsp_load_text();
189    clear_xruns_text();
190  }
191
192  if (buffer == NULL)
193  {
194    return false;
195  }
196
197  if (name_ptr_ptr != NULL)
198  {
199    *name_ptr_ptr = buffer;
200  }
201  else
202  {
203    free(buffer);
204  }
205
206  return true;
207}
208
209void on_studio_started(void)
210{
211  g_studio_state = STUDIO_STATE_STARTED;
212  studio_state_changed(NULL);
213}
214
215void on_studio_stopped(void)
216{
217  g_studio_state = STUDIO_STATE_STOPPED;
218  studio_state_changed(NULL);
219}
220
221void on_studio_crashed(void)
222{
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."));
226}
227
228static void on_studio_renamed(const char * new_studio_name)
229{
230  if (studio_loaded())
231  {
232    set_view_name(g_studio_view, new_studio_name);
233    set_studio_status_text(new_studio_name);
234  }
235}
236
237void menu_request_save_studio(void)
238{
239  log_info("save studio request");
240  if (!studio_proxy_save())
241  {
242    error_message_box(_("Studio save failed, please inspect logs."));
243  }
244}
245
246void menu_request_save_as_studio(void)
247{
248  char * new_name;
249
250  log_info("save as studio request");
251
252  if (name_dialog(_("Save studio as"), _("Studio name"), "", &new_name))
253  {
254    if (!studio_proxy_save_as(new_name))
255    {
256      error_message_box(_("Saving of studio failed, please inspect logs."));
257    }
258
259    free(new_name);
260  }
261}
262
263void menu_request_start_studio(void)
264{
265  log_info("start studio request");
266  if (!studio_proxy_start())
267  {
268    error_message_box(_("Studio start failed, please inspect logs."));
269  }
270}
271
272void menu_request_stop_studio(void)
273{
274  log_info("stop studio request");
275  if (!studio_proxy_stop())
276  {
277    error_message_box(_("Studio stop failed, please inspect logs."));
278  }
279}
280
281void menu_request_unload_studio(void)
282{
283  log_info("unload studio request");
284  if (!studio_proxy_unload())
285  {
286    error_message_box(_("Studio unload failed, please inspect logs."));
287  }
288}
289
290void menu_request_rename_studio(void)
291{
292  char * new_name;
293
294  if (name_dialog(_("Rename studio"), _("Studio name"), get_view_name(g_studio_view), &new_name))
295  {
296    if (!studio_proxy_rename(new_name))
297    {
298      error_message_box(_("Studio rename failed, please inspect logs."));
299    }
300
301    free(new_name);
302  }
303}
304
305void set_studio_callbacks(void)
306{
307  studio_proxy_set_startstop_callbacks(on_studio_started, on_studio_stopped, on_studio_crashed);
308  studio_proxy_set_renamed_callback(on_studio_renamed);
309}
Note: See TracBrowser for help on using the browser.