1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * gmidimonitor main code.
6 * This file is part of gmidimonitor
8 * Copyright (C) 2005,2006,2007,2008,2011 Nedko Arnaudov <nedko@arnaudov.name>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23 *****************************************************************************/
30 #include <glib/gprintf.h>
33 #include <sys/types.h>
37 #include <lash/lash.h>
46 GtkBuilder
* g_builder
= NULL
;
47 GtkWidget
* g_main_window_ptr
;
49 gboolean g_midi_ignore
= FALSE
;
54 lash_client_t
* g_lashc
;
57 const char * g_note_names
[12] =
76 GtkWidget
* child_ptr
;
77 GtkListStore
* list_store_ptr
;
78 GtkTreeViewColumn
* column_ptr
;
79 GtkCellRenderer
* text_renderer_ptr
;
83 ui_filename
= path_get_data_filename("gmidimonitor.ui");
84 if (ui_filename
== NULL
)
86 g_warning("Cannot find UI description file.");
90 /* load the interface builder */
92 g_builder
= gtk_builder_new();
93 if (!gtk_builder_add_from_file (g_builder
, ui_filename
, &error
))
95 g_warning ("Couldn't load builder file: %s", error
->message
);
100 /* Retrieve the main window and connect the signals in the interface */
101 g_main_window_ptr
= GTK_WIDGET (gtk_builder_get_object (g_builder
, "main_window"));
102 gtk_builder_connect_signals(g_builder
, NULL
);
104 child_ptr
= GTK_WIDGET (gtk_builder_get_object (g_builder
, "list"));
106 text_renderer_ptr
= gtk_cell_renderer_text_new();
109 G_OBJECT(text_renderer_ptr
),
114 /* column_ptr = gtk_tree_view_column_new_with_attributes( */
116 /* text_renderer_ptr, */
117 /* "text", COL_TIME, */
120 /* gtk_tree_view_append_column( */
121 /* GTK_TREE_VIEW(child_ptr), */
124 column_ptr
= gtk_tree_view_column_new_with_attributes(
130 gtk_tree_view_append_column(
131 GTK_TREE_VIEW(child_ptr
),
134 column_ptr
= gtk_tree_view_column_new_with_attributes(
140 gtk_tree_view_append_column(
141 GTK_TREE_VIEW(child_ptr
),
144 gtk_widget_show_all(g_main_window_ptr
);
146 list_store_ptr
= gtk_list_store_new(
152 gtk_tree_view_set_model(GTK_TREE_VIEW(child_ptr
), GTK_TREE_MODEL(list_store_ptr
));
155 /* stop button toggle */
156 void on_button_stop_toggled(
157 GtkAction
* action_ptr
,
158 GtkWidget
* widget_ptr
)
160 GtkWidget
* child_ptr
;
162 child_ptr
= GTK_WIDGET (gtk_builder_get_object (g_builder
, "button_stop"));
164 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(child_ptr
)))
166 g_midi_ignore
= TRUE
;
170 g_midi_ignore
= FALSE
;
174 void on_clear_clicked
175 (GtkButton
*button
, gpointer user_data
)
177 gtk_list_store_clear(
179 gtk_tree_view_get_model(
181 gtk_builder_get_object(
190 process_lash_event(lash_event_t
* event_ptr
)
192 enum LASH_Event_Type type
;
195 type
= lash_event_get_type(event_ptr
);
196 str
= lash_event_get_string(event_ptr
);
201 g_warning("LASH_Quit received.\n");
206 case LASH_Restore_File
:
207 case LASH_Save_Data_Set
:
209 g_warning("LASH Event. Type = %u, string = \"%s\"\n",
211 (str
== NULL
)?"":str
);
216 process_lash_config(lash_config_t
* config_ptr
)
222 key
= lash_config_get_key(config_ptr
);
223 data
= lash_config_get_value(config_ptr
);
224 data_size
= lash_config_get_value_size(config_ptr
);
226 g_warning("LASH Config. Key = \"%s\"\n", key
);
229 /* process lash events callback */
231 process_lash_events(gpointer data
)
233 lash_event_t
* event_ptr
;
234 lash_config_t
* config_ptr
;
237 while ((event_ptr
= lash_get_event(g_lashc
)) != NULL
)
239 process_lash_event(event_ptr
);
240 lash_event_destroy(event_ptr
);
243 /* Process configs */
244 while ((config_ptr
= lash_get_config(g_lashc
)) != NULL
)
246 process_lash_config(config_ptr
);
247 lash_config_destroy(config_ptr
);
253 #endif /* #ifdef HAVE_LASH_1_0 */
264 main(int argc
, char *argv
[])
267 lash_event_t
* lash_event_ptr
;
269 GString
* client_name_str_ptr
;
272 gboolean want_any
= TRUE
;
274 gboolean want_jack
= FALSE
;
275 gboolean jack_enabled
= FALSE
;
278 gboolean want_alsa
= FALSE
;
279 gboolean alsa_enabled
= FALSE
;
281 gboolean io_enabled
= FALSE
;
284 for (i
= 1; i
< argc
; i
++)
287 if (strcmp(argv
[i
], "--jack") == 0)
295 if (strcmp(argv
[i
], "--alsa") == 0)
302 if (strcmp(argv
[i
], "--help") != 0)
304 fprintf(stderr
, "Unrecognized parameter \"%s\"\n", argv
[i
]);
309 ret
== 0 ? stdout
: stderr
,
327 gtk_init(&argc
, &argv
);
332 if (getenv("LADISH_APPNAME") != NULL
)
335 lash_extract_args(&argc
, &argv
),
338 LASH_PROTOCOL_VERSION
);
341 g_warning("Failed to connect to LASH. Session management will not occur.\n");
345 lash_event_ptr
= lash_event_new_with_type(LASH_Client_Name
);
346 lash_event_set_string(lash_event_ptr
, "GMIDImonitor");
347 lash_send_event(g_lashc
, lash_event_ptr
);
348 g_timeout_add(250, process_lash_events
, NULL
);
353 /* interface creation */
356 client_name_str_ptr
= g_string_new("");
357 g_string_printf(client_name_str_ptr
, "MIDI monitor");
362 if (want_jack
|| want_any
)
364 jack_enabled
= jack_init(client_name_str_ptr
->str
);
367 g_printf("JACK MIDI enabled\n");
378 if (want_alsa
|| (want_any
&& !io_enabled
))
380 alsa_enabled
= alsa_init(client_name_str_ptr
->str
);
383 g_printf("ALSA MIDI enabled\n");
395 signal(SIGINT
, &sigint_handler
);
396 signal(SIGTERM
, &sigint_handler
);