std::vector<AssDialogue*> DialogTimingProcessor::SortDialogues() {
	std::set<std::string> styles;
	for (size_t i = 0; i < StyleList->GetCount(); ++i) {
		if (StyleList->IsChecked(i))
			styles.insert(from_wx(StyleList->GetString(i)));
	}

	std::vector<AssDialogue*> sorted;

	if (onlySelection->IsChecked()) {
		SubtitleSelection sel = c->selectionController->GetSelectedSet();
		copy_if(sel.begin(), sel.end(), back_inserter(sorted),
			[&](AssDialogue *d) { return !d->Comment && styles.count(d->Style); });
	}
	else {
		transform(c->ass->Line.begin(), c->ass->Line.end(), back_inserter(sorted), cast<AssDialogue*>());
		sorted.erase(boost::remove_if(sorted, bind(bad_line, &styles, _1)), sorted.end());
	}

	// Check if rows are valid
	for (auto diag : sorted) {
		if (diag->Start > diag->End) {
			int line = count_if(c->ass->Line.begin(), c->ass->Line.iterator_to(*diag), cast<const AssDialogue*>());
			wxMessageBox(
				wxString::Format(_("One of the lines in the file (%i) has negative duration. Aborting."), line),
				_("Invalid script"),
				wxOK | wxICON_ERROR | wxCENTER);
			sorted.clear();
			break;
		}
	}

	boost::sort(sorted, AssFile::CompStart);
	return sorted;
}
示例#2
0
void AssKaraoke::SplitLines(std::set<AssDialogue*> const& lines, agi::Context *c) {
	if (lines.empty()) return;

	AssKaraoke kara;

	SubtitleSelection sel = c->selectionController->GetSelectedSet();

	bool did_split = false;
	for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) {
		AssDialogue *diag = dynamic_cast<AssDialogue*>(&*it);
		if (!diag || !lines.count(diag)) continue;

		kara.SetLine(diag);

		// If there aren't at least two tags there's nothing to split
		if (kara.size() < 2) continue;

		bool in_sel = sel.count(diag) > 0;

		for (auto const& syl : kara) {
			AssDialogue *new_line = new AssDialogue(*diag);

			new_line->Start = syl.start_time;
			new_line->End = syl.start_time + syl.duration;
			new_line->Text = syl.GetText(false);

			c->ass->Line.insert(it, *new_line);

			if (in_sel)
				sel.insert(new_line);
		}

		--it; // Move `it` to the last of the new lines
		sel.erase(diag);
		delete diag;

		did_split = true;
	}

	if (!did_split) return;

	c->ass->Commit(_("splitting"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL);

	AssDialogue *new_active = c->selectionController->GetActiveLine();
	if (!sel.count(c->selectionController->GetActiveLine()))
		new_active = *sel.begin();
	c->selectionController->SetSelectionAndActive(sel, new_active);
}
示例#3
0
void VisualTool<FeatureType>::RemoveSelection(FeatureType *feat) {
	if (!sel_features.erase(feat) || !feat->line) return;
	for (auto sel : sel_features)
		if (sel->line == feat->line) return;

	SubtitleSelection sel = c->selectionController->GetSelectedSet();

	// Don't deselect the only selected line
	if (sel.size() <= 1) return;

	sel.erase(feat->line);

	// Set the active line to an arbitrary selected line if we just
	// deselected the active line
	AssDialogue *new_active = c->selectionController->GetActiveLine();
	if (feat->line == new_active)
		new_active = *sel.begin();

	c->selectionController->SetSelectionAndActive(sel, new_active);
}