Changeset 137 for trunk/libjdkmidijava

Show
Ignore:
Timestamp:
09/21/06 16:46:57 (4 years ago)
Author:
jeffk@…
Message:

minor indents changed

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/libjdkmidijava/trunk/src/com/jdkoftinoff/midi/MIDI.java

    r130 r137  
    11/* 
    22 * MIDI.java 
    3  * 
     3 *  
    44 * Created on 10 September 2006; 16:49 By Jeff Koftinoff <jeffk@jdkoftinoff.com> 
    5  * 
     5 *  
    66 * https://clicker.jdkoftinoff.com/projects/trac/jdks/wiki/libjdkmidijava 
    7  * 
    8  *  libjdkmidijava Java Class Library for MIDI 
    9  * 
    10  *  Copyright (C) 2006  J.D. Koftinoff Software, Ltd. 
    11  *  www.jdkoftinoff.com 
    12  *  jeffk@jdkoftinoff.com 
    13  * 
    14  *  *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) September 11, 2006 *** 
    15  * 
    16  * 
    17  *  This program is free software; you can redistribute it and/or modify 
    18  *  it under the terms of the GNU General Public License as published by 
    19  *  the Free Software Foundation; either version 2 of the License, or 
    20  *  (at your option) any later version. 
    21  * 
    22  *  This program is distributed in the hope that it will be useful, 
    23  *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    24  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    25  *  GNU General Public License for more details. 
    26  * 
    27  *  You should have received a copy of the GNU General Public License 
    28  *  along with this program; if not, write to the Free Software 
    29  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
    30  * 
     7 *  
     8 * libjdkmidijava Java Class Library for MIDI 
     9 *  
     10 * Copyright (C) 2006 J.D. Koftinoff Software, Ltd. www.jdkoftinoff.com 
     11 * jeffk@jdkoftinoff.com 
     12 *  
     13 * *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) September 11, 2006 
     14 * *** 
     15 *  
     16 *  
     17 * This program is free software; you can redistribute it and/or modify it under 
     18 * the terms of the GNU General Public License as published by the Free Software 
     19 * Foundation; either version 2 of the License, or (at your option) any later 
     20 * version. 
     21 *  
     22 * This program is distributed in the hope that it will be useful, but WITHOUT 
     23 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
     24 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
     25 * details. 
     26 *  
     27 * You should have received a copy of the GNU General Public License along with 
     28 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 
     29 * Place, Suite 330, Boston, MA 02111-1307 USA 
     30 *  
    3131 */ 
    3232 
     
    3434 
    3535/** 
    36  * The MIDI class is only used for standard MIDI constants and simple utility static methods. 
     36 * The MIDI class is only used for standard MIDI constants and simple utility 
     37 * static methods. 
     38 *  
    3739 * @author jeffk 
    3840 */ 
    3941public class MIDI 
    4042{ 
    41      
    42     /** 
    43      *  Message Length Lookup table for normal status bytes, shifted right 4 bits. 
    44      * A value of -1 means to use the lut_sysmsglen lookup table instead. 
    45      */ 
    46     public static int [] lut_msglen = { 
    47         0,0,0,0,0,0,0,0, 
    48         3,  // 0x80=note off, 3 bytes 
    49         3,  // 0x90=note on, 3 bytes 
    50         3,  // 0xa0=poly pressure, 3 bytes 
    51         3,  // 0xb0=control change, 3 bytes 
    52         2,  // 0xc0=program change, 2 bytes 
    53         2,  // 0xd0=channel pressure, 2 bytes 
    54         3,  // 0xe0=pitch bend, 3 bytes 
    55         -1  // 0xf0=other things. may vary. 
     43 
     44    /** 
     45     * Message Length Lookup table for normal status bytes, shifted right 4 
     46     * bits. A value of -1 means to use the lut_sysmsglen lookup table instead. 
     47     */ 
     48    public static int[] lut_msglen = 
     49    { 
     50            0, 0, 0, 0, 0, 0, 0, 0, 3, // 0x80=note off, 3 bytes 
     51            3, // 0x90=note on, 3 bytes 
     52            3, // 0xa0=poly pressure, 3 bytes 
     53            3, // 0xb0=control change, 3 bytes 
     54            2, // 0xc0=program change, 2 bytes 
     55            2, // 0xd0=channel pressure, 2 bytes 
     56            3, // 0xe0=pitch bend, 3 bytes 
     57            -1 // 0xf0=other things. may vary. 
    5658    }; 
    57      
    58     /** 
    59      * Message Length lookup table for system status bytes with values from 0xf0 to 0xff. 
    60      * A value of -1 means that the message length can not be determined until an EOX. 
    61      */ 
    62     public static int [] lut_sysmsglen = 
    63     { 
    64         -1, // 0xf0=sysex start. may vary 
    65         2,  // 0xf1=MIDI Time Code. 2 bytes 
    66         3,  // 0xf2=MIDI Song position. 3 bytes 
    67         2,  // 0xf3=MIDI Song Select. 2 bytes. 
    68         0,  // 0xf4=undefined 
    69         0,  // 0xf5=undefined 
    70         1,  // 0xf6=TUNE Request 
    71         0,  // 0xf7=sysex end. 
    72         1,  // 0xf8=timing clock. 1 byte 
    73         1,  // 0xf9=proposed measure end? 
    74         1,  // 0xfa=start. 1 byte 
    75         1,  // 0xfb=continue. 1 byte 
    76         1,  // 0xfc=stop. 1 byte 
    77         0,  // 0xfd=undefined 
    78         1,  // 0xfe=active sensing. 1 byte 
    79         3   // 0xff= not reset, but a META-EVENT, which is always 3 bytes 
     59 
     60    /** 
     61     * Message Length lookup table for system status bytes with values from 0xf0 
     62     * to 0xff. A value of -1 means that the message length can not be 
     63     * determined until an EOX. 
     64     */ 
     65    public static int[] lut_sysmsglen = 
     66    { 
     67            -1, // 0xf0=sysex start. may vary 
     68            2, // 0xf1=MIDI Time Code. 2 bytes 
     69            3, // 0xf2=MIDI Song position. 3 bytes 
     70            2, // 0xf3=MIDI Song Select. 2 bytes. 
     71            0, // 0xf4=undefined 
     72            0, // 0xf5=undefined 
     73            1, // 0xf6=TUNE Request 
     74            0, // 0xf7=sysex end. 
     75            1, // 0xf8=timing clock. 1 byte 
     76            1, // 0xf9=proposed measure end? 
     77            1, // 0xfa=start. 1 byte 
     78            1, // 0xfb=continue. 1 byte 
     79            1, // 0xfc=stop. 1 byte 
     80            0, // 0xfd=undefined 
     81            1, // 0xfe=active sensing. 1 byte 
     82            3 
     83    // 0xff= not reset, but a META-EVENT, which is always 3 bytes 
    8084    }; 
    81      
    82      
    83     /** 
    84      * Look up table see if a midi note in the range 0 to 11 inclusive 
    85      * would be a white key or a black key on a piano keyboard 
    86      */ 
    87      
    88     public static boolean [] lut_is_white = 
    89     { 
    90         true,   // C 
    91         false,  //   C# 
    92         true,   // D 
    93         false,  //   D# 
    94         true,   // E 
    95         true,   // F 
    96         false,  //   F# 
    97         true,   // G 
    98         false,  //   G# 
    99         true,   // A 
    100         false,  //   A# 
    101         true    // B 
     85 
     86    /** 
     87     * Look up table see if a midi note in the range 0 to 11 inclusive would be 
     88     * a white key or a black key on a piano keyboard 
     89     */ 
     90 
     91    public static boolean[] lut_is_white = 
     92    { 
     93            true, // C 
     94            false, // C# 
     95            true, // D 
     96            false, // D# 
     97            true, // E 
     98            true, // F 
     99            false, // F# 
     100            true, // G 
     101            false, // G# 
     102            true, // A 
     103            false, // A# 
     104            true 
     105    // B 
    102106    }; 
    103      
    104      
    105     /** 
    106      *  Message Length function. Not valid for Meta-events (0xff). Returns -1 if you need to call 
    107      * GetSystemMessageLength() instead. 
    108      */ 
    109      
     107 
     108    /** 
     109     * Message Length function. Not valid for Meta-events (0xff). Returns -1 if 
     110     * you need to call GetSystemMessageLength() instead. 
     111     */ 
     112 
    110113    public static final int getMessageLength(int status) 
    111114    { 
    112         return lut_msglen[status>>4]; 
    113     } 
    114      
    115     /** 
    116      * Message Length of system messages. Not valid for Meta-events (0xff). Returns -1 if this message 
    117      * length is unknown until parsing is complete. 
    118      */ 
    119      
    120     public static final int getSystemMessageLength( int stat ) 
    121     { 
    122         return lut_sysmsglen[stat-0xf0]; 
    123     } 
    124      
    125      
     115        return lut_msglen[status >> 4]; 
     116    } 
     117 
     118    /** 
     119     * Message Length of system messages. Not valid for Meta-events (0xff). 
     120     * Returns -1 if this message length is unknown until parsing is complete. 
     121     */ 
     122 
     123    public static final int getSystemMessageLength(int stat) 
     124    { 
     125        return lut_sysmsglen[stat - 0xf0]; 
     126    } 
     127 
    126128    /** 
    127129     * Piano key color white test 
    128130     */ 
    129      
    130     public static final boolean isNoteWhite( int note ) 
    131     { 
    132         return lut_is_white[ note%12 ]; 
    133     } 
    134      
     131 
     132    public static final boolean isNoteWhite(int note) 
     133    { 
     134        return lut_is_white[note % 12]; 
     135    } 
     136 
    135137    /** 
    136138     * Piano key color black test 
    137139     */ 
    138      
    139     public static final boolean isNoteBlack( int note ) 
    140     { 
    141         return !lut_is_white[ note%12 ]; 
    142     } 
    143      
    144      
     140 
     141    public static final boolean isNoteBlack(int note) 
     142    { 
     143        return !lut_is_white[note % 12]; 
     144    } 
     145 
    145146    /** 
    146147     * Note # to standard octave conversion 
    147148     */ 
    148      
    149     public static final int getNoteOctave( int note ) 
    150     { 
    151         return (note/12)-1; 
    152     } 
    153      
    154      
    155      
     149 
     150    public static final int getNoteOctave(int note) 
     151    { 
     152        return (note / 12) - 1; 
     153    } 
     154 
    156155    /** 
    157156     * MIDI Status byte values 
    158157     */ 
    159      
     158 
    160159    public class Status 
    161160    { 
    162         public static final int NOTE_ON  = 0x80; 
     161        public static final int NOTE_ON = 0x80; 
     162 
    163163        public static final int NOTE_OFF = 0x90; 
     164 
    164165        public static final int POLY_PRESSURE = 0xa0; 
     166 
    165167        public static final int CONTROL_CHANGE = 0xb0; 
     168 
    166169        public static final int PROGRAM_CHANGE = 0xc0; 
     170 
    167171        public static final int CHANNEL_PRESSURE = 0xd0; 
     172 
    168173        public static final int PITCH_BEND = 0xe0; 
     174 
    169175        public static final int SYSEX_START = 0xf0; 
     176 
    170177        public static final int MTC = 0xf1; 
     178 
    171179        public static final int SONG_POSITION = 0xf2; 
     180 
    172181        public static final int SONG_SELECT = 0xf3; 
     182 
    173183        public static final int TUNE_REQUEST = 0xf6; 
     184 
    174185        public static final int SYSEX_END = 0xf7; 
     186 
    175187        public static final int TIMING_CLOCK = 0xf8; 
     188 
    176189        public static final int MEASURE_END = 0xf9; 
     190 
    177191        public static final int START = 0xfa; 
     192 
    178193        public static final int CONTINUE = 0xfb; 
     194 
    179195        public static final int STOP = 0xfc; 
     196 
    180197        public static final int ACTIVE_SENSE = 0xfe; 
     198 
    181199        public static final int RESET = 0xff; 
    182          
    183     } 
    184      
     200 
     201    } 
     202 
    185203    /** 
    186204     * Controller Numbers 
    187205     */ 
    188      
     206 
    189207    public class Controller 
    190208    { 
    191         public static final int LSB=0x20;           // add this to a non-switch controller to access the LSB. 
    192         public static final int GM_BANK=0x00;       // general midi bank select 
    193         public static final int MODULATION=0x01;    // modulation 
    194         public static final int BREATH=0x02;        // breath controller 
    195         public static final int FOOT=0x04;          // foot controller 
    196         public static final int PORTA_TIME=0x05;    // portamento time 
    197         public static final int DATA_ENTRY=0x06;    // data entry value 
    198         public static final int MAIN_VOLUME=0x07;   // main volume control 
    199         public static final int BALANCE=0x08;       // balance control 
    200         public static final int PAN=0x0a;           // panpot stereo control 
    201         public static final int EXPRESSION=0x0b;    // expression control 
    202         public static final int GENERAL_1=0x10;     // general purpose controller 1 
    203         public static final int GENERAL_2=0x11;     // general purpose controller 2 
    204         public static final int GENERAL_3=0x12;     // general purpose controller 3 
    205         public static final int GENERAL_4=0x13;     // general purpose controller 4 
    206          
    207         public static final int DAMPER=0x40;        // hold pedal (sustain) 
    208         public static final int PORTA=0x41;         // portamento switch 
    209         public static final int SOSTENUTO=0x42;     // sostenuto switch 
    210         public static final int SOFT_PEDAL=0x43;    // soft pedal 
    211         public static final int HOLD_2=0x45;        // hold pedal 2 
    212          
    213         public static final int GENERAL_5=0x50;     // general purpose controller 5 
    214         public static final int GENERAL_6=0x51;     // general purpose controller 6 
    215         public static final int GENERAL_7=0x52;     // general purpose controller 7 
    216         public static final int GENERAL_8=0x53;     // general purpose controller 8 
    217          
    218         public static final int EFFECT_DEPTH=0x5b;  // external effects depth 
    219         public static final int TREMELO_DEPTH=0x5c; // tremelo depth 
    220         public static final int CHORUS_DEPTH=0x5d;  // chorus depth 
    221         public static final int CELESTE_DEPTH=0x5e; // celeste (detune) depth 
    222         public static final int PHASER_DEPTH=0x5f;  // phaser effect depth 
    223          
    224         public static final int DATA_INC=0x60;      // increment data value 
    225         public static final int DATA_DEC=0x61;      // decrement data value 
    226          
    227         public static final int NONRPN_LSB=0x62;    // non registered parameter LSB 
    228         public static final int NONRPN_MSB=0x63;    // non registered parameter MSB 
    229          
    230         public static final int RPN_LSB=0x64;       // registered parameter LSB 
    231         public static final int RPN_MSB=0x65;       // registered parameter MSB 
    232          
    233         public static final int RESET=0x79;         // reset all controllers 
    234          
    235         public static final int LOCAL=0x79;         // local control on/off 
    236         public static final int ALL_NOTES_OFF=0x7a; // all notes off 
    237         public static final int OMNI_OFF=0x7c;      // omni off; all notes off 
    238         public static final int OMNI_ON=0x7d;       // omni on; all notes off 
    239         public static final int MONO=0x7e;          // mono on; all notes off 
    240         public static final int POLY=0x7f;          // poly on; all notes off 
    241     } 
    242      
     209        public static final int LSB = 0x20; // add this to a non-switch 
     210                                            // controller to access the LSB. 
     211 
     212        public static final int GM_BANK = 0x00; // general midi bank select 
     213 
     214        public static final int MODULATION = 0x01; // modulation 
     215 
     216        public static final int BREATH = 0x02; // breath controller 
     217 
     218        public static final int FOOT = 0x04; // foot controller 
     219 
     220        public static final int PORTA_TIME = 0x05; // portamento time 
     221 
     222        public static final int DATA_ENTRY = 0x06; // data entry value 
     223 
     224        public static final int MAIN_VOLUME = 0x07; // main volume control 
     225 
     226        public static final int BALANCE = 0x08; // balance control 
     227 
     228        public static final int PAN = 0x0a; // panpot stereo control 
     229 
     230        public static final int EXPRESSION = 0x0b; // expression control 
     231 
     232        public static final int GENERAL_1 = 0x10; // general purpose 
     233                                                    // controller 1 
     234 
     235        public static final int GENERAL_2 = 0x11; // general purpose 
     236                                                    // controller 2 
     237 
     238        public static final int GENERAL_3 = 0x12; // general purpose 
     239                                                    // controller 3 
     240 
     241        public static final int GENERAL_4 = 0x13; // general purpose 
     242                                                    // controller 4 
     243 
     244        public static final int DAMPER = 0x40; // hold pedal (sustain) 
     245 
     246        public static final int PORTA = 0x41; // portamento switch 
     247 
     248        public static final int SOSTENUTO = 0x42; // sostenuto switch 
     249 
     250        public static final int SOFT_PEDAL = 0x43; // soft pedal 
     251 
     252        public static final int HOLD_2 = 0x45; // hold pedal 2 
     253 
     254        public static final int GENERAL_5 = 0x50; // general purpose 
     255                                                    // controller 5 
     256 
     257        public static final int GENERAL_6 = 0x51; // general purpose 
     258                                                    // controller 6 
     259 
     260        public static final int GENERAL_7 = 0x52; // general purpose 
     261                                                    // controller 7 
     262 
     263        public static final int GENERAL_8 = 0x53; // general purpose 
     264                                                    // controller 8 
     265 
     266        public static final int EFFECT_DEPTH = 0x5b; // external effects 
     267                                                        // depth 
     268 
     269        public static final int TREMELO_DEPTH = 0x5c; // tremelo depth 
     270 
     271        public static final int CHORUS_DEPTH = 0x5d; // chorus depth 
     272 
     273        public static final int CELESTE_DEPTH = 0x5e; // celeste (detune) 
     274                                                        // depth 
     275 
     276        public static final int PHASER_DEPTH = 0x5f; // phaser effect depth 
     277 
     278        public static final int DATA_INC = 0x60; // increment data value 
     279 
     280        public static final int DATA_DEC = 0x61; // decrement data value 
     281 
     282        public static final int NONRPN_LSB = 0x62; // non registered parameter 
     283                                                    // LSB 
     284 
     285        public static final int NONRPN_MSB = 0x63; // non registered parameter 
     286                                                    // MSB 
     287 
     288        public static final int RPN_LSB = 0x64; // registered parameter LSB 
     289 
     290        public static final int RPN_MSB = 0x65; // registered parameter MSB 
     291 
     292        public static final int RESET = 0x79; // reset all controllers 
     293 
     294        public static final int LOCAL = 0x79; // local control on/off 
     295 
     296        public static final int ALL_NOTES_OFF = 0x7a; // all notes off 
     297 
     298        public static final int OMNI_OFF = 0x7c; // omni off; all notes off 
     299 
     300        public static final int OMNI_ON = 0x7d; // omni on; all notes off 
     301 
     302        public static final int MONO = 0x7e; // mono on; all notes off 
     303 
     304        public static final int POLY = 0x7f; // poly on; all notes off 
     305    } 
     306 
    243307    /** 
    244308     * Registered Parameter Numbers: 
    245309     */ 
    246      
     310 
    247311    public class RPNs 
    248312    { 
    249         public static final int BEND_WIDTH =0x00;   // bender sensitivity 
    250         public static final int FINE_TUNE =0x01;    // fine tuning 
    251         public static final int COARSE_TUNE =0x02;  // coarse tuning 
    252     } 
    253      
    254     /** 
    255      * META Event types (stored in first data byte if status==EVENT 
    256      * These types are the same as MIDIFile meta-events, 
    257      * except when a meta-event is in a MIDIMessage, there is a limit 
    258      * of two data bytes. So the format of the meta-events in a 
    259      * MIDIMessage class will be different than the standard MIDIFile 
    260      * meta-events. 
    261      */ 
    262      
     313        public static final int BEND_WIDTH = 0x00; // bender sensitivity 
     314 
     315        public static final int FINE_TUNE = 0x01; // fine tuning 
     316 
     317        public static final int COARSE_TUNE = 0x02; // coarse tuning 
     318    } 
     319 
     320    /** 
     321     * META Event types (stored in first data byte if status==EVENT These types 
     322     * are the same as MIDIFile meta-events, except when a meta-event is in a 
     323     * MIDIMessage, there is a limit of two data bytes. So the format of the 
     324     * meta-events in a MIDIMessage class will be different than the standard 
     325     * MIDIFile meta-events. 
     326     */ 
     327 
    263328    public class Meta 
    264329    { 
    265         public static final int SEQUENCE_NUMBER =0x00;   // value=16 bits. type 2 files 
    266          
    267         public static final int GENERIC_TEXT =0x01;   // value=16 bits, text item # 
    268         public static final int COPYRIGHT =0x02;   // value=17 bits, text item # 
    269         public static final int INSTRUMENT_NAME =0x03; 
    270         public static final int TRACK_NAME=0x04; 
    271         public static final int LYRIC_TEXT=0x05; 
    272         public static final int MARKER_TEXT=0x06; 
    273         public static final int CUE_TEXT=0x07; 
    274          
    275         public static final int OUTPUT_CABLE=0x21; 
    276         public static final int TRACK_LOOP=0x2E; 
    277         public static final int DATA_END=0x2f; 
    278         public static final int END_OF_TRACK=0x2F; 
    279         public static final int TEMPO=0x51;             // value=16 bits, tempo(bpm)*256 
    280         public static final int SMPTE=0x54;             // what for? 
    281         public static final int TIMESIG=0x58;           // value=num, denom 
    282         public static final int KEYSIG=0x59;            // value=# of sharps/flats, major/minor 
    283         public static final int BEAT_MARKER=0x7e; 
    284         public static final int SEQUENCER_SPECIFIC=0x7F; 
    285         public static final int NO_OPERATION=0x7f; 
    286     } 
    287      
    288      
     330        public static final int SEQUENCE_NUMBER = 0x00; // value=16 bits. type 2 
     331                                                        // files 
     332 
     333        public static final int GENERIC_TEXT = 0x01; // value=16 bits, text 
     334                                                        // item # 
     335 
     336        public static final int COPYRIGHT = 0x02; // value=17 bits, text item 
     337                                                    // # 
     338 
     339        public static final int INSTRUMENT_NAME = 0x03; 
     340 
     341        public static final int TRACK_NAME = 0x04; 
     342 
     343        public static final int LYRIC_TEXT = 0x05; 
     344 
     345        public static final int MARKER_TEXT = 0x06; 
     346 
     347        public static final int CUE_TEXT = 0x07; 
     348 
     349        public static final int OUTPUT_CABLE = 0x21; 
     350 
     351        public static final int TRACK_LOOP = 0x2E; 
     352 
     353        public static final int DATA_END = 0x2f; 
     354 
     355        public static final int END_OF_TRACK = 0x2F; 
     356 
     357        public static final int TEMPO = 0x51; // value=16 bits, tempo(bpm)*256 
     358 
     359        public static final int SMPTE = 0x54; // what for? 
     360 
     361        public static final int TIMESIG = 0x58; // value=num, denom 
     362 
     363        public static final int KEYSIG = 0x59; // value=# of sharps/flats, 
     364                                                // major/minor 
     365 
     366        public static final int BEAT_MARKER = 0x7e; 
     367 
     368        public static final int SEQUENCER_SPECIFIC = 0x7F; 
     369 
     370        public static final int NO_OPERATION = 0x7f; 
     371    } 
     372 
    289373}