Reworked track settings.
[demorecorder] / src / EqualizerPreset.vala
1 /*  Demo Recorder for MAEMO 5
2 *   Copyright (C) 2010 Dru Moore <usr@dru-id.co.uk>
3 *   This program is free software; you can redistribute it and/or modify
4 *   it under the terms of the GNU General Public License version 2,
5 *   or (at your option) any later version, as published by the Free
6 *   Software Foundation
7 *
8 *   This program is distributed in the hope that it will be useful,
9 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *   GNU General Public License for more details
12 *
13 *   You should have received a copy of the GNU General Public
14 *   License along with this program; if not, write to the
15 *   Free Software Foundation, Inc.,
16 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 */
18 namespace IdWorks {
19   
20   public struct EqualizerSettings {
21     public double[] bands;
22     public string name;
23     
24     public EqualizerSettings() {    
25       this.name = "";
26       this.bands = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
27     }
28     public EqualizerSettings.with_name(string val) {    
29       this.name = val;
30       this.bands = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
31     }
32     public EqualizerSettings.with_values(string name, double[] bands) {
33       this.name = name;
34       this.bands = bands;
35     }
36     
37     public string to_string() {
38       return "%s: bands:{%02f %02f %02f %02f %02f %02f %02f %02f %02f %02f}\n".printf(
39       name
40       , bands[0]
41       , bands[1]
42       , bands[2]
43       , bands[3]
44       , bands[4]
45       , bands[5]
46       , bands[6]
47       , bands[7]
48       , bands[8]
49       , bands[9]);
50     }
51     
52     public string serialize_to_string() {
53       return "EqualizerPreset:%s,%02f,%02f,%02f,%02f,%02f,%02f,%02f,%02f,%02f,%02f\n".printf(
54       name.replace(",", "\\,")
55       , bands[0]
56       , bands[1]
57       , bands[2]
58       , bands[3]
59       , bands[4]
60       , bands[5]
61       , bands[6]
62       , bands[7]
63       , bands[8]
64       , bands[9]);
65     }
66     public string to_xml_string() {
67       return ("<EqualizerSettings>\n" +
68               "<name><![CDATA[%s]]></name>\n" +
69               "<band_0 type=\"double\">>%02f</band_0>\n" +
70               "<band_1 type=\"double\">>%02f</band_1>\n" +
71               "<band_2 type=\"double\">>%02f</band_2>\n" +
72               "<band_3 type=\"double\">>%02f</band_3>\n" +
73               "<band_4 type=\"double\">>%02f</band_4>\n" +
74               "<band_5 type=\"double\">>%02f</band_5>\n" +
75               "<band_6 type=\"double\">>%02f</band_6>\n" +
76               "<band_7 type=\"double\">>%02f</band_7>\n" +
77               "<band_8 type=\"double\">>%02f</band_8>\n" +
78               "<band_9 type=\"double\">>%02f</band_9>\n" +
79               "</EqualizerSettings>\n").printf(
80               name,
81               bands[0],
82               bands[1],
83               bands[2],
84               bands[3],
85               bands[4],
86               bands[5],
87               bands[6],
88               bands[7],
89               bands[8],
90               bands[9]
91             );
92     }
93     public void from_xml_string(Xml.Node* node) {}
94   
95     public bool deserialize_from_string(string data) {
96       bool good = false;
97       // call parser to build an array of string of parts
98       string[] values = CdlParser.ParseLine(data);
99       // check length of array
100       if (13 == values.length) {
101         // parse parts into this
102         name = values[0];
103         for (int i = 0; i < 10; ++i) {
104           bands[i] = values[i + 1].to_double();
105         }
106         good = true;
107       }
108       return good;
109     }
110   
111   }
112   
113 }