[gnome-subtitles] Initial (skeleton) support for splitting and merging subtitles.



commit 16a9befcc7099740c22cdeaeea2cd799993e8cc7
Author: Pedro Castro <mail pedrocastro org>
Date:   Thu Jun 9 19:46:45 2011 +0100

    Initial (skeleton) support for splitting and merging subtitles.

 gnome-subtitles.mdp                                |    2 +
 src/Glade/MainWindow.glade                         |   41 +++++++++---
 .../Core/Command/DeleteSubtitlesCommand.cs         |    2 +-
 .../Core/Command/SplitSubtitlesCommand.cs          |   65 +++++++++++++++++++
 src/GnomeSubtitles/Core/EventHandlers.cs           |   10 +++
 src/SubLib/Core/Timing/SplitOperator.cs            |   67 ++++++++++++++++++++
 6 files changed, 177 insertions(+), 10 deletions(-)
---
diff --git a/gnome-subtitles.mdp b/gnome-subtitles.mdp
index 0ad0b60..46b2b91 100644
--- a/gnome-subtitles.mdp
+++ b/gnome-subtitles.mdp
@@ -255,6 +255,8 @@
     <File subtype="Code" buildaction="Compile" name="src/SubLib/Exceptions/TranslatorException.cs" />
     <File subtype="Code" buildaction="Compile" name="src/SubLib/Core/Translator.cs" />
     <File subtype="Code" buildaction="Compile" name="src/GnomeSubtitles/Core/GlobalAccelerators.cs" />
+    <File subtype="Code" buildaction="Compile" name="src/GnomeSubtitles/Core/Command/SplitSubtitlesCommand.cs" />
+    <File subtype="Code" buildaction="Compile" name="src/SubLib/Core/Timing/SplitOperator.cs" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
diff --git a/src/Glade/MainWindow.glade b/src/Glade/MainWindow.glade
index c06544b..532f723 100644
--- a/src/Glade/MainWindow.glade
+++ b/src/Glade/MainWindow.glade
@@ -247,8 +247,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                         <signal name="activate" handler="OnEditRedo"/>
-                        <accelerator key="Z" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                         <accelerator key="Y" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="Z" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -338,6 +338,29 @@
                       </widget>
                     </child>
                     <child>
+                      <widget class="GtkMenuItem" id="editSplit">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">_Split</property>
+                        <property name="use_underline">True</property>
+                        <signal name="activate" handler="OnEditSplit"/>
+                        <accelerator key="m" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkMenuItem" id="editMerge">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">_Merge</property>
+                        <property name="use_underline">True</property>
+                        <signal name="activate" handler="OnEditMerge"/>
+                        <accelerator key="m" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                      </widget>
+                    </child>
+                    <child>
+                      <widget class="GtkSeparatorMenuItem" id="editSeparator4">
+                        <property name="visible">True</property>
+                      </widget>
+                    </child>
+                    <child>
                       <widget class="GtkMenuItem" id="editInsertSubtitle">
                         <property name="visible">True</property>
                         <property name="label" translatable="yes">_Insert Subtitle</property>
@@ -420,7 +443,7 @@
                       </widget>
                     </child>
                     <child>
-                      <widget class="GtkSeparatorMenuItem" id="editSeparator4">
+                      <widget class="GtkSeparatorMenuItem" id="editSeparator5">
                         <property name="visible">True</property>
                       </widget>
                     </child>
@@ -561,8 +584,8 @@
                         <property name="label" translatable="yes">Find Ne_xt</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnSearchFindNext"/>
-                        <accelerator key="g" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="F3" signal="activate"/>
+                        <accelerator key="g" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -572,8 +595,8 @@
                         <property name="label" translatable="yes">Find Pre_vious</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnSearchFindPrevious"/>
-                        <accelerator key="g" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                         <accelerator key="F3" signal="activate" modifiers="GDK_SHIFT_MASK"/>
+                        <accelerator key="g" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -817,8 +840,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">False</property>
                         <signal name="activate" handler="OnVideoPlayPause"/>
-                        <accelerator key="p" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="F5" signal="activate"/>
+                        <accelerator key="p" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="videoPlayPauseImage">
                             <property name="visible">True</property>
@@ -845,8 +868,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">False</property>
                         <signal name="activate" handler="OnVideoRewind"/>
-                        <accelerator key="k" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="F6" signal="activate"/>
+                        <accelerator key="k" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="videoRewindImage">
                             <property name="visible">True</property>
@@ -864,8 +887,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">False</property>
                         <signal name="activate" handler="OnVideoForward"/>
-                        <accelerator key="l" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="F7" signal="activate"/>
+                        <accelerator key="l" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="videoForwardImage">
                             <property name="visible">True</property>
@@ -905,8 +928,8 @@
                         <property name="label" translatable="yes">Seek _to Selection</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoSeekToSelection"/>
-                        <accelerator key="r" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                         <accelerator key="F4" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
+                        <accelerator key="r" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -916,8 +939,8 @@
                         <property name="label" translatable="yes">Select Nearest Subtitle</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoSelectNearestSubtitle"/>
-                        <accelerator key="F4" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="r" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F4" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
diff --git a/src/GnomeSubtitles/Core/Command/DeleteSubtitlesCommand.cs b/src/GnomeSubtitles/Core/Command/DeleteSubtitlesCommand.cs
index 3ac51db..a6b2d23 100644
--- a/src/GnomeSubtitles/Core/Command/DeleteSubtitlesCommand.cs
+++ b/src/GnomeSubtitles/Core/Command/DeleteSubtitlesCommand.cs
@@ -29,7 +29,7 @@ public class DeleteSubtitlesCommand : MultipleSelectionCommand {
 	private Subtitle[] subtitles = null;
 	
 	public DeleteSubtitlesCommand () : base(description, false, SelectionIntended.Simple, null) {
-		StoreSubtitles();
+		StoreSubtitles(); //FIXME move to Execute
 	}
 
 	
diff --git a/src/GnomeSubtitles/Core/Command/SplitSubtitlesCommand.cs b/src/GnomeSubtitles/Core/Command/SplitSubtitlesCommand.cs
new file mode 100644
index 0000000..a1903a7
--- /dev/null
+++ b/src/GnomeSubtitles/Core/Command/SplitSubtitlesCommand.cs
@@ -0,0 +1,65 @@
+/*
+ * This file is part of Gnome Subtitles.
+ * Copyright (C) 2011 Pedro Castro
+ *
+ * Gnome Subtitles is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Gnome Subtitles is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+using GnomeSubtitles.Ui.View;
+using Gtk;
+using Mono.Unix;
+using SubLib.Core.Domain;
+
+namespace GnomeSubtitles.Core.Command {
+
+public class SplitSubtitlesCommand : MultipleSelectionCommand {
+	private static string description = Catalog.GetString("Splitting subtitles");
+	//private Subtitle[] originalSubtitles = null;
+	
+	public SplitSubtitlesCommand () : base(description, false, SelectionIntended.Simple, null) {
+		
+	}
+
+	public override bool Execute () {
+	//	this.originalSubtitles = GetSelectedSubtitles();
+		
+		
+		return true;
+	}
+	
+	public override void Undo () {
+		
+	}
+
+	public override void Redo () {
+		Undo();
+	}
+	
+	
+	/* Private members */
+
+	private Subtitle[] GetSelectedSubtitles () {
+		int count = Paths.Length;
+		Subtitle[] subtitles = new Subtitle[count];
+		for (int index = 0 ; index < count ; index++) {
+			TreePath path = Paths[index];
+			subtitles[index] = Base.Document.Subtitles[path];
+		}
+		return subtitles;
+	}
+
+}
+
+}
diff --git a/src/GnomeSubtitles/Core/EventHandlers.cs b/src/GnomeSubtitles/Core/EventHandlers.cs
index 2a50226..a2e337e 100644
--- a/src/GnomeSubtitles/Core/EventHandlers.cs
+++ b/src/GnomeSubtitles/Core/EventHandlers.cs
@@ -135,6 +135,16 @@ public class EventHandlers {
 		Base.CommandManager.Execute(new ChangeUnderlineStyleCommand(newUnderlineValue));
 	}
 	
+	public void OnEditSplit (object o, EventArgs args) {
+		Console.WriteLine ("OnEditSplit");
+		
+		
+	}
+	
+	public void OnEditMerge (object o, EventArgs args) {
+		Console.WriteLine ("OnEditMerge");
+	}
+	
 	public void OnEditInsertSubtitleBefore (object o, EventArgs args) {
 		if ((Base.Document.Subtitles.Count == 0) || (Base.Ui.View.Selection.Count == 0))
 			Base.CommandManager.Execute(new InsertFirstSubtitleCommand());
diff --git a/src/SubLib/Core/Timing/SplitOperator.cs b/src/SubLib/Core/Timing/SplitOperator.cs
new file mode 100644
index 0000000..e155399
--- /dev/null
+++ b/src/SubLib/Core/Timing/SplitOperator.cs
@@ -0,0 +1,67 @@
+/*
+ * This file is part of SubLib.
+ * Copyright (C) 2011 Pedro Castro
+ *
+ * SubLib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * SubLib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+using SubLib.Core.Domain;
+using System;
+
+namespace SubLib.Core.Timing {
+
+/// <summary>Performs split operations.</summary>
+public class SplitOperator {
+	private Subtitles subtitles = null;
+	
+	public SplitOperator (Subtitles subtitles) {
+		this.subtitles = subtitles;
+	}
+
+	/* Public members */
+	
+	
+	/// <summary>Changes the current frame rate of the subtitles.</summary>
+	/// <param name="frameRate">The new frame rate to be used.</param>
+	/// <remarks>This changes the frame rate currently being used with the subtitles, which is sometimes
+	/// refered to as the output frame rate.</remarks>
+	public void ChangeCurrent (float frameRate) {
+		float currentFrameRate = subtitles.Properties.CurrentFrameRate;
+		if (currentFrameRate != frameRate) {
+			subtitles.Properties.SetCurrentFrameRate(frameRate);
+			subtitles.UpdateFramesFromTimes(frameRate);
+		}
+	}
+	
+	/// <summary>Updates the subtitles' frames using the specified frame rate as the one they had when they were opened.</summary>
+	/// <param name="frameRate">The original subtitles' frame rate.</param>
+	/// <remarks>This results on having the subtitles with the frames they would have if they had been opened with this frame rate.
+	/// The original frame rate is sometimes refered to as the input frame rate.</remarks>
+	public void ChangeOriginal (float frameRate) {
+		SubtitleProperties properties = subtitles.Properties;
+		float originalFrameRate = properties.OriginalFrameRate;
+		float currentFrameRate = properties.CurrentFrameRate;
+
+		if (originalFrameRate != frameRate) {
+			float conversionFrameRate = currentFrameRate * originalFrameRate / frameRate;
+			subtitles.UpdateFramesFromTimes(conversionFrameRate);
+			subtitles.UpdateTimesFromFrames(currentFrameRate);
+			properties.SetOriginalFrameRate(frameRate);
+		}
+	}
+
+}
+
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]