Reworked track settings.
[demorecorder] / src / Track.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 protected struct Track {
21
22   public string uri;
23   public string label;
24   public bool active;
25   public bool mute;
26   public double volume;
27   public double pan;
28   public TrackBin bin;
29   //public TrackTransport transport;
30   
31   public Track() {
32     this.uri = "";
33     this.label = "";
34     this.active = false;
35     this.mute = false;
36     this.volume = 0.0;
37     this.pan = 0.0;
38     this.bin = null;
39     //this.transport = null;
40   }
41   
42   public Track.with_uri(string uri, string label, bool active, bool mute, double volume, double pan) {
43     this.uri = uri;
44     this.label = label;
45     this.active = active;
46     this.mute = mute;
47     this.volume = volume;
48     this.pan = pan;
49     this.bin = new TrackBin(label);
50     this.bin.set_uri(uri);
51     //this.transport = null;
52   }
53   
54   //public void set_transport(TrackTransport transport) {
55     //this.transport = transport;
56     //this.transport.active_toggled.connect(active_toggled_callback);
57   //}
58   
59   public SettingsStructures.TrackSettings get_settings_structure() {
60     SettingsStructures.TrackSettings ret = SettingsStructures.TrackSettings();
61     ret.uri = uri;
62     ret.name = label;
63     ret.notes = "";
64     ret.active = active;
65     ret.volume = SettingsStructures.VolumeSettings.with_values(volume, mute);
66     ret.panorama = SettingsStructures.PanoramaSettings.with_values(pan);
67     ret.dynamics = SettingsStructures.DynamicsSettings();
68     ret.echo = SettingsStructures.EchoSettings();
69     ret.equalizer = SettingsStructures.EqualizerSettings();
70     return ret;
71   }
72   public void from_settings_structure(SettingsStructures.TrackSettings settings) {
73     this.uri = settings.uri;
74     this.label = settings.name;
75     this.active = settings.active;
76     this.mute = settings.volume.mute;
77     this.volume = settings.volume.volume;
78     this.pan = settings.panorama.panorama;
79     this.bin = new TrackBin(this.label);
80     this.bin.set_uri(this.uri);
81   }
82   
83   public static string tracklist_to_xml_string(List<Track?> tracklist) {
84     string ret = "<TrackList>\n";
85     for (int idx = 0; idx < tracklist.length(); ++idx) {
86       ret += ((Track)tracklist.nth_data(idx)).get_settings_structure().to_xml_string();
87     }
88     return ret + "</TrackList>\n";
89   }
90   
91   public static void tracklist_from_xml_node_helper(Xml.Node* node, ref unowned List<Track?> tracks) {
92     // Loop over the passed node's children
93     for (Xml.Node* iter = node->children; iter != null; iter = iter->next) {
94       // Spaces between tags are also nodes, discard them
95       if (iter->type != Xml.ElementType.ELEMENT_NODE) {
96         continue;
97       }
98       // Get the node's name
99       if ("TrackList" == iter->name) {
100         tracklist_from_xml_node(iter, ref tracks);
101         break;
102       }
103     }
104   }
105   
106   public static void tracklist_from_xml_node(Xml.Node* node, ref unowned List<Track?> tracks) {
107     // Loop over the passed node's children
108     for (Xml.Node* iter = node->children; iter != null; iter = iter->next) {
109       // Spaces between tags are also nodes, discard them
110       if (iter->type != Xml.ElementType.ELEMENT_NODE) {
111         continue;
112       }
113       // Get the node's name
114       string node_name = iter->name;
115       // Get the nodes type
116       //string? type = XmlHelpers.get_node_attribute(iter, "type");
117       if ("TrackSettings" == node_name)
118       {
119         SettingsStructures.TrackSettings track = SettingsStructures.TrackSettings();
120         track.from_xml_node(iter);
121         Track t = Track();
122         t.from_settings_structure(track);
123         tracks.append(t);
124       }
125     }
126   }
127
128 }
129
130 }