Subversion Repositories svn.mios

Rev

Rev 290 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 290 Rev 628
Line 1... Line 1...
1
/*
1
/*
2
 * @(#)MidiUtils.java   beta7   2006/04/23
2
 * @(#)MidiUtils.java   beta8   2006/04/23
3
 *
3
 *
4
 * Copyright (C) 2006    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.
Line 21... Line 21...
21
package org.midibox.midi;
21
package org.midibox.midi;
22
22
23
import javax.sound.midi.ShortMessage;
23
import javax.sound.midi.ShortMessage;
24
24
25
public class MidiUtils {
25
public class MidiUtils {
-
 
26
-
 
27
    public static String[] ccNames = { "Bank Select", "Modulation Wheel",
-
 
28
            "Breath Controller", "Undefined", "Foot Controller",
-
 
29
            "Portamento Time", "Data Entry", "Volume", "Balance", "Undefined",
-
 
30
            "Pan", "Expression Controller", "Effect Control 1",
-
 
31
            "Effect Control 2", "Undefined", "Undefined", "GP Controller 1",
-
 
32
            "GP Controller 2", "GP Controller 3", "GP Controller 4",
-
 
33
            "Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
-
 
34
            "Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
-
 
35
            "Undefined", "Undefined", "LSB 0 (Bank Select)",
-
 
36
            "LSB 1 (Modulation Wheel)", "LSB 2 (Breath Controller)",
-
 
37
            "LSB 3 (Undefined)", "LSB 4 (Foot Controller)",
-
 
38
            "LSB 5 (Portamento Time)", "LSB 6 (Data Entry)",
-
 
39
            "LSB 7 (Channel Volume)", "LSB 8 (Balance)", "LSB 9 (Undefined)",
-
 
40
            "LSB 10 (Pan)", "LSB 11 (Expression Controller)",
-
 
41
            "LSB 12 (Effect  1)", "LSB 13 (Effect  2)", "LSB 14 (Undefined)",
-
 
42
            "LSB 15 (Undefined)", "LSB 16 (GP ler 1)", "LSB 17 (GP ler 2)",
-
 
43
            "LSB 18 (GP ler 3)", "LSB 19 (GP ler 4)", "LSB 20 (Undefined)",
-
 
44
            "LSB 21 (Undefined)", "LSB 22 (Undefined)", "LSB 23 (Undefined)",
-
 
45
            "LSB 24 (Undefined)", "LSB 25 (Undefined)", "LSB 26 (Undefined)",
-
 
46
            "LSB 27 (Undefined)", "LSB 28 (Undefined)", "LSB 29 (Undefined)",
-
 
47
            "LSB 30 (Undefined)", "LSB 31 (Undefined)",
-
 
48
            "Damper Pedal On/Off (Sustain)", "Portamento On/Off",
-
 
49
            "Sustenuto On/Off", "Soft Pedal On/Off", "Legato Footswitch",
-
 
50
            "Hold 2", "Sound Controller 1", "Sound Controller 2",
-
 
51
            "Sound Controller 3", "Sound Controller 4", "Sound Controller 5",
-
 
52
            "Sound Controller 6", "Sound Controller 7", "Sound Controller 8",
-
 
53
            "Sound Controller 9", "Sound Controller 10", "GP Controller 5",
-
 
54
            "GP Controller 6", "GP Controller 7", "GP Controller 8",
-
 
55
            "Portamento Control", "Undefined", "Undefined", "Undefined",
-
 
56
            "Undefined", "Undefined", "Undefined", "Effects 1 Depth",
-
 
57
            "Effects 2 Depth", "Effects 3 Depth", "Effects 4 Depth",
-
 
58
            "Effects 5 Depth", "Data Increment", "Data Decrement",
-
 
59
            "Non-Reg. Param. No. - LSB", "Non-Reg. Param. No. - MSB",
-
 
60
            "Reg. Param. No. - LSB", "Reg. Param. No. - MSB", "Undefined",
-
 
61
            "Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
-
 
62
            "Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
-
 
63
            "Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
-
 
64
            "Undefined", "Undefined", "All Sound Off", "Reset All Controllers",
-
 
65
            "Local Control On/Off", "All Notes Off", "Omni Mode Off",
-
 
66
            "Omni Mode On", "Poly Mode On/Off", "Poly Mode On" };
-
 
67
-
 
68
    public static String[] cc14BitNames = { "Bank Select (14 bit)",
-
 
69
            "Modulation Wheel (14 bit)", "Breath Controller (14 bit)",
-
 
70
            "Undefined (14 bit)", "Foot Controller (14 bit)",
-
 
71
            "Portamento Time (14 bit)", "Data Entry MSB (14 bit)",
-
 
72
            "Volume (14 bit)", "Balance (14 bit)", "Undefined (14 bit)",
-
 
73
            "Pan (14 bit)", "Expression Controller (14 bit)",
-
 
74
            "Effect Control 1 (14 bit)", "Effect Control 2 (14 bit)",
-
 
75
            "Undefined (14 bit)", "Undefined (14 bit)",
-
 
76
            "GP Controller 1 (14 bit)", "GP Controller 2 (14 bit)",
-
 
77
            "GP Controller 3 (14 bit)", "GP Controller 4 (14 bit)",
-
 
78
            "Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
-
 
79
            "Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
-
 
80
            "Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
-
 
81
            "Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
-
 
82
            "Bank Select (14 bit)", "Modulation Wheel (14 bit)",
-
 
83
            "Breath Controller (14 bit)", "Undefined (14 bit)",
-
 
84
            "Foot Controller (14 bit)", "Portamento Time (14 bit)",
-
 
85
            "Data Entry MSB (14 bit)", "Volume (14 bit)", "Balance (14 bit)",
-
 
86
            "Undefined (14 bit)", "Pan (14 bit)",
-
 
87
            "Expression Controller (14 bit)", "Effect Control 1 (14 bit)",
-
 
88
            "Effect Control 2 (14 bit)", "Undefined (14 bit)",
-
 
89
            "Undefined (14 bit)", "GP Controller 1 (14 bit)",
-
 
90
            "GP Controller 2 (14 bit)", "GP Controller 3 (14 bit)",
-
 
91
            "GP Controller 4 (14 bit)", "Undefined (14 bit)",
-
 
92
            "Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
-
 
93
            "Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
-
 
94
            "Undefined (14 bit)", "Undefined (14 bit)", "Undefined (14 bit)",
-
 
95
            "Undefined (14 bit)", "Undefined (14 bit)",
-
 
96
            "Damper Pedal On/Off (Sustain)", "Portamento On/Off",
-
 
97
            "Sustenuto On/Off", "Soft Pedal On/Off", "Legato Footswitch",
-
 
98
            "Hold 2", "Sound Controller 1", "Sound Controller 2",
-
 
99
            "Sound Controller 3", "Sound Controller 4", "Sound Controller 5",
-
 
100
            "Sound Controller 6", "Sound Controller 7", "Sound Controller 8",
-
 
101
            "Sound Controller 9", "Sound Controller 10", "GP Controller 5",
-
 
102
            "GP Controller 6", "GP Controller 7", "GP Controller 8",
-
 
103
            "Portamento Control", "Undefined", "Undefined", "Undefined",
-
 
104
            "Undefined", "Undefined", "Undefined", "Effects 1 Depth",
-
 
105
            "Effects 2 Depth", "Effects 3 Depth", "Effects 4 Depth",
-
 
106
            "Effects 5 Depth", "Data Increment", "Data Decrement",
-
 
107
            "Non-Reg. Param. No. (14 bit)", "Non-Reg. Param. No. (14 bit)",
-
 
108
            "Reg. Param. No. (14 bit)", "Reg. Param. No. (14 bit)",
-
 
109
            "Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
-
 
110
            "Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
-
 
111
            "Undefined", "Undefined", "Undefined", "Undefined", "Undefined",
-
 
112
            "Undefined", "Undefined", "Undefined", "All Sound Off",
-
 
113
            "Reset All Controllers", "Local Control On/Off", "All Notes Off",
-
 
114
            "Omni Mode Off", "Omni Mode On", "Poly Mode On/Off", "Poly Mode On" };
-
 
115
-
 
116
    public static final String[] s_astrKeyNames = { "C", "C#", "D", "D#", "E",
-
 
117
            "F", "F#", "G", "G#", "A", "A#", "B" };
-
 
118
-
 
119
    public static final String[] s_astrKeySignatures = { "Cb", "Gb", "Db",
-
 
120
            "Ab", "Eb", "Bb", "F", "C", "G", "D", "A", "E", "B", "F#", "C#" };
-
 
121
-
 
122
    public static final String[] SYSTEM_MESSAGE_TEXT = {
-
 
123
            "System Exclusive (should not be in ShortMessage!)",
-
 
124
            "MTC Quarter Frame: ", "Song Position: ", "Song Select: ",
-
 
125
            "Undefined", "Undefined", "Tune Request",
-
 
126
            "End of SysEx (should not be in ShortMessage!)", "Timing clock",
-
 
127
            "Undefined", "Start", "Continue", "Stop", "Undefined",
-
 
128
            "Active Sensing", "System Reset" };
-
 
129
-
 
130
    public static final String[] QUARTER_FRAME_MESSAGE_TEXT = {
-
 
131
            "frame count LS: ", "frame count MS: ", "seconds count LS: ",
-
 
132
            "seconds count MS: ", "minutes count LS: ", "minutes count MS: ",
-
 
133
            "hours count LS: ", "hours count MS: " };
-
 
134
-
 
135
    public static final String[] FRAME_TYPE_TEXT = { "24 frames/second",
-
 
136
            "25 frames/second", "30 frames/second (drop)",
-
 
137
            "30 frames/second (non-drop)", };
26
138
27
    public static final char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6',
139
    public static final char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6',
28
            '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
140
            '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
-
 
141
-
 
142
    public static String getKeyName(int nKeyNumber) {
-
 
143
        if (nKeyNumber > 127) {
-
 
144
            return "illegal value";
-
 
145
        } else {
-
 
146
            int nNote = nKeyNumber % 12;
-
 
147
            int nOctave = nKeyNumber / 12;
-
 
148
            return s_astrKeyNames[nNote] + (nOctave - 1);
-
 
149
        }
-
 
150
    }
29
151
30
    public static int get14bitValue(int nLowerPart, int nHigherPart) {
152
    public static int get14bitValue(int nLowerPart, int nHigherPart) {
31
        return (nLowerPart & 0x7F) | ((nHigherPart & 0x7F) << 7);
153
        return (nLowerPart & 0x7F) | ((nHigherPart & 0x7F) << 7);
32
    }
154
    }
33
155
34
    public static int signedByteToUnsigned(byte b) {
156
    public static int signedByteToUnsigned(byte b) {
35
        return b & 0xFF;
157
        return b & 0xFF;
-
 
158
    }
-
 
159
-
 
160
    // convert from microseconds per quarter note to beats per minute and vice
-
 
161
    // versa
-
 
162
    public static float convertTempo(float value) {
-
 
163
        if (value <= 0) {
-
 
164
            value = 0.1f;
-
 
165
        }
-
 
166
        return 60000000.0f / value;
36
    }
167
    }
37
168
38
    public static String getHexString(byte[] aByte) {
169
    public static String getHexString(byte[] aByte) {
39
        StringBuffer sbuf = new StringBuffer(aByte.length * 3 + 2);
170
        StringBuffer sbuf = new StringBuffer(aByte.length * 3 + 2);
40
        for (int i = 0; i < aByte.length; i++) {
171
        for (int i = 0; i < aByte.length; i++) {