root/trunk/libjdkmidi/trunk/include/jdkmidi/tempo.h

Revision 552, 3.9 kB (checked in by jeffk@…, 8 months ago)

formatting fixed

Line 
1/*
2 *  libjdkmidi-2004 C++ Class Library for MIDI
3 *
4 *  Copyright (C) 2004  J.D. Koftinoff Software, Ltd.
5 *  www.jdkoftinoff.com
6 *  jeffk@jdkoftinoff.com
7 *
8 *  *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 ***
9 *
10 *  This program is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License as published by
12 *  the Free Software Foundation; either version 2 of the License, or
13 *  (at your option) any later version.
14 *
15 *  This program is distributed in the hope that it will be useful,
16 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 *  GNU General Public License for more details.
19 *
20 *  You should have received a copy of the GNU General Public License
21 *  along with this program; if not, write to the Free Software
22 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23*/
24/*
25** Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd.
26**
27** All rights reserved.
28**
29** No one may duplicate this source code in any form for any reason
30** without the written permission given by J.D. Koftinoff Software, Ltd.
31**
32*/
33
34#ifndef JDKMIDI_TEMPO_H
35#define JDKMIDI_TEMPO_H
36
37//
38// This class makes it easy to deal with Tempos as fixed point
39// numbers.
40//
41// The actual tempo is stored times 256 for 1/256 bpm accuracy.
42//
43// The default operator int() etc., automatically convert the
44// fixed point number so the value is in normal beats per minutes.
45//
46//
47
48#include "jdkmidi/midi.h"
49
50namespace jdkmidi
51{
52
53  class  MIDITempo
54  {
55    public:
56      MIDITempo()
57      {
58        tempo=120<<8;
59      }
60      MIDITempo ( int a )
61      {
62        tempo= ( unsigned long ) a << 8;
63      }
64      MIDITempo ( unsigned int a )
65      {
66        tempo= ( unsigned long ) a << 8;
67      }
68      MIDITempo ( long a )
69      {
70        tempo= ( unsigned long ) a << 8;
71      }
72      MIDITempo ( unsigned long a )
73      {
74        tempo=a << 8;
75      }
76      MIDITempo ( float a )
77      {
78        tempo= ( unsigned long ) ( a*256.0 );
79      }
80      MIDITempo ( const MIDITempo &a )
81      {
82        tempo=a.GetFullTempo();
83      }
84     
85      operator short ()
86      {
87        return ( short ) ( ( tempo+0x80 ) >>8 );
88      }
89      operator unsigned short ()
90      {
91        return ( unsigned short ) ( ( tempo+0x80 ) >>8 );
92      }
93     
94      operator int ()
95      {
96        return ( int ) ( ( tempo+0x80 ) >>8 );
97      }
98      operator unsigned int ()
99      {
100        return ( unsigned int ) ( ( tempo+0x80 ) >>8 );
101      }
102      operator long ()
103      {
104        return ( long ) ( ( tempo+0x80 ) >>8 );
105      }
106      operator unsigned long ()
107      {
108        return ( unsigned long ) ( ( tempo+0x80 ) >>8 );
109      }
110      operator float ()
111      {
112        return ( float ) tempo / 256.0f;
113      }
114      void operator = ( unsigned short a )
115      {
116        tempo= ( unsigned long ) a << 8;
117      }
118      void operator = ( short a )
119      {
120        tempo= ( unsigned long ) a << 8;
121      }
122     
123      void operator = ( unsigned int a )
124      {
125        tempo= ( unsigned long ) a << 8;
126      }
127      void operator = ( int a )
128      {
129        tempo= ( unsigned long ) a << 8;
130      }
131      void operator = ( unsigned long a )
132      {
133        tempo= ( unsigned long ) a << 8;
134      }
135      void operator = ( long a )
136      {
137        tempo= ( unsigned long ) a << 8;
138      }
139     
140      void operator = ( float a )
141      {
142        tempo= ( unsigned long ) ( a*256.0 );
143      }
144     
145      unsigned long GetFullTempo() const
146      {
147        return tempo;
148      }
149      void SetFullTempo ( unsigned long v )
150      {
151        tempo=v;
152      }
153     
154      unsigned long GetMIDIFileTempo()
155      {
156        if ( tempo ) return ( 60000000L/256 ) /tempo;
157        else
158          return ( 60000000L/256 ) / ( 120*256 );
159      }
160     
161    protected:
162      unsigned long tempo;
163  };
164 
165}
166
167#endif
168
Note: See TracBrowser for help on using the browser.