From 4abd0810ded6d82ce0dcbf0279e9fdc35ae9a4d8 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Fri, 23 Dec 2005 22:06:49 +0000 Subject: [PATCH] add lash support, add pid to alsa seq client id git-svn-id: svn://svn.gna.org/svn/gmidimonitor/trunk@8 d9434dc6-2408-0410-b8be-9e73975a53a3 --- GNUmakefile | 4 +-- main.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 94 insertions(+), 3 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index fcc34fd..93b3619 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -2,8 +2,8 @@ PREFIX=/usr BIN_DIR=$(PREFIX)/bin DATA_DIR=$(PREFIX)/share/gmidimonitor -CFLAGS := $(strip $(shell pkg-config --cflags gtk+-2.0 libglade-2.0)) -Wall -Werror -DDATA_DIR='"$(DATA_DIR)"' -LIBS := $(strip $(shell pkg-config --libs gtk+-2.0 libglade-2.0 gmodule-2.0 gthread-2.0 alsa)) +CFLAGS := $(strip $(shell pkg-config --cflags gtk+-2.0 libglade-2.0 lash-1.0)) -Wall -Werror -DDATA_DIR='"$(DATA_DIR)"' +LIBS := $(strip $(shell pkg-config --libs gtk+-2.0 libglade-2.0 gmodule-2.0 gthread-2.0 alsa lash-1.0)) OBJECTS=about.o path.o glade.o main.o diff --git a/main.c b/main.c index fd5a978..b4fc3ea 100644 --- a/main.c +++ b/main.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "path.h" #include "glade.h" @@ -25,6 +26,8 @@ gboolean g_midi_ignore = FALSE; int g_row_count; +lash_client_t * g_lashc; + static const char * g_note_names[12] = { "C", @@ -987,12 +990,78 @@ midi_thread(void * context_ptr) return NULL; } +void +process_lash_event(lash_event_t * event_ptr) +{ + enum LASH_Event_Type type; + const char * str; + + type = lash_event_get_type(event_ptr); + str = lash_event_get_string(event_ptr); + + switch (type) + { + case LASH_Quit: + g_warning("LASH_Quit received.\n"); + g_lashc = NULL; + gtk_main_quit(); + break; + case LASH_Save_File: + case LASH_Restore_File: + case LASH_Save_Data_Set: + default: + g_warning("LASH Event. Type = %u, string = \"%s\"\n", + (unsigned int)type, + (str == NULL)?"":str); + } +} + +void +process_lash_config(lash_config_t * config_ptr) +{ + const char * key; + const void * data; + size_t data_size; + + key = lash_config_get_key(config_ptr); + data = lash_config_get_value(config_ptr); + data_size = lash_config_get_value_size(config_ptr); + + g_warning("LASH Config. Key = \"%s\"\n", key); +} + +/* process lash events callback */ +gboolean +process_lash_events(gpointer data) +{ + lash_event_t * event_ptr; + lash_config_t * config_ptr; + + /* Process events */ + while ((event_ptr = lash_get_event(g_lashc)) != NULL) + { + process_lash_event(event_ptr); + lash_event_destroy(event_ptr); + } + + /* Process configs */ + while ((config_ptr = lash_get_config(g_lashc)) != NULL) + { + process_lash_config(config_ptr); + lash_config_destroy(config_ptr); + } + + return TRUE; +} + int main(int argc, char *argv[]) { int ret; snd_seq_port_info_t * port_info = NULL; pthread_t midi_tid; + lash_event_t * lash_event_ptr; + GString * seq_client_name_str_ptr; /* init threads */ g_thread_init(NULL); @@ -1003,6 +1072,24 @@ main(int argc, char *argv[]) path_init(argv[0]); + g_lashc = lash_init( + lash_extract_args(&argc, &argv), + "gmidimonitor", + 0, + LASH_PROTOCOL_VERSION); + + if (g_lashc == NULL) + { + g_warning("Failed to connect to LASH. Session management will not occur.\n"); + } + else + { + lash_event_ptr = lash_event_new_with_type(LASH_Client_Name); + lash_event_set_string(lash_event_ptr, "GMIDImonitor"); + lash_send_event(g_lashc, lash_event_ptr); + g_timeout_add(250, process_lash_events, NULL); + } + /* interface creation */ create_mainwindow(); @@ -1018,7 +1105,11 @@ main(int argc, char *argv[]) goto path_uninit; } - snd_seq_set_client_name(g_seq_ptr, "MIDI monitor"); + seq_client_name_str_ptr = g_string_new(""); + g_string_sprintf(seq_client_name_str_ptr, "MIDI monitor (%u)", (unsigned int)getpid()); + snd_seq_set_client_name(g_seq_ptr, seq_client_name_str_ptr->str); + + lash_alsa_client_id(g_lashc, snd_seq_client_id(g_seq_ptr)); snd_seq_port_info_alloca(&port_info); -- 2.11.4.GIT