Subversion Repositories svn.mios

Rev

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

Rev Author Line No. Line
628 adamjking 1
/*
2
 * @(#)MidiParameter.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.Observable;
24
 
25
import javax.sound.midi.MidiMessage;
26
import javax.sound.midi.Receiver;
27
import javax.sound.midi.ShortMessage;
28
 
721 adamjking 29
public class MidiParameter extends Observable {
628 adamjking 30
 
31
    public final static int NOTE_OFF = ShortMessage.NOTE_OFF;
32
 
33
    public final static int NOTE_ON = ShortMessage.NOTE_ON;
34
 
35
    public final static int AFTERTOUCH = ShortMessage.POLY_PRESSURE;
36
 
37
    public final static int CONTROL_CHANGE = ShortMessage.CONTROL_CHANGE;
38
 
39
    public final static int PROGRAM_CHANGE = ShortMessage.PROGRAM_CHANGE;
40
 
41
    public final static int CHANNEL_PRESSURE = ShortMessage.CHANNEL_PRESSURE;
42
 
43
    public final static int PITCH_BEND = ShortMessage.PITCH_BEND;
44
 
45
    public final static Object STATUS = new Object();
46
 
47
    public final static Object CHANNEL = new Object();
48
 
49
    public final static Object NUMBER = new Object();
50
 
51
    public final static Object VALUE = new Object();
721 adamjking 52
 
628 adamjking 53
    public final static Object HIGH_RESOLUTION = new Object();
54
 
55
    protected int channel;
56
 
57
    protected int status;
58
 
59
    protected int value;
60
 
721 adamjking 61
    protected int number;  
628 adamjking 62
 
63
    protected boolean highResolution;
64
 
721 adamjking 65
    public MidiParameter(int status, int channel,
66
            int number, int value) {
628 adamjking 67
        setMidiStatus(status);
68
        setMidiChannel(channel);
69
        setMidiNumber(number);
721 adamjking 70
        setMidiValue(value);
628 adamjking 71
        setHighResolution(false);
72
    }
73
 
721 adamjking 74
 
628 adamjking 75
    public int getMidiStatus() {
76
        return status;
77
    }
78
 
79
    public void setMidiStatus(int status) {
80
 
81
        this.status = status;
82
 
83
        setChanged();
84
        notifyObservers(STATUS);
85
        clearChanged();
86
    }
87
 
88
    public int getMidiChannel() {
89
        return channel;
90
    }
91
 
92
    public void setMidiChannel(int channel) {
93
 
94
        this.channel = channel;
95
 
96
        setChanged();
97
        notifyObservers(CHANNEL);
98
        clearChanged();
99
    }
100
 
101
    public int getMidiValue() {
102
        return value & getMidiMaxValue();
103
    }
104
 
721 adamjking 105
    public void setMidiValue(int value) {
628 adamjking 106
 
107
        this.value = value & getMidiMaxValue();
108
 
109
        setChanged();
110
        notifyObservers(VALUE);
111
        clearChanged();
112
    }
113
 
114
    public int getMidiMaxValue() {
115
 
116
        int currentStatus = getMidiStatus();
117
 
118
        if (currentStatus == PITCH_BEND
119
                || (currentStatus == CONTROL_CHANGE && highResolution)) {
120
            return 16383;
121
        } else {
122
            return 127;
123
        }
124
    }
125
 
657 adamjking 126
    public int getMidiMinValue() {
127
 
128
        return 0;
129
    }
130
 
628 adamjking 131
    public String getMidiName() {
132
 
133
        if (status == NOTE_ON || status == NOTE_OFF) {
134
            return "Note " + MidiUtils.getKeyName(number);
135
        } else if (status == AFTERTOUCH) {
136
            return "Aftertouch " + MidiUtils.getKeyName(number);
137
        } else if (status == CONTROL_CHANGE) {
138
            if (highResolution) {
139
                return MidiUtils.cc14BitNames[number];
140
            } else {
141
                return MidiUtils.ccNames[number];
142
            }
143
        } else if (status == PROGRAM_CHANGE) {
144
            return "Program Change";
145
        } else if (status == CHANNEL_PRESSURE) {
146
            return "Channel Pressure";
147
        } else if (status == PITCH_BEND) {
148
            return "Pitch Bend";
149
        } else {
150
            return "undefined";
151
        }
152
    }
153
 
154
    public int getMidiNumber() {
155
        return number;
156
    }
157
 
158
    public void setMidiNumber(int number) {
159
        this.number = number;
160
 
161
        int currentStatus = getMidiStatus();
162
 
163
        setChanged();
164
        notifyObservers(NUMBER);
165
        clearChanged();
166
    }
167
 
168
    public boolean isHighResolution() {
169
        return highResolution;
170
    }
171
 
172
    public void setHighResolution(boolean highResolution) {
173
        this.highResolution = highResolution;
174
 
175
        setChanged();
176
        notifyObservers(HIGH_RESOLUTION);
177
        clearChanged();
178
    }
179
}