13
0

temporal: introduce Temporal::reset() with TempoMap initialization

Ardour uses some global variables and singletons. These global variables
can be initialized with a value prior to program execution (especially
if they are const), but some of the static variables are modified, and
it is crucial that they always are reset when switching to another
session. To keep things simple and explicit and consistent, we thus
introduce Temporal::reset() to reset TempoMap (and later on also the
superclock rate). This is somewhat similar to Temporal::init(), which
usually only is invoked once (on program start) to initialize singletons
(such as the TempoMap).

9964f20c added TempoMap initialization to Session::create() ... but only
when not using a template. This create method is mainly preparing the
filesystem for a new session, and TempoMap initialization doesn't seem
like a perfect fit for it. It also seemed odd that it only initialized
TempoMap for clean new sessions, while existing sessions and templates
initialized it elsewhere.

Instead, invoke the TempoMap initialization early in the Session
creation process. This might introduce an extra and unnecessary TempoMap
initialization when loading an existing session or using a template, but
that will be cheap and do no harm, while providing a guarantee that we
always use the same default value.
This commit is contained in:
Mads Kiilerich 2022-10-05 19:12:37 +02:00 committed by Paul Davis
parent 226ff63e3c
commit 80ffa58c81
4 changed files with 11 additions and 5 deletions

View File

@ -361,6 +361,8 @@ Session::Session (AudioEngine &eng,
_cue_events.reserve (1024);
Temporal::reset();
pre_engine_init (fullpath); // sets _is_new
setup_lua ();

View File

@ -640,11 +640,6 @@ Session::create (const string& session_template, BusProfile const * bus_profile,
<< endmsg;
return -1;
}
} else {
(void) TempoMap::write_copy(); /* we are going to throw away the return value and replace the map entirely */
TempoMap::WritableSharedPtr new_map (new TempoMap (Tempo (120, 4), Meter (4, 4)));
TempoMap::update (new_map);;
}
/* set up Master Out and Monitor Out if necessary */

View File

@ -76,6 +76,13 @@ void Temporal::init ()
}
}
void Temporal::reset ()
{
(void) TempoMap::write_copy(); /* we are going to throw away the return value and replace the map entirely */
TempoMap::WritableSharedPtr new_map (new TempoMap (Tempo (120, 4), Meter (4, 4)));
TempoMap::update (new_map);;
}
std::ostream&
operator<< (std::ostream& o, Temporal::ratio_t const & r)
{

View File

@ -30,8 +30,10 @@ namespace Temporal {
#ifdef COMPILER_MSVC
LIBTEMPORAL_API void init ();
LIBTEMPORAL_API void reset ();
#else
extern void init ();
extern void reset ();
#endif
/* Any position measured in audio samples.