}
double
-MetricSection::minute_at_frame (const framepos_t& frame) const
+MetricSection::minute_at_frame (const framepos_t frame) const
{
return (frame / (double) _sample_rate) / 60.0;
}
, _locked_to_meter (false)
, _clamped (false)
{
- _legacy_bbt = BBT_Time (0, 0, 0);
-
BBT_Time bbt;
std::string start_bbt;
if (node.get_property ("start", start_bbt)) {
* for use with musical units whose granularity is coarser than frames (e.g. ticks)
*/
double
-TempoSection::pulse_at_frame (const framepos_t& f) const
+TempoSection::pulse_at_frame (const framepos_t f) const
{
const bool constant = type() == Constant || _c == 0.0 || (initial() && f < frame());
if (constant) {
}
/* user supplies the exact pulse if pls == MusicTime */
TempoSection*
-TempoMap::add_tempo (const Tempo& tempo, const double& pulse, const framepos_t& frame, PositionLockStyle pls)
+TempoMap::add_tempo (const Tempo& tempo, const double& pulse, const framepos_t frame, PositionLockStyle pls)
{
if (tempo.note_types_per_minute() <= 0.0) {
warning << "Cannot add tempo. note types per minute must be greater than zero." << endmsg;
TempoSection* ts = 0;
{
Glib::Threads::RWLock::WriterLock lm (lock);
- ts = add_tempo_locked (tempo, pulse, minute_at_frame (frame), pls, true, false);
+ /* here we default to not clamped for a new tempo section. preference? */
+ ts = add_tempo_locked (tempo, pulse, minute_at_frame (frame), pls, true, false, false);
recompute_map (_metrics);
}
}
void
-TempoMap::replace_tempo (TempoSection& ts, const Tempo& tempo, const double& pulse, const framepos_t& frame, PositionLockStyle pls)
+TempoMap::replace_tempo (TempoSection& ts, const Tempo& tempo, const double& pulse, const framepos_t frame, PositionLockStyle pls)
{
if (tempo.note_types_per_minute() <= 0.0) {
warning << "Cannot replace tempo. note types per minute must be greater than zero." << endmsg;
}
} else {
remove_tempo_locked (ts);
- new_ts = add_tempo_locked (tempo, pulse, minute_at_frame (frame), pls, true, locked_to_meter);
- new_ts->set_clamped (ts_clamped);
-
- if (new_ts && new_ts->type() == TempoSection::Constant) {
- new_ts->set_end_note_types_per_minute (new_ts->note_types_per_minute());
+ new_ts = add_tempo_locked (tempo, pulse, minute_at_frame (frame), pls, true, locked_to_meter, ts_clamped);
+ /* enforce clampedness of next tempo section */
+ TempoSection* next_t = next_tempo_section_locked (_metrics, new_ts);
+ if (next_t && next_t->clamped()) {
+ next_t->set_note_types_per_minute (new_ts->end_note_types_per_minute());
}
}
TempoSection*
TempoMap::add_tempo_locked (const Tempo& tempo, double pulse, double minute
- , PositionLockStyle pls, bool recompute, bool locked_to_meter)
+ , PositionLockStyle pls, bool recompute, bool locked_to_meter, bool clamped)
{
TempoSection* t = new TempoSection (pulse, minute, tempo, pls, _frame_rate);
t->set_locked_to_meter (locked_to_meter);
+ t->set_clamped (clamped);
do_insert (t);
for (Metrics::iterator i = _metrics.begin(); i != _metrics.end(); ++i) {
TempoSection* const this_t = dynamic_cast<TempoSection*>(*i);
if (this_t) {
- bool const ipm = t->position_lock_style() == MusicTime;
- bool const lm = t->locked_to_meter();
-
- if ((ipm && this_t->pulse() == t->pulse()) || (!ipm && this_t->frame() == t->frame())
- || (lm && this_t->pulse() == t->pulse())) {
+ if (this_t == t) {
if (prev_tempo && prev_tempo->type() == TempoSection::Ramp) {
prev_tempo->set_end_note_types_per_minute (t->note_types_per_minute());
}
if (pls == AudioTime) {
/* add meter-locked tempo at the natural time in the current map (frame may differ). */
Tempo const tempo_at_time = tempo_at_minute_locked (_metrics, time_minutes);
- TempoSection* mlt = add_tempo_locked (tempo_at_time, pulse, time_minutes, AudioTime, true, true);
+ TempoSection* mlt = add_tempo_locked (tempo_at_time, pulse, time_minutes, AudioTime, true, true, false);
if (!mlt) {
return 0;
continue;
}
}
+
if (prev_t) {
if (t->position_lock_style() == AudioTime) {
prev_t->set_c (prev_t->compute_c_minute (prev_t->end_note_types_per_minute(), t->minute()));
* This function uses both tempo and meter.
*/
double
-TempoMap::beat_at_frame (const framecnt_t& frame) const
+TempoMap::beat_at_frame (const framecnt_t frame) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
*
*/
Tempo
-TempoMap::tempo_at_frame (const framepos_t& frame) const
+TempoMap::tempo_at_frame (const framepos_t frame) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
}
bool
-TempoMap::set_active_tempi (const Metrics& metrics, const framepos_t& frame)
+TempoMap::set_active_tempi (const Metrics& metrics, const framepos_t frame)
{
for (Metrics::const_iterator i = metrics.begin(); i != metrics.end(); ++i) {
TempoSection* t;
}
}
-#if (0)
- recompute_tempi (imaginary);
-
- if (check_solved (imaginary)) {
- return true;
- } else {
- dunp (imaginary, std::cout);
- }
-#endif
-
MetricSectionFrameSorter fcmp;
imaginary.sort (fcmp);
section->set_minute (section_prev->minute_at_ntpm (section_prev->end_note_types_per_minute(), pulse));
}
-#if (0)
- recompute_tempi (imaginary);
-
- if (check_solved (imaginary)) {
- return true;
- } else {
- dunp (imaginary, std::cout);
- }
-#endif
-
MetricSectionSorter cmp;
imaginary.sort (cmp);
* if sub_num is zero, the musical position will be taken from the supplied frame.
*/
void
-TempoMap::gui_set_tempo_position (TempoSection* ts, const framepos_t& frame, const int& sub_num)
+TempoMap::gui_set_tempo_position (TempoSection* ts, const framepos_t frame, const int& sub_num)
{
Metrics future_map;
* leaving the meter position unchanged.
*/
void
-TempoMap::gui_set_meter_position (MeterSection* ms, const framepos_t& frame)
+TempoMap::gui_set_meter_position (MeterSection* ms, const framepos_t frame)
{
Metrics future_map;
}
void
-TempoMap::gui_stretch_tempo (TempoSection* ts, const framepos_t frame, const framepos_t end_frame)
+TempoMap::gui_stretch_tempo (TempoSection* ts, const framepos_t frame, const framepos_t end_frame, const double start_qnote, const double end_qnote)
{
/*
Ts (future prev_t) Tnext
return;
}
- TempoSection* prev_t = copy_metrics_and_point (_metrics, future_map, ts);
+ TempoSection* ts_copy = copy_metrics_and_point (_metrics, future_map, ts);
- if (!prev_t) {
+ if (!ts_copy) {
return;
}
framepos_t const min_dframe = 2;
double new_bpm;
- if (prev_t->clamped()) {
- TempoSection* next_t = next_tempo_section_locked (future_map, prev_t);
- TempoSection* prev_to_prev_t = previous_tempo_section_locked (future_map, prev_t);
- /* the change in frames is the result of changing the slope of at most 2 previous tempo sections.
- constant to constant is straightforward, as the tempo prev to prev_t has constant slope.
- */
- double contribution = 0.0;
- if (next_t && prev_to_prev_t && prev_to_prev_t->type() == TempoSection::Ramp) {
- contribution = (prev_t->frame() - prev_to_prev_t->frame()) / (double) (next_t->frame() - prev_to_prev_t->frame());
- }
- framepos_t const fr_off = (end_frame - frame);
- const frameoffset_t prev_t_frame_contribution = fr_off - (contribution * (double) fr_off);
-
- if (frame > prev_to_prev_t->frame() + min_dframe && (frame + prev_t_frame_contribution) > prev_to_prev_t->frame() + min_dframe) {
- new_bpm = prev_t->note_types_per_minute() * ((frame - prev_to_prev_t->frame())
- / (double) ((frame + prev_t_frame_contribution) - prev_to_prev_t->frame()));
+ if (ts_copy->clamped()) {
+ TempoSection* next_t = next_tempo_section_locked (future_map, ts_copy);
+ TempoSection* prev_to_ts_copy = previous_tempo_section_locked (future_map, ts_copy);
+ /* the change in frames is the result of changing the slope of at most 2 previous tempo sections.
+ constant to constant is straightforward, as the tempo prev to ts_copy has constant slope.
+ */ double contribution = 0.0;
+ if (next_t && prev_to_ts_copy && prev_to_ts_copy->type() == TempoSection::Ramp) {
+ contribution = (ts_copy->pulse() - prev_to_ts_copy->pulse()) / (double) (next_t->pulse() - prev_to_ts_copy->pulse());
+ }
+ framepos_t const fr_off = end_frame - frame;
+ frameoffset_t const ts_copy_frame_contribution = fr_off - (contribution * (double) fr_off);
+
+ if (frame > prev_to_ts_copy->frame() + min_dframe && (frame + ts_copy_frame_contribution) > prev_to_ts_copy->frame() + min_dframe) {
+ new_bpm = ts_copy->note_types_per_minute() * ((start_qnote - (prev_to_ts_copy->pulse() * 4.0))
+ / (end_qnote - (prev_to_ts_copy->pulse() * 4.0)));
} else {
- new_bpm = prev_t->note_types_per_minute();
+ new_bpm = ts_copy->note_types_per_minute();
}
} else {
- if (frame > prev_t->frame() + min_dframe && end_frame > prev_t->frame() + min_dframe) {
+ if (frame > ts_copy->frame() + min_dframe && end_frame > ts_copy->frame() + min_dframe) {
- new_bpm = prev_t->note_types_per_minute() * ((frame - prev_t->frame())
- / (double) (end_frame - prev_t->frame()));
+ new_bpm = ts_copy->note_types_per_minute() * ((frame - ts_copy->frame())
+ / (double) (end_frame - ts_copy->frame()));
} else {
- new_bpm = prev_t->note_types_per_minute();
+ new_bpm = ts_copy->note_types_per_minute();
}
new_bpm = min (new_bpm, (double) 1000.0);
goto out;
}
- if (prev_t && prev_t->type() == TempoSection::Ramp) {
- prev_t->set_note_types_per_minute (new_bpm);
- } else {
- prev_t->set_end_note_types_per_minute (new_bpm);
- prev_t->set_note_types_per_minute (new_bpm);
- }
+ ts_copy->set_note_types_per_minute (new_bpm);
- if (prev_t->clamped()) {
+ if (ts_copy->clamped()) {
TempoSection* prev = 0;
- if ((prev = previous_tempo_section_locked (future_map, prev_t)) != 0) {
- prev->set_end_note_types_per_minute (prev_t->note_types_per_minute());
+ if ((prev = previous_tempo_section_locked (future_map, ts_copy)) != 0) {
+ prev->set_end_note_types_per_minute (ts_copy->note_types_per_minute());
}
}
recompute_meters (future_map);
if (check_solved (future_map)) {
- if (prev_t && prev_t->type() == TempoSection::Ramp) {
- ts->set_note_types_per_minute (new_bpm);
- } else {
- ts->set_end_note_types_per_minute (new_bpm);
- ts->set_note_types_per_minute (new_bpm);
- }
+ ts->set_note_types_per_minute (new_bpm);
+
if (ts->clamped()) {
TempoSection* prev = 0;
if ((prev = previous_tempo_section_locked (_metrics, ts)) != 0) {
prev->set_end_note_types_per_minute (ts->note_types_per_minute());
}
}
+
recompute_tempi (_metrics);
recompute_meters (_metrics);
}
* This function is sensitive to tempo and meter.
*/
double
-TempoMap::exact_beat_at_frame (const framepos_t& frame, const int32_t sub_num) const
+TempoMap::exact_beat_at_frame (const framepos_t frame, const int32_t sub_num) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
}
double
-TempoMap::exact_beat_at_frame_locked (const Metrics& metrics, const framepos_t& frame, const int32_t divisions) const
+TempoMap::exact_beat_at_frame_locked (const Metrics& metrics, const framepos_t frame, const int32_t divisions) const
{
return beat_at_pulse_locked (_metrics, exact_qn_at_frame_locked (metrics, frame, divisions) / 4.0);
}
* This function is tempo-sensitive.
*/
double
-TempoMap::exact_qn_at_frame (const framepos_t& frame, const int32_t sub_num) const
+TempoMap::exact_qn_at_frame (const framepos_t frame, const int32_t sub_num) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
}
double
-TempoMap::exact_qn_at_frame_locked (const Metrics& metrics, const framepos_t& frame, const int32_t sub_num) const
+TempoMap::exact_qn_at_frame_locked (const Metrics& metrics, const framepos_t frame, const int32_t sub_num) const
{
double qn = pulse_at_minute_locked (metrics, minute_at_frame (frame)) * 4.0;
do that stuff based on the beat_at_frame and frame_at_beat api
*/
double
-TempoMap::frames_per_quarter_note_at (const framepos_t& frame, const framecnt_t& sr) const
+TempoMap::frames_per_quarter_note_at (const framepos_t frame, const framecnt_t sr) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
}
if (prev_t) {
- if (prev_t->type() != TempoSection::Constant) {
+ if (prev_t->end_note_types_per_minute() < 0.0) {
prev_t->set_end_note_types_per_minute (t->note_types_per_minute());
}
}
prev_t = t;
}
}
+
+ if (prev_t) {
+ prev_t->set_end_note_types_per_minute (prev_t->note_types_per_minute());
+ }
}
XMLNode&
fix_legacy_end_session();
break;
}
-
- break;
}
}