Also move karaoke markers after the dragged marker if Ctrl is held down. Closes #1557.

This commit is contained in:
Thomas Goyne 2012-11-30 15:07:35 -08:00
parent 5b31f10d0b
commit af35e50810

View file

@ -38,6 +38,9 @@
#include <deque> #include <deque>
#endif #endif
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/sliced.hpp>
/// @class KaraokeMarker /// @class KaraokeMarker
/// @brief AudioMarker implementation for AudioTimingControllerKaraoke /// @brief AudioMarker implementation for AudioTimingControllerKaraoke
class KaraokeMarker : public AudioMarker { class KaraokeMarker : public AudioMarker {
@ -344,22 +347,28 @@ void AudioTimingControllerKaraoke::ModifyStart(int delta) {
bool AudioTimingControllerKaraoke::IsNearbyMarker(int ms, int sensitivity) const { bool AudioTimingControllerKaraoke::IsNearbyMarker(int ms, int sensitivity) const {
TimeRange range(ms - sensitivity, ms + sensitivity); TimeRange range(ms - sensitivity, ms + sensitivity);
return any_of(markers.begin(), markers.end(), [&](KaraokeMarker const& km) {
for (auto const& marker : markers) return range.contains(km);
if (range.contains(marker)) });
return true;
return false;
} }
std::vector<AudioMarker*> AudioTimingControllerKaraoke::OnLeftClick(int ms, bool, int sensitivity, int) { template<typename Out, typename In>
static std::vector<Out *> copy_ptrs(In &vec, size_t start, size_t end) {
std::vector<Out *> ret;
ret.reserve(end - start);
for (; start < end; ++start)
ret.push_back(&vec[start]);
return ret;
}
std::vector<AudioMarker*> AudioTimingControllerKaraoke::OnLeftClick(int ms, bool ctrl_down, int sensitivity, int) {
TimeRange range(ms - sensitivity, ms + sensitivity); TimeRange range(ms - sensitivity, ms + sensitivity);
size_t syl = distance(markers.begin(), lower_bound(markers.begin(), markers.end(), ms)); size_t syl = distance(markers.begin(), lower_bound(markers.begin(), markers.end(), ms));
if (syl < markers.size() && range.contains(markers[syl])) if (syl < markers.size() && range.contains(markers[syl]))
return std::vector<AudioMarker*>(1, &markers[syl]); return copy_ptrs<AudioMarker>(markers, syl, ctrl_down ? markers.size() : syl + 1);
if (syl > 0 && range.contains(markers[syl - 1])) if (syl > 0 && range.contains(markers[syl - 1]))
return std::vector<AudioMarker*>(1, &markers[syl - 1]); return copy_ptrs<AudioMarker>(markers, syl - 1, ctrl_down ? markers.size() : syl);
cur_syl = syl; cur_syl = syl;
@ -419,13 +428,22 @@ void AudioTimingControllerKaraoke::AnnounceChanges(int syl) {
} }
void AudioTimingControllerKaraoke::OnMarkerDrag(std::vector<AudioMarker*> const& m, int new_position, int) { void AudioTimingControllerKaraoke::OnMarkerDrag(std::vector<AudioMarker*> const& m, int new_position, int) {
assert(m.size() == 1); int old_position = m[0]->GetPosition();
AnnounceChanges(MoveMarker(static_cast<KaraokeMarker*>(m[0]), new_position)); int syl = MoveMarker(static_cast<KaraokeMarker *>(m[0]), new_position);
if (syl < 0) return;
if (m.size() > 1) {
int delta = m[0]->GetPosition() - old_position;
for (AudioMarker *marker : m | boost::adaptors::sliced(1, m.size()))
MoveMarker(static_cast<KaraokeMarker *>(marker), marker->GetPosition() + delta);
syl = cur_syl;
}
AnnounceChanges(syl);
} }
void AudioTimingControllerKaraoke::GetLabels(TimeRange const& range, std::vector<AudioLabel> &out) const { void AudioTimingControllerKaraoke::GetLabels(TimeRange const& range, std::vector<AudioLabel> &out) const {
for (auto const& label : labels) { push_back(out, labels | boost::adaptors::filtered([&](AudioLabel const& l) {
if (range.overlaps(label.range)) return range.overlaps(l.range);
out.push_back(label); }));
}
} }