Subversion Repositories svn.mios

Rev

Rev 709 | Rev 722 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
709 adamjking 1
package org.midibox.apps.miosstudio.xml;
2
 
721 adamjking 3
import org.midibox.apps.miosstudio.MIOSStudio;
4
import org.midibox.midi.xml.MidiDeviceManagerXML;
5
import org.midibox.midi.xml.MidiDeviceRoutingXML;
6
import org.midibox.midi.xml.MidiFilterDeviceManagerXML;
7
import org.midibox.midi.xml.MidiFilterDeviceXML;
8
import org.midibox.midi.xml.MidiKeyboardControllerDeviceXML;
9
import org.midibox.midi.xml.MidiMonitorFilteredDeviceXML;
10
import org.midibox.mios.xml.DebugFunctionDeviceXML;
11
import org.midibox.mios.xml.HexFileUploadDeviceManagerXML;
12
import org.midibox.mios.xml.LCDMessageDeviceXML;
13
import org.midibox.utils.xml.XMLUtils;
14
import org.w3c.dom.Element;
15
import org.w3c.dom.Node;
709 adamjking 16
 
721 adamjking 17
public class MIOSStudioXML extends XMLUtils {
18
 
19
    protected MIOSStudio miosStudio;
20
 
21
    protected String midiThruFilterDeviceTag = "midiThruFilterDevice";
22
 
23
    protected String midiDeviceManagerTag = "midiDeviceManager";
24
 
25
    protected String midiFilterDeviceManagerTag = "midiFilterDeviceManager";
26
 
27
    protected String midiInPortMonitorDeviceTag = "midiInPortMonitorDevice";
28
 
29
    protected String midiOutPortMonitorDeviceTag = "midiOutPortMonitorDevice";
30
 
31
    protected String midiKeyboardControllerDeviceTag = "midiKeyboardControllerDevice";
32
 
33
    protected String hexFileUploadDeviceManagerTag = "hexFileUploadDeviceManager";
34
 
35
    protected String lcdMessageDeviceTag = "lcdMessageDevice";
36
 
37
    protected String debugFunctionDeviceTag = "debugFunctionDevice";
38
 
39
    protected String miosTerminalDeviceTag = "miosTeminalDevice";
40
 
41
    protected String midiDeviceRoutingTag = "midiDeviceRouting";
42
 
43
    protected String midiThruOutPortAttr = "midiThruOutPort";
44
 
45
    protected String routeIndividualDevicesAttr = "routeIndividualDevices";
46
 
47
    public MIOSStudioXML(MIOSStudio miosStudio, String rootElementTag) {
48
 
49
        super(rootElementTag);
50
 
51
        this.miosStudio = miosStudio;
52
 
53
        tags.add(midiThruFilterDeviceTag);
54
        tags.add(midiDeviceManagerTag);
55
        tags.add(midiFilterDeviceManagerTag);
56
        tags.add(midiOutPortMonitorDeviceTag);
57
        tags.add(midiInPortMonitorDeviceTag);
58
        tags.add(midiKeyboardControllerDeviceTag);
59
        tags.add(hexFileUploadDeviceManagerTag);
60
        tags.add(lcdMessageDeviceTag);
61
        tags.add(debugFunctionDeviceTag);
62
        tags.add(miosTerminalDeviceTag);
63
        tags.add(midiDeviceRoutingTag);
64
    }
65
 
66
    protected void parseElement(Element element) {
67
 
68
        super.parseElement(element);
69
 
70
        String name = element.getNodeName();
71
 
72
        if (name == rootElementTag) {
73
 
74
            miosStudio.setMidiThruOutPort(Boolean.parseBoolean(element
75
                    .getAttribute(midiThruOutPortAttr)));
76
 
77
            miosStudio.setRouteIndividualDevices(Boolean.parseBoolean(element
78
                    .getAttribute(routeIndividualDevicesAttr)));
79
 
80
        } else if (name == midiThruFilterDeviceTag) {
81
 
82
            MidiFilterDeviceXML midiFilterDeviceXML = new MidiFilterDeviceXML(
83
                    miosStudio.getMidiThruFilterDevice(),
84
                    midiThruFilterDeviceTag);
85
 
86
            midiFilterDeviceXML.loadXML(element);
87
 
88
        } else if (name == midiDeviceManagerTag) {
89
 
90
            MidiDeviceManagerXML midiDeviceManagerXML = new MidiDeviceManagerXML(
91
                    miosStudio.getMidiDeviceManager(), midiDeviceManagerTag);
92
 
93
            midiDeviceManagerXML.loadXML(element);
94
 
95
        } else if (name == midiFilterDeviceManagerTag) {
96
 
97
            MidiFilterDeviceManagerXML midiFilterDeviceManagerXML = new MidiFilterDeviceManagerXML(
98
                    miosStudio.getMidiFilterManager(),
99
                    midiFilterDeviceManagerTag);
100
 
101
            midiFilterDeviceManagerXML.loadXML(element);
102
 
103
        } else if (name == midiOutPortMonitorDeviceTag) {
104
 
105
            MidiMonitorFilteredDeviceXML midiMonitorFilteredDeviceXML = new MidiMonitorFilteredDeviceXML(miosStudio.getMidiOutPortMonitorDevice(), midiOutPortMonitorDeviceTag);
106
 
107
            midiMonitorFilteredDeviceXML.loadXML(element);
108
 
109
        } else if (name == midiInPortMonitorDeviceTag) {
110
 
111
            MidiMonitorFilteredDeviceXML midiMonitorFilteredDeviceXML = new MidiMonitorFilteredDeviceXML(miosStudio.getMidiInPortMonitorDevice(), midiInPortMonitorDeviceTag);
112
 
113
            midiMonitorFilteredDeviceXML.loadXML(element);
114
 
115
        } else if (name == midiKeyboardControllerDeviceTag) {
116
 
117
            // TODO
118
 
119
        } else if (name == hexFileUploadDeviceManagerTag) {
120
 
121
            // TODO
122
 
123
        } else if (name == lcdMessageDeviceTag) {
124
 
125
            // TODO
126
 
127
        } else if (name == debugFunctionDeviceTag) {
128
 
129
            // TODO
130
 
131
        } else if (name == miosTerminalDeviceTag) {
132
 
133
            MidiMonitorFilteredDeviceXML midiMonitorFilteredDeviceXML = new MidiMonitorFilteredDeviceXML(miosStudio.getMIOSTerminalDevice(), miosTerminalDeviceTag);
134
 
135
            midiMonitorFilteredDeviceXML.loadXML(element);
136
 
137
        } else if (name == midiDeviceRoutingTag) {
138
 
139
            boolean routeIndividualDevices = miosStudio.isRouteIndividualDevices();        
140
 
141
            miosStudio.setRouteIndividualDevices(true);
142
 
143
            MidiDeviceRoutingXML midiDeviceRoutingXML = new MidiDeviceRoutingXML(miosStudio.getMidiDeviceRouting(), midiDeviceRoutingTag);
144
 
145
            midiDeviceRoutingXML.loadXML(element);
146
 
147
            miosStudio.setRouteIndividualDevices(routeIndividualDevices);
148
        }      
149
    }
150
 
151
    public void saveXML(Node node) {
152
 
153
        super.saveXML(node);
154
 
155
        rootElement.setAttribute(routeIndividualDevicesAttr, miosStudio
156
                .isRouteIndividualDevices() ? "true" : "false");
157
 
158
        rootElement.setAttribute(midiThruOutPortAttr, miosStudio
159
                .isMidiThruOutPort() ? "true" : "false");
160
 
161
        MidiFilterDeviceXML midiFilterDeviceXML = new MidiFilterDeviceXML(
162
                miosStudio.getMidiThruFilterDevice(), midiThruFilterDeviceTag);
163
 
164
        midiFilterDeviceXML.saveXML(rootElement);
165
 
166
        saveMIDIXML(miosStudio);
167
 
168
        saveMIOSXML(miosStudio);
169
 
170
        MidiDeviceRoutingXML midiDeviceRoutingXML = new MidiDeviceRoutingXML(
171
                miosStudio.getMidiDeviceRouting(), midiDeviceRoutingTag);
172
 
173
        midiDeviceRoutingXML.saveXML(rootElement);
174
    }
175
 
176
    protected void saveMIDIXML(MIOSStudio miosStudio) {
177
 
178
        MidiDeviceManagerXML midiDeviceManagerXML = new MidiDeviceManagerXML(
179
                miosStudio.getMidiDeviceManager(), midiDeviceManagerTag);
180
 
181
        midiDeviceManagerXML.saveXML(rootElement);
182
 
183
        MidiFilterDeviceManagerXML midiFilterDeviceManagerXML = new MidiFilterDeviceManagerXML(
184
                miosStudio.getMidiFilterManager(), midiFilterDeviceManagerTag);
185
 
186
        midiFilterDeviceManagerXML.saveXML(rootElement);
187
 
188
        MidiMonitorFilteredDeviceXML midiMonitorFilteredDeviceXML = new MidiMonitorFilteredDeviceXML(
189
                miosStudio.getMidiOutPortMonitorDevice(),
190
                midiOutPortMonitorDeviceTag);
191
 
192
        midiMonitorFilteredDeviceXML.saveXML(rootElement);
193
 
194
        midiMonitorFilteredDeviceXML = new MidiMonitorFilteredDeviceXML(
195
                miosStudio.getMidiInPortMonitorDevice(),
196
                midiInPortMonitorDeviceTag);
197
 
198
        midiMonitorFilteredDeviceXML.saveXML(rootElement);
199
 
200
        MidiKeyboardControllerDeviceXML midiControllerDeviceXML = new MidiKeyboardControllerDeviceXML(
201
                miosStudio.getMidiKeyboardControllerDevice(),
202
                midiKeyboardControllerDeviceTag);
203
 
204
        midiControllerDeviceXML.saveXML(rootElement);
205
    }
206
 
207
    protected void saveMIOSXML(MIOSStudio miosStudio) {
208
 
209
        HexFileUploadDeviceManagerXML hexFileUploadDeviceManagerXML = new HexFileUploadDeviceManagerXML(
210
                miosStudio.getHexFileUploadDeviceManager(),
211
                hexFileUploadDeviceManagerTag);
212
 
213
        hexFileUploadDeviceManagerXML.saveXML(rootElement);
214
 
215
        LCDMessageDeviceXML lcdMessageDeviceXML = new LCDMessageDeviceXML(
216
                miosStudio.getLcdMessageDevice(), lcdMessageDeviceTag);
217
 
218
        lcdMessageDeviceXML.saveXML(rootElement);
219
 
220
        DebugFunctionDeviceXML debugFunctionDeviceXML = new DebugFunctionDeviceXML(
221
                miosStudio.getDebugFunctionDevice(), debugFunctionDeviceTag);
222
 
223
        debugFunctionDeviceXML.saveXML(rootElement);
224
 
225
        MidiMonitorFilteredDeviceXML midiMonitorFilteredDeviceXML = new MidiMonitorFilteredDeviceXML(
226
                miosStudio.getMIOSTerminalDevice(), miosTerminalDeviceTag);
227
 
228
        midiMonitorFilteredDeviceXML.saveXML(rootElement);
229
    }
709 adamjking 230
}