Skip to contentSkip to conversation

envy24control save state of LRGang button in config file

PATCH Applied Dirk Jagdmann 2 participants 3 messages Jul 26, 2005 – Jul 30, 2005 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 envy24control save state of LRGang button in config file

Hello Developers,

this patch saves the state of the "LR Gang" buttons in a config/pref file, because this button's state is not preserved throughout runs of envy24control. At present it only works, when envy24control is compiled with GTK2 as I have used routines which were introduced with Glib2.

While this works fine I think we should discuss if envy24control could/should be compiled with gtk2 by default (currently gtk1 is default). As I think all Linux distributions now ship with Gtk2 and most other software uses gtk2 by now, I think it would be a reasonable thing for the next release of Alsa. This would also mean, that this patch will work with the default configuration :)

Signature · 3 lines
---> doj / cubic
----> http://cubic.org/~doj
-----> http://llg.cubic.org

Index: Makefile.am
===================================================================
RCS file: /cvsroot/alsa/alsa-tools/envy24control/Makefile.am,v retrieving revision 1.15

Makefile.am +1 -1
diff -u -r1.15 Makefile.am
@@ -3,8 +3,8 @@
 man_MANS = envy24control.1
 envy24control_SOURCES = envy24control.c envy24control.h levelmeters.c midi.c \
                         mixer.c patchbay.c hardware.c driverevents.c volume.c \
-			profiles.c profiles.h midi.h
+			profiles.c profiles.h midi.h config.c config.h
 envy24control_LDFLAGS = @ENVY24CONTROL_LIBS@
 EXTRA_DIST = envy24control.1 depcomp configure.in-gtk2 \
 	     strstr_icase_blank.c new_process.c README.profiles

Index: envy24control.c
===================================================================
RCS file: /cvsroot/alsa/alsa-tools/envy24control/envy24control.c,v retrieving revision 1.35

envy24control.c +6 -1
diff -u -r1.35 envy24control.c
@@ -22,6 +22,7 @@
 
 #include "envy24control.h"
 #include "midi.h"
+#include "config.h"
 #define _GNU_SOURCE
 #include <getopt.h>
 
@@ -244,7 +244,9 @@
 	gtk_widget_show(toggle);
 	gtk_box_pack_end(GTK_BOX(vbox), toggle, FALSE, FALSE, 0);
 	/* gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), TRUE); */
-	
+	gtk_signal_connect(GTK_OBJECT(toggle), "toggled",
+			   GTK_SIGNAL_FUNC(config_set_stereo), (gpointer)stream-1);
+
 	hbox = gtk_hbox_new(TRUE, 6);
 	gtk_widget_show(hbox);
 	gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
@@ -2116,6 +2117,7 @@
 	}
 
 	/* Initialize code */
+	config_open();
 	level_meters_init();
 	mixer_init();
 	patchbay_init();
@@ -2185,6 +2187,7 @@
 
 	snd_ctl_close(ctl);
 	midi_close();
+	config_close();
 
 	return EXIT_SUCCESS;
 }

Index: mixer.c
===================================================================
RCS file: /cvsroot/alsa/alsa-tools/envy24control/mixer.c,v retrieving revision 1.11

mixer.c +3 -0
diff -u -r1.11 mixer.c
@@ -19,6 +19,7 @@
 
 #include "envy24control.h"
 #include "midi.h"
+#include "config.h"
 
 #define	MULTI_PLAYBACK_SWITCH		"Multi Playback Switch"
 #define MULTI_PLAYBACK_VOLUME		"Multi Playback Volume"
@@ -263,4 +269,6 @@
 		if (stream_is_active[stream - 1])
 			mixer_update_stream(stream, 1, 1);
 	}
+
+	config_restore_stereo();
 }

#include <gtk/gtk.h>
#include "envy24control.h"

#if GLIB_CHECK_VERSION(2,2,0)

#if GLIB_CHECK_VERSION(2,8,0)
#define MYMKDIR g_mkdir_with_parents
#else
#include <sys/stat.h>
#include <sys/types.h>
#define MYMKDIR mkdir
#endif

GKeyFile *config_file;
gboolean config_stereo[20];
gchar *config_filename;

void config_open()
{
config_filename=g_strdup_printf("%s/%s", g_get_user_config_dir(), "envy24control"); config_file=g_key_file_new();
g_key_file_load_from_file(config_file, config_filename, G_KEY_FILE_KEEP_COMMENTS, NULL);
}

void config_close()
{
gsize len=0;
gchar *s; g_key_file_set_boolean_list(config_file, "mixer", "stereo",

			      config_stereo, sizeof(config_stereo)/sizeof(config_stereo[0]));
  s=g_key_file_to_data(config_file, &len, NULL);
  if(s && len)
    {
      MYMKDIR(g_get_user_config_dir(), 0700);
      FILE *f=fopen(config_filename, "wb");
      if(f)
	{
	  fwrite(s, len, 1, f);
	  fclose(f);
	}
    }

g_free(config_filename); config_filename=0;
g_key_file_free(config_file); config_file=0;
}

void config_set_stereo(GtkWidget *but, gpointer data) {
gint i=(gint)data; config_stereo[i]=GTK_TOGGLE_BUTTON(but)->active;
}

void config_restore_stereo()
{
gint i;
gsize len=0;
gboolean *s=g_key_file_get_boolean_list(config_file, "mixer", "stereo", &len, NULL); if(s)

      for(i=0; i!=len; ++i)
	{
	  config_stereo[i]=s[i];
	  if(mixer_stereo_toggle[i])
	    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mixer_stereo_toggle[i]), s[i]);
	}
}

#else

/* to be done */
void config_open() { }
void config_close() { }
void config_set_stereo(GtkWidget *but, gpointer data) { } void config_restore_stereo() { }

#endif

#ifndef CONFIG__H
#define CONFIG__H

void config_open();
void config_close();
void config_set_stereo(GtkWidget *but, gpointer data); void config_restore_stereo();

#endif

#1 lore raw
Quoted 6 lines · Dirk Jagdmann

Hello Developers,

this patch saves the state of the "LR Gang" buttons in a config/pref file, because this button's state is not preserved throughout runs of envy24control. At present it only works, when envy24control is compiled with GTK2 as I have used routines which were introduced with Glib2.

Applied to CVS.

Quoted 6 lines

While this works fine I think we should discuss if envy24control could/should be compiled with gtk2 by default (currently gtk1 is default). As I think all Linux distributions now ship with Gtk2 and most other software uses gtk2 by now, I think it would be a reasonable thing for the next release of Alsa. This would also mean, that this patch will work with the default configuration :)

Any objections from others?

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs

-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click

#2 lore raw
In reply to Dirk Jagdmann

Hello,

The last mail I sent for this topic contained a non functional patch, which has not been included in CVS yet. I resend the patch, which should now work.

Signature · 3 lines
---> doj / cubic
----> http://cubic.org/~doj
-----> http://llg.cubic.org

Index: Makefile.am
===================================================================
RCS file: /cvsroot/alsa/alsa-tools/envy24control/Makefile.am,v retrieving revision 1.15

Makefile.am +1 -1
diff -u -r1.15 Makefile.am
@@ -3,8 +3,8 @@
 man_MANS = envy24control.1
 envy24control_SOURCES = envy24control.c envy24control.h levelmeters.c midi.c \
                         mixer.c patchbay.c hardware.c driverevents.c volume.c \
-			profiles.c profiles.h midi.h
+			profiles.c profiles.h midi.h config.c config.h
 envy24control_LDFLAGS = @ENVY24CONTROL_LIBS@
 EXTRA_DIST = envy24control.1 depcomp configure.in-gtk2 \
 	     strstr_icase_blank.c new_process.c README.profiles
 

Index: envy24control.c
===================================================================
RCS file: /cvsroot/alsa/alsa-tools/envy24control/envy24control.c,v retrieving revision 1.35

envy24control.c +6 -1
diff -u -r1.35 envy24control.c
@@ -22,6 +22,7 @@
 
 #include "envy24control.h"
 #include "midi.h"
+#include "config.h"
 #define _GNU_SOURCE
 #include <getopt.h>
 
@@ -244,7 +244,9 @@
 	gtk_widget_show(toggle);
 	gtk_box_pack_end(GTK_BOX(vbox), toggle, FALSE, FALSE, 0);
 	/* gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), TRUE); */
-	
+	gtk_signal_connect(GTK_OBJECT(toggle), "toggled",
+			   GTK_SIGNAL_FUNC(config_set_stereo), (gpointer)stream-1);
+
 	hbox = gtk_hbox_new(TRUE, 6);
 	gtk_widget_show(hbox);
 	gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
@@ -2116,6 +2117,7 @@
 	}
 
 	/* Initialize code */
+	config_open();
 	level_meters_init();
 	mixer_init();
 	patchbay_init();
@@ -2185,6 +2187,7 @@
 
 	snd_ctl_close(ctl);
 	midi_close();
+	config_close();
 
 	return EXIT_SUCCESS;
 }

Index: mixer.c
===================================================================
RCS file: /cvsroot/alsa/alsa-tools/envy24control/mixer.c,v retrieving revision 1.11

mixer.c +3 -0
diff -u -r1.11 mixer.c
@@ -19,6 +19,7 @@
 
 #include "envy24control.h"
 #include "midi.h"
+#include "config.h"
 
 #define	MULTI_PLAYBACK_SWITCH		"Multi Playback Switch"
 #define MULTI_PLAYBACK_VOLUME		"Multi Playback Volume"
@@ -263,4 +269,6 @@
 		if (stream_is_active[stream - 1])
 			mixer_update_stream(stream, 1, 1);
 	}
+
+	config_restore_stereo();
 }