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/sequencer.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 #ifndef _JDKMIDI_SEQUENCER_H
00025 #define _JDKMIDI_SEQUENCER_H
00026 
00027 #include "jdkmidi/track.h"
00028 #include "jdkmidi/multitrack.h"
00029 #include "jdkmidi/tempo.h"
00030 #include "jdkmidi/matrix.h"
00031 #include "jdkmidi/process.h"
00032 
00033 namespace jdkmidi
00034 {
00035   
00036   class MIDISequencerGUIEvent;
00037   class MIDISequencerGUIEventNotifier;
00038   class MIDISequencerTrackState;
00039   class MIDISequencer;
00040   
00041   class MIDISequencerGUIEvent
00042     {
00043     public:
00044       MIDISequencerGUIEvent()
00045         {
00046           bits=0;
00047         }
00048       
00049       MIDISequencerGUIEvent( unsigned long bits_ )
00050         : bits(bits_)
00051         {
00052         }
00053       
00054       MIDISequencerGUIEvent( const MIDISequencerGUIEvent &e )
00055         : bits(e.bits)
00056         {
00057         }
00058       
00059       MIDISequencerGUIEvent( int group, int subgroup, int item=0 )
00060         {
00061           bits =  ((group&0xff)<<24)
00062             | ((subgroup&0xfff)<<12)
00063             | ((item&0xfff)<<0);
00064         }
00065       
00066       operator unsigned long () const
00067         {
00068           return bits;
00069         }
00070       
00071       void SetEvent( int group, int subgroup = 0, int item = 0 )
00072         {
00073           bits =  ((group&0xff)<<24)
00074             | ((subgroup&0xfff)<<12)
00075             | ((item&0xfff)<<0);
00076         }
00077       
00078       int GetEventGroup() const
00079         {
00080           return (int)((bits>>24)&0xff);
00081         }
00082       
00083       int GetEventSubGroup() const
00084         {
00085           return (int)((bits>>12)&0xfff);
00086         }
00087       
00088       int GetEventItem() const
00089         {
00090           return (int)((bits>>0)&0xfff);
00091         }
00092       
00093       // main groups
00094       enum
00095         {
00096           GROUP_ALL = 0,
00097           GROUP_CONDUCTOR,
00098           GROUP_TRANSPORT,
00099           GROUP_TRACK
00100         };
00101       
00102       // items in conductor group
00103       enum
00104         {
00105           GROUP_CONDUCTOR_ALL = 0,
00106           GROUP_CONDUCTOR_TEMPO,
00107           GROUP_CONDUCTOR_TIMESIG
00108         };
00109       
00110       // items in transport group
00111       enum
00112         {
00113           GROUP_TRANSPORT_ALL = 0,
00114           GROUP_TRANSPORT_MODE,
00115           GROUP_TRANSPORT_MEASURE,
00116           GROUP_TRANSPORT_BEAT,
00117           GROUP_TRANSPORT_ENDOFSONG
00118         };
00119       
00120       // items in TRACK group
00121       enum
00122         {
00123           GROUP_TRACK_ALL = 0,
00124           GROUP_TRACK_NAME,
00125           GROUP_TRACK_PG,
00126           GROUP_TRACK_NOTE,
00127           GROUP_TRACK_VOLUME
00128         };
00129       
00130     private:
00131       unsigned long bits;
00132     };
00133   
00134   
00135   class MIDISequencerGUIEventNotifier
00136     {
00137     public:
00138       MIDISequencerGUIEventNotifier();
00139       
00140       virtual ~MIDISequencerGUIEventNotifier();
00141       
00142       virtual void Notify( const MIDISequencer *seq, MIDISequencerGUIEvent e ) = 0;
00143       virtual bool GetEnable() const = 0;
00144       virtual void SetEnable( bool f ) = 0;
00145     };
00146   
00147   
00148   class MIDISequencerGUIEventNotifierText :
00149     public MIDISequencerGUIEventNotifier
00150     {
00151     public:
00152       MIDISequencerGUIEventNotifierText(FILE *f);
00153       
00154       virtual ~MIDISequencerGUIEventNotifierText();
00155       
00156       virtual void Notify( const MIDISequencer *seq, MIDISequencerGUIEvent e );
00157       virtual bool GetEnable() const;
00158       virtual void SetEnable( bool f );
00159       
00160     private:
00161       
00162       FILE *f;
00163       bool en;
00164     };
00165   
00166   class MIDISequencerTrackNotifier : public MIDIProcessor
00167     {
00168     public:
00169       MIDISequencerTrackNotifier(
00170         MIDISequencer *seq_,
00171         int trk,
00172         MIDISequencerGUIEventNotifier *n
00173         );
00174       
00175       virtual ~MIDISequencerTrackNotifier();
00176       
00177       void SetNotifier(
00178         MIDISequencer *seq_,
00179         int trk,
00180         MIDISequencerGUIEventNotifier *n
00181         )
00182         {
00183           seq = seq_;
00184           track_num = trk;
00185           notifier=n;
00186         }
00187       
00188       
00189       void Notify( int item );
00190       void NotifyConductor( int item );
00191       
00192     private:
00193       MIDISequencer *seq;
00194       int track_num;
00195       MIDISequencerGUIEventNotifier *notifier;
00196     };
00197   
00198   class MIDISequencerTrackProcessor : public MIDIProcessor
00199     {
00200     public:
00201       MIDISequencerTrackProcessor();
00202       virtual ~MIDISequencerTrackProcessor();
00203       
00204       virtual void Reset();
00205       virtual bool Process( MIDITimedBigMessage *msg );
00206       
00207       bool mute;          // track is muted
00208       bool solo;          // track is solod
00209       int velocity_scale;     // current velocity scale value for note ons, 100=normal
00210       int rechannel;        // rechannelization value, or -1 for none
00211       int transpose;        // amount to transpose note values
00212       
00213       MIDIProcessor *extra_proc;  // extra midi processing for this track
00214     };
00215   
00216   class MIDISequencerTrackState : public MIDISequencerTrackNotifier 
00217     {
00218     public:
00219       
00220       MIDISequencerTrackState(
00221         MIDISequencer *seq_,
00222         int trk,
00223         MIDISequencerGUIEventNotifier *n
00224         );
00225       virtual ~MIDISequencerTrackState();
00226       
00227       virtual void GoToZero();
00228       virtual void Reset();
00229       virtual bool Process( MIDITimedBigMessage *msg );
00230       
00231       float tempobpm;       // current tempo in beats per minute
00232       int pg;           // current program change, or -1
00233       int volume;         // current volume controller value
00234       int timesig_numerator;    // numerator of current time signature
00235       int timesig_denominator;  // denominator of current time signature
00236       int bender_value;     // last seen bender value
00237       char track_name[256];   // track name
00238       bool got_good_track_name; // true if we dont want to use generic text events for track name
00239       
00240       bool notes_are_on;      // true if there are any notes currently on
00241       MIDIMatrix note_matrix;   // to keep track of all notes on
00242       
00243       
00244     }; 
00245   
00246   
00247   class MIDISequencerState
00248     {
00249     public:
00250       MIDISequencerState(  MIDISequencer *s,
00251                            MIDIMultiTrack *multitrack_,
00252                            MIDISequencerGUIEventNotifier *n );
00253       
00254       MIDISequencerState( const MIDISequencerState &s );
00255       ~MIDISequencerState();
00256       
00257       const MIDISequencerState & operator = ( const MIDISequencerState &s );
00258       
00259       MIDISequencerGUIEventNotifier *notifier;
00260       MIDIMultiTrack *multitrack;
00261       int num_tracks;
00262       
00263       MIDISequencerTrackState *track_state[64];
00264       MIDIMultiTrackIterator iterator;
00265       MIDIClockTime cur_clock;
00266       float cur_time_ms;
00267       int cur_beat;
00268       int cur_measure;
00269       MIDIClockTime next_beat_time;
00270     };
00271   
00272   class MIDISequencer 
00273     {
00274     public:
00275       
00276       MIDISequencer(
00277         MIDIMultiTrack *m,
00278         MIDISequencerGUIEventNotifier *n=0
00279         );
00280       
00281       virtual ~MIDISequencer();
00282       
00283       void ResetTrack( int trk );
00284       void ResetAllTracks();
00285       
00286       MIDIClockTime GetCurrentMIDIClockTime() const;
00287       double GetCurrentTimeInMs() const;
00288       int GetCurrentBeat() const;
00289       int GetCurrentMeasure() const;
00290       
00291       double GetCurrentTempoScale() const;
00292       double GetCurrentTempo() const;
00293       
00294       MIDISequencerState *GetState();
00295       const MIDISequencerState *GetState() const;
00296       
00297       void SetState( MIDISequencerState * );
00298       
00299       MIDISequencerTrackState * GetTrackState( int trk );
00300       const MIDISequencerTrackState * GetTrackState( int trk ) const;
00301       
00302       MIDISequencerTrackProcessor * GetTrackProcessor( int trk );
00303       const MIDISequencerTrackProcessor * GetTrackProcessor( int trk ) const;
00304       
00305       int GetNumTracks() const  {   return state.num_tracks;  }
00306       
00307       bool GetSoloMode() const;
00308       
00309       void SetCurrentTempoScale( float scale );
00310       void SetSoloMode( bool m, int trk=-1 );
00311       
00312       void GoToZero();
00313       bool GoToTime( MIDIClockTime time_clk );
00314       bool GoToTimeMs( float time_ms );
00315       bool GoToMeasure( int measure, int beat=0 );
00316       
00317       bool GetNextEventTimeMs( float *t );
00318       bool GetNextEventTime( MIDIClockTime *t );
00319       bool GetNextEvent( int *tracknum, MIDITimedBigMessage *msg );
00320       
00321       void ScanEventsAtThisTime();
00322       
00323     protected:
00324       
00325       MIDITimedBigMessage beat_marker_msg;
00326       
00327       bool solo_mode;
00328       int tempo_scale;
00329       
00330       int num_tracks;
00331       MIDISequencerTrackProcessor *track_processors[64];
00332       
00333       MIDISequencerState state;
00334       
00335     } ;
00336 }
00337 
00338 #endif