Subversion Repositories svn.mios

Rev

Rev 628 | Rev 845 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 628 Rev 808
1
/*
1
/*
2
 * @(#)SysexSendReceive.java    beta8   2006/04/23
2
 * @(#)SysexSendReceive.java    beta8   2006/04/23
3
 *
3
 *
4
 * Copyright (C) 2008    Adam King (adamjking@optusnet.com.au)
4
 * Copyright (C) 2008    Adam King (adamjking@optusnet.com.au)
5
 *
5
 *
6
 * This application is free software; you can redistribute it and/or modify
6
 * This application is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
9
 * (at your option) any later version.
10
 *
10
 *
11
 * This application is distributed in the hope that it will be useful,
11
 * This application is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
14
 * GNU General Public License for more details.
15
 *
15
 *
16
 * You should have received a copy of the GNU General Public License
16
 * You should have received a copy of the GNU General Public License
17
 * along with this application; if not, write to the Free Software
17
 * along with this application; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
19
 */
20
20
21
package org.midibox.midi;
21
package org.midibox.midi;
22
22
23
import java.io.File;
23
import java.io.File;
24
import java.util.LinkedList;
24
import java.util.LinkedList;
25
import java.util.Observable;
25
import java.util.Observable;
26
26
27
import javax.sound.midi.MidiMessage;
27
import javax.sound.midi.MidiMessage;
28
import javax.sound.midi.Receiver;
28
import javax.sound.midi.Receiver;
29
import javax.sound.midi.SysexMessage;
29
import javax.sound.midi.SysexMessage;
30
30
31
public class SysexSendReceive extends Observable implements Receiver {
31
public class SysexSendReceive extends Observable implements Receiver {
32
32
33
    protected Receiver receiver;
33
    protected Receiver receiver;
34
34
35
    protected File file;
35
    protected File file;
36
36
37
    protected long fileLastModified;
37
    protected long fileLastModified;
38
38
39
    protected SysexFile sysexFile;
39
    protected SysexFile sysexFile;
40
40
41
    protected SysexSendReceiveWorkerTask sysexSendReceiveWorkerTask;
41
    protected SysexSendReceiveWorkerTask sysexSendReceiveWorkerTask;
42
42
43
    protected int sendBufferSize;
43
    protected int sendBufferSize;
44
44
45
    protected LinkedList receivedBytes;
45
    protected LinkedList receivedBytes;
46
46
47
    public SysexSendReceive(Receiver receiver) {
47
    public SysexSendReceive(Receiver receiver) {
48
        super();
48
        super();
49
        this.receiver = receiver;
49
        this.receiver = receiver;
50
        sendBufferSize = 256;
50
        sendBufferSize = 256;
51
        receivedBytes = new LinkedList();
51
        receivedBytes = new LinkedList();
52
    }
52
    }
53
53
54
    public File getFile() {
54
    public File getFile() {
55
        return file;
55
        return file;
56
    }
56
    }
57
57
58
    public boolean fileChanged() {
58
    public boolean fileChanged() {
59
        return file.lastModified() != fileLastModified;
59
        return file.lastModified() != fileLastModified;
60
    }
60
    }
61
61
62
    public void setFile(File file) {
62
    public void setFile(File file) {
63
        this.file = file;
63
        this.file = file;
64
        fileLastModified = file.lastModified();
64
        fileLastModified = file.lastModified();
65
65
66
        readSysexFile();
66
        readSysexFile();
67
67
68
        setChanged();
68
        setChanged();
69
        notifyObservers(file);
69
        notifyObservers(file);
70
        clearChanged();
70
        clearChanged();
71
    }
71
    }
72
72
73
    public void readSysexFile() {
73
    public void readSysexFile() {
74
        sysexFile = new SysexFile();
74
        sysexFile = new SysexFile();
75
        if (!sysexFile.read(file.getPath())) {
75
        if (!sysexFile.read(file.getPath())) {
76
            // TODO
76
            // TODO
77
        }
77
        }
78
    }
78
    }
79
79
80
    public SysexFile getSysexFile() {
80
    public SysexFile getSysexFile() {
81
        return sysexFile;
81
        return sysexFile;
82
    }
82
    }
83
83
84
    public int getSendBufferSize() {
84
    public int getSendBufferSize() {
85
        return sendBufferSize;
85
        return sendBufferSize;
86
    }
86
    }
87
87
88
    public void setSendBufferSize(int sendBufferSize) {
88
    public void setSendBufferSize(int sendBufferSize) {
89
        this.sendBufferSize = sendBufferSize;
89
        this.sendBufferSize = sendBufferSize;
90
    }
90
    }
91
91
92
    public LinkedList getReceivedBytes() {
92
    public LinkedList getReceivedBytes() {
93
        return receivedBytes;
93
        return receivedBytes;
94
    }
94
    }
95
95
96
    public void send(MidiMessage message, long timestamp) {
96
    public void send(MidiMessage message, long timestamp) {
97
        if (message instanceof SysexMessage) {
97
        if (message instanceof SysexMessage) {
98
            receivedBytes.add(((SysexMessage) message).getData());
98
            receivedBytes.add(((SysexMessage) message).getData());
99
99
100
            setChanged();
100
            setChanged();
101
            notifyObservers(receivedBytes);
101
            notifyObservers(receivedBytes);
102
            clearChanged();
102
            clearChanged();
103
        }
103
        }
104
    }
104
    }
105
105
106
    public void close() {
106
    public void close() {
107
107
-
 
108
    }
-
 
109
-
 
110
    public void setReceiver(Receiver receiver) {
-
 
111
        this.receiver = receiver;
108
    }
112
    }
109
113
110
    public class SysexSendReceiveWorkerTask extends Thread {
114
    public class SysexSendReceiveWorkerTask extends Thread {
111
115
112
        public void run() {
116
        public void run() {
113
117
114
        }
118
        }
115
    }
119
    }
116
}
120
}
117
 
121