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

src/jdkmidi_fileshow.cpp

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 #include "jdkmidi/world.h"
00035 
00036 #include "jdkmidi/fileshow.h"
00037 
00038 #ifndef DEBUG_MDFSH
00039 # define DEBUG_MDFSH  0
00040 #endif
00041 
00042 #if DEBUG_MDFSH
00043 # undef DBG
00044 # define DBG(a) a
00045 #endif
00046 
00047 namespace jdkmidi
00048 {
00049   
00050   
00051   MIDIFileShow::MIDIFileShow( FILE *out_ )  
00052     : 
00053     out( out_ )
00054   {
00055     ENTER("MIDIFileShow::MIDIFileShow()");
00056     
00057   } 
00058   
00059   MIDIFileShow::~MIDIFileShow() 
00060   {
00061     ENTER("MIDIFileShow::~MIDIFileShow()");
00062     
00063   } 
00064   
00065   void    MIDIFileShow::mf_error( char *e ) 
00066   {
00067     fprintf( out, "\nParse Error: %s\n", e );
00068     MIDIFileEvents::mf_error( e );
00069   } 
00070   
00071   void    MIDIFileShow::mf_starttrack( int trk )  
00072   {
00073     fprintf( out, "Start Track #%d\n", trk );
00074   } 
00075   
00076   void    MIDIFileShow::mf_endtrack( int trk) 
00077   {
00078     fprintf( out, "End Track   #%d\n", trk );
00079   } 
00080   
00081   void    MIDIFileShow::mf_header( int format, int ntrks, int d ) 
00082   {
00083     fprintf( out, "Header: Type=%d Tracks=%d", format, ntrks );
00084     
00085     
00086     division=d;
00087     
00088     if( division>0x8000 )
00089     {
00090       unsigned char smpte_rate = ((unsigned char)((-division)>>8));
00091       unsigned char smpte_division = (unsigned char)(division&0xff);
00092       
00093       fprintf( out, " SMPTE=%d Division=%d\n", smpte_rate, smpte_division );
00094     }
00095     else
00096     {
00097       fprintf( out, " Division=%d\n", division );
00098     }
00099   } 
00100   
00101   void  MIDIFileShow::show_time( MIDIClockTime time ) 
00102   {
00103     if( division>0 )
00104     {
00105       unsigned long beat = time/division;
00106       unsigned long clk = time%division;
00107       
00108       fprintf( out, "Time: %6ld:%3ld    ", beat, clk );
00109     }
00110     else
00111     {
00112       fprintf( out, "Time: %9ld     ", time );
00113     }
00114   } 
00115   
00116 //
00117 // The possible events in a MIDI Files
00118 //
00119   
00120   void    MIDIFileShow::mf_system_mode( const MIDITimedMessage &msg   ) 
00121   {
00122     show_time( msg.GetTime() );
00123     char buf[64];   
00124     fprintf( out, "%s\n", msg.MsgToText(buf) );
00125   } 
00126   
00127   void    MIDIFileShow::mf_note_on( const MIDITimedMessage &msg   ) 
00128   {
00129     show_time( msg.GetTime() );
00130     char buf[64];   
00131     fprintf( out, "%s\n", msg.MsgToText(buf) );
00132     
00133   } 
00134   
00135   void    MIDIFileShow::mf_note_off( const MIDITimedMessage &msg  ) 
00136   {
00137     show_time( msg.GetTime() );
00138     char buf[64];   
00139     fprintf( out, "%s\n", msg.MsgToText(buf) );
00140   } 
00141   
00142   void    MIDIFileShow::mf_poly_after( const MIDITimedMessage &msg  ) 
00143   {
00144     show_time( msg.GetTime() );
00145     char buf[64];
00146     fprintf( out, "%s\n", msg.MsgToText(buf) );
00147   } 
00148   
00149   void    MIDIFileShow::mf_bender( const MIDITimedMessage &msg  ) 
00150   {
00151     show_time( msg.GetTime() );
00152     char buf[64];   
00153     fprintf( out, "%s\n", msg.MsgToText(buf) );
00154   } 
00155   
00156   void    MIDIFileShow::mf_program(const MIDITimedMessage &msg  ) 
00157   {
00158     show_time( msg.GetTime() );
00159     char buf[64];   
00160     fprintf( out, "%s\n", msg.MsgToText(buf) );
00161   } 
00162   
00163   void    MIDIFileShow::mf_chan_after( const MIDITimedMessage &msg  ) 
00164   {
00165     show_time( msg.GetTime() );
00166     char buf[64];   
00167     fprintf( out, "%s\n", msg.MsgToText(buf) );
00168   } 
00169   
00170   void    MIDIFileShow::mf_control( const MIDITimedMessage &msg   ) 
00171   {
00172     show_time( msg.GetTime() );
00173     char buf[64];   
00174     fprintf( out, "%s\n", msg.MsgToText(buf) );
00175   } 
00176   
00177   void    MIDIFileShow::mf_sysex( MIDIClockTime time, const MIDISystemExclusive &ex ) 
00178   {
00179     show_time( time );
00180     fprintf( out, "SysEx     Length=%d\n", ex.GetLength() );
00181     
00182     for( int i=0; i<ex.GetLength(); ++i )
00183     {
00184       if( (i&0x1f)==0 )
00185         fprintf( out, "\n" );
00186       fprintf( out, "%02x ", (int)ex.GetData(i) );
00187     }
00188     fprintf( out, "\n" );
00189   } 
00190   
00191   void    MIDIFileShow::mf_arbitrary(MIDIClockTime time, int len, unsigned char *data   ) 
00192   {
00193     show_time( time );
00194     fprintf( out, "RAW MIDI DATA    Length=%d\n", len );
00195     
00196     for( int i=0; i<len; ++i )
00197     {
00198       if( (i&0x1f)==0 )
00199         fprintf( out, "\n" );
00200       fprintf( out, "%02x ", (int)data[i] );
00201     }
00202     fprintf( out, "\n" );
00203   } 
00204   
00205   void    MIDIFileShow::mf_metamisc(MIDIClockTime time, int type, int len, unsigned char *data  ) 
00206   {
00207     show_time( time );
00208     
00209     fprintf( out, "META-EVENT       TYPE=%d Length=%d\n", type, len );
00210     
00211     for( int i=0; i<len; ++i )
00212     {
00213       if( (i&0x1f)==0 )
00214         fprintf( out, "\n" );
00215       fprintf( out, "%02x ", (int)data[i] );
00216     }
00217     fprintf( out, "\n" ); 
00218   } 
00219   
00220   void    MIDIFileShow::mf_seqnum(MIDIClockTime time, int num ) 
00221   {
00222     show_time( time );
00223     
00224     fprintf( out, "Sequence Number  %d\n", num );
00225   } 
00226   
00227   void    MIDIFileShow::mf_smpte(MIDIClockTime time, int a, int b, int c, int d, int e) 
00228   {
00229     show_time( time );
00230     
00231     fprintf( out, "SMPTE Event      %02x,%02x,%02x,%02x,%02x\n", a,b,c,d,e );
00232   } 
00233   
00234   void    MIDIFileShow::mf_timesig (
00235     MIDIClockTime time,
00236     int num,
00237     int denom_power,
00238     int midi_clocks_per_metronome,
00239     int notated_32nds_per_midi_quarter_note ) 
00240   {
00241     show_time( time );
00242     
00243     fprintf( out, "Time Signature   %d/%d  Clks/Metro.=%d 32nd/Quarter=%d\n",
00244              num,
00245              denom_power,
00246              midi_clocks_per_metronome,
00247              notated_32nds_per_midi_quarter_note );
00248     
00249   } 
00250   
00251   
00252   void    MIDIFileShow::mf_tempo(MIDIClockTime time, unsigned long tempo  ) 
00253   {
00254     show_time( time );
00255     
00256     fprintf( out, "Tempo              %4.2f BPM (%9ld usec/beat)\n",
00257              (60000000.0/(double)tempo), tempo );
00258   } 
00259   
00260   void    MIDIFileShow::mf_keysig(MIDIClockTime time, int sf, int mi )  
00261   {
00262     show_time( time );
00263     
00264     fprintf( out, "Key Signature      " );
00265     
00266     if( mi )
00267       fprintf( out, "MINOR KEY  " );
00268     else
00269       fprintf( out, "MAJOR KEY  " );
00270     
00271     if( sf<0 )
00272       fprintf( out, "%d Flats\n", -sf );
00273     else
00274       fprintf( out, "%d Sharps\n", sf );
00275   } 
00276   
00277   void    MIDIFileShow::mf_sqspecific( MIDIClockTime time, int len, unsigned char *data ) 
00278   {
00279     show_time( time );
00280     
00281     fprintf( out, "Sequencer Specific     Length=%d\n", len );
00282     
00283     for( int i=0; i<len; ++i )
00284     {
00285       if( (i&0x1f)==0 )
00286         fprintf( out, "\n" );
00287       fprintf( out, "%02x ", (int)data[i] );
00288     }
00289     fprintf( out, "\n" );
00290     
00291   } 
00292   
00293   void    MIDIFileShow::mf_text(MIDIClockTime time, int type, int len, unsigned char *txt ) 
00294   {
00295     static char * text_event_names[16] =
00296       {
00297         "SEQ. #    ",
00298         "GENERIC   ",
00299         "COPYRIGHT ",
00300         "INST. NAME",
00301         "TRACK NAME",
00302         "LYRIC     ",
00303         "MARKER    ",
00304         "CUE       ",
00305         "UNKNOWN   ",
00306         "UNKNOWN   ",
00307         "UNKNOWN   ",
00308         "UNKNOWN   ",
00309         "UNKNOWN   ",
00310         "UNKNOWN   ",
00311         "UNKNOWN   ",
00312         "UNKNOWN   "
00313       };
00314     
00315     if( type>15 )
00316       type=15;
00317     
00318     show_time( time );
00319     
00320     fprintf( out, "TEXT   %s  '%s'\n", text_event_names[type], (char *)txt );
00321   } 
00322   
00323   void    MIDIFileShow::mf_eot( MIDIClockTime time )  
00324   {
00325     show_time( time );
00326     fprintf( out, "End Of Track\n" );
00327   } 
00328   
00329   
00330   
00331 }