2009-10-26 22:32:11 -04:00
|
|
|
/*
|
2010-12-14 14:07:50 -05:00
|
|
|
Copyright (C) 2002-2010 Paul Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
option) any later version.
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2010-12-14 14:07:50 -05:00
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2010-12-14 14:07:50 -05:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with this program; if not, write to the Free Software Foundation,
|
|
|
|
Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2009-10-26 22:32:11 -04:00
|
|
|
*/
|
|
|
|
|
2010-12-14 13:13:37 -05:00
|
|
|
#ifndef __timecode_bbt_time_h__
|
|
|
|
#define __timecode_bbt_time_h__
|
2009-10-26 22:32:11 -04:00
|
|
|
|
2009-10-27 13:47:54 -04:00
|
|
|
#include <ostream>
|
2009-10-26 22:32:11 -04:00
|
|
|
#include <stdint.h>
|
2010-11-04 16:37:46 -04:00
|
|
|
#include <iomanip>
|
2009-10-26 22:32:11 -04:00
|
|
|
|
2014-01-12 11:33:58 -05:00
|
|
|
#include "timecode/visibility.h"
|
|
|
|
|
2010-12-14 13:13:37 -05:00
|
|
|
namespace Timecode {
|
2009-10-26 22:32:11 -04:00
|
|
|
|
2010-12-14 13:13:37 -05:00
|
|
|
/** Bar, Beat, Tick Time (i.e. Tempo-Based Time) */
|
2014-01-12 11:33:58 -05:00
|
|
|
struct LIBTIMECODE_API BBT_Time {
|
2012-01-06 11:39:40 -05:00
|
|
|
static const double ticks_per_beat;
|
2010-12-14 15:28:37 -05:00
|
|
|
|
2010-11-04 16:37:36 -04:00
|
|
|
uint32_t bars;
|
|
|
|
uint32_t beats;
|
|
|
|
uint32_t ticks;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-12-14 13:13:37 -05:00
|
|
|
BBT_Time ()
|
|
|
|
: bars (1), beats (1), ticks (0) {}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-11-04 16:37:36 -04:00
|
|
|
BBT_Time (uint32_t ba, uint32_t be, uint32_t t)
|
|
|
|
: bars (ba), beats (be), ticks (t) {}
|
2010-12-14 15:28:37 -05:00
|
|
|
|
|
|
|
BBT_Time (double beats);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-11-04 16:37:36 -04:00
|
|
|
bool operator< (const BBT_Time& other) const {
|
|
|
|
return bars < other.bars ||
|
|
|
|
(bars == other.bars && beats < other.beats) ||
|
|
|
|
(bars == other.bars && beats == other.beats && ticks < other.ticks);
|
|
|
|
}
|
2012-01-02 18:32:33 -05:00
|
|
|
|
|
|
|
bool operator<= (const BBT_Time& other) const {
|
|
|
|
return bars < other.bars ||
|
|
|
|
(bars <= other.bars && beats <= other.beats) ||
|
|
|
|
(bars <= other.bars && beats <= other.beats && ticks <= other.ticks);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator> (const BBT_Time& other) const {
|
|
|
|
return bars > other.bars ||
|
|
|
|
(bars == other.bars && beats > other.beats) ||
|
|
|
|
(bars == other.bars && beats == other.beats && ticks > other.ticks);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator>= (const BBT_Time& other) const {
|
|
|
|
return bars > other.bars ||
|
|
|
|
(bars >= other.bars && beats >= other.beats) ||
|
|
|
|
(bars >= other.bars && beats >= other.beats && ticks >= other.ticks);
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-11-04 16:37:36 -04:00
|
|
|
bool operator== (const BBT_Time& other) const {
|
|
|
|
return bars == other.bars && beats == other.beats && ticks == other.ticks;
|
|
|
|
}
|
2012-01-07 12:11:17 -05:00
|
|
|
|
|
|
|
bool operator!= (const BBT_Time& other) const {
|
|
|
|
return bars != other.bars || beats != other.beats || ticks != other.ticks;
|
|
|
|
}
|
2009-10-26 22:32:11 -04:00
|
|
|
};
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-10-26 22:32:11 -04:00
|
|
|
}
|
|
|
|
|
2009-10-27 13:47:54 -04:00
|
|
|
inline std::ostream&
|
2010-12-14 13:13:37 -05:00
|
|
|
operator<< (std::ostream& o, const Timecode::BBT_Time& bbt)
|
2009-10-27 13:47:54 -04:00
|
|
|
{
|
|
|
|
o << bbt.bars << '|' << bbt.beats << '|' << bbt.ticks;
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2010-11-04 16:37:46 -04:00
|
|
|
inline std::ostream&
|
2010-12-14 13:13:37 -05:00
|
|
|
print_padded (std::ostream& o, const Timecode::BBT_Time& bbt)
|
2010-11-04 16:37:46 -04:00
|
|
|
{
|
|
|
|
o << std::setfill ('0') << std::right
|
|
|
|
<< std::setw (3) << bbt.bars << "|"
|
|
|
|
<< std::setw (2) << bbt.beats << "|"
|
|
|
|
<< std::setw (4) << bbt.ticks;
|
|
|
|
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2010-12-14 13:13:37 -05:00
|
|
|
#endif /* __timecode_bbt_time_h__ */
|