Subversion Repositories svn.mios

Rev

Rev 721 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
628 adamjking 1
/*
2
 * @(#)MidiParameterControlManager.java beta8   2006/04/23
3
 *
4
 * Copyright (C) 2008    Adam King (adamjking@optusnet.com.au)
5
 *
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
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This application is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
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
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
20
 
21
package org.midibox.midi;
22
 
23
import java.util.Iterator;
24
import java.util.LinkedList;
25
import java.util.Observable;
26
import java.util.Observer;
27
 
28
import javax.sound.midi.MidiMessage;
29
import javax.sound.midi.Receiver;
30
 
31
public class MidiParameterControlManager extends Observable implements
32
        Observer, Receiver {
33
 
34
    protected LinkedList midiParameters;
35
 
36
    protected int globalChannel = 0;
37
 
38
    protected Receiver receiver;
39
 
40
    public MidiParameterControlManager(Receiver receiver, int globalChannel) {
41
        this.globalChannel = globalChannel;
42
        this.receiver = receiver;
43
        midiParameters = new LinkedList();
44
    }
45
 
46
    public Receiver getReceiver() {
47
        return receiver;
48
    }
49
 
50
    public void setReceiver(Receiver receiver) {
51
        this.receiver = receiver;
52
 
53
        Iterator it = midiParameters.iterator();
54
 
55
        while (it.hasNext()) {
56
            MidiParameterControl midiParameter = (MidiParameterControl) it
57
                    .next();
58
            if (midiParameter.isGlobal()) {
59
                midiParameter.setReceiver(receiver);
60
            }
61
        }
62
    }
63
 
64
    public LinkedList getMidiParameters() {
65
        return midiParameters;
66
    }
67
 
68
    public void addMidiParameter(MidiParameter midiParameter) {
69
        midiParameters.remove(midiParameter);
70
        midiParameters.add(midiParameter);
71
        midiParameter.deleteObserver(this);
72
        midiParameter.addObserver(this);
73
    }
74
 
75
    public void removeMidiParameter(MidiParameter midiParameter) {
76
        midiParameter.deleteObserver(this);
77
        midiParameter.addObserver(this);
78
    }
79
 
80
    public int getGlobalChannel() {
81
        return globalChannel;
82
    }
83
 
84
    public void setGlobalChannel(int globalChannel) {
85
        this.globalChannel = globalChannel;
86
 
87
        Iterator it = midiParameters.iterator();
88
 
89
        while (it.hasNext()) {
90
            MidiParameterControl midiParameter = (MidiParameterControl) it
91
                    .next();
92
            if (midiParameter.isGlobal()) {
93
                midiParameter.setMidiChannel(globalChannel);
94
            }
95
        }
96
 
97
        setChanged();
98
        notifyObservers();
99
        clearChanged();
100
    }
101
 
102
    public void close() {
103
 
104
    }
105
 
106
    public void send(MidiMessage message, long timestamp) {
107
        Object[] parametersArray = midiParameters.toArray();
108
 
109
        for (int p = 0; p < parametersArray.length; p++) {
110
            if (parametersArray[p] != null) {
111
                ((MidiParameter) parametersArray[p]).send(message, timestamp);
112
            }
113
        }
114
    }
115
 
116
    public void update(Observable observable, Object object) {
117
        if (object == MidiParameterControl.GLOBAL) {
118
            if (((MidiParameterControl) observable).isGlobal()) {
119
                ((MidiParameterControl) observable)
120
                        .setMidiChannel(globalChannel);
121
            }
122
        }
123
    }
124
}