summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authornick_m <mainsbridge@gmail.com>2016-12-29 01:39:31 +1100
committernick_m <mainsbridge@gmail.com>2016-12-29 01:39:31 +1100
commitd0580ecfbc1182f3c57b4d04e514f1d944225f14 (patch)
tree12c6854fd3955f85f1e4a9064b2cc4ac9ae35c62 /libs
parent0869aa0f6c045bea9ae3b1a030570f27faa90358 (diff)
allow all types of range location (loop, start, end etc.) to be glued to bars and beats.
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/ardour/location.h18
-rw-r--r--libs/ardour/location.cc110
-rw-r--r--libs/ardour/midi_scene_changer.cc2
-rw-r--r--libs/ardour/session.cc6
-rw-r--r--libs/ardour/session_state.cc4
5 files changed, 84 insertions, 56 deletions
diff --git a/libs/ardour/ardour/location.h b/libs/ardour/ardour/location.h
index 6b61dae746..24ee563915 100644
--- a/libs/ardour/ardour/location.h
+++ b/libs/ardour/ardour/location.h
@@ -58,7 +58,7 @@ class LIBARDOUR_API Location : public SessionHandleRef, public PBD::StatefulDest
};
Location (Session &);
- Location (Session &, framepos_t, framepos_t, const std::string &, Flags bits = Flags(0));
+ Location (Session &, framepos_t, framepos_t, const std::string &, Flags bits = Flags(0), const uint32_t sub_num = 0);
Location (const Location& other);
Location (Session &, const XMLNode&);
Location* operator= (const Location& other);
@@ -73,11 +73,11 @@ class LIBARDOUR_API Location : public SessionHandleRef, public PBD::StatefulDest
framepos_t end() const { return _end; }
framecnt_t length() const { return _end - _start; }
- int set_start (framepos_t s, bool force = false, bool allow_bbt_recompute = true);
- int set_end (framepos_t e, bool force = false, bool allow_bbt_recompute = true);
- int set (framepos_t start, framepos_t end, bool allow_bbt_recompute = true);
+ int set_start (framepos_t s, bool force = false, bool allow_beat_recompute = true, const uint32_t sub_num = 0);
+ int set_end (framepos_t e, bool force = false, bool allow_beat_recompute = true, const uint32_t sub_num = 0);
+ int set (framepos_t start, framepos_t end, bool allow_beat_recompute = true, const uint32_t sub_num = 0);
- int move_to (framepos_t pos);
+ int move_to (framepos_t pos, const uint32_t sub_num);
const std::string& name() const { return _name; }
void set_name (const std::string &str);
@@ -143,7 +143,7 @@ class LIBARDOUR_API Location : public SessionHandleRef, public PBD::StatefulDest
PositionLockStyle position_lock_style() const { return _position_lock_style; }
void set_position_lock_style (PositionLockStyle ps);
- void recompute_frames_from_bbt ();
+ void recompute_frames_from_beat ();
static PBD::Signal0<void> scene_changed; /* for use by backend scene change management, class level */
PBD::Signal0<void> SceneChangeChanged; /* for use by objects interested in this object */
@@ -151,9 +151,9 @@ class LIBARDOUR_API Location : public SessionHandleRef, public PBD::StatefulDest
private:
std::string _name;
framepos_t _start;
- double _bbt_start;
+ double _start_beat;
framepos_t _end;
- double _bbt_end;
+ double _end_beat;
Flags _flags;
bool _locked;
PositionLockStyle _position_lock_style;
@@ -161,7 +161,7 @@ class LIBARDOUR_API Location : public SessionHandleRef, public PBD::StatefulDest
void set_mark (bool yn);
bool set_flag_internal (bool yn, Flags flag);
- void recompute_bbt_from_frames ();
+ void recompute_beat_from_frames (const uint32_t sub_num);
};
/** A collection of session locations including unique dedicated locations (loop, punch, etc) */
diff --git a/libs/ardour/location.cc b/libs/ardour/location.cc
index 2fd63b6195..1b53c705d8 100644
--- a/libs/ardour/location.cc
+++ b/libs/ardour/location.cc
@@ -54,7 +54,9 @@ PBD::Signal1<void,Location*> Location::changed;
Location::Location (Session& s)
: SessionHandleRef (s)
, _start (0)
+ , _start_beat (0.0)
, _end (0)
+ , _end_beat (0.0)
, _flags (Flags (0))
, _locked (false)
, _position_lock_style (AudioTime)
@@ -64,7 +66,7 @@ Location::Location (Session& s)
}
/** Construct a new Location, giving it the position lock style determined by glue-new-markers-to-bars-and-beats */
-Location::Location (Session& s, framepos_t sample_start, framepos_t sample_end, const std::string &name, Flags bits)
+Location::Location (Session& s, framepos_t sample_start, framepos_t sample_end, const std::string &name, Flags bits, const uint32_t sub_num)
: SessionHandleRef (s)
, _name (name)
, _start (sample_start)
@@ -74,7 +76,7 @@ Location::Location (Session& s, framepos_t sample_start, framepos_t sample_end,
, _position_lock_style (s.config.get_glue_new_markers_to_bars_and_beats() ? MusicTime : AudioTime)
{
- recompute_bbt_from_frames ();
+ recompute_beat_from_frames (sub_num);
assert (_start >= 0);
assert (_end >= 0);
@@ -85,9 +87,9 @@ Location::Location (const Location& other)
, StatefulDestructible()
, _name (other._name)
, _start (other._start)
- , _bbt_start (other._bbt_start)
+ , _start_beat (other._start_beat)
, _end (other._end)
- , _bbt_end (other._bbt_end)
+ , _end_beat (other._end_beat)
, _flags (other._flags)
, _position_lock_style (other._position_lock_style)
@@ -125,8 +127,8 @@ Location::operator== (const Location& other)
if (_name != other._name ||
_start != other._start ||
_end != other._end ||
- _bbt_start != other._bbt_start ||
- _bbt_end != other._bbt_end ||
+ _start_beat != other._start_beat ||
+ _end_beat != other._end_beat ||
_flags != other._flags ||
_position_lock_style != other._position_lock_style) {
return false;
@@ -143,9 +145,9 @@ Location::operator= (const Location& other)
_name = other._name;
_start = other._start;
- _bbt_start = other._bbt_start;
+ _start_beat = other._start_beat;
_end = other._end;
- _bbt_end = other._bbt_end;
+ _end_beat = other._end_beat;
_flags = other._flags;
_position_lock_style = other._position_lock_style;
@@ -178,10 +180,10 @@ Location::set_name (const std::string& str)
/** Set start position.
* @param s New start.
* @param force true to force setting, even if the given new start is after the current end.
- * @param allow_bbt_recompute True to recompute BBT start time from the new given start time.
+ * @param allow_beat_recompute True to recompute BEAT start time from the new given start time.
*/
int
-Location::set_start (framepos_t s, bool force, bool allow_bbt_recompute)
+Location::set_start (framepos_t s, bool force, bool allow_beat_recompute, const uint32_t sub_num)
{
if (s < 0) {
return -1;
@@ -201,8 +203,8 @@ Location::set_start (framepos_t s, bool force, bool allow_bbt_recompute)
if (_start != s) {
_start = s;
_end = s;
- if (allow_bbt_recompute) {
- recompute_bbt_from_frames ();
+ if (allow_beat_recompute) {
+ recompute_beat_from_frames (sub_num);
}
start_changed (this); /* EMIT SIGNAL */
@@ -235,8 +237,8 @@ Location::set_start (framepos_t s, bool force, bool allow_bbt_recompute)
framepos_t const old = _start;
_start = s;
- if (allow_bbt_recompute) {
- recompute_bbt_from_frames ();
+ if (allow_beat_recompute) {
+ recompute_beat_from_frames (sub_num);
}
start_changed (this); /* EMIT SIGNAL */
StartChanged (); /* EMIT SIGNAL */
@@ -255,10 +257,10 @@ Location::set_start (framepos_t s, bool force, bool allow_bbt_recompute)
/** Set end position.
* @param s New end.
* @param force true to force setting, even if the given new end is before the current start.
- * @param allow_bbt_recompute True to recompute BBT end time from the new given end time.
+ * @param allow_beat_recompute True to recompute BEAT end time from the new given end time.
*/
int
-Location::set_end (framepos_t e, bool force, bool allow_bbt_recompute)
+Location::set_end (framepos_t e, bool force, bool allow_beat_recompute, const uint32_t sub_num)
{
if (e < 0) {
return -1;
@@ -278,8 +280,8 @@ Location::set_end (framepos_t e, bool force, bool allow_bbt_recompute)
if (_start != e) {
_start = e;
_end = e;
- if (allow_bbt_recompute) {
- recompute_bbt_from_frames ();
+ if (allow_beat_recompute) {
+ recompute_beat_from_frames (sub_num);
}
//start_changed (this); /* EMIT SIGNAL */
//StartChanged (); /* EMIT SIGNAL */
@@ -303,8 +305,8 @@ Location::set_end (framepos_t e, bool force, bool allow_bbt_recompute)
framepos_t const old = _end;
_end = e;
- if (allow_bbt_recompute) {
- recompute_bbt_from_frames ();
+ if (allow_beat_recompute) {
+ recompute_beat_from_frames (sub_num);
}
end_changed(this); /* EMIT SIGNAL */
@@ -321,7 +323,7 @@ Location::set_end (framepos_t e, bool force, bool allow_bbt_recompute)
}
int
-Location::set (framepos_t s, framepos_t e, bool allow_bbt_recompute)
+Location::set (framepos_t s, framepos_t e, bool allow_beat_recompute, const uint32_t sub_num)
{
if (s < 0 || e < 0) {
return -1;
@@ -341,8 +343,8 @@ Location::set (framepos_t s, framepos_t e, bool allow_bbt_recompute)
_start = s;
_end = s;
- if (allow_bbt_recompute) {
- recompute_bbt_from_frames ();
+ if (allow_beat_recompute) {
+ recompute_beat_from_frames (sub_num);
}
start_change = true;
@@ -364,8 +366,8 @@ Location::set (framepos_t s, framepos_t e, bool allow_bbt_recompute)
framepos_t const old = _start;
_start = s;
- if (allow_bbt_recompute) {
- recompute_bbt_from_frames ();
+ if (allow_beat_recompute) {
+ recompute_beat_from_frames (sub_num);
}
start_change = true;
@@ -382,8 +384,8 @@ Location::set (framepos_t s, framepos_t e, bool allow_bbt_recompute)
framepos_t const old = _end;
_end = e;
- if (allow_bbt_recompute) {
- recompute_bbt_from_frames ();
+ if (allow_beat_recompute) {
+ recompute_beat_from_frames (sub_num);
}
end_change = true;
@@ -411,7 +413,7 @@ Location::set (framepos_t s, framepos_t e, bool allow_bbt_recompute)
}
int
-Location::move_to (framepos_t pos)
+Location::move_to (framepos_t pos, const uint32_t sub_num)
{
if (pos < 0) {
return -1;
@@ -424,7 +426,7 @@ Location::move_to (framepos_t pos)
if (_start != pos) {
_start = pos;
_end = _start + length();
- recompute_bbt_from_frames ();
+ recompute_beat_from_frames (sub_num);
changed (this); /* EMIT SIGNAL */
Changed (); /* EMIT SIGNAL */
@@ -580,6 +582,14 @@ Location::get_state ()
node->add_property ("start", buf);
snprintf (buf, sizeof (buf), "%" PRId64, end());
node->add_property ("end", buf);
+
+ if (position_lock_style() == MusicTime) {
+ snprintf (buf, sizeof (buf), "%lf", _start_beat);
+ node->add_property ("start-beat", buf);
+ snprintf (buf, sizeof (buf), "%lf", _end_beat);
+ node->add_property ("end-beat", buf);
+ }
+
node->add_property ("flags", enum_2_string (_flags));
node->add_property ("locked", (_locked ? "yes" : "no"));
node->add_property ("position-lock-style", enum_2_string (_position_lock_style));
@@ -689,7 +699,27 @@ Location::set_state (const XMLNode& node, int version)
_scene_change = SceneChange::factory (*scene_child, version);
}
- recompute_bbt_from_frames ();
+ if (position_lock_style() == AudioTime) {
+ recompute_beat_from_frames (0);
+ } else{
+ /* music */
+ bool has_beat = false;
+
+ if ((prop = node.property ("start-beat")) != 0) {
+ sscanf (prop->value().c_str(), "%lf", &_start_beat);
+ has_beat = true;
+ }
+
+ if ((prop = node.property ("end-beat")) != 0) {
+ sscanf (prop->value().c_str(), "%lf", &_end_beat);
+ has_beat = true;
+ }
+
+ if (!has_beat) {
+ recompute_beat_from_frames (0);
+ }
+ }
+
changed (this); /* EMIT SIGNAL */
Changed (); /* EMIT SIGNAL */
@@ -709,32 +739,30 @@ Location::set_position_lock_style (PositionLockStyle ps)
_position_lock_style = ps;
- recompute_bbt_from_frames ();
+ if (ps == MusicTime) {
+ recompute_beat_from_frames (0);
+ }
position_lock_style_changed (this); /* EMIT SIGNAL */
PositionLockStyleChanged (); /* EMIT SIGNAL */
}
void
-Location::recompute_bbt_from_frames ()
+Location::recompute_beat_from_frames (const uint32_t sub_num)
{
- if (_position_lock_style != MusicTime) {
- return;
- }
-
- _bbt_start = _session.tempo_map().beat_at_frame (_start);
- _bbt_end = _session.tempo_map().beat_at_frame (_end);
+ _start_beat = _session.tempo_map().exact_beat_at_frame (_start, sub_num);
+ _end_beat = _session.tempo_map().exact_beat_at_frame (_end, sub_num);
}
void
-Location::recompute_frames_from_bbt ()
+Location::recompute_frames_from_beat ()
{
if (_position_lock_style != MusicTime) {
return;
}
TempoMap& map (_session.tempo_map());
- set (map.frame_at_beat (_bbt_start), map.frame_at_beat (_bbt_end), false);
+ set (map.frame_at_beat (_start_beat), map.frame_at_beat (_end_beat), false);
}
void
@@ -1060,7 +1088,7 @@ Locations::set_state (const XMLNode& node, int version)
Location* session_range_location = 0;
if (version < 3000) {
- session_range_location = new Location (_session, 0, 0, _("session"), Location::IsSessionRange);
+ session_range_location = new Location (_session, 0, 0, _("session"), Location::IsSessionRange, 0);
new_locations.push_back (session_range_location);
}
diff --git a/libs/ardour/midi_scene_changer.cc b/libs/ardour/midi_scene_changer.cc
index 0c2880dcaf..ce2559180f 100644
--- a/libs/ardour/midi_scene_changer.cc
+++ b/libs/ardour/midi_scene_changer.cc
@@ -314,7 +314,7 @@ MIDISceneChanger::program_change_input (MIDI::Parser& parser, MIDI::byte program
return;
}
- loc = new Location (_session, time, time, new_name, Location::IsMark);
+ loc = new Location (_session, time, time, new_name, Location::IsMark, 0);
new_mark = true;
}
diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc
index 112a933e19..56b3f2a38c 100644
--- a/libs/ardour/session.cc
+++ b/libs/ardour/session.cc
@@ -1682,7 +1682,7 @@ Session::set_session_extents (framepos_t start, framepos_t end)
Location* existing;
if ((existing = _locations->session_range_location()) == 0) {
//if there is no existing session, we need to make a new session location (should never happen)
- existing = new Location (*this, 0, 0, _("session"), Location::IsSessionRange);
+ existing = new Location (*this, 0, 0, _("session"), Location::IsSessionRange, 0);
}
if (end <= start) {
@@ -5582,7 +5582,7 @@ void
Session::update_locations_after_tempo_map_change (const Locations::LocationList& loc)
{
for (Locations::LocationList::const_iterator i = loc.begin(); i != loc.end(); ++i) {
- (*i)->recompute_frames_from_bbt ();
+ (*i)->recompute_frames_from_beat ();
}
}
@@ -6340,7 +6340,7 @@ Session::current_end_frame () const
void
Session::set_session_range_location (framepos_t start, framepos_t end)
{
- _session_range_location = new Location (*this, start, end, _("session"), Location::IsSessionRange);
+ _session_range_location = new Location (*this, start, end, _("session"), Location::IsSessionRange, 0);
_locations->add (_session_range_location);
}
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index 506bc58fdf..3d839d8186 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -634,7 +634,7 @@ Session::create (const string& session_template, BusProfile* bus_profile)
/* Initial loop location, from absolute zero, length 10 seconds */
- Location* loc = new Location (*this, 0, 10.0 * _engine.sample_rate(), _("Loop"), Location::IsAutoLoop);
+ Location* loc = new Location (*this, 0, 10.0 * _engine.sample_rate(), _("Loop"), Location::IsAutoLoop, 0);
_locations->add (loc, true);
set_auto_loop_location (loc);
}
@@ -1220,7 +1220,7 @@ Session::state (bool full_state)
Locations loc (*this);
// for a template, just create a new Locations, populate it
// with the default start and end, and get the state for that.
- Location* range = new Location (*this, 0, 0, _("session"), Location::IsSessionRange);
+ Location* range = new Location (*this, 0, 0, _("session"), Location::IsSessionRange, 0);
range->set (max_framepos, 0);
loc.add (range);
XMLNode& locations_state = loc.get_state();