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

« back to all changes in this revision

Viewing changes to TuxGuitar-midi/src/org/herac/tuxguitar/io/midi/MidiMessageUtils.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;
 
2
 
 
3
import org.herac.tuxguitar.io.midi.base.MidiMessage;
 
4
import org.herac.tuxguitar.song.models.TGTimeSignature;
 
5
 
 
6
public class MidiMessageUtils {
 
7
        
 
8
        public static final byte TICK_MOVE = 0x01;
 
9
        
 
10
        private static int fixValue(int value){
 
11
                int fixedValue = value;
 
12
                fixedValue = Math.min(fixedValue,127);
 
13
                fixedValue = Math.max(fixedValue,0);
 
14
                return fixedValue;
 
15
        }
 
16
        
 
17
        private static int fixChannel(int channel){
 
18
                int fixedChannel = channel;
 
19
                fixedChannel = Math.min(fixedChannel,15);
 
20
                fixedChannel = Math.max(fixedChannel,0);
 
21
                return fixedChannel;
 
22
        }
 
23
        
 
24
        public static MidiMessage noteOn(int channel,int note,int velocity){
 
25
                return MidiMessage.shortMessage(MidiMessage.NOTE_ON, fixChannel(channel), fixValue(note), fixValue(velocity));
 
26
        }
 
27
        
 
28
        public static MidiMessage noteOff(int channel,int note,int velocity){
 
29
                return MidiMessage.shortMessage(MidiMessage.NOTE_OFF, fixChannel(channel), fixValue(note), fixValue(velocity));
 
30
        }
 
31
        
 
32
        public static MidiMessage controlChange(int channel,int controller,int value){
 
33
                return MidiMessage.shortMessage(MidiMessage.CONTROL_CHANGE, fixChannel(channel), fixValue(controller), fixValue(value));
 
34
        }
 
35
        
 
36
        public static MidiMessage programChange(int channel,int instrument){
 
37
                return MidiMessage.shortMessage(MidiMessage.PROGRAM_CHANGE, fixChannel(channel), fixValue(instrument));
 
38
        }
 
39
        
 
40
        public static MidiMessage pitchBend(int channel,int value){
 
41
                return MidiMessage.shortMessage(MidiMessage.PITCH_BEND, fixChannel(channel), 0, fixValue(value));
 
42
        }
 
43
        
 
44
        public static MidiMessage systemReset(){
 
45
                return MidiMessage.shortMessage(MidiMessage.SYSTEM_RESET);
 
46
        }
 
47
        
 
48
        public static MidiMessage tempoInUSQ(int usq){
 
49
                MidiMessage message = new MidiMessage(MidiMessage.TYPE_META, MidiMessage.TEMPO_CHANGE);
 
50
                message.setData(new byte[]{(byte)((usq >> 16) & 0xff),(byte)((usq >> 8) & 0xff),(byte)((usq) & 0xff) });
 
51
                //message.setData(new byte[]{(byte)((usq >> 16) & 0x00FF),(byte)((usq >> 8) & 0x00FF),(byte)((usq) & 0x00FF) });
 
52
                return message;
 
53
        }
 
54
        
 
55
        public static MidiMessage timeSignature(TGTimeSignature ts){
 
56
                MidiMessage message = new MidiMessage(MidiMessage.TYPE_META, MidiMessage.TIME_SIGNATURE_CHANGE);
 
57
                message.setData(new byte[]{  (byte)ts.getNumerator(),(byte)ts.getDenominator().getIndex(),(byte)(96 / ts.getDenominator().getValue()),8 });
 
58
                return message;
 
59
        }
 
60
        
 
61
        public static MidiMessage endOfTrack(){
 
62
                return MidiMessage.metaMessage(47,new byte[]{});
 
63
        }
 
64
}
 
 
b'\\ No newline at end of file'