2
* Copyright 1994-2011 Olivier Girondel
4
* This file is part of lebiniou.
6
* lebiniou is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 2 of the License, or
9
* (at your option) any later version.
11
* lebiniou is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with lebiniou. If not, see <http://www.gnu.org/licenses/>.
20
#include "sequencemanager.h"
26
SequenceManager_store_bank(SequenceManager_t *sm, const u_char bank)
28
assert(bank < MAX_BANKS);
29
sm->banks[sm->cur_bankset][bank] = sm->cur->id;
34
SequenceManager_use_bankset(SequenceManager_t *sm, const u_char bs)
36
assert(bs < MAX_BANKS);
42
SequenceManager_save_banks(const SequenceManager_t *sm)
46
const gchar *home_dir = NULL;
50
home_dir = g_get_home_dir();
51
filename = g_strdup_printf("%s/." PACKAGE_NAME, home_dir);
54
filename = g_strdup_printf("%s/." PACKAGE_NAME "/banks.xml", home_dir);
56
/* FIXME check return code of xml* functions */
57
doc = xmlNewDoc((const xmlChar *)"1.0");
58
node = doc->children = xmlNewDocNode(doc, NULL, (const xmlChar *)"banks", NULL);
60
for (bs = 0; bs < MAX_BANKS; bs++)
61
for (b = 0; b < MAX_BANKS; b++)
62
if (sm->banks[bs][b]) {
66
memset(str, '\0', 20);
67
g_snprintf(str, 19, "%li", sm->banks[bs][b]);
69
nd = xmlNewChild(node, NULL, (const xmlChar *)"bank", (const xmlChar *)str);
71
memset(str, '\0', 20);
72
g_snprintf(str, 19, "%d", bs);
73
xmlSetProp(nd, (const xmlChar *)"set", (const xmlChar *)str);
78
xmlKeepBlanksDefault(0);
79
xmlSaveFormatFile(filename, doc, 1);
86
SequenceManager_load_banks(SequenceManager_t *sm)
88
xmlDocPtr doc = NULL; /* XmlTree */
89
const gchar *home_dir = NULL;
91
xmlNodePtr node = NULL, bank_node = NULL;
94
for (i = 0; i < MAX_BANKS; i++)
95
for (j = 0; j < MAX_BANKS; j++)
98
home_dir = g_get_home_dir();
99
filename = g_strdup_printf("%s/." PACKAGE_NAME "/banks.xml", home_dir);
102
xmlKeepBlanksDefault(0);
103
xmlSubstituteEntitiesDefault(1);
105
doc = xmlParseFile(filename);
110
node = xmlDocGetRootElement(doc);
112
xerror("Banks: xmlDocGetRootElement error\n");
114
node = xmlFindElement("banks", node);
116
xerror("Banks: no <banks> found\n");
118
bank_node = node->xmlChildrenNode;
119
if (bank_node == NULL) /* Empty banks.xml file */
122
while (bank_node != NULL) {
128
youhou = xmlGetProp(bank_node, (const xmlChar *)"set");
129
tmp1 = getintfield(youhou);
132
assert(tmp1 < MAX_BANKS);
134
youhou = xmlGetProp(bank_node, (const xmlChar *)"id");
135
tmp2 = getintfield(youhou);
138
assert(tmp2 < MAX_BANKS);
140
res = xmlGetOptionalLong(doc, bank_node, &tmp3);
142
xerror("Banks: no value set\n");
144
sm->banks[tmp1][tmp2] = tmp3;
146
printf("[i] Bankset: %li Bank: %li Sequence id: %li\n", tmp1, tmp2, tmp3);
150
bank_node = bank_node->next;