~ubuntu-branches/ubuntu/oneiric/tuxguitar/oneiric

« back to all changes in this revision

Viewing changes to TuxGuitar-midi/src/org/herac/tuxguitar/io/midi/base/MidiMessage.java

  • Committer: Bazaar Package Importer
  • Author(s): Philippe Coval
  • Date: 2008-06-19 00:30:30 UTC
  • mto: (5.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20080619003030-h719szrhsngou7c6
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.herac.tuxguitar.io.midi.base;
 
2
 
 
3
public class MidiMessage{
 
4
        
 
5
        public static final int TYPE_SHORT = 1;
 
6
        public static final int TYPE_META = 2;
 
7
        
 
8
        public static final int NOTE_OFF = 0x80;
 
9
        public static final int NOTE_ON = 0x90;
 
10
        public static final int CONTROL_CHANGE = 0xB0;
 
11
        public static final int PROGRAM_CHANGE = 0xC0;
 
12
        public static final int PITCH_BEND = 0xE0;
 
13
        public static final int SYSTEM_RESET = 0xFF;
 
14
        public static final int TEMPO_CHANGE = 0x51;
 
15
        public static final int TIME_SIGNATURE_CHANGE = 0x58;
 
16
        
 
17
        private int message;
 
18
        private int command;
 
19
        private byte[] data;
 
20
        
 
21
        public MidiMessage(int message, int command) {
 
22
                this.message = message;
 
23
                this.command = command;
 
24
        }
 
25
        
 
26
        public void setData(byte[] data) {
 
27
                this.data = data;
 
28
        }
 
29
        
 
30
        public byte[] getData() {
 
31
                return this.data;
 
32
        }
 
33
        
 
34
        public int getType(){
 
35
                return this.message;
 
36
        }
 
37
        
 
38
        public int getCommand(){
 
39
                return this.command;
 
40
        }
 
41
        
 
42
        public static MidiMessage shortMessage(int command, int channel, int data1, int data2){
 
43
                MidiMessage message = new MidiMessage(TYPE_SHORT,command);
 
44
                message.setData(new byte[]{ (byte)( (command & 0xF0) | (channel & 0x0F) ),(byte)data1, (byte)data2  });
 
45
                return message;
 
46
        }
 
47
        
 
48
        public static MidiMessage shortMessage(int command, int channel, int data){
 
49
                MidiMessage message = new MidiMessage(TYPE_SHORT,command);
 
50
                message.setData(new byte[]{ (byte)( (command & 0xF0) | (channel & 0x0F) ),(byte)data });
 
51
                return message;
 
52
        }
 
53
        
 
54
        public static MidiMessage shortMessage(int command){
 
55
                MidiMessage message = new MidiMessage(TYPE_SHORT,command);
 
56
                message.setData(new byte[]{ (byte)command  });
 
57
                return message;
 
58
        }
 
59
        
 
60
        public static MidiMessage metaMessage(int command, byte[] data){
 
61
                MidiMessage message = new MidiMessage(TYPE_META,command);
 
62
                message.setData(data);
 
63
                return message;
 
64
        }
 
65
}