[specimen] PATCH: save master volume (WORKS NOW)

Juuso Alasuutari iuso at sourcemage.org
Sat Sep 1 05:03:50 CDT 2007


On Friday 31 August 2007 22:05:07 Juuso Alasuutari wrote:
> Here's a patch for saving and loading the master volume with the bank. It
> adds a child node called "master" to the XML data, which in turn contains a
> node called "volume" for storing the value. (It might come in handy to save
> other master settings later on, which is why I didn't implement a single
> node called master_volume.)
>
> This patch doesn't interact with the GUI, so for this to be usable the
> master section needs to be refreshed after loading a patch. When the patch
> is loaded the master volume is adjusted accordingly, but the slider stays
> as-is. I hope someone who knows GTK+2 can help implement the refreshing, I
> myself have no clue whatsoever how to do it.

I ended up writing the GUI refresh code myself after all. After some studying 
I found out that I only needed to add a few lines to gui.c. I changed 
gui_refresh() to also call master_section update() in addition to 
patch_list_update(), and touched the bank open & new bank routines.

While I'm at it, I think I'll work on the channel volume bug discussed earlier 
on (http://zhevny.com/pipermail/specimen/2007-March/000114.html). I'll see if 
I can add a new section to the GUI for per-channel settings, such as volume 
adjustment listening to cc 7. It should of course also be saveable.

By the way: I'm not sure if the older Specimen versions will be able to load 
these new beef files. I will have to test that in practice. But I think it's 
the price we have to pay for implementing some critical new improvements.


BEGIN PATCH------------------------------------------------------------
--- src/beef.c~	2007-09-01 12:35:33.000000000 +0300
+++ src/beef.c	2007-09-01 12:36:04.000000000 +0300
@@ -5,6 +5,7 @@
 #include <glib.h>
 #include "specimen.h"
 #include "patch.h"
+#include "mixer.h"
 
 int beef_write (char *name)
 {
@@ -19,6 +20,7 @@
     int i, j, count;
     xmlDocPtr doc;
     xmlNodePtr rootnode;
+    xmlNodePtr xmlmaster;
     xmlNodePtr xmlpatch;
 
 #define NR_OF_PPT 5
@@ -40,6 +42,12 @@
     rootnode = xmlNewDocNode (doc, NULL, (const xmlChar *) "beef", NULL);
     xmlDocSetRootElement (doc, rootnode);
 
+    xmlmaster = xmlNewTextChild (rootnode, NULL, (const xmlChar *) "master",
+                                 NULL);
+    sprintf (tmp, "%f", mixer_get_volume ());
+    xmlNewTextChild (xmlmaster, NULL, (const xmlChar *) "volume",
+                     (const xmlChar *) tmp);
+
     /* walk the walk */
     count = patch_dump (&id);
     for (i = 0; i < count; i++)
@@ -338,7 +346,7 @@
 {
     xmlDocPtr doc;
     xmlNodePtr rootnode;
-    xmlNodePtr xmlpatch;
+    xmlNodePtr childnode;
     xmlNodePtr cur;
     xmlChar *key;
     int id;
@@ -369,16 +377,32 @@
 
 
     patch_destroy_all ( );
-    for (xmlpatch = rootnode->xmlChildrenNode; xmlpatch != NULL;
-	 xmlpatch = xmlpatch->next)
+    for (childnode = rootnode->xmlChildrenNode; childnode != NULL;
+	 childnode = childnode->next)
     {
 
 	key = NULL;
-	if (!xmlStrcmp (xmlpatch->name, (const xmlChar *) "patch"))
+	if (!xmlStrcmp (childnode->name, (const xmlChar *) "master"))
+	{
+	    for (cur = childnode->xmlChildrenNode; cur != NULL;
+		 cur = cur->next)
+	    {
+		if (!xmlStrcmp (cur->name, (const xmlChar *) "volume"))
+		{
+		    key =
+			xmlNodeListGetString (doc, cur->xmlChildrenNode,
+					      1);
+		    mixer_set_volume (atof ((const char *) key));
+		}
+	    }
+	}
+
+	key = NULL;
+	if (!xmlStrcmp (childnode->name, (const xmlChar *) "patch"))
 	{
 	    id = patch_create ("Loading...");
 
-	    for (cur = xmlpatch->xmlChildrenNode; cur != NULL;
+	    for (cur = childnode->xmlChildrenNode; cur != NULL;
 		 cur = cur->next)
 	    {
 		if (!xmlStrcmp (cur->name, (const xmlChar *) "name"))
--- src/gui/gui.c~	2007-09-01 12:35:45.000000000 +0300
+++ src/gui/gui.c	2007-09-01 12:35:57.000000000 +0300
@@ -334,7 +334,8 @@
 {
     if (bank_ops_new ( ) == 0)
     {
-	patch_list_update (PATCH_LIST(patch_list), 0, PATCH_LIST_INDEX);
+	mixer_set_volume (DEFAULT_VOLUME);
+	gui_refresh ( );
     }
 }
 
@@ -342,9 +343,7 @@
 static void cb_menu_file_open_bank (GtkWidget * widget, gpointer data)
 {
     if (bank_ops_open ( ) == 0)
-    {
-	patch_list_update (PATCH_LIST(patch_list), 0, PATCH_LIST_INDEX);
-    }
+	gui_refresh ( );
 }
 
 
@@ -602,6 +601,7 @@
 
 void gui_refresh(void)
 {
+    master_section_update (MASTER_SECTION(master_section));
     patch_list_update (PATCH_LIST(patch_list), 0, PATCH_LIST_INDEX);
 }
 
END PATCH--------------------------------------------------------------

-- 
        Juuso Alasuutari
[[ Source Mage GNU/Linux ]]

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the Specimen mailing list