Implement the timing adjustment commands

Originally committed to SVN as r6933.
This commit is contained in:
Thomas Goyne 2012-07-14 13:35:15 +00:00
parent 60c38bd2e5
commit 38217c6c59
7 changed files with 199 additions and 33 deletions

View File

@ -125,6 +125,15 @@ public:
/// Add lead-out time to the current timing unit /// Add lead-out time to the current timing unit
virtual void AddLeadOut() = 0; virtual void AddLeadOut() = 0;
/// Modify the length of the current and possibly following timing units
/// @param delta Amount to add in centiseconds
/// @param shift_following Should the following things be shifted by delta?
virtual void ModifyLength(int delta, bool shift_following) = 0;
/// Modify the start time of the current timing unit
/// @param delta Amount to add in centiseconds
virtual void ModifyStart(int delta) = 0;
/// @brief Determine if a position is close to a draggable marker /// @brief Determine if a position is close to a draggable marker
/// @param ms The time in milliseconds to test /// @param ms The time in milliseconds to test
/// @param sensitivity Distance in milliseconds to consider markers as nearby /// @param sensitivity Distance in milliseconds to consider markers as nearby

View File

@ -398,6 +398,8 @@ public:
void Revert(); void Revert();
void AddLeadIn(); void AddLeadIn();
void AddLeadOut(); void AddLeadOut();
void ModifyLength(int delta, bool shift_following);
void ModifyStart(int delta);
bool IsNearbyMarker(int ms, int sensitivity) const; bool IsNearbyMarker(int ms, int sensitivity) const;
std::vector<AudioMarker*> OnLeftClick(int ms, bool ctrl_down, int sensitivity, int snap_range); std::vector<AudioMarker*> OnLeftClick(int ms, bool ctrl_down, int sensitivity, int snap_range);
std::vector<AudioMarker*> OnRightClick(int ms, bool, int sensitivity, int snap_range); std::vector<AudioMarker*> OnRightClick(int ms, bool, int sensitivity, int snap_range);
@ -600,6 +602,18 @@ void AudioTimingControllerDialogue::AddLeadOut()
SetMarkers(std::vector<AudioMarker*>(1, m), *m + OPT_GET("Audio/Lead/OUT")->GetInt()); SetMarkers(std::vector<AudioMarker*>(1, m), *m + OPT_GET("Audio/Lead/OUT")->GetInt());
} }
void AudioTimingControllerDialogue::ModifyLength(int delta, bool) {
DialogueTimingMarker *m = active_line.GetRightMarker();
SetMarkers(std::vector<AudioMarker*>(1, m),
std::max<int>(*m + delta * 10, *active_line.GetLeftMarker()));
}
void AudioTimingControllerDialogue::ModifyStart(int delta) {
DialogueTimingMarker *m = active_line.GetLeftMarker();
SetMarkers(std::vector<AudioMarker*>(1, m),
std::min<int>(*m + delta * 10, *active_line.GetRightMarker()));
}
bool AudioTimingControllerDialogue::IsNearbyMarker(int ms, int sensitivity) const bool AudioTimingControllerDialogue::IsNearbyMarker(int ms, int sensitivity) const
{ {
assert(sensitivity >= 0); assert(sensitivity >= 0);

View File

@ -114,6 +114,8 @@ class AudioTimingControllerKaraoke : public AudioTimingController {
void DoCommit(); void DoCommit();
void ApplyLead(bool announce_primary); void ApplyLead(bool announce_primary);
int MoveMarker(KaraokeMarker *marker, int new_position);
void AnnounceChanges(int syl);
public: public:
// AudioTimingController implementation // AudioTimingController implementation
@ -129,6 +131,8 @@ public:
void Revert(); void Revert();
void AddLeadIn(); void AddLeadIn();
void AddLeadOut(); void AddLeadOut();
void ModifyLength(int delta, bool shift_following);
void ModifyStart(int delta);
bool IsNearbyMarker(int ms, int sensitivity) const; bool IsNearbyMarker(int ms, int sensitivity) const;
std::vector<AudioMarker*> OnLeftClick(int ms, bool, int sensitivity, int); std::vector<AudioMarker*> OnLeftClick(int ms, bool, int sensitivity, int);
std::vector<AudioMarker*> OnRightClick(int, bool, int, int) { return std::vector<AudioMarker*>(); } std::vector<AudioMarker*> OnRightClick(int, bool, int, int) { return std::vector<AudioMarker*>(); }
@ -292,16 +296,36 @@ void AudioTimingControllerKaraoke::AddLeadOut() {
void AudioTimingControllerKaraoke::ApplyLead(bool announce_primary) { void AudioTimingControllerKaraoke::ApplyLead(bool announce_primary) {
kara->SetLineTimes(start_marker, end_marker); kara->SetLineTimes(start_marker, end_marker);
if (!announce_primary)
AnnounceUpdatedStyleRanges();
AnnounceChanges(announce_primary ? cur_syl : cur_syl + 2);
}
AnnounceUpdatedStyleRanges(); void AudioTimingControllerKaraoke::ModifyLength(int delta, bool shift_following) {
AnnounceMarkerMoved(); if (cur_syl == markers.size()) return;
if (announce_primary)
AnnounceUpdatedPrimaryRange();
if (auto_commit) int cur, end, step;
DoCommit(); if (delta < 0) {
else cur = cur_syl;
commit_id = -1; end = shift_following ? markers.size() : cur_syl + 1;
step = 1;
}
else {
cur = shift_following ? markers.size() - 1 : cur_syl;
end = cur_syl - 1;
step = -1;
}
for (; cur != end; cur += step) {
MoveMarker(&markers[cur], markers[cur] + delta * 10);
}
AnnounceChanges(cur_syl);
}
void AudioTimingControllerKaraoke::ModifyStart(int delta) {
if (cur_syl == 0) return;
MoveMarker(&markers[cur_syl - 1], markers[cur_syl - 1] + delta * 10);
AnnounceChanges(cur_syl);
} }
bool AudioTimingControllerKaraoke::IsNearbyMarker(int ms, int sensitivity) const { bool AudioTimingControllerKaraoke::IsNearbyMarker(int ms, int sensitivity) const {
@ -331,29 +355,35 @@ std::vector<AudioMarker*> AudioTimingControllerKaraoke::OnLeftClick(int ms, bool
return std::vector<AudioMarker*>(); return std::vector<AudioMarker*>();
} }
void AudioTimingControllerKaraoke::OnMarkerDrag(std::vector<AudioMarker*> const& m, int new_position, int) { int AudioTimingControllerKaraoke::MoveMarker(KaraokeMarker *marker, int new_position) {
assert(m.size() == 1);
KaraokeMarker *marker = static_cast<KaraokeMarker*>(m[0]);
// No rearranging of syllables allowed // No rearranging of syllables allowed
new_position = mid( new_position = mid(
marker == &markers.front() ? start_marker.GetPosition() : (marker - 1)->GetPosition(), marker == &markers.front() ? start_marker.GetPosition() : (marker - 1)->GetPosition(),
new_position, new_position,
marker == &markers.back() ? end_marker.GetPosition() : (marker + 1)->GetPosition()); marker == &markers.back() ? end_marker.GetPosition() : (marker + 1)->GetPosition());
if (new_position == marker->GetPosition())
return -1;
marker->Move(new_position); marker->Move(new_position);
size_t syl = marker - &markers.front() + 1; size_t syl = marker - &markers.front() + 1;
kara->SetStartTime(syl, new_position); kara->SetStartTime(syl, new_position);
labels[syl - 1].range = TimeRange(labels[syl - 1].range.begin(), new_position);
labels[syl].range = TimeRange(new_position, labels[syl].range.end());
return syl;
}
void AudioTimingControllerKaraoke::AnnounceChanges(int syl) {
if (syl < 0) return;
if (syl == cur_syl || syl == cur_syl + 1) { if (syl == cur_syl || syl == cur_syl + 1) {
AnnounceUpdatedPrimaryRange(); AnnounceUpdatedPrimaryRange();
AnnounceUpdatedStyleRanges(); AnnounceUpdatedStyleRanges();
} }
AnnounceMarkerMoved(); AnnounceMarkerMoved();
labels[syl - 1].range = TimeRange(labels[syl - 1].range.begin(), new_position);
labels[syl].range = TimeRange(new_position, labels[syl].range.end());
AnnounceLabelChanged(); AnnounceLabelChanged();
if (auto_commit) if (auto_commit)
@ -362,6 +392,11 @@ void AudioTimingControllerKaraoke::OnMarkerDrag(std::vector<AudioMarker*> const&
commit_id = -1; commit_id = -1;
} }
void AudioTimingControllerKaraoke::OnMarkerDrag(std::vector<AudioMarker*> const& m, int new_position, int) {
assert(m.size() == 1);
AnnounceChanges(MoveMarker(static_cast<KaraokeMarker*>(m[0]), new_position));
}
void AudioTimingControllerKaraoke::GetLabels(TimeRange const& range, std::vector<AudioLabel> &out) const { void AudioTimingControllerKaraoke::GetLabels(TimeRange const& range, std::vector<AudioLabel> &out) const {
for (size_t i = 0; i < labels.size(); ++i) { for (size_t i = 0; i < labels.size(); ++i) {
if (range.overlaps(labels[i].range)) if (range.overlaps(labels[i].range))

View File

@ -279,6 +279,71 @@ struct time_add_lead_out : public Command {
} }
}; };
struct time_length_increase : public Command {
CMD_NAME("time/length/increase")
STR_MENU("Increase length")
STR_DISP("Increase length")
STR_HELP("Increase the length of the current timing unit")
void operator()(agi::Context *c) {
if (c->audioController->GetTimingController())
c->audioController->GetTimingController()->ModifyLength(1, false);
}
};
struct time_length_increase_shift : public Command {
CMD_NAME("time/length/increase/shift")
STR_MENU("Increase length and shift")
STR_DISP("Increase length and shift")
STR_HELP("Increase the length of the current timing unit and shift the following items")
void operator()(agi::Context *c) {
if (c->audioController->GetTimingController())
c->audioController->GetTimingController()->ModifyLength(1, true);
}
};
struct time_length_decrease : public Command {
CMD_NAME("time/length/decrease")
STR_MENU("Decrease length")
STR_DISP("Decrease length")
STR_HELP("Decrease the length of the current timing unit")
void operator()(agi::Context *c) {
if (c->audioController->GetTimingController())
c->audioController->GetTimingController()->ModifyLength(-1, false);
}
};
struct time_length_decrease_shift : public Command {
CMD_NAME("time/length/decrease/shift")
STR_MENU("Decrease length and shift")
STR_DISP("Decrease length and shift")
STR_HELP("Decrease the length of the current timing unit and shift the following items")
void operator()(agi::Context *c) {
if (c->audioController->GetTimingController())
c->audioController->GetTimingController()->ModifyLength(-1, true);
}
};
struct time_start_increase : public Command {
CMD_NAME("time/start/increase")
STR_MENU("Shift start time forward")
STR_DISP("Shift start time forward")
STR_HELP("Shift the start time of the current timing unit forward")
void operator()(agi::Context *c) {
if (c->audioController->GetTimingController())
c->audioController->GetTimingController()->ModifyStart(1);
}
};
struct time_start_decrease : public Command {
CMD_NAME("time/start/decrease")
STR_MENU("Shift start time backward")
STR_DISP("Shift start time backward")
STR_HELP("Shift the start time of the current timing unit backward")
void operator()(agi::Context *c) {
if (c->audioController->GetTimingController())
c->audioController->GetTimingController()->ModifyStart(-1);
}
};
/// Set start of selected subtitles to current video frame. /// Set start of selected subtitles to current video frame.
struct time_snap_start_video : public validate_video_loaded { struct time_snap_start_video : public validate_video_loaded {
@ -327,11 +392,17 @@ namespace cmd {
reg(new time_continuous_end); reg(new time_continuous_end);
reg(new time_continuous_start); reg(new time_continuous_start);
reg(new time_frame_current); reg(new time_frame_current);
reg(new time_length_decrease);
reg(new time_length_decrease_shift);
reg(new time_length_increase);
reg(new time_length_increase_shift);
reg(new time_next); reg(new time_next);
reg(new time_prev); reg(new time_prev);
reg(new time_shift); reg(new time_shift);
reg(new time_snap_end_video); reg(new time_snap_end_video);
reg(new time_snap_scene); reg(new time_snap_scene);
reg(new time_snap_start_video); reg(new time_snap_start_video);
reg(new time_start_decrease);
reg(new time_start_increase);
} }
} }

View File

@ -68,6 +68,42 @@ namespace {
hotkey::inst->SetHotkeyMap(hk_map); hotkey::inst->SetHotkeyMap(hk_map);
} }
const char *renamed_commands[][2] = {
{ "timing shift start backward", "time/start/decrease" },
{ "timing shift start forward", "time/start/increase" },
{ "timing shift end backward", "time/length/decrease" },
{ "timing shift end forward", "time/length/increase" },
{ "timing karaoke decrease length" , "time/length/decrease" },
{ "timing karaoke increase length" , "time/length/increase" },
{ "timing karaoke decrease length and shift following" , "time/length/decrease/shift" },
{ "timing karaoke increase length and shift following" , "time/length/increase/shift" },
{ 0, 0}
};
void rename_commands() {
std::map<std::string, const char *> name_map;
for (size_t i = 0; renamed_commands[i][0]; ++i)
name_map[renamed_commands[i][0]] = renamed_commands[i][1];
bool renamed_any = false;
agi::hotkey::Hotkey::HotkeyMap hk_map = hotkey::inst->GetHotkeyMap();
for (agi::hotkey::Hotkey::HotkeyMap::iterator it = hk_map.begin(); it != hk_map.end(); ) {
std::map<std::string, const char *>::iterator ren = name_map.find(it->first);
if (ren != name_map.end()) {
hk_map.insert(make_pair(std::string(ren->second),
agi::hotkey::Combo(it->second.Context(), ren->second, it->second.Get())));
hk_map.erase(it++);
renamed_any = true;
}
else
++it;
}
if (renamed_any)
hotkey::inst->SetHotkeyMap(hk_map);
}
} }
namespace hotkey { namespace hotkey {
@ -79,9 +115,10 @@ void init() {
GET_DEFAULT_CONFIG(default_hotkey)); GET_DEFAULT_CONFIG(default_hotkey));
int last_version = OPT_GET("Version/Last Version")->GetInt(); int last_version = OPT_GET("Version/Last Version")->GetInt();
if (last_version < 6294) { if (last_version < 6294)
migrate_hotkeys(removed_commands_6294, added_hotkeys_6294); migrate_hotkeys(removed_commands_6294, added_hotkeys_6294);
} if (last_version < 6933)
rename_commands();
} }
void clear() { void clear() {

View File

@ -12,25 +12,25 @@
"key" : "KP_8" "key" : "KP_8"
} }
], ],
"timing shift start backward" : [ "time/start/decrease" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "KP_4" "key" : "KP_4"
} }
], ],
"timing shift start forward" : [ "time/start/increase" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "KP_6" "key" : "KP_6"
} }
], ],
"timing shift end backward" : [ "time/length/decrease" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "KP_7" "key" : "KP_7"
} }
], ],
"timing shift end forward" : [ "time/length/increase" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "KP_9" "key" : "KP_9"
@ -385,25 +385,25 @@
"key" : "V" "key" : "V"
} }
], ],
"timing karaoke decrease length" : [ "time/length/decrease" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "KP_Subtract" "key" : "KP_Subtract"
} }
], ],
"timing karaoke decrease length and shift following" : [ "time/length/decrease/shift" : [
{ {
"modifiers" : [ "Shift" ], "modifiers" : [ "Shift" ],
"key" : "KP_Subtract" "key" : "KP_Subtract"
} }
], ],
"timing karaoke increase length" : [ "time/length/increase" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "KP_Add" "key" : "KP_Add"
} }
], ],
"timing karaoke increase length and shift following" : [ "time/length/increase/shift" : [
{ {
"modifiers" : [ "Shift" ], "modifiers" : [ "Shift" ],
"key" : "KP_Add" "key" : "KP_Add"

View File

@ -12,25 +12,25 @@
"key" : "KP_8" "key" : "KP_8"
} }
], ],
"timing shift start backward" : [ "time/start/decrease" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "KP_4" "key" : "KP_4"
} }
], ],
"timing shift start forward" : [ "time/start/increase" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "KP_6" "key" : "KP_6"
} }
], ],
"timing shift end backward" : [ "time/length/decrease" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "KP_7" "key" : "KP_7"
} }
], ],
"timing shift end forward" : [ "time/length/increase" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "KP_9" "key" : "KP_9"
@ -395,25 +395,25 @@
"key" : "V" "key" : "V"
} }
], ],
"timing karaoke decrease length" : [ "time/length/decrease" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "KP_Subtract" "key" : "KP_Subtract"
} }
], ],
"timing karaoke decrease length and shift following" : [ "time/length/decrease/shift" : [
{ {
"modifiers" : [ "Shift" ], "modifiers" : [ "Shift" ],
"key" : "KP_Subtract" "key" : "KP_Subtract"
} }
], ],
"timing karaoke increase length" : [ "time/length/increase" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "KP_Add" "key" : "KP_Add"
} }
], ],
"timing karaoke increase length and shift following" : [ "time/length/increase/shift" : [
{ {
"modifiers" : [ "Shift" ], "modifiers" : [ "Shift" ],
"key" : "KP_Add" "key" : "KP_Add"