NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
smpte.h
Go to the documentation of this file.
1/*
2 * NiCMidi - A C++ Class Library for MIDI
3 *
4 * Copyright (C) 2004 J.D. Koftinoff Software, Ltd.
5 * www.jdkoftinoff.com jeffk@jdkoftinoff.com
6 * Copyright (C) 2010 V.R.Madgazin
7 * www.vmgames.com vrm@vmgames.com
8 * Copyright (C) 2021, 2022 Nicola Cassetta
9 * https://github.com/ncassetta/NiCMidi
10 *
11 * This file is part of NiCMidi
12 *
13 * NiCMidi is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU Lesser General Public License as
15 * published by the Free Software Foundation, either version 3 of
16 * the License, or (at your option) any later version.
17 *
18 * NiCMidi is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with NiCMidi. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27
30
31#ifndef _NICMIDI_SMPTE_H
32#define _NICMIDI_SMPTE_H
33
34
37
46};
47
48
57};
59
60
69class SMPTE {
70 public:
71
75 SAMPLE_RATE sample_rate = SAMPLE_48000);
77 void SetSMPTERate (SMPTE_RATE r) { smpte_rate = r; sample_number_dirty = true; }
79 SMPTE_RATE GetSMPTERate() const { return smpte_rate; }
81 void SetSampleRate (SAMPLE_RATE r) { sample_rate = r; sample_number_dirty = true; }
82
84 SAMPLE_RATE GetSampleRate() const { return sample_rate; }
85
86 /* NEW */
88 void SetOffset (unsigned long n) { sample_offset = n; }
90 void SetOffset (unsigned char h, unsigned char m, unsigned char s,
91 unsigned char f = 0, unsigned char sf = 0);
93 unsigned long GetOffset () const { return sample_offset; }
94 /* end NEW */
95
101 unsigned long GetSampleNumber();
105 void SetSampleNumber (unsigned long n)
106 { sample_number = n; sample_number_dirty = true; }
112 unsigned long GetMilliSeconds ();
116 void SetMilliSeconds (unsigned long msecs);
117
125
127 unsigned char GetHours(); // TODO: is this right? perhaps hours could be an int
129 unsigned char GetMinutes();
131 unsigned char GetSeconds();
133 unsigned char GetFrames();
135 unsigned char GetSubFrames();
137
141
145 void SetTime (unsigned char h, unsigned char m, unsigned char s,
146 unsigned char f = 0, unsigned char sf = 0);
148 void SetHours (unsigned char h) { hours = h; sample_number_dirty = true; }
150 void SetMinutes (unsigned char m) { minutes = m; sample_number_dirty = true; }
152 void SetSeconds (unsigned char s) { seconds = s; sample_number_dirty = true; }
154 void SetFrames (unsigned char f) { frames = f; sample_number_dirty = true; }
156 void SetSubFrames (unsigned char sf) { sub_frames = sf; sample_number_dirty = true; }
158
162
164 void AddSamples (long n);
166 void IncSamples() { AddSamples (1); }
168 void DecSamples() { AddSamples (-1); }
170
174
176 void AddHours (signed char h);
178 void AddMinutes (signed char m);
180 void AddSeconds (signed char s);
182 void AddFrames (signed char f);
184 void AddSubFrames (signed char sf);
186 void IncHours() { AddHours (1); }
188 void IncMinutes() { AddMinutes (1); }
190 void IncSeconds() { AddSeconds (1); }
192 void IncFrames() { AddFrames (1); }
196 void DecHours() { AddHours (-1); }
198 void DecMinutes() { AddMinutes (-1); }
200 void DecSeconds() { AddSeconds (-1); }
202 void DecFrames() { AddFrames (-1); }
204 void DecSubFrames() { AddSubFrames (-1); }
206
210
212 bool operator== (SMPTE &s) { return Compare (s) == 0; }
214 bool operator!= (SMPTE &s) { return Compare (s) != 0; }
216 bool operator< (SMPTE &s) { return Compare (s) < 0; }
218 bool operator> (SMPTE &s) { return Compare (s) > 0; }
220 bool operator<= (SMPTE &s) { return Compare (s) <= 0; }
222 bool operator>= (SMPTE &s) { return Compare (s) >= 0; }
223 /* These were eliminated: what should return if SMPTE rates are not equal?
224 SMPTE& operator+= (SMPTE &s) { SetSampleNumber (sample_number + s.GetSampleNumber()); return *this; }
225 SMPTE& operator-= (SMPTE &s) { SetSampleNumber (sample_number - s.GetSampleNumber()); return *this; }
226 SMPTE& operator+ (SMPTE &s);
227 SMPTE& operator- (SMPTE &s);
228 */
230
231 protected:
237 int Compare (SMPTE &s);
238
240 // Max frames for every SMPTE_RATE.
241 static const unsigned char smpte_max_frames[];
242 // Converts the SMPTE_RATE enum to a double frequency.
243 static const double smpte_rates[];
244 // Converts the SMPTE_RATE enum to a long frequency times 100.
245 static const long smpte_rates_long[];
246 // Converts the SAMPLE_RATE enum to a double frequency.
247 static const double sample_rates[];
248 // Converts the SAMPLE_RATE enum to a long frequency times 10.
249 static const long sample_rates_long[];
251
252 private:
253 SMPTE_RATE smpte_rate; // The SMPTE rate
254 SAMPLE_RATE sample_rate; // The sample rate
255 unsigned long sample_number; // The sample number
256 /* NEW */
257 unsigned long sample_offset; // The initial time offset
258
259 unsigned char hours; // SMPTE hours
260 unsigned char minutes; // SMPTE minutes
261 unsigned char seconds; // SMPTE seconds
262 unsigned char frames; // SMPTE frames
263 unsigned char sub_frames; // SMPTE subframes
264 bool sample_number_dirty;// True if we must perform a conversion
265
266/* These were eliminated: what if SMPTE rates are not equal?
267 friend SMPTE operator + ( SMPTE a, SMPTE b );
268 friend SMPTE operator - ( SMPTE a, SMPTE b );
269*/
270};
271
272
273#endif
Performs conversions between number of samples, milliseconds and smpte format (hours::minutes::second...
Definition: smpte.h:69
void SetSubFrames(unsigned char sf)
Loads the SMPTE with the given smpte subframes, leaving unchanged other parameters.
Definition: smpte.h:156
void AddSamples(long n)
Adds n samples.
SMPTE(SMPTE_RATE smpte_rate=SMPTE_RATE_30, SAMPLE_RATE sample_rate=SAMPLE_48000)
The constructor sets the smpte rate to SMPTE_30, the sample rate to SAMPLE_48000 and the offset time ...
bool operator>=(SMPTE &s)
Greater or equal.
Definition: smpte.h:222
void SetOffset(unsigned char h, unsigned char m, unsigned char s, unsigned char f=0, unsigned char sf=0)
Sets an offset to be added to the current time, given the smpte time parameters.
void DecFrames()
Subtract one frame from smpte time.
Definition: smpte.h:202
void IncFrames()
Adds one frame to smpte time.
Definition: smpte.h:192
void DecSamples()
Subtracts one sample.
Definition: smpte.h:168
void SetHours(unsigned char h)
Loads the SMPTE with the given smpte hours, leaving unchanged other parameters.
Definition: smpte.h:148
int Compare(SMPTE &s)
Performs internal comparison between sample numbers.
unsigned char GetMinutes()
Returns the smpte minutes.
void DecHours()
Subtract one hour from smpte time.
Definition: smpte.h:196
unsigned char GetSeconds()
Returns the smpte seconds.
SAMPLE_RATE GetSampleRate() const
Returns the sample rate. See SAMPLE_RATE for avalaible sample rates formats.
Definition: smpte.h:84
unsigned long GetOffset() const
Returns the time offset (in samples).
Definition: smpte.h:93
void SetSMPTERate(SMPTE_RATE r)
Sets the smpte rate. See SMPTE_RATE for avalaible smpte rate formats.
Definition: smpte.h:77
void SetFrames(unsigned char f)
Loads the SMPTE with the given smpte frames, leaving unchanged other parameters.
Definition: smpte.h:154
unsigned char GetHours()
Returns the smpte hours.
bool operator!=(SMPTE &s)
Not equal.
Definition: smpte.h:214
unsigned char GetFrames()
Returns the smpte frames.
bool operator<=(SMPTE &s)
Lesser or equal.
Definition: smpte.h:220
bool operator==(SMPTE &s)
Equal.
Definition: smpte.h:212
void SetSampleRate(SAMPLE_RATE r)
Sets the sample rate. See SAMPLE_RATE for avalaible sample rates formats.
Definition: smpte.h:81
void AddMinutes(signed char m)
Adds minutes to smpte time.
void IncSeconds()
Adds one second to smpte time.
Definition: smpte.h:190
unsigned long GetSampleNumber()
Performs a smpte-to-samples or milliseconds-to-samples conversion.
void SetMinutes(unsigned char m)
Loads the SMPTE with the given smpte minutes, leaving unchanged other parameters.
Definition: smpte.h:150
void SetSampleNumber(unsigned long n)
Loads the SMPTE with the given amount of samples.
Definition: smpte.h:105
SMPTE_RATE GetSMPTERate() const
Returns the smpte rate. See SMPTE_RATE for avalaible smpte rate formats.
Definition: smpte.h:79
void AddSeconds(signed char s)
Adds seconds to smpte time.
void AddFrames(signed char f)
Adds frames to smpte time.
void SetMilliSeconds(unsigned long msecs)
Loads the SMPTE with the given time in milliseconds.
void IncSubFrames()
Adds one subframe to smpte time.
Definition: smpte.h:194
void IncMinutes()
Adds one minute to smpte time.
Definition: smpte.h:188
unsigned long GetMilliSeconds()
Performs a smpte-to-millisecond or sample-to-millisecond conversion.
void AddSubFrames(signed char sf)
Adds subframes to smpte time.
void SampleToTime()
Performs internal samples-to-smpte conversion.
unsigned char GetSubFrames()
Returns the smpte subframes.
void DecSeconds()
Subtract one second from smpte time.
Definition: smpte.h:200
bool operator<(SMPTE &s)
Lesser.
Definition: smpte.h:216
void TimeToSample()
Performs internal smpte-to-samples conversion.
void SetTime(unsigned char h, unsigned char m, unsigned char s, unsigned char f=0, unsigned char sf=0)
Loads the SMPTE with the given time (in smpte format).
void IncSamples()
Adds one sample.
Definition: smpte.h:166
void DecMinutes()
Subtract one minute from smpte time.
Definition: smpte.h:198
void SetSeconds(unsigned char s)
Loads the SMPTE with the given smpte seconds, leaving unchanged other parameters.
Definition: smpte.h:152
void AddHours(signed char h)
Adds hours to smpte time.
void IncHours()
Adds one hour to smpte time.
Definition: smpte.h:186
bool operator>(SMPTE &s)
Greater.
Definition: smpte.h:218
void SetOffset(unsigned long n)
Sets an offset to be added to the current time, given the amount of samples.
Definition: smpte.h:88
void DecSubFrames()
Subtract one subframe from smpte time.
Definition: smpte.h:204
SMPTE_RATE
The smpte rates (determine the frames/sec rate)
Definition: smpte.h:39
SAMPLE_RATE
The sample rates (determine the sample/sec rate)
Definition: smpte.h:50
@ SMPTE_RATE_25
25 frames/sec
Definition: smpte.h:41
@ SMPTE_RATE_30DF
30 frames/sec drop
Definition: smpte.h:45
@ SMPTE_RATE_24
24 frames/sec
Definition: smpte.h:40
@ SMPTE_RATE_30
30 frames/sec
Definition: smpte.h:44
@ SMPTE_RATE_2997DF
29.97 frames/sec drop
Definition: smpte.h:43
@ SMPTE_RATE_2997
29.97 frames/sec
Definition: smpte.h:42
@ SAMPLE_47952
47952 samples/sec
Definition: smpte.h:54
@ SAMPLE_32000
32000 samples/sec
Definition: smpte.h:51
@ SAMPLE_44100
44100 samples/sec
Definition: smpte.h:53
@ SAMPLE_48000
48000 samples/sec
Definition: smpte.h:55
@ SAMPLE_48048
48048 samples/sec
Definition: smpte.h:56
@ SAMPLE_44056
44056 samples/sec
Definition: smpte.h:52