2012-02-02 00:59:12 +01:00
|
|
|
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
|
2011-11-16 20:55:49 +01:00
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
//
|
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
2012-02-02 00:59:12 +01:00
|
|
|
/// @file audio_marker.cpp
|
|
|
|
/// @see audio_marker.h
|
2011-11-16 20:55:49 +01:00
|
|
|
/// @ingroup audio_ui
|
|
|
|
///
|
|
|
|
|
2012-02-02 00:59:12 +01:00
|
|
|
#include "audio_marker.h"
|
2011-11-16 20:55:49 +01:00
|
|
|
|
|
|
|
#include "include/aegisub/context.h"
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2011-11-16 20:55:49 +01:00
|
|
|
#include "pen.h"
|
2014-05-22 01:23:28 +02:00
|
|
|
#include "project.h"
|
|
|
|
#include "video_controller.h"
|
2011-11-16 20:55:49 +01:00
|
|
|
|
2014-04-23 22:53:24 +02:00
|
|
|
#include <libaegisub/make_unique.h>
|
2013-06-08 06:19:40 +02:00
|
|
|
|
2011-11-16 20:55:49 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
2014-03-13 02:39:07 +01:00
|
|
|
class AudioMarkerKeyframe final : public AudioMarker {
|
2011-11-16 20:55:49 +01:00
|
|
|
Pen *style;
|
2012-02-02 00:58:58 +01:00
|
|
|
int position;
|
2011-11-16 20:55:49 +01:00
|
|
|
public:
|
2012-02-02 00:58:58 +01:00
|
|
|
AudioMarkerKeyframe(Pen *style, int position) : style(style), position(position) { }
|
2013-11-21 18:13:36 +01:00
|
|
|
int GetPosition() const override { return position; }
|
|
|
|
FeetStyle GetFeet() const override { return Feet_None; }
|
|
|
|
wxPen GetStyle() const override { return *style; }
|
2012-02-02 00:58:58 +01:00
|
|
|
operator int() const { return position; }
|
2011-11-16 20:55:49 +01:00
|
|
|
};
|
|
|
|
|
2011-11-16 20:56:09 +01:00
|
|
|
AudioMarkerProviderKeyframes::AudioMarkerProviderKeyframes(agi::Context *c, const char *opt_name)
|
2014-05-22 01:23:28 +02:00
|
|
|
: p(c->project.get())
|
|
|
|
, keyframe_slot(p->AddKeyframesListener(&AudioMarkerProviderKeyframes::Update, this))
|
|
|
|
, timecode_slot(p->AddTimecodesListener(&AudioMarkerProviderKeyframes::Update, this))
|
2011-11-16 20:56:09 +01:00
|
|
|
, enabled_slot(OPT_SUB(opt_name, &AudioMarkerProviderKeyframes::Update, this))
|
|
|
|
, enabled_opt(OPT_GET(opt_name))
|
2014-04-23 22:53:24 +02:00
|
|
|
, style(agi::make_unique<Pen>("Colour/Audio Display/Keyframe"))
|
2011-11-16 20:55:49 +01:00
|
|
|
{
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioMarkerProviderKeyframes::~AudioMarkerProviderKeyframes() { }
|
|
|
|
|
|
|
|
void AudioMarkerProviderKeyframes::Update() {
|
2014-05-22 01:23:28 +02:00
|
|
|
auto const& keyframes = p->Keyframes();
|
|
|
|
auto const& timecodes = p->Timecodes();
|
2011-11-16 20:55:49 +01:00
|
|
|
|
|
|
|
if (keyframes.empty() || !timecodes.IsLoaded() || !enabled_opt->GetBool()) {
|
|
|
|
if (!markers.empty()) {
|
|
|
|
markers.clear();
|
|
|
|
AnnounceMarkerMoved();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
markers.clear();
|
|
|
|
markers.reserve(keyframes.size());
|
2012-11-04 04:53:03 +01:00
|
|
|
for (int frame : keyframes)
|
2012-11-28 16:35:26 +01:00
|
|
|
markers.emplace_back(style.get(), timecodes.TimeAtFrame(frame, agi::vfr::START));
|
2011-11-16 20:55:49 +01:00
|
|
|
AnnounceMarkerMoved();
|
|
|
|
}
|
|
|
|
|
2012-02-02 00:58:58 +01:00
|
|
|
void AudioMarkerProviderKeyframes::GetMarkers(TimeRange const& range, AudioMarkerVector &out) const {
|
2011-11-16 20:55:49 +01:00
|
|
|
// Find first and last keyframes inside the range
|
2013-09-16 21:10:00 +02:00
|
|
|
auto a = lower_bound(markers.begin(), markers.end(), range.begin());
|
|
|
|
auto b = upper_bound(markers.begin(), markers.end(), range.end());
|
2011-11-16 20:55:49 +01:00
|
|
|
|
|
|
|
// Place pointers to the markers in the output vector
|
|
|
|
for (; a != b; ++a)
|
|
|
|
out.push_back(&*a);
|
|
|
|
}
|
2012-02-02 00:59:12 +01:00
|
|
|
|
2014-03-13 02:39:07 +01:00
|
|
|
class VideoPositionMarker final : public AudioMarker {
|
2014-05-14 21:42:44 +02:00
|
|
|
Pen style{"Colour/Audio Display/Play Cursor"};
|
|
|
|
int position = -1;
|
2012-02-02 00:59:12 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
void SetPosition(int new_pos) { position = new_pos; }
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
int GetPosition() const override { return position; }
|
|
|
|
FeetStyle GetFeet() const override { return Feet_None; }
|
|
|
|
wxPen GetStyle() const override { return style; }
|
2012-02-02 00:59:12 +01:00
|
|
|
operator int() const { return position; }
|
|
|
|
};
|
|
|
|
|
|
|
|
VideoPositionMarkerProvider::VideoPositionMarkerProvider(agi::Context *c)
|
2014-03-25 22:49:26 +01:00
|
|
|
: vc(c->videoController.get())
|
2012-02-02 00:59:12 +01:00
|
|
|
, video_seek_slot(vc->AddSeekListener(&VideoPositionMarkerProvider::Update, this))
|
|
|
|
, enable_opt_changed_slot(OPT_SUB("Audio/Display/Draw/Video Position", &VideoPositionMarkerProvider::OptChanged, this))
|
|
|
|
{
|
|
|
|
OptChanged(*OPT_GET("Audio/Display/Draw/Video Position"));
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoPositionMarkerProvider::~VideoPositionMarkerProvider() { }
|
|
|
|
|
|
|
|
void VideoPositionMarkerProvider::Update(int frame_number) {
|
|
|
|
marker->SetPosition(vc->TimeAtFrame(frame_number));
|
|
|
|
AnnounceMarkerMoved();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPositionMarkerProvider::OptChanged(agi::OptionValue const& opt) {
|
|
|
|
if (opt.GetBool()) {
|
|
|
|
video_seek_slot.Unblock();
|
2014-04-23 22:53:24 +02:00
|
|
|
marker = agi::make_unique<VideoPositionMarker>();
|
2012-02-02 00:59:12 +01:00
|
|
|
marker->SetPosition(vc->GetFrameN());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
video_seek_slot.Block();
|
|
|
|
marker.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPositionMarkerProvider::GetMarkers(const TimeRange &range, AudioMarkerVector &out) const {
|
|
|
|
if (marker && range.contains(*marker))
|
|
|
|
out.push_back(marker.get());
|
|
|
|
}
|
2012-04-27 21:07:29 +02:00
|
|
|
|
|
|
|
SecondsMarkerProvider::SecondsMarkerProvider()
|
2014-04-23 22:53:24 +02:00
|
|
|
: pen(agi::make_unique<Pen>("Colour/Audio Display/Seconds Line", 1, wxPENSTYLE_DOT))
|
2012-04-27 21:07:29 +02:00
|
|
|
, enabled(OPT_GET("Audio/Display/Draw/Seconds"))
|
|
|
|
, enabled_opt_changed(OPT_SUB("Audio/Display/Draw/Seconds", &SecondsMarkerProvider::EnabledOptChanged, this))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SecondsMarkerProvider::EnabledOptChanged() {
|
|
|
|
AnnounceMarkerMoved();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SecondsMarkerProvider::GetMarkers(TimeRange const& range, AudioMarkerVector &out) const {
|
|
|
|
if (!enabled->GetBool()) return;
|
|
|
|
|
|
|
|
if ((range.length() + 999) / 1000 > (int)markers.size())
|
|
|
|
markers.resize((range.length() + 999) / 1000, Marker(pen.get()));
|
|
|
|
|
|
|
|
size_t i = 0;
|
|
|
|
for (int time = ((range.begin() + 999) / 1000) * 1000; time < range.end(); time += 1000) {
|
|
|
|
markers[i].position = time;
|
|
|
|
out.push_back(&markers[i++]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPen SecondsMarkerProvider::Marker::GetStyle() const {
|
|
|
|
return *style;
|
|
|
|
}
|