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 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 <sys/types.h>
33 #include <lash/lash.h>
43 GtkWidget
* g_main_window_ptr
;
45 gboolean g_midi_ignore
= FALSE
;
50 lash_client_t
* g_lashc
;
53 const char * g_note_names
[12] =
72 GtkWidget
* child_ptr
;
73 GtkListStore
* list_store_ptr
;
74 GtkTreeViewColumn
* column_ptr
;
75 GtkCellRenderer
* text_renderer_ptr
;
77 g_main_window_ptr
= construct_glade_widget("main_window");
79 child_ptr
= get_glade_widget_child(g_main_window_ptr
, "list");
81 text_renderer_ptr
= gtk_cell_renderer_text_new();
84 G_OBJECT(text_renderer_ptr
),
89 /* column_ptr = gtk_tree_view_column_new_with_attributes( */
91 /* text_renderer_ptr, */
92 /* "text", COL_TIME, */
95 /* gtk_tree_view_append_column( */
96 /* GTK_TREE_VIEW(child_ptr), */
99 column_ptr
= gtk_tree_view_column_new_with_attributes(
105 gtk_tree_view_append_column(
106 GTK_TREE_VIEW(child_ptr
),
109 column_ptr
= gtk_tree_view_column_new_with_attributes(
115 gtk_tree_view_append_column(
116 GTK_TREE_VIEW(child_ptr
),
119 gtk_widget_show_all(g_main_window_ptr
);
121 list_store_ptr
= gtk_list_store_new(
127 gtk_tree_view_set_model(GTK_TREE_VIEW(child_ptr
), GTK_TREE_MODEL(list_store_ptr
));
130 /* stop button toggle */
131 void on_button_stop_toggled(
132 GtkAction
* action_ptr
,
133 GtkWidget
* widget_ptr
)
135 GtkWidget
* child_ptr
;
137 child_ptr
= get_glade_widget_child(widget_ptr
, "button_stop");
139 if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(child_ptr
)))
141 g_midi_ignore
= TRUE
;
145 g_midi_ignore
= FALSE
;
149 void on_clear_clicked
150 (GtkButton
*button
, gpointer user_data
)
152 gtk_list_store_clear(
154 gtk_tree_view_get_model(
156 get_glade_widget_child(
165 process_lash_event(lash_event_t
* event_ptr
)
167 enum LASH_Event_Type type
;
170 type
= lash_event_get_type(event_ptr
);
171 str
= lash_event_get_string(event_ptr
);
176 g_warning("LASH_Quit received.\n");
181 case LASH_Restore_File
:
182 case LASH_Save_Data_Set
:
184 g_warning("LASH Event. Type = %u, string = \"%s\"\n",
186 (str
== NULL
)?"":str
);
191 process_lash_config(lash_config_t
* config_ptr
)
197 key
= lash_config_get_key(config_ptr
);
198 data
= lash_config_get_value(config_ptr
);
199 data_size
= lash_config_get_value_size(config_ptr
);
201 g_warning("LASH Config. Key = \"%s\"\n", key
);
204 /* process lash events callback */
206 process_lash_events(gpointer data
)
208 lash_event_t
* event_ptr
;
209 lash_config_t
* config_ptr
;
212 while ((event_ptr
= lash_get_event(g_lashc
)) != NULL
)
214 process_lash_event(event_ptr
);
215 lash_event_destroy(event_ptr
);
218 /* Process configs */
219 while ((config_ptr
= lash_get_config(g_lashc
)) != NULL
)
221 process_lash_config(config_ptr
);
222 lash_config_destroy(config_ptr
);
228 #endif /* #ifdef HAVE_LASH_1_0 */
231 main(int argc
, char *argv
[])
234 lash_event_t
* lash_event_ptr
;
236 GString
* client_name_str_ptr
;
243 gtk_init(&argc
, &argv
);
248 if (getenv("LADISH_APPNAME") != NULL
)
251 lash_extract_args(&argc
, &argv
),
254 LASH_PROTOCOL_VERSION
);
257 g_warning("Failed to connect to LASH. Session management will not occur.\n");
261 lash_event_ptr
= lash_event_new_with_type(LASH_Client_Name
);
262 lash_event_set_string(lash_event_ptr
, "GMIDImonitor");
263 lash_send_event(g_lashc
, lash_event_ptr
);
264 g_timeout_add(250, process_lash_events
, NULL
);
269 /* interface creation */
272 client_name_str_ptr
= g_string_new("");
273 g_string_sprintf(client_name_str_ptr
, "MIDI monitor");
278 if (!jack_init(client_name_str_ptr
->str
))
285 if (!alsa_init(client_name_str_ptr
->str
))
287 goto fail_uninit_jack
;