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 *****************************************************************************/
29 #include <glib/gprintf.h>
32 #include <sys/types.h>
36 #include <lash/lash.h>
46 GtkWidget
* g_main_window_ptr
;
48 gboolean g_midi_ignore
= FALSE
;
53 lash_client_t
* g_lashc
;
56 const char * g_note_names
[12] =
75 GtkWidget
* child_ptr
;
76 GtkListStore
* list_store_ptr
;
77 GtkTreeViewColumn
* column_ptr
;
78 GtkCellRenderer
* text_renderer_ptr
;
80 g_main_window_ptr
= construct_glade_widget("main_window");
82 child_ptr
= get_glade_widget_child(g_main_window_ptr
, "list");
84 text_renderer_ptr
= gtk_cell_renderer_text_new();
87 G_OBJECT(text_renderer_ptr
),
92 /* column_ptr = gtk_tree_view_column_new_with_attributes( */
94 /* text_renderer_ptr, */
95 /* "text", COL_TIME, */
98 /* gtk_tree_view_append_column( */
99 /* GTK_TREE_VIEW(child_ptr), */
102 column_ptr
= gtk_tree_view_column_new_with_attributes(
108 gtk_tree_view_append_column(
109 GTK_TREE_VIEW(child_ptr
),
112 column_ptr
= gtk_tree_view_column_new_with_attributes(
118 gtk_tree_view_append_column(
119 GTK_TREE_VIEW(child_ptr
),
122 gtk_widget_show_all(g_main_window_ptr
);
124 list_store_ptr
= gtk_list_store_new(
130 gtk_tree_view_set_model(GTK_TREE_VIEW(child_ptr
), GTK_TREE_MODEL(list_store_ptr
));
133 /* stop button toggle */
134 void on_button_stop_toggled(
135 GtkAction
* action_ptr
,
136 GtkWidget
* widget_ptr
)
138 GtkWidget
* child_ptr
;
140 child_ptr
= get_glade_widget_child(widget_ptr
, "button_stop");
142 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(child_ptr
)))
144 g_midi_ignore
= TRUE
;
148 g_midi_ignore
= FALSE
;
152 void on_clear_clicked
153 (GtkButton
*button
, gpointer user_data
)
155 gtk_list_store_clear(
157 gtk_tree_view_get_model(
159 get_glade_widget_child(
168 process_lash_event(lash_event_t
* event_ptr
)
170 enum LASH_Event_Type type
;
173 type
= lash_event_get_type(event_ptr
);
174 str
= lash_event_get_string(event_ptr
);
179 g_warning("LASH_Quit received.\n");
184 case LASH_Restore_File
:
185 case LASH_Save_Data_Set
:
187 g_warning("LASH Event. Type = %u, string = \"%s\"\n",
189 (str
== NULL
)?"":str
);
194 process_lash_config(lash_config_t
* config_ptr
)
200 key
= lash_config_get_key(config_ptr
);
201 data
= lash_config_get_value(config_ptr
);
202 data_size
= lash_config_get_value_size(config_ptr
);
204 g_warning("LASH Config. Key = \"%s\"\n", key
);
207 /* process lash events callback */
209 process_lash_events(gpointer data
)
211 lash_event_t
* event_ptr
;
212 lash_config_t
* config_ptr
;
215 while ((event_ptr
= lash_get_event(g_lashc
)) != NULL
)
217 process_lash_event(event_ptr
);
218 lash_event_destroy(event_ptr
);
221 /* Process configs */
222 while ((config_ptr
= lash_get_config(g_lashc
)) != NULL
)
224 process_lash_config(config_ptr
);
225 lash_config_destroy(config_ptr
);
231 #endif /* #ifdef HAVE_LASH_1_0 */
242 main(int argc
, char *argv
[])
245 lash_event_t
* lash_event_ptr
;
247 GString
* client_name_str_ptr
;
250 gboolean want_any
= TRUE
;
252 gboolean want_jack
= FALSE
;
253 gboolean jack_enabled
= FALSE
;
256 gboolean want_alsa
= FALSE
;
257 gboolean alsa_enabled
= FALSE
;
259 gboolean io_enabled
= FALSE
;
262 for (i
= 1; i
< argc
; i
++)
265 if (strcmp(argv
[i
], "--jack") == 0)
273 if (strcmp(argv
[i
], "--alsa") == 0)
280 if (strcmp(argv
[i
], "--help") != 0)
282 fprintf(stderr
, "Unrecognized parameter \"%s\"\n", argv
[i
]);
287 ret
== 0 ? stdout
: stderr
,
306 gtk_init(&argc
, &argv
);
311 if (getenv("LADISH_APPNAME") != NULL
)
314 lash_extract_args(&argc
, &argv
),
317 LASH_PROTOCOL_VERSION
);
320 g_warning("Failed to connect to LASH. Session management will not occur.\n");
324 lash_event_ptr
= lash_event_new_with_type(LASH_Client_Name
);
325 lash_event_set_string(lash_event_ptr
, "GMIDImonitor");
326 lash_send_event(g_lashc
, lash_event_ptr
);
327 g_timeout_add(250, process_lash_events
, NULL
);
332 /* interface creation */
335 client_name_str_ptr
= g_string_new("");
336 g_string_sprintf(client_name_str_ptr
, "MIDI monitor");
341 if (want_jack
|| want_any
)
343 jack_enabled
= jack_init(client_name_str_ptr
->str
);
346 g_printf("JACK MIDI enabled\n");
357 if (want_alsa
|| (want_any
&& !io_enabled
))
359 alsa_enabled
= alsa_init(client_name_str_ptr
->str
);
362 g_printf("ALSA MIDI enabled\n");
374 signal(SIGINT
, &sigint_handler
);
375 signal(SIGTERM
, &sigint_handler
);