Commit graph

684 commits

Author SHA1 Message Date
Paul Davis
8f815e21ea temporal: rename Point::sample() to Point::sample_is_dangerous()
It is risky to take the sample value returned by this method and then convert it back
to either superclocks or beats, mostly because tempo & meter times are generally in
music time, and converting from superclocks to samples loses precision.

This rename is there to serve as a reminder to developers to be careful when using
this method
2025-12-29 09:14:02 -07:00
Paul Davis
369fc2c15c temporal: fix a major thinko when removing/replacing map points
Despite comments already in the code, the logic used to remove a
{Tempo,Meter,BarTime} point from the _points list was incorrect. While it is
true that we can use a duple of (type,time) to find a given point,
::remove_point() was not doing that and instead assumed just the time value
could be used.

This meant that if you placed a tempo and meter at the same point in time, then
changed one of them, ::remove_point() could remove the wrong point from the
_points list.

In #10063 this manifests as the wrong grid being drawn after a tempo point
edit.

This commit alters the ::core_remove_xxx() methods to return a pointer to the
actual Point object that was removed from {_tempos,_meters,_bartimes} and then
we pass that to ::remove_point() for lookup and removal by address.

It also "fixes" a couple of instances of ::core_remove_xxx() without any
removal from the _points list (since ::core_remove_tempo() and
::core_remove_meter() do not do this; ::core_remove_bartime() does,
however). It is not immediately obvious what bad behavior would arise from the
existing code in these cases, but it seems clearly incorrect that the _points
list would contain points no longer present in _tempos or _meters.
2025-12-27 12:14:49 -07:00
Paul Davis
f1b80cdbe1 temporal: add & use a couple of TempMap methods for unit testing 2025-12-27 12:14:49 -07:00
Paul Davis
f742ef661b temporal: slightly improve addRemoveTest 2025-12-27 12:14:49 -07:00
Paul Davis
fee0af27cf temporal: new addRemoveTest unit test 2025-12-27 12:14:49 -07:00
Robin Gareus
34609232f0
Remove deprecated no-op function (1/2)
Glib::thread_init has been deprecated since 2.32,ib
is no longer necessary and no longer has any effect.

This fixes builds with modern glib[mm] versions, notably
with msys2 in Windows.
2025-11-20 23:10:52 +01:00
Paul Davis
e50032ecb5 for debug builds, show stacktrace for TempoMap::fetch_condition() failure 2025-11-11 14:35:55 -07:00
Paul Davis
1114a05f1f fix incorrect locally scoped tempo map management
This is tricky to explain, so rather than explain what was wrong, I'll describe
how it works now.

Whenever a ScopedTempoMapOwner::in() call occurs, we check the current thread-local
tempo map ptr. If it is not owned by us (and we have a local tempo map that we
want to use), set it so that it is.

We continue to fetch() the global tempo map ptr back into the thread-local ptr
when the local scope depth drops to zero.
2025-10-20 14:58:16 -06:00
Paul Davis
e975fc5b7d slightly more debug information when starting local tempo scope 2025-10-20 14:58:16 -06:00
Paul Davis
77bc293aee add a variation on the EC_LOCAL_TEMPO_SCOPE macro 2025-09-11 15:14:14 -06:00
Paul Davis
901e32f17f temporal: add stacktraces to DEBUG_TRACE output for start/end local tempo map 2025-09-01 11:17:24 -06:00
Paul Davis
f6ec3828ed temporal: fix local tempo map depth mgmt when starting a local tempo map 2025-09-01 11:17:24 -06:00
Robin Gareus
060462a9f1
Fix struct/class tag mismatch
> 'TempoMapScope' defined as a struct here but previously declared
> as a class; this is valid, but may result in linker errors under
> the Microsoft C++ ABI [clang-diagnostic-mismatched-tags]
2025-08-29 17:22:41 +02:00
Paul Davis
7dadddb3dc temporal: provide TempoMap::global_fetch()
This always returns a shared ptr to the global tempo map, without setting the
thread-local pointer
2025-08-23 22:35:16 -06:00
Paul Davis
bb13bd48b2 several more bbt_delta() unit tests 2025-08-22 10:59:06 -06:00
Paul Davis
27ffd1628d temporal: remove iterative bbt_delta() since unit test shows breakage 2025-08-22 10:51:16 -06:00
Paul Davis
fd53cf87ed temporal: new non-iterative implementation of Meter::bbt_delta() 2025-08-22 10:45:12 -06:00
Paul Davis
26e63fca9b add unit test for Meter::bbt_delta() 2025-08-22 10:45:12 -06:00
Paul Davis
e9460bb372 temporal: fix unused variable warning in TempoMap::paste() 2025-08-20 17:43:45 -06:00
Paul Davis
de843db102 temporal: lots more DEBUG_TRACE statements for grid debugging 2025-08-20 17:43:34 -06:00
Paul Davis
607f3577bd temporal: in the event of the most common logic failure, provide more info
TEMPORAL_MAP_ASSERT() doesn't give us any actual values or context.
2025-08-20 17:43:24 -06:00
Paul Davis
a8168f826d remove incorrect bbt_delta() in BBT_Time, provide Meter::bbt_delta
There are two implementations here, the more efficient one (commented out) does
not work correctly yet.
2025-08-20 17:43:05 -06:00
Paul Davis
469f3e4d2a unit tests: fix an unusual deadlock/block in TempoMap::write_copy()
this call works in other tests, no time to investigate it right now, and
technically the test doesn't require a write copy at all.
2025-08-19 10:53:06 -06:00
Paul Davis
69174b555e unit tests: use std::cout for any debug output in tempo map cut buffer test 2025-08-19 10:53:06 -06:00
Paul Davis
1312e8f992 temporal: implement TempoMap::bbt_distance() but do not use it
This was implemented to try to fix paste() but was not needed. It might be
useful in the future, or just as an expression of the logic of this. Note that
the BBT_Offset it returns only has the beats field set, which is ... odd. So
this is likely not quite finished.
2025-08-19 10:53:06 -06:00
Paul Davis
29be601cce temporal: undefine macro after use 2025-08-19 10:53:06 -06:00
Paul Davis
7c9b9ceb7e temporal: show BBT marker point names in operator<< 2025-08-19 10:53:06 -06:00
Paul Davis
2aad1ac5f5 temporal: fix TempoMap::paste() to pass unit test
the BBT times of the newly inserted points during paste() are meaningless until
we recompute them using ::reset_starting_at(). So don't try to compute some
sort of likely value, just use the value from the cut buffer, and call
reset_starting_at() after every point inserted.
2025-08-19 10:53:06 -06:00
Paul Davis
f0111bcea5 temporal: BBT_Time cannot have any round_to_*() or round_up_to_*() methods
A meter (time signature) is required to do the math correctly for any operation that may
cross or reach the next bar boundary, which round_to_*() and round_up_to_*() may do.
2025-08-19 10:53:06 -06:00
Paul Davis
f010133c5f slightly improve a DEBUG_TRACE message for DEBUG::Grid 2025-08-13 10:51:44 -06:00
Paul Davis
46f2dba306 temporal: fix Meter::to_quarters (BBT_Offset)
Because Paul can't do math
2025-08-13 10:51:44 -06:00
John Emmas
ca820d6380 Remove some unneeded DLL export specifiers (and repo some that were in the wrong place) 2025-08-13 11:22:06 +01:00
Paul Davis
b95c29770c initialize scope owner in default TempoMap constructor
This constructor should not really exist, but it does.
2025-08-12 21:44:50 -06:00
Paul Davis
20b984384d NO-OP: move TempoMap destructor in code to be after constructors 2025-08-12 21:44:50 -06:00
Paul Davis
b205c0bc4b scoped tempo maps: logic fixes and some comment-documentation 2025-08-12 07:53:30 -06:00
Paul Davis
2fc669964e Revert "A new class ('ScopedTempoMapOwner') exposes functions which need to be visible outside of libtemporal"
This reverts commit d3a15b11ba.

This arrived at an awkward time as ScopedTempoMapOwner was being rearranged at
the source level. It will be reapplied in a subsequent commit.
2025-08-12 07:15:17 -06:00
John Emmas
d3a15b11ba A new class ('ScopedTempoMapOwner') exposes functions which need to be visible outside of libtemporal
(and since there's no 'scope.cc', libtemporal itself needs to #include scope.h for those symbols to get exported)
2025-08-12 13:19:24 +01:00
Paul Davis
ec61deaa8a macro to stop local tempo map code from doing anything 2025-08-11 18:05:24 -06:00
Paul Davis
dd41fddcad temporal: fix up some logic relating to scoped tempo maps 2025-08-11 15:41:34 -06:00
Paul Davis
023290b99d temporal: add sanity check to TempoMap::fetch()
Threads should never call ::fetch() if they have a local tempo map in
use.
2025-08-11 15:41:34 -06:00
Paul Davis
1ecbdf164d moved scoped tempo map from GUI to libtemporal 2025-08-11 15:41:34 -06:00
Paul Davis
d7b490143a add comment on why _superclock_ticks_per_second is initializedto zero 2025-08-06 15:06:14 -06:00
Paul Davis
b80b4b7869 remove debugging output 2025-08-05 11:42:23 -06:00
Paul Davis
b65adb59cd temporal: fix some subtle misbehavior in TempoMap::cut_copy() 2025-08-05 11:37:35 -06:00
Paul Davis
0f1c5a9d7d temporal: add new smf_*() API for building a tempo map from SMF info 2025-08-05 11:37:35 -06:00
Paul Davis
ba00dc0920 temporal: add TempoMap::duration() method 2025-08-05 11:37:35 -06:00
Paul Davis
b6f1ff336e when adding a tempo/meter at end of map, no reset necessary
Also, the reset would malfunction which really ought to be fixed
2025-07-30 22:18:12 -06:00
Paul Davis
fc692f5680 Fix for timepos_t::earlier() - superclock_t vs.samplepos_t confusion 2025-06-17 14:03:43 -06:00
Paul Davis
b6e1846c39 temporal: fix implementation of timepos_t::operator+= (BBT_Offset const &)
TempoMap::bbtwalk_to_quarters() converts the distance of the walk into quarters, but
we need the endpoint of the walk
2025-05-13 12:16:11 -06:00
Paul Davis
0e42868d35 fix arithmetic error in Meter::to_quarters 2025-04-11 11:23:36 -06:00