Subversion Repositories svn.mios

Rev

Rev 720 | 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.midi.xml;
2
 
3
import org.midibox.midi.MidiFilter;
721 adamjking 4
import org.midibox.utils.xml.XMLUtils;
709 adamjking 5
import org.w3c.dom.Element;
6
import org.w3c.dom.Node;
7
 
721 adamjking 8
public class MidiFilterXML extends XMLUtils {
709 adamjking 9
 
721 adamjking 10
    protected MidiFilter midiFilter;
11
 
12
    protected String voiceMessagesTag = "voiceMessages";
709 adamjking 13
 
721 adamjking 14
    protected String voiceMessageTag = "voiceMessage";
709 adamjking 15
 
721 adamjking 16
    protected String channelsTag = "channels";
709 adamjking 17
 
721 adamjking 18
    protected String channelTag = "channel";
709 adamjking 19
 
721 adamjking 20
    protected String controlChangeMessagesTag = "controlChangeMessages";
709 adamjking 21
 
721 adamjking 22
    protected String controlChangeMessageTag = "controlChangeMessage";
709 adamjking 23
 
721 adamjking 24
    protected String systemCommonMessagesTag = "systemCommonMessages";
709 adamjking 25
 
721 adamjking 26
    protected String systemCommonMessageTag = "systemCommonMessage";
709 adamjking 27
 
721 adamjking 28
    protected String systemRealtimeMessagesTag = "systemRealtimeMessages";
709 adamjking 29
 
721 adamjking 30
    protected String systemRealtimeMessageTag = "systemRealtimeMessage";
709 adamjking 31
 
721 adamjking 32
    protected String sysexMessagesTag = "sysexMessages";
709 adamjking 33
 
721 adamjking 34
    protected String metaMessagesTag = "metaMessage";
709 adamjking 35
 
721 adamjking 36
    protected String numberAttr = "number";
709 adamjking 37
 
721 adamjking 38
    protected String enableAttr = "enable";
709 adamjking 39
 
721 adamjking 40
    public MidiFilterXML(MidiFilter midiFilter, String rootElementTag) {
709 adamjking 41
 
721 adamjking 42
        super(rootElementTag);
709 adamjking 43
 
721 adamjking 44
        this.midiFilter = midiFilter;
45
 
46
        tags.add(voiceMessagesTag);
47
        tags.add(voiceMessageTag);
48
        tags.add(channelsTag);
49
        tags.add(channelTag);
50
        tags.add(controlChangeMessagesTag);
51
        tags.add(controlChangeMessageTag);
52
        tags.add(systemCommonMessagesTag);
53
        tags.add(systemCommonMessageTag);
54
        tags.add(systemRealtimeMessagesTag);
55
        tags.add(systemRealtimeMessageTag);
56
        tags.add(sysexMessagesTag);
57
        tags.add(metaMessagesTag);
58
    }
709 adamjking 59
 
721 adamjking 60
    protected void parseElement(Element element) {
61
 
62
        super.parseElement(element);
709 adamjking 63
 
721 adamjking 64
        String name = element.getNodeName();
709 adamjking 65
 
721 adamjking 66
        String numberString = element.getAttribute(numberAttr);
709 adamjking 67
 
721 adamjking 68
        String enableString = element.getAttribute(enableAttr);
709 adamjking 69
 
721 adamjking 70
        int n = 0;
709 adamjking 71
 
721 adamjking 72
        boolean e = false;
709 adamjking 73
 
721 adamjking 74
        if (numberString != "") {
709 adamjking 75
 
721 adamjking 76
            n = Integer.parseInt(numberString);
77
        }
709 adamjking 78
 
721 adamjking 79
        if (enableString != "") {
714 adamjking 80
 
721 adamjking 81
            e = Boolean.parseBoolean(enableString);
82
        }
714 adamjking 83
 
721 adamjking 84
        if (name == channelsTag) {
709 adamjking 85
 
721 adamjking 86
        } else if (name == channelTag) {
714 adamjking 87
 
721 adamjking 88
            midiFilter.setChannel(n, e);
714 adamjking 89
 
721 adamjking 90
        } else if (name == voiceMessagesTag) {
714 adamjking 91
 
721 adamjking 92
            midiFilter.setVoiceMessages(e);
714 adamjking 93
 
721 adamjking 94
        } else if (name == voiceMessageTag) {
714 adamjking 95
 
721 adamjking 96
            midiFilter.setVoiceMessage(n, e);
709 adamjking 97
 
721 adamjking 98
        } else if (name == systemCommonMessagesTag) {
714 adamjking 99
 
721 adamjking 100
            midiFilter.setSystemCommonMessages(e);
714 adamjking 101
 
721 adamjking 102
        } else if (name == systemCommonMessageTag) {
709 adamjking 103
 
721 adamjking 104
            midiFilter.setSystemCommonMessage(n, e);
714 adamjking 105
 
721 adamjking 106
        } else if (name == systemRealtimeMessagesTag) {
714 adamjking 107
 
721 adamjking 108
            midiFilter.setSystemRealtimeMessages(e);
714 adamjking 109
 
721 adamjking 110
        } else if (name == systemRealtimeMessageTag) {
714 adamjking 111
 
721 adamjking 112
            midiFilter.setSystemRealtimeMessage(n, e);
714 adamjking 113
 
721 adamjking 114
        } else if (name == sysexMessagesTag) {
709 adamjking 115
 
721 adamjking 116
            midiFilter.setSysexMessages(e);
714 adamjking 117
 
721 adamjking 118
        } else if (name == metaMessagesTag) {
714 adamjking 119
 
721 adamjking 120
            midiFilter.setMetaMessages(e);
709 adamjking 121
 
721 adamjking 122
        } else if (name == controlChangeMessagesTag) {
714 adamjking 123
 
721 adamjking 124
        } else if (name == controlChangeMessageTag) {
714 adamjking 125
 
721 adamjking 126
            midiFilter.setControlChange(n, e);
709 adamjking 127
        }
128
    }
129
 
721 adamjking 130
    public void saveXML(Node node) {
709 adamjking 131
 
721 adamjking 132
        super.saveXML(node);
709 adamjking 133
 
721 adamjking 134
        Element voiceMessagesElement = document.createElement(voiceMessagesTag);
709 adamjking 135
 
721 adamjking 136
        rootElement.appendChild(voiceMessagesElement);
709 adamjking 137
 
721 adamjking 138
        voiceMessagesElement.setAttribute(enableAttr, midiFilter
139
                .isVoiceMessages() ? "true" : "false");
709 adamjking 140
 
721 adamjking 141
        for (int c = 0; c < midiFilter.getVoiceMessages().length; c++) {
709 adamjking 142
 
721 adamjking 143
            Element voiceMessage = document.createElement(voiceMessageTag);
709 adamjking 144
 
721 adamjking 145
            voiceMessagesElement.appendChild(voiceMessage);
709 adamjking 146
 
721 adamjking 147
            voiceMessage.setAttribute(numberAttr, "" + ((c | 8) << 4));
709 adamjking 148
 
721 adamjking 149
            voiceMessage.setAttribute(enableAttr, (midiFilter
150
                    .getVoiceMessages()[c]) ? "true" : "false");
709 adamjking 151
        }
152
 
721 adamjking 153
        Element controlChangeMessagesElement = document
154
                .createElement(controlChangeMessagesTag);
709 adamjking 155
 
721 adamjking 156
        voiceMessagesElement.appendChild(controlChangeMessagesElement);
709 adamjking 157
 
721 adamjking 158
        for (int cc = 0; cc < midiFilter.getControlChangeMessages().length; cc++) {
709 adamjking 159
 
721 adamjking 160
            Element controlChangeMessage = document
161
                    .createElement(controlChangeMessageTag);
709 adamjking 162
 
721 adamjking 163
            controlChangeMessagesElement.appendChild(controlChangeMessage);
709 adamjking 164
 
721 adamjking 165
            controlChangeMessage.setAttribute(numberAttr, "" + (cc));
709 adamjking 166
 
721 adamjking 167
            controlChangeMessage.setAttribute(enableAttr, (midiFilter
168
                    .getControlChangeMessages()[cc]) ? "true" : "false");
714 adamjking 169
        }
170
 
721 adamjking 171
        Element channelsElement = document.createElement(channelsTag);
720 adamjking 172
 
173
        voiceMessagesElement.appendChild(channelsElement);
709 adamjking 174
 
714 adamjking 175
        for (int c = 0; c < midiFilter.getChannels().length; c++) {
709 adamjking 176
 
721 adamjking 177
            Element channel = document.createElement(channelTag);
709 adamjking 178
 
179
            channelsElement.appendChild(channel);
180
 
721 adamjking 181
            channel.setAttribute(numberAttr, "" + (c + 1));
709 adamjking 182
 
721 adamjking 183
            channel.setAttribute(enableAttr,
184
                    (midiFilter.getChannels()[c]) ? "true" : "false");
185
        }
714 adamjking 186
 
721 adamjking 187
        Element systemCommonMessagesElement = document
188
                .createElement(systemCommonMessagesTag);
714 adamjking 189
 
721 adamjking 190
        rootElement.appendChild(systemCommonMessagesElement);
191
 
192
        systemCommonMessagesElement.setAttribute(enableAttr, midiFilter
193
                .isSystemCommonMessages() ? "true" : "false");
194
 
714 adamjking 195
        for (int c = 0; c < midiFilter.getSystemCommonMessages().length; c++) {
196
 
721 adamjking 197
            Element systemCommonMessage = document
198
                    .createElement(systemCommonMessageTag);
714 adamjking 199
 
200
            systemCommonMessagesElement.appendChild(systemCommonMessage);
201
 
721 adamjking 202
            systemCommonMessage.setAttribute(numberAttr, "" + (c | 0xF0));
714 adamjking 203
 
721 adamjking 204
            systemCommonMessage.setAttribute(enableAttr, (midiFilter
205
                    .getSystemCommonMessages()[c]) ? "true" : "false");
714 adamjking 206
        }
207
 
721 adamjking 208
        Element systemRealtimeMessagesElement = document
209
                .createElement(systemRealtimeMessagesTag);
714 adamjking 210
 
721 adamjking 211
        rootElement.appendChild(systemRealtimeMessagesElement);
714 adamjking 212
 
721 adamjking 213
        systemRealtimeMessagesElement.setAttribute(enableAttr, midiFilter
214
                .isSystemRealtimeMessages() ? "true" : "false");
215
 
714 adamjking 216
        for (int c = 0; c < midiFilter.getSystemRealtimeMessages().length; c++) {
217
 
721 adamjking 218
            Element systemRealtimeMessage = document
219
                    .createElement(systemRealtimeMessageTag);
714 adamjking 220
 
221
            systemRealtimeMessagesElement.appendChild(systemRealtimeMessage);
222
 
721 adamjking 223
            systemRealtimeMessage.setAttribute(numberAttr, ""
224
                    + ((c + 8 | 0xF0)));
714 adamjking 225
 
721 adamjking 226
            systemRealtimeMessage.setAttribute(enableAttr, (midiFilter
227
                    .getSystemRealtimeMessages()[c]) ? "true" : "false");
714 adamjking 228
        }
229
 
721 adamjking 230
        Element sysexMessagesElement = document.createElement(sysexMessagesTag);
714 adamjking 231
 
721 adamjking 232
        rootElement.appendChild(sysexMessagesElement);
714 adamjking 233
 
721 adamjking 234
        sysexMessagesElement.setAttribute(enableAttr, midiFilter
235
                .isSysexMessages() ? "true" : "false");
714 adamjking 236
 
721 adamjking 237
        Element metaMessagesElement = document.createElement(metaMessagesTag);
238
 
239
        rootElement.appendChild(metaMessagesElement);
240
 
241
        metaMessagesElement.setAttribute(enableAttr, midiFilter
242
                .isMetaMessages() ? "true" : "false");
709 adamjking 243
    }
244
}