~ubuntu-branches/ubuntu/utopic/lebiniou/utopic

« back to all changes in this revision

Viewing changes to src/sequencemanager_banks.c

  • Committer: Package Import Robot
  • Author(s): Olivier Girondel
  • Date: 2012-04-22 22:07:40 UTC
  • mfrom: (6.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120422220740-xncgwhc3g71nopnu
Tags: 3.18-1
* New upstream release 3.18.
* Support older libswscale.
* Add missing Build-Depends: libfreetype6-dev, libasound2-dev,
  libpulse-dev. (Closes: #669437)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright 1994-2011 Olivier Girondel
3
 
 *
4
 
 *  This file is part of lebiniou.
5
 
 *
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.
10
 
 *
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.
15
 
 *
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/>.
18
 
 */
19
 
 
20
 
#include "sequencemanager.h"
21
 
#include "globals.h"
22
 
#include "xmlutils.h"
23
 
 
24
 
 
25
 
void
26
 
SequenceManager_store_bank(SequenceManager_t *sm, const u_char bank)
27
 
{
28
 
  assert(bank < MAX_BANKS);
29
 
  sm->banks[sm->cur_bankset][bank] = sm->cur->id;
30
 
}
31
 
 
32
 
 
33
 
void
34
 
SequenceManager_use_bankset(SequenceManager_t *sm, const u_char bs)
35
 
{
36
 
  assert(bs < MAX_BANKS);
37
 
  sm->cur_bankset = bs;
38
 
}
39
 
 
40
 
 
41
 
void
42
 
SequenceManager_save_banks(const SequenceManager_t *sm)
43
 
{
44
 
  xmlDoc *doc;
45
 
  xmlNode *node;
46
 
  const gchar *home_dir = NULL;
47
 
  char *filename;
48
 
  int bs, b;
49
 
 
50
 
  home_dir = g_get_home_dir();
51
 
  filename = g_strdup_printf("%s/." PACKAGE_NAME, home_dir);
52
 
  rmkdir(filename);
53
 
  g_free(filename);
54
 
  filename = g_strdup_printf("%s/." PACKAGE_NAME "/banks.xml", home_dir);
55
 
 
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);
59
 
 
60
 
  for (bs = 0; bs < MAX_BANKS; bs++)
61
 
    for (b = 0; b < MAX_BANKS; b++)
62
 
      if (sm->banks[bs][b]) {
63
 
        char str[20];
64
 
        xmlNode *nd;
65
 
 
66
 
        memset(str, '\0', 20);
67
 
        g_snprintf(str, 19, "%li", sm->banks[bs][b]);
68
 
 
69
 
        nd = xmlNewChild(node, NULL, (const xmlChar *)"bank", (const xmlChar *)str);
70
 
 
71
 
        memset(str, '\0', 20);
72
 
        g_snprintf(str, 19, "%d", bs);
73
 
        xmlSetProp(nd, (const xmlChar *)"set", (const xmlChar *)str);
74
 
 
75
 
        xml_set_id(nd, b);
76
 
      }
77
 
  
78
 
  xmlKeepBlanksDefault(0);
79
 
  xmlSaveFormatFile(filename, doc, 1);
80
 
  xmlFreeDoc(doc);
81
 
  g_free(filename);
82
 
}
83
 
 
84
 
 
85
 
void
86
 
SequenceManager_load_banks(SequenceManager_t *sm)
87
 
{
88
 
  xmlDocPtr doc = NULL; /* XmlTree */
89
 
  const gchar *home_dir = NULL;
90
 
  char *filename;
91
 
  xmlNodePtr node = NULL, bank_node = NULL;
92
 
  int i, j;
93
 
 
94
 
  for (i = 0; i < MAX_BANKS; i++)
95
 
    for (j = 0; j < MAX_BANKS; j++)
96
 
      sm->banks[i][j] = 0;
97
 
 
98
 
  home_dir = g_get_home_dir();
99
 
  filename = g_strdup_printf("%s/." PACKAGE_NAME "/banks.xml", home_dir);
100
 
 
101
 
  /* BLA ! */
102
 
  xmlKeepBlanksDefault(0);
103
 
  xmlSubstituteEntitiesDefault(1);
104
 
 
105
 
  doc = xmlParseFile(filename);
106
 
  g_free(filename);
107
 
  if (doc == NULL)
108
 
    return;
109
 
 
110
 
  node = xmlDocGetRootElement(doc);
111
 
  if (node == NULL)
112
 
    xerror("Banks: xmlDocGetRootElement error\n");
113
 
 
114
 
  node = xmlFindElement("banks", node);
115
 
  if (node == NULL)
116
 
    xerror("Banks: no <banks> found\n");
117
 
 
118
 
  bank_node = node->xmlChildrenNode;
119
 
  if (bank_node == NULL) /* Empty banks.xml file */
120
 
    return;
121
 
 
122
 
  while (bank_node != NULL) {
123
 
    long tmp1, tmp2;
124
 
    xmlChar *youhou;
125
 
    int res;
126
 
    long tmp3;
127
 
 
128
 
    youhou = xmlGetProp(bank_node, (const xmlChar *)"set");
129
 
    tmp1 = getintfield(youhou);
130
 
    xmlFree(youhou);
131
 
    assert(tmp1 >= 0);
132
 
    assert(tmp1 < MAX_BANKS);
133
 
 
134
 
    youhou = xmlGetProp(bank_node, (const xmlChar *)"id");
135
 
    tmp2 = getintfield(youhou);
136
 
    xmlFree(youhou);
137
 
    assert(tmp2 >= 0);
138
 
    assert(tmp2 < MAX_BANKS);
139
 
 
140
 
    res = xmlGetOptionalLong(doc, bank_node, &tmp3);
141
 
    if (res == -1)
142
 
      xerror("Banks: no value set\n");
143
 
    else {
144
 
      sm->banks[tmp1][tmp2] = tmp3;
145
 
#ifdef DEBUG
146
 
      printf("[i] Bankset: %li Bank: %li Sequence id: %li\n", tmp1, tmp2, tmp3);
147
 
#endif
148
 
    }
149
 
 
150
 
    bank_node = bank_node->next;
151
 
  }
152
 
}