Subversion Repositories svn.mios

Rev

Rev 800 | 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;
808 adamjking 6
import org.midibox.midi.xml.MidiFilterManagerXML;
7
import org.midibox.midi.xml.MidiFilterXML;
8
import org.midibox.midi.xml.MidiKeyboardControllerXML;
9
import org.midibox.midi.xml.MidiMonitorFilteredXML;
10
import org.midibox.midi.xml.SysexSendReceiveManagerXML;
11
import org.midibox.mios.xml.DebugFunctionXML;
12
import org.midibox.mios.xml.HexFileUploadManagerXML;
13
import org.midibox.mios.xml.LCDMessageXML;
721 adamjking 14
import org.midibox.utils.xml.XMLUtils;
15
import org.w3c.dom.Element;
16
import org.w3c.dom.Node;
709 adamjking 17
 
721 adamjking 18
public class MIOSStudioXML extends XMLUtils {
723 adamjking 19
 
722 adamjking 20
    public static final String TAG_ROOT_ELEMENT = "miosStudio";
721 adamjking 21
 
808 adamjking 22
    public static final String TAG_MIDI_THRU_FILTER = "thruMidiFilter";
721 adamjking 23
 
722 adamjking 24
    public static final String TAG_MIDI_DEVICE_MANAGER = "midiDeviceManager";
721 adamjking 25
 
808 adamjking 26
    public static final String TAG_MIDI_FILTER_MANAGER = "midiFilterManager";
721 adamjking 27
 
808 adamjking 28
    public static final String TAG_IN_PORT_MIDI_MONITOR_FILTERED = "inPortMidiMonitorFiltered";
721 adamjking 29
 
808 adamjking 30
    public static final String TAG_OUT_PORT_MIDI_MONITOR_FILTERED = "outPortMidiMonitorFiltered";
721 adamjking 31
 
808 adamjking 32
    public static final String TAG_MIDI_KEYBOARD_CONTROLLER = "midiKeyboardController";
721 adamjking 33
 
808 adamjking 34
    public static final String TAG_SYSEX_SEND_RECEIVE_MANAGER = "sysexSendReciveManager";
721 adamjking 35
 
808 adamjking 36
    public static final String TAG_HEX_FILE_UPLOAD_MANAGER = "hexFileUploadManager";
721 adamjking 37
 
808 adamjking 38
    public static final String TAG_LCD_MESSAGE = "lcdMessage";
721 adamjking 39
 
808 adamjking 40
    public static final String TAG_DEBUG_FUNCTION = "debugFunction";
721 adamjking 41
 
808 adamjking 42
    public static final String TAG_MIOS_TERMINAL_MIDI_MONITOR_FILTERED = "miosTeminalMidiMonitorFiltered";
43
 
722 adamjking 44
    public static final String TAG_MIDI_DEVICE_ROUTING = "midiDeviceRouting";
721 adamjking 45
 
722 adamjking 46
    public static final String ATTR_MIDI_THRU_OUT_PORT = "midiThruOutPort";
723 adamjking 47
 
722 adamjking 48
    public static final String ATTR_ROUTE_INDIVIDUAL_DEVICES = "routeIndividualDevices";
723 adamjking 49
 
722 adamjking 50
    protected MIOSStudio miosStudio;
721 adamjking 51
 
52
    public MIOSStudioXML(MIOSStudio miosStudio, String rootElementTag) {
53
 
54
        super(rootElementTag);
55
 
56
        this.miosStudio = miosStudio;
57
 
808 adamjking 58
        addTag(TAG_MIDI_THRU_FILTER);
753 adamjking 59
        addTag(TAG_MIDI_DEVICE_MANAGER);
808 adamjking 60
        addTag(TAG_MIDI_FILTER_MANAGER);
61
        addTag(TAG_OUT_PORT_MIDI_MONITOR_FILTERED);
62
        addTag(TAG_IN_PORT_MIDI_MONITOR_FILTERED);
63
        addTag(TAG_MIDI_KEYBOARD_CONTROLLER);
64
        addTag(TAG_SYSEX_SEND_RECEIVE_MANAGER);
65
        addTag(TAG_HEX_FILE_UPLOAD_MANAGER);
66
        addTag(TAG_LCD_MESSAGE);
67
        addTag(TAG_DEBUG_FUNCTION);
68
        addTag(TAG_MIOS_TERMINAL_MIDI_MONITOR_FILTERED);
753 adamjking 69
        addTag(TAG_MIDI_DEVICE_ROUTING);
721 adamjking 70
    }
71
 
72
    protected void parseElement(Element element) {
73
 
74
        super.parseElement(element);
75
 
76
        String name = element.getNodeName();
77
 
78
        if (name == rootElementTag) {
79
 
722 adamjking 80
            miosStudio.setMidiThruOutPort(stringToBoolean(element
81
                    .getAttribute(ATTR_MIDI_THRU_OUT_PORT)));
721 adamjking 82
 
722 adamjking 83
            miosStudio.setRouteIndividualDevices(stringToBoolean(element
84
                    .getAttribute(ATTR_ROUTE_INDIVIDUAL_DEVICES)));
721 adamjking 85
 
808 adamjking 86
        } else if (name == TAG_MIDI_THRU_FILTER) {
721 adamjking 87
 
808 adamjking 88
            MidiFilterXML midiFilterXML = new MidiFilterXML(miosStudio
89
                    .getMidiThruFilter(), TAG_MIDI_THRU_FILTER);
721 adamjking 90
 
808 adamjking 91
            midiFilterXML.loadXML(element);
721 adamjking 92
 
722 adamjking 93
        } else if (name == TAG_MIDI_DEVICE_MANAGER) {
721 adamjking 94
 
95
            MidiDeviceManagerXML midiDeviceManagerXML = new MidiDeviceManagerXML(
722 adamjking 96
                    miosStudio.getMidiDeviceManager(), TAG_MIDI_DEVICE_MANAGER);
721 adamjking 97
 
98
            midiDeviceManagerXML.loadXML(element);
99
 
808 adamjking 100
        } else if (name == TAG_MIDI_FILTER_MANAGER) {
721 adamjking 101
 
808 adamjking 102
            MidiFilterManagerXML midiFilterDeviceManagerXML = new MidiFilterManagerXML(
103
                    miosStudio.getMidiFilterManager(), TAG_MIDI_FILTER_MANAGER);
723 adamjking 104
 
721 adamjking 105
            midiFilterDeviceManagerXML.loadXML(element);
723 adamjking 106
 
808 adamjking 107
        } else if (name == TAG_OUT_PORT_MIDI_MONITOR_FILTERED) {
723 adamjking 108
 
808 adamjking 109
            MidiMonitorFilteredXML midiMonitorFilteredXML = new MidiMonitorFilteredXML(
110
                    miosStudio.getMidiOutPortMonitor(),
111
                    TAG_OUT_PORT_MIDI_MONITOR_FILTERED);
723 adamjking 112
 
808 adamjking 113
            midiMonitorFilteredXML.loadXML(element);
723 adamjking 114
 
808 adamjking 115
        } else if (name == TAG_IN_PORT_MIDI_MONITOR_FILTERED) {
723 adamjking 116
 
808 adamjking 117
            MidiMonitorFilteredXML midiMonitorFilteredXML = new MidiMonitorFilteredXML(
118
                    miosStudio.getMidiInPortMonitor(),
119
                    TAG_IN_PORT_MIDI_MONITOR_FILTERED);
723 adamjking 120
 
808 adamjking 121
            midiMonitorFilteredXML.loadXML(element);
723 adamjking 122
 
808 adamjking 123
        } else if (name == TAG_MIDI_KEYBOARD_CONTROLLER) {
723 adamjking 124
 
808 adamjking 125
            MidiKeyboardControllerXML midiKeyboardControllerXML = new MidiKeyboardControllerXML(
126
                    miosStudio.getMidiKeyboardController(),
127
                    TAG_MIDI_KEYBOARD_CONTROLLER);
723 adamjking 128
 
808 adamjking 129
            midiKeyboardControllerXML.loadXML(element);
723 adamjking 130
 
808 adamjking 131
        } else if (name == TAG_SYSEX_SEND_RECEIVE_MANAGER) {
800 adamjking 132
 
808 adamjking 133
            SysexSendReceiveManagerXML sysexSendReceiveManagerXML = new SysexSendReceiveManagerXML(
134
                    miosStudio.getSysexSendReceiveManager(),
135
                    TAG_SYSEX_SEND_RECEIVE_MANAGER);
800 adamjking 136
 
808 adamjking 137
            sysexSendReceiveManagerXML.loadXML(element);
800 adamjking 138
 
808 adamjking 139
        } else if (name == TAG_HEX_FILE_UPLOAD_MANAGER) {
723 adamjking 140
 
808 adamjking 141
            HexFileUploadManagerXML hexFileUploadManagerXML = new HexFileUploadManagerXML(
142
                    miosStudio.getHexFileUploadManager(),
143
                    TAG_HEX_FILE_UPLOAD_MANAGER);
723 adamjking 144
 
808 adamjking 145
            hexFileUploadManagerXML.loadXML(element);
723 adamjking 146
 
808 adamjking 147
        } else if (name == TAG_LCD_MESSAGE) {
723 adamjking 148
 
808 adamjking 149
            LCDMessageXML lcdMessageXML = new LCDMessageXML(miosStudio
150
                    .getLcdMessage(), TAG_LCD_MESSAGE);
723 adamjking 151
 
808 adamjking 152
            lcdMessageXML.loadXML(element);
723 adamjking 153
 
808 adamjking 154
        } else if (name == TAG_DEBUG_FUNCTION) {
723 adamjking 155
 
808 adamjking 156
            DebugFunctionXML debugFunctionXML = new DebugFunctionXML(miosStudio
157
                    .getDebugFunction(), TAG_DEBUG_FUNCTION);
723 adamjking 158
 
808 adamjking 159
            debugFunctionXML.loadXML(element);
723 adamjking 160
 
808 adamjking 161
        } else if (name == TAG_MIOS_TERMINAL_MIDI_MONITOR_FILTERED) {
723 adamjking 162
 
808 adamjking 163
            MidiMonitorFilteredXML midiMonitorFilteredXML = new MidiMonitorFilteredXML(
164
                    miosStudio.getMIOSTerminal(),
165
                    TAG_MIOS_TERMINAL_MIDI_MONITOR_FILTERED);
723 adamjking 166
 
808 adamjking 167
            midiMonitorFilteredXML.loadXML(element);
721 adamjking 168
 
723 adamjking 169
        } else if (name == TAG_MIDI_DEVICE_ROUTING) {
170
 
171
            boolean routeIndividualDevices = miosStudio
172
                    .isRouteIndividualDevices();
173
 
721 adamjking 174
            miosStudio.setRouteIndividualDevices(true);
723 adamjking 175
 
176
            MidiDeviceRoutingXML midiDeviceRoutingXML = new MidiDeviceRoutingXML(
177
                    miosStudio.getMidiDeviceRouting(), TAG_MIDI_DEVICE_ROUTING);
178
 
721 adamjking 179
            midiDeviceRoutingXML.loadXML(element);
723 adamjking 180
 
721 adamjking 181
            miosStudio.setRouteIndividualDevices(routeIndividualDevices);
723 adamjking 182
        }
721 adamjking 183
    }
184
 
185
    public void saveXML(Node node) {
186
 
187
        super.saveXML(node);
188
 
722 adamjking 189
        rootElement.setAttribute(ATTR_ROUTE_INDIVIDUAL_DEVICES, miosStudio
721 adamjking 190
                .isRouteIndividualDevices() ? "true" : "false");
191
 
722 adamjking 192
        rootElement.setAttribute(ATTR_MIDI_THRU_OUT_PORT, miosStudio
721 adamjking 193
                .isMidiThruOutPort() ? "true" : "false");
194
 
808 adamjking 195
        MidiFilterXML midiFilterXML = new MidiFilterXML(miosStudio
196
                .getMidiThruFilter(), TAG_MIDI_THRU_FILTER);
721 adamjking 197
 
808 adamjking 198
        midiFilterXML.saveXML(rootElement);
721 adamjking 199
 
200
        saveMIDIXML(miosStudio);
201
 
202
        saveMIOSXML(miosStudio);
203
 
204
        MidiDeviceRoutingXML midiDeviceRoutingXML = new MidiDeviceRoutingXML(
722 adamjking 205
                miosStudio.getMidiDeviceRouting(), TAG_MIDI_DEVICE_ROUTING);
721 adamjking 206
 
207
        midiDeviceRoutingXML.saveXML(rootElement);
208
    }
209
 
210
    protected void saveMIDIXML(MIOSStudio miosStudio) {
211
 
212
        MidiDeviceManagerXML midiDeviceManagerXML = new MidiDeviceManagerXML(
722 adamjking 213
                miosStudio.getMidiDeviceManager(), TAG_MIDI_DEVICE_MANAGER);
721 adamjking 214
 
215
        midiDeviceManagerXML.saveXML(rootElement);
216
 
808 adamjking 217
        MidiFilterManagerXML midiFilterDeviceManagerXML = new MidiFilterManagerXML(
218
                miosStudio.getMidiFilterManager(), TAG_MIDI_FILTER_MANAGER);
721 adamjking 219
 
220
        midiFilterDeviceManagerXML.saveXML(rootElement);
221
 
808 adamjking 222
        MidiMonitorFilteredXML midiMonitorFilteredXML = new MidiMonitorFilteredXML(
223
                miosStudio.getMidiOutPortMonitor(),
224
                TAG_OUT_PORT_MIDI_MONITOR_FILTERED);
721 adamjking 225
 
808 adamjking 226
        midiMonitorFilteredXML.saveXML(rootElement);
721 adamjking 227
 
808 adamjking 228
        midiMonitorFilteredXML = new MidiMonitorFilteredXML(miosStudio
229
                .getMidiInPortMonitor(), TAG_IN_PORT_MIDI_MONITOR_FILTERED);
721 adamjking 230
 
808 adamjking 231
        midiMonitorFilteredXML.saveXML(rootElement);
721 adamjking 232
 
808 adamjking 233
        MidiKeyboardControllerXML midiControllerXML = new MidiKeyboardControllerXML(
234
                miosStudio.getMidiKeyboardController(),
235
                TAG_MIDI_KEYBOARD_CONTROLLER);
721 adamjking 236
 
808 adamjking 237
        midiControllerXML.saveXML(rootElement);
800 adamjking 238
 
808 adamjking 239
        SysexSendReceiveManagerXML sysexSendReceiveManagerXML = new SysexSendReceiveManagerXML(
240
                miosStudio.getSysexSendReceiveManager(),
241
                TAG_SYSEX_SEND_RECEIVE_MANAGER);
242
 
243
        sysexSendReceiveManagerXML.saveXML(rootElement);
721 adamjking 244
    }
245
 
246
    protected void saveMIOSXML(MIOSStudio miosStudio) {
247
 
808 adamjking 248
        HexFileUploadManagerXML hexFileUploadManagerXML = new HexFileUploadManagerXML(
249
                miosStudio.getHexFileUploadManager(),
250
                TAG_HEX_FILE_UPLOAD_MANAGER);
721 adamjking 251
 
808 adamjking 252
        hexFileUploadManagerXML.saveXML(rootElement);
721 adamjking 253
 
808 adamjking 254
        LCDMessageXML lcdMessageXML = new LCDMessageXML(miosStudio
255
                .getLcdMessage(), TAG_LCD_MESSAGE);
721 adamjking 256
 
808 adamjking 257
        lcdMessageXML.saveXML(rootElement);
721 adamjking 258
 
808 adamjking 259
        DebugFunctionXML debugFunctionXML = new DebugFunctionXML(miosStudio
260
                .getDebugFunction(), TAG_DEBUG_FUNCTION);
721 adamjking 261
 
808 adamjking 262
        debugFunctionXML.saveXML(rootElement);
721 adamjking 263
 
808 adamjking 264
        MidiMonitorFilteredXML midiMonitorFilteredXML = new MidiMonitorFilteredXML(
265
                miosStudio.getMIOSTerminal(),
266
                TAG_MIOS_TERMINAL_MIDI_MONITOR_FILTERED);
721 adamjking 267
 
808 adamjking 268
        midiMonitorFilteredXML.saveXML(rootElement);
721 adamjking 269
    }
709 adamjking 270
}