2 Parser library for the PowerTab (PTB) file format
3 Parser for tuning dictionary files
4 (c) 2005-2006: Jelmer Vernooij <jelmer@samba.org>
6 This program 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 This program 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 this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "dlinklist.h"
42 #define malloc_p(t,n) (t *) calloc(sizeof(t), n)
44 struct ptb_tuning_dict *ptb_read_tuning_dict(const char *f)
46 struct ptb_tuning_dict *ptbf = malloc_p(struct ptb_tuning_dict, 1);
57 read(fd, &ptbf->nr_tunings, 1);
59 read(fd, unknown, 7); /* Class name (CTuning) */
61 ptbf->tunings = malloc_p(struct ptb_tuning, ptbf->nr_tunings);
62 for (i = 0; i < ptbf->nr_tunings; i++) {
64 read(fd, &name_len, 1);
66 ptbf->tunings[i].name = malloc_p(char, name_len+1);
67 read(fd, ptbf->tunings[i].name, name_len);
68 ptbf->tunings[i].name[name_len] = '\0';
70 read(fd, &ptbf->tunings[i].capo, 1);
71 read(fd, &ptbf->tunings[i].nr_strings, 1);
72 ptbf->tunings[i].strings = malloc_p(uint8_t, ptbf->tunings[i].nr_strings);
73 read(fd, ptbf->tunings[i].strings, ptbf->tunings[i].nr_strings);
83 int ptb_write_tuning_dict(const char *f, struct ptb_tuning_dict *t)
85 struct ptb_tuning_dict *ptbf = malloc_p(struct ptb_tuning_dict, 1);
100 write(fd, &ptbf->nr_tunings, 1);
101 write(fd, unknown, 7);
102 write(fd, "CTuning", 7); /* Class name */
104 for (i = 0; i < ptbf->nr_tunings; i++) {
105 uint8_t name_len = strlen(ptbf->tunings[i].name);
106 uint32_t next = 0x8001;
107 write(fd, &name_len, 1);
109 write(fd, ptbf->tunings[i].name, name_len);
111 write(fd, &ptbf->tunings[i].capo, 1);
112 write(fd, &ptbf->tunings[i].nr_strings, 1);
113 write(fd, ptbf->tunings[i].strings, ptbf->tunings[i].nr_strings);
123 const char *ptb_tuning_get_note(char n)
125 const char *notes[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
129 void ptb_free_tuning_dict(struct ptb_tuning_dict *t)
132 for (i = 0; i < t->nr_tunings; i++) {
133 free(t->tunings[i].name);
134 free(t->tunings[i].strings);