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

tests/jdkmidi_test_drv.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 #include "jdkmidi/world.h"
00026 #include "jdkmidi/track.h"
00027 #include "jdkmidi/multitrack.h"
00028 #include "jdkmidi/filereadmultitrack.h"
00029 #include "jdkmidi/fileread.h"
00030 #include "jdkmidi/fileshow.h"
00031 #include "jdkmidi/sequencer.h"
00032 #include "jdkmidi/manager.h"
00033 #include "jdkmidi/driverdump.h"
00034 
00035 using namespace jdkmidi;
00036 
00037 void DumpTrackNames( MIDISequencer *seq ) 
00038 {
00039   fprintf( stdout, "TEMPO = %f\n",
00040            seq->GetTrackState(0)->tempobpm
00041     );
00042   
00043   for( int i=0; i<seq->GetNumTracks(); ++i )
00044   {
00045     fprintf( stdout, "TRK #%2d : NAME = '%s'\n", 
00046              i,
00047              seq->GetTrackState(i)->track_name
00048       );
00049   } 
00050 } 
00051 
00052 
00053 void PlayDumpManager( MIDIManager *mgr ) 
00054 { 
00055   MIDISequencer *seq = mgr->GetSeq();
00056   double pretend_clock_time = 0.0;
00057   
00058   seq->GoToTime( (unsigned long)pretend_clock_time );
00059   
00060   mgr->SeqPlay();
00061   
00062   // simulate a clock going forward with 10ms resolution for 1 minute
00063   
00064   for( pretend_clock_time=0.0; pretend_clock_time<60.0*1000.0; pretend_clock_time+=100 )
00065   {
00066     mgr->GetDriver()->TimeTick( (unsigned long)pretend_clock_time );  
00067   }
00068   
00069   mgr->SeqStop();
00070   mgr->GetDriver()->AllNotesOff();
00071   
00072 } 
00073 
00074 
00075 int main( int argc, char **argv )
00076 {
00077   if( argc>1 )
00078   {
00079     MIDIFileReadStreamFile rs( argv[1] );
00080     MIDIMultiTrack tracks(64);
00081     MIDIFileReadMultiTrack track_loader( &tracks );
00082     MIDIFileRead reader( &rs, &track_loader );
00083     MIDISequencerGUIEventNotifierText gui( stdout );
00084     MIDISequencer seq( &tracks, &gui );
00085     MIDIDriverDump driver(128,stdout);
00086     MIDIManager mgr( &driver, &gui );
00087     
00088     reader.Parse();
00089     
00090     seq.GoToZero();
00091     mgr.SetSeq( &seq );
00092     
00093     DumpTrackNames( &seq );
00094     
00095     PlayDumpManager( &mgr );
00096   }
00097   
00098   return 0;
00099 }