jdkmidi class library documentation

Copyright © 2004 J.D. Koftinoff Software, Ltd.

Released under the GNU General Public License (GPL)




Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

include/jdkmidi/midi.h

Go to the documentation of this file.
00001 /*
00002  *  libjdkmidi-2004 C++ Class Library for MIDI
00003  *
00004  *  Copyright (C) 2004  J.D. Koftinoff Software, Ltd.
00005  *  www.jdkoftinoff.com
00006  *  jeffk@jdkoftinoff.com
00007  *
00008  *  *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 ***
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 /*
00025 **  Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd.
00026 **
00027 **  All rights reserved.
00028 **
00029 **  No one may duplicate this source code in any form for any reason
00030 **  without the written permission given by J.D. Koftinoff Software, Ltd.
00031 **
00032 */
00033 
00034 
00035 #ifndef _JDKMIDI_MIDI_H
00036 #define _JDKMIDI_MIDI_H
00037 
00038 #include "jdkmidi/world.h"
00039 
00040 namespace jdkmidi
00041 {
00042   
00043   typedef unsigned long MIDIClockTime;
00044   
00045 //
00046 // MIDI Status bytes
00047 //
00048   
00049   enum
00050     {
00051       NOTE_OFF  =0x80,
00052       NOTE_ON   =0x90,
00053       POLY_PRESSURE =0xa0,
00054       CONTROL_CHANGE  =0xb0,
00055       PROGRAM_CHANGE  =0xc0,
00056       CHANNEL_PRESSURE=0xd0,
00057       PITCH_BEND  =0xe0,
00058       SYSEX_START =0xf0,
00059       MTC   =0xf1,
00060       SONG_POSITION =0xf2,
00061       SONG_SELECT =0xf3,
00062       TUNE_REQUEST  =0xf6,
00063       SYSEX_END =0xf7,
00064       RESET   =0xff,  // 0xff never used as reset in a MIDIMessage
00065       META_EVENT  =0xff // 0xff is for non MIDI messages
00066     };
00067   
00068   
00069   
00070   //
00071   // MIDI Real Time Messages
00072   //
00073   
00074   enum
00075     {
00076       TIMING_CLOCK  =0xf8,
00077       MEASURE_END =0xf9,  // proposed measure end byte
00078       START   =0xfa,
00079       CONTINUE  =0xfb,
00080       STOP    =0xfc,
00081       ACTIVE_SENSE  =0xfe   
00082     };
00083   
00084   
00085   //
00086   // Controller Numbers
00087   //
00088   
00089   enum
00090     {
00091       C_LSB   =0x20,  // add this to a non-switch controller
00092       // to access the LSB.
00093       
00094       C_GM_BANK =0x00,  // general midi bank select
00095       C_MODULATION  =0x01,  // modulation
00096       C_BREATH  =0x02,  // breath controller
00097       C_FOOT    =0x04,  // foot controller
00098       C_PORTA_TIME  =0x05,  // portamento time
00099       C_DATA_ENTRY  =0x06,  // data entry value
00100       C_MAIN_VOLUME =0x07,  // main volume control
00101       C_BALANCE =0x08,  // balance control
00102       C_PAN   =0x0a,  // panpot stereo control
00103       C_EXPRESSION  =0x0b,  // expression control
00104       C_GENERAL_1 =0x10,  // general purpose controller 1
00105       C_GENERAL_2 =0x11,  // general purpose controller 2
00106       C_GENERAL_3 =0x12,  // general purpose controller 3
00107       C_GENERAL_4 =0x13,  // general purpose controller 4
00108       
00109       C_DAMPER  =0x40,  // hold pedal (sustain)
00110       C_PORTA   =0x41,  // portamento switch
00111       C_SOSTENUTO =0x42,  // sostenuto switch
00112       C_SOFT_PEDAL  =0x43,  // soft pedal
00113       C_HOLD_2  =0x45,  // hold pedal 2
00114       
00115       C_GENERAL_5 =0x50,  // general purpose controller 5
00116       C_GENERAL_6 =0x51,  // general purpose controller 6
00117       C_GENERAL_7 =0x52,  // general purpose controller 7
00118       C_GENERAL_8 =0x53,  // general purpose controller 8
00119       
00120       C_EFFECT_DEPTH  =0x5b,  // external effects depth
00121       C_TREMELO_DEPTH =0x5c,  // tremelo depth
00122       C_CHORUS_DEPTH  =0x5d,  // chorus depth
00123       C_CELESTE_DEPTH =0x5e,  // celeste (detune) depth
00124       C_PHASER_DEPTH  =0x5f,  // phaser effect depth
00125       
00126       C_DATA_INC  =0x60,  // increment data value
00127       C_DATA_DEC  =0x61,  // decrement data value
00128       
00129       C_NONRPN_LSB  =0x62,  // non registered parameter LSB
00130       C_NONRPN_MSB  =0x63,  // non registered parameter MSB
00131       
00132       C_RPN_LSB =0x64,  // registered parameter LSB
00133       C_RPN_MSB =0x65,  // registered parameter MSB
00134       
00135       
00136       
00137       C_RESET   =0x79,  // reset all controllers
00138       
00139       C_LOCAL   =0x79,  // local control on/off
00140       C_ALL_NOTES_OFF =0x7a,  // all notes off
00141       C_OMNI_OFF  =0x7c,  // omni off, all notes off
00142       C_OMNI_ON =0x7d,  // omni on, all notes off
00143       C_MONO    =0x7e,  // mono on, all notes off
00144       C_POLY    =0x7f // poly on, all notes off
00145     };
00146   
00147   
00148   //
00149   // Registered Parameter Numbers:
00150   //
00151   
00152   enum
00153     {
00154       RPN_BEND_WIDTH  =0x00,  // bender sensitivity
00155       RPN_FINE_TUNE =0x01,  // fine tuning
00156       RPN_COARSE_TUNE =0x02 // coarse tuning
00157     };
00158   
00159   
00160   
00161   //
00162   // META Event types (stored in first data byte if status==META_EVENT)
00163   // These types are the same as MIDIFile meta-events,
00164   // except when a meta-event is in a MIDIMessage, there is a limit
00165   // of two data bytes. So the format of the meta-events in a
00166   // MIDIMessage class will be different than the standard MIDIFile
00167   // meta-events.
00168   //
00169   
00170   enum
00171     {
00172       META_SEQUENCE_NUMBER  =0x00,  // value=16 bits. type 2 files
00173       
00174       META_GENERIC_TEXT =0x01,  // value=16 bits, text item #
00175       META_COPYRIGHT    =0x02,  // value=17 bits, text item #
00176       META_INSTRUMENT_NAME  =0x03,
00177       META_TRACK_NAME   =0x04,
00178       META_LYRIC_TEXT   =0x05,
00179       META_MARKER_TEXT  =0x06,
00180       META_CUE_TEXT   =0x07,      
00181      
00182       META_OUTPUT_CABLE =0x21,
00183       META_TRACK_LOOP   =0x2E,
00184       META_DATA_END   =0x2f,      
00185       META_END_OF_TRACK =0x2F,
00186       META_TEMPO    =0x51,  // value=16 bits, tempo(bpm)*256
00187       META_SMPTE    =0x54,  // what for?
00188       META_TIMESIG    =0x58,  // value=num, denom
00189       META_KEYSIG   =0x59,  // value=# of sharps/flats, major/minor
00190       META_BEAT_MARKER =0x7e,
00191       META_SEQUENCER_SPECIFIC =0x7F,
00192       META_NO_OPERATION =0x7f
00193       
00194     };
00195 
00196   extern  const signed  char  lut_msglen[16];
00197   extern  const signed  char  lut_sysmsglen[16];
00198   extern  const bool  lut_is_white[12]; 
00199   
00200   
00201   //
00202   // Message Length functions. Not valid for Meta-events (0xff)
00203   //
00204   
00205   inline  signed char GetMessageLength( unsigned char stat )
00206     { 
00207       return lut_msglen[stat>>4]; 
00208     }
00209   
00210   inline  signed char GetSystemMessageLength( unsigned char stat )
00211     { 
00212       return lut_sysmsglen[stat-0xf0];  
00213     }
00214   
00215   
00216   //
00217   // Piano key color methods
00218   //
00219   
00220   inline  bool  IsNoteWhite( unsigned char note )
00221     { 
00222       return lut_is_white[ note%12 ]; 
00223     }
00224   
00225   inline  bool  IsNoteBlack( unsigned char note ) 
00226     { 
00227       return !lut_is_white[ note%12 ];  
00228     }
00229   
00230   
00231   //
00232   // Note # to standard octave conversion
00233   //
00234   
00235   inline  int GetNoteOctave( unsigned char note )
00236     { return (note/12)-1; }
00237   
00238   
00239   
00240 }
00241 
00242 
00243 
00244 
00245 #endif
00246