13
0

temporal: a guess at how to use BBT markers from within TempoMap::paste()

Basically, if the paste position is not zero and not on a bar line, we will a BBT marker there,
using the existing tempo & meter at that position before the paste.

If the end of the paste is not on a bar line, we will place a BBT marker there,
using the tempo & meter that existed before the paste.

TempoMap::paste() now also accepts an optional final argument that if provided is
used to name the BBT markers, if they are created
This commit is contained in:
Paul Davis 2023-08-30 15:21:50 -06:00
parent 7997c83b01
commit 6c44dbf9d6
2 changed files with 47 additions and 32 deletions

View File

@ -971,52 +971,60 @@ TempoMap::cut_copy (timepos_t const & start, timepos_t const & end, bool copy, b
} }
void void
TempoMap::paste (TempoMapCutBuffer const & cb, timepos_t const & position, bool ripple) TempoMap::paste (TempoMapCutBuffer const & cb, timepos_t const & position, bool ripple, std::string suggested_name)
{ {
std::cerr << "\n\n PASTE \n\n";
if (cb.empty()) { if (cb.empty()) {
std::cerr << "nothing to paste\n";
return; return;
} }
dump (std::cerr); dump (std::cerr);
std::cerr << "tm paste, ripple " << ripple << std::endl;
if (ripple) { if (ripple) {
shift (position, cb.duration()); shift (position, cb.duration());
} }
dump (std::cerr); dump (std::cerr);
bool replaced_ignored;
/* We need to look these up first, before we change the map */
const timepos_t end_position = position + cb.duration(); const timepos_t end_position = position + cb.duration();
Tempo end_tempo = tempo_at (end_position); const Tempo end_tempo = tempo_at (end_position);
Meter end_meter = meter_at (end_position); const Meter end_meter = meter_at (end_position);
/* iterate over _points since they are already in sclock order, and we /* iterate over _points since they are already in sclock order, and we
* won't need to post-sort the way we would if we handled tempos, * won't need to post-sort the way we would if we handled tempos,
* meters, bartimes separately. * meters, bartimes separately.
*/ */
BBT_Time pos_bbt = bbt_at (position); BBT_Time pos_bbt = bbt_at (position);
Beats pos_beats = quarters_at (position); Beats pos_beats = quarters_at (position);
bool ignored; bool ignored;
bool replaced; bool replaced;
Tempo const * st = cb.start_tempo(); MusicTimePoint* mtp;
Meter const * mt = cb.start_meter(); superclock_t s;
std::string name;
#if 0 /* Do not try to put a BBT marker at absolute zero or anywhere on a bar */
MusicTimePoint* mtp = new MusicTimePoint (*this, position.superclocks(), pos_beats, pos_bbt, tempo_at (position), meter_at (position), _("paste start"));
core_add_bartime (mtp, replaced); if (!position.is_zero() && (pos_bbt.ticks != 0 || pos_bbt.beats != 1)) {
if (!replaced) {
core_add_tempo (mtp, ignored); if (suggested_name.empty()) {
core_add_meter (mtp, ignored); name = _("paste>");
core_add_point (mtp); } else {
name = string_compose (X_("%1>"), suggested_name);
}
mtp = new MusicTimePoint (*this, position.superclocks(), pos_beats, pos_bbt, tempo_at (position), meter_at (position), name);
core_add_bartime (mtp, replaced);
if (!replaced) {
core_add_tempo (mtp, ignored);
core_add_meter (mtp, ignored);
core_add_point (mtp);
}
} }
#endif
superclock_t s;
for (auto const & p : cb.points()) { for (auto const & p : cb.points()) {
TempoPoint const * tp; TempoPoint const * tp;
@ -1067,15 +1075,22 @@ TempoMap::paste (TempoMapCutBuffer const & cb, timepos_t const & position, bool
pos_bbt = bbt_at (end_position); pos_bbt = bbt_at (end_position);
pos_beats = quarters_at (end_position); pos_beats = quarters_at (end_position);
#if 0 if (pos_bbt.ticks != 0 || pos_bbt.beats != 1) {
mtp = new MusicTimePoint (*this, end_position.superclocks(), pos_beats, pos_bbt, end_tempo, end_meter, _("paste end"));
core_add_bartime (mtp, replaced); if (suggested_name.empty()) {
if (!replaced) { name = _("<paste");
core_add_tempo (mtp, ignored); } else {
core_add_meter (mtp, ignored); name = string_compose (X_("<%1"), suggested_name);
core_add_point (mtp); }
mtp = new MusicTimePoint (*this, end_position.superclocks(), pos_beats, pos_bbt, end_tempo, end_meter, name);
core_add_bartime (mtp, replaced);
if (!replaced) {
core_add_tempo (mtp, ignored);
core_add_meter (mtp, ignored);
core_add_point (mtp);
}
} }
#endif
reset_starting_at (s); reset_starting_at (s);
dump (std::cerr); dump (std::cerr);

View File

@ -897,7 +897,7 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
LIBTEMPORAL_API TempoMapCutBuffer* cut (timepos_t const & start, timepos_t const & end, bool ripple); LIBTEMPORAL_API TempoMapCutBuffer* cut (timepos_t const & start, timepos_t const & end, bool ripple);
LIBTEMPORAL_API TempoMapCutBuffer* copy (timepos_t const & start, timepos_t const & end); LIBTEMPORAL_API TempoMapCutBuffer* copy (timepos_t const & start, timepos_t const & end);
LIBTEMPORAL_API void paste (TempoMapCutBuffer const &, timepos_t const & position, bool ripple); LIBTEMPORAL_API void paste (TempoMapCutBuffer const &, timepos_t const & position, bool ripple, std::string = std::string());
LIBTEMPORAL_API void shift (timepos_t const & at, BBT_Offset const & by); LIBTEMPORAL_API void shift (timepos_t const & at, BBT_Offset const & by);
LIBTEMPORAL_API void shift (timepos_t const & at, timecnt_t const & by); LIBTEMPORAL_API void shift (timepos_t const & at, timecnt_t const & by);