[longomatch] Rework plays selection logic
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Rework plays selection logic
- Date: Wed, 24 Sep 2014 20:16:42 +0000 (UTC)
commit 687241d4beb41dfca2dcdc3f0f28490e1cfa347a
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Wed Aug 27 14:15:12 2014 +0200
Rework plays selection logic
Split event in LoadPlay and PlayLoaded and move all the play
loading logic to the PlaylistManager class
LongoMatch.Core/Common/EventsBroker.cs | 15 +++-
LongoMatch.Core/Handlers/Handlers.cs | 6 +-
LongoMatch.Drawing/Widgets/PlaysTimeline.cs | 2 +-
LongoMatch.Drawing/Widgets/PositionTagger.cs | 2 +-
LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs | 2 +-
LongoMatch.GUI/Gui/Component/CodingWidget.cs | 6 +-
LongoMatch.GUI/Gui/Component/NotesWidget.cs | 6 +-
.../Gui/Component/PlaysListTreeWidget.cs | 11 +++
.../Gui/Component/PlaysPositionViewer.cs | 17 ++---
LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs | 2 +-
LongoMatch.Services/Services/EventsManager.cs | 96 ++++++--------------
LongoMatch.Services/Services/PlaylistManager.cs | 73 ++++++++++++---
12 files changed, 130 insertions(+), 108 deletions(-)
---
diff --git a/LongoMatch.Core/Common/EventsBroker.cs b/LongoMatch.Core/Common/EventsBroker.cs
index 363bff8..cb94533 100644
--- a/LongoMatch.Core/Common/EventsBroker.cs
+++ b/LongoMatch.Core/Common/EventsBroker.cs
@@ -30,7 +30,8 @@ namespace LongoMatch.Common
public event NewTagHandler NewTagEvent;
public event PlaysDeletedHandler PlaysDeleted;
- public event PlaySelectedHandler PlaySelected;
+ public event LoadPlayHandler LoadPlayEvent;
+ public event PlayLoadedHandler PlayLoadedEvent;
public event PlayCategoryChangedHandler PlayCategoryChanged;
public event TimeNodeChangedHandler TimeNodeChanged;
public event SnapshotSeriesHandler SnapshotSeries;
@@ -96,10 +97,16 @@ namespace LongoMatch.Common
PlaysDeleted(plays);
}
- public void EmitPlaySelected(Play play)
+ public void EmitLoadPlay (Play play)
{
- if (PlaySelected != null)
- PlaySelected(play);
+ if (LoadPlayEvent != null)
+ LoadPlayEvent (play);
+ }
+
+ public void EmitPlayLoaded (Play play)
+ {
+ if (PlayLoadedEvent != null)
+ PlayLoadedEvent (play);
}
public void EmitSnapshotSeries(Play play)
diff --git a/LongoMatch.Core/Handlers/Handlers.cs b/LongoMatch.Core/Handlers/Handlers.cs
index b90360c..d5d1185 100644
--- a/LongoMatch.Core/Handlers/Handlers.cs
+++ b/LongoMatch.Core/Handlers/Handlers.cs
@@ -32,8 +32,10 @@ namespace LongoMatch.Handlers
{
/*Tagging Events*/
- /* A Play was selected */
- public delegate void PlaySelectedHandler(Play play);
+ /* A Play needs to be loaded */
+ public delegate void LoadPlayHandler(Play play);
+ /* A Play was loaded */
+ public delegate void PlayLoadedHandler(Play play);
/* A new play needs to be create for a specific category at the current play time */
public delegate void NewTagHandler (TaggerButton tagger, List<Player> plays, List<Tag> tags, Time
start, Time stop);
//A play was edited
diff --git a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
index f62b2b8..ff96824 100644
--- a/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
+++ b/LongoMatch.Drawing/Widgets/PlaysTimeline.cs
@@ -199,7 +199,7 @@ namespace LongoMatch.Drawing.Widgets
{
if (selections.Count > 0) {
PlayObject po = selections.Last ().Drawable as PlayObject;
- Config.EventsBroker.EmitPlaySelected (po.Play);
+ Config.EventsBroker.EmitLoadPlay (po.Play);
}
}
diff --git a/LongoMatch.Drawing/Widgets/PositionTagger.cs b/LongoMatch.Drawing/Widgets/PositionTagger.cs
index 72cfcb8..31e003d 100644
--- a/LongoMatch.Drawing/Widgets/PositionTagger.cs
+++ b/LongoMatch.Drawing/Widgets/PositionTagger.cs
@@ -118,7 +118,7 @@ namespace LongoMatch.Drawing.Widgets
Play p = (selections.Last ().Drawable as PositionObject).Play;
playSelected = p;
if (EmitSignals) {
- Config.EventsBroker.EmitPlaySelected (p);
+ Config.EventsBroker.EmitLoadPlay (p);
}
}
}
diff --git a/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs b/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
index 17b0d94..4e7f45f 100644
--- a/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
+++ b/LongoMatch.GUI.Multimedia/Gui/PlayerBin.cs
@@ -300,7 +300,7 @@ namespace LongoMatch.Gui
//timescale.Sensitive = true;
loadedPlay = null;
ImageLoaded = false;
- Config.EventsBroker.EmitPlaySelected (null);
+ Config.EventsBroker.EmitLoadPlay (null);
}
public void SetSensitive ()
diff --git a/LongoMatch.GUI/Gui/Component/CodingWidget.cs b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
index 956ea63..7039012 100644
--- a/LongoMatch.GUI/Gui/Component/CodingWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/CodingWidget.cs
@@ -68,7 +68,7 @@ namespace LongoMatch.Gui.Component
playspositionviewer1.HeightRequest = 200;
Config.EventsBroker.Tick += HandleTick;
- Config.EventsBroker.PlaySelected += HandlePlaySelected;
+ Config.EventsBroker.PlayLoadedEvent += HandlePlayLoaded;
LongoMatch.Gui.Helpers.Misc.DisableFocus (this);
buttonswidget.Mode = TagMode.Free;
@@ -82,7 +82,7 @@ namespace LongoMatch.Gui.Component
w.Destroy ();
}
Config.EventsBroker.Tick -= HandleTick;
- Config.EventsBroker.PlaySelected -= HandlePlaySelected;
+ Config.EventsBroker.PlayLoadedEvent -= HandlePlayLoaded;
buttonswidget.Destroy ();
timeline.Destroy ();
playspositionviewer1.Destroy ();
@@ -209,7 +209,7 @@ namespace LongoMatch.Gui.Component
currentPage = (int)args.PageNum;
}
- void HandlePlaySelected (Play play)
+ void HandlePlayLoaded (Play play)
{
loadedPlay = play;
timeline.SelectedTimeNode = play;
diff --git a/LongoMatch.GUI/Gui/Component/NotesWidget.cs b/LongoMatch.GUI/Gui/Component/NotesWidget.cs
index 018c78d..a9e7fad 100644
--- a/LongoMatch.GUI/Gui/Component/NotesWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/NotesWidget.cs
@@ -38,12 +38,12 @@ namespace LongoMatch.Gui.Component
this.Build();
this.buf = textview1.Buffer;
buf.Changed += new EventHandler(OnEdition);
- Config.EventsBroker.PlaySelected += HandlePlaySelected;
+ Config.EventsBroker.PlayLoadedEvent += HandlePlayLoaded;
}
protected override void OnDestroyed ()
{
- Config.EventsBroker.PlaySelected -= HandlePlaySelected;
+ Config.EventsBroker.PlayLoadedEvent -= HandlePlayLoaded;
base.OnDestroyed ();
}
@@ -78,7 +78,7 @@ namespace LongoMatch.Gui.Component
}
}
- void HandlePlaySelected (Play play)
+ void HandlePlayLoaded (Play play)
{
Play = play;
}
diff --git a/LongoMatch.GUI/Gui/Component/PlaysListTreeWidget.cs
b/LongoMatch.GUI/Gui/Component/PlaysListTreeWidget.cs
index 6e5f892..b9b845c 100644
--- a/LongoMatch.GUI/Gui/Component/PlaysListTreeWidget.cs
+++ b/LongoMatch.GUI/Gui/Component/PlaysListTreeWidget.cs
@@ -46,8 +46,15 @@ namespace LongoMatch.Gui.Component
this.Build();
treeview.EditProperties += OnEditProperties;
treeview.NewRenderingJob += OnNewRenderingJob;
+ Config.EventsBroker.PlayLoadedEvent += HandlePlayLoaded;
}
+ protected override void OnDestroyed ()
+ {
+ Config.EventsBroker.PlayLoadedEvent -= HandlePlayLoaded;
+ base.OnDestroyed ();
+ }
+
public PlaysFilter Filter {
set{
treeview.Filter = value;
@@ -195,5 +202,9 @@ namespace LongoMatch.Gui.Component
Config.EventsBroker.EmitRenderPlaylist (playlist);
}
+
+ void HandlePlayLoaded (Play play) {
+ treeview.QueueDraw ();
+ }
}
}
diff --git a/LongoMatch.GUI/Gui/Component/PlaysPositionViewer.cs
b/LongoMatch.GUI/Gui/Component/PlaysPositionViewer.cs
index c2f4beb..2966574 100644
--- a/LongoMatch.GUI/Gui/Component/PlaysPositionViewer.cs
+++ b/LongoMatch.GUI/Gui/Component/PlaysPositionViewer.cs
@@ -39,18 +39,10 @@ namespace LongoMatch.Gui.Component
field.Tagger.ShowMenuEvent += HandleShowMenuEvent;
hfield.Tagger.ShowMenuEvent += HandleShowMenuEvent;
goal.Tagger.ShowMenuEvent += HandleShowMenuEvent;
- Config.EventsBroker.PlaySelected += HandlePlaySelected;
+ Config.EventsBroker.PlayLoadedEvent += HandlePlayLoaded;
menu = new PlaysMenu ();
}
- protected override bool OnDestroyEvent (Gdk.Event evnt)
- {
- return base.OnDestroyEvent (evnt);
- field.Destroy ();
- hfield.Destroy ();
- goal.Destroy ();
- }
-
public void LoadProject (Project project) {
this.project = project;
if (project != null) {
@@ -77,7 +69,7 @@ namespace LongoMatch.Gui.Component
QueueDraw ();
}
- void HandlePlaySelected (Play play)
+ void HandlePlayLoaded (Play play)
{
if (play != null) {
field.Tagger.SelectPlay (play);
@@ -100,8 +92,11 @@ namespace LongoMatch.Gui.Component
protected override void OnDestroyed ()
{
+ field.Destroy ();
+ hfield.Destroy ();
+ goal.Destroy ();
+ Config.EventsBroker.PlayLoadedEvent -= HandlePlayLoaded;
base.OnDestroyed ();
- Config.EventsBroker.PlaySelected -= HandlePlaySelected;
}
}
}
diff --git a/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs b/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
index b10599d..ea47de3 100644
--- a/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
+++ b/LongoMatch.GUI/Gui/TreeView/ListTreeViewBase.cs
@@ -147,7 +147,7 @@ namespace LongoMatch.Gui.Component
if(!(item is Play))
return;
- Config.EventsBroker.EmitPlaySelected (item as Play);
+ Config.EventsBroker.EmitLoadPlay (item as Play);
}
protected virtual void OnEdit (object obj, EventArgs args) {
diff --git a/LongoMatch.Services/Services/EventsManager.cs b/LongoMatch.Services/Services/EventsManager.cs
index 406cc66..f4f1bf1 100644
--- a/LongoMatch.Services/Services/EventsManager.cs
+++ b/LongoMatch.Services/Services/EventsManager.cs
@@ -33,7 +33,7 @@ namespace LongoMatch.Services
public class EventsManager
{
/* Current play loaded. null if no play is loaded */
- TimeNode loadedPlay = null;
+ Play loadedPlay = null;
/* current project in use */
Project openedProject;
ProjectType projectType;
@@ -79,25 +79,26 @@ namespace LongoMatch.Services
private void ConnectSignals ()
{
Config.EventsBroker.NewTagEvent += OnNewTag;
- Config.EventsBroker.TimeNodeChanged += OnTimeNodeChanged;
Config.EventsBroker.PlaysDeleted += OnPlaysDeleted;
- Config.EventsBroker.PlaySelected += OnPlaySelected;
Config.EventsBroker.PlayCategoryChanged += OnPlayCategoryChanged;
Config.EventsBroker.DuplicatePlays += OnDuplicatePlays;
- //Config.EventsBroker.PlayListNodeSelectedEvent += (tn) => {
- // loadedPlay = tn;};
Config.EventsBroker.SnapshotSeries += OnSnapshotSeries;
+ Config.EventsBroker.PlayLoadedEvent += HandlePlayLoaded;
Config.EventsBroker.ShowProjectStatsEvent += HandleShowProjectStatsEvent;
Config.EventsBroker.TagSubcategoriesChangedEvent +=
HandleTagSubcategoriesChangedEvent;
Config.EventsBroker.OpenedProjectChanged += HandleOpenedProjectChanged;
- Config.EventsBroker.DrawFrame += OnDrawFrame;
- Config.EventsBroker.PlaybackRateChanged += HandlePlaybackRateChanged;
+ Config.EventsBroker.DrawFrame += HandleDrawFrame;
Config.EventsBroker.Detach += HandleDetach;
}
+ void HandlePlayLoaded (Play play)
+ {
+ loadedPlay = play;
+ }
+
void HandleDetach ()
{
analysisWindow.DetachPlayer ();
@@ -113,6 +114,28 @@ namespace LongoMatch.Services
guiToolkit.ShowProjectStats (project);
}
+ void HandleDrawFrame (Play play, int drawingIndex)
+ {
+ Image pixbuf;
+ FrameDrawing drawing = null;
+
+ player.Pause ();
+ if (play == null) {
+ play = loadedPlay as Play;
+ }
+ if (play != null) {
+ if (drawingIndex == -1) {
+ drawing = new FrameDrawing ();
+ drawing.Render = player.CurrentTime;
+ } else {
+ drawing = play.Drawings [drawingIndex];
+ }
+ player.Seek (drawing.Render, true);
+ }
+ pixbuf = player.CurrentFrame;
+ guiToolkit.DrawingTool (pixbuf, play, drawing);
+ }
+
void RenderPlay (Project project, Play play, MediaFile file)
{
Playlist playlist;
@@ -146,16 +169,6 @@ namespace LongoMatch.Services
}
- void LoadPlay (Play play, Time seekTime, bool playing)
- {
- player.LoadPlay (openedProject.Description.File, play,
- seekTime, playing);
- loadedPlay = play;
- if (playing) {
- player.Play ();
- }
- }
-
private Image CaptureFrame (Time tagtime)
{
Image frame = null;
@@ -228,33 +241,6 @@ namespace LongoMatch.Services
AddNewPlay (tagger as AnalysisCategory, start, stop, players, tags, frame);
}
- void HandlePlaybackRateChanged (float rate)
- {
- if (loadedPlay != null) {
- loadedPlay.Rate = rate;
- }
- }
-
- void OnPlaySelected (Play play)
- {
- if (play != null) {
- LoadPlay (play, play.Start, true);
- } else {
- loadedPlay = null;
- }
- }
-
- protected virtual void OnTimeNodeChanged (TimeNode tNode, object val)
- {
- /* FIXME: Tricky, create a new handler for categories */
- if (tNode is Play && val is Time) {
- LoadPlay (tNode as Play, val as Time, false);
- } else if (tNode is Category) {
- analysisWindow.UpdateCategories ();
- }
- filter.Update ();
- }
-
protected virtual void OnPlaysDeleted (List<Play> plays)
{
Log.Debug (plays.Count + " plays deleted");
@@ -287,28 +273,6 @@ namespace LongoMatch.Services
guiToolkit.ExportFrameSeries (openedProject, play, Config.SnapshotsDir);
}
- protected virtual void OnDrawFrame (Play play, int drawingIndex)
- {
- Image pixbuf;
- FrameDrawing drawing = null;
-
- player.Pause ();
- if (play == null) {
- play = loadedPlay as Play;
- }
- if (play != null) {
- if (drawingIndex == -1) {
- drawing = new FrameDrawing ();
- drawing.Render = player.CurrentTime;
- } else {
- drawing = play.Drawings [drawingIndex];
- }
- player.Seek (drawing.Render, true);
- }
- pixbuf = player.CurrentFrame;
- guiToolkit.DrawingTool (pixbuf, play, drawing);
- }
-
protected virtual void OnPlayCategoryChanged (Play play, Category cat)
{
List<Play> plays = new List<Play> ();
diff --git a/LongoMatch.Services/Services/PlaylistManager.cs b/LongoMatch.Services/Services/PlaylistManager.cs
index 78161ce..375cb9c 100644
--- a/LongoMatch.Services/Services/PlaylistManager.cs
+++ b/LongoMatch.Services/Services/PlaylistManager.cs
@@ -36,6 +36,7 @@ namespace LongoMatch.Services
IPlaylistElement loadedElement;
Playlist loadedPlaylist;
Play loadedPlay;
+ PlaysFilter filter;
public PlaylistManager (IGUIToolkit guiToolkit, IRenderingJobsManager videoRenderer)
{
@@ -44,15 +45,6 @@ namespace LongoMatch.Services
BindEvents ();
}
- void HandleOpenedProjectChanged (Project project, ProjectType projectType,
- PlaysFilter filter, IAnalysisWindow analysisWindow)
- {
- openedProject = project;
- if (project != null) {
- player = analysisWindow.Player;
- }
- }
-
void BindEvents ()
{
Config.EventsBroker.NewPlaylistEvent += HandleNewPlaylist;
@@ -61,24 +53,63 @@ namespace LongoMatch.Services
Config.EventsBroker.OpenedProjectChanged += HandleOpenedProjectChanged;
Config.EventsBroker.PreviousPlaylistElementEvent += HandlePrev;
Config.EventsBroker.NextPlaylistElementEvent += HandleNext;
- Config.EventsBroker.PlaySelected += HandlePlaySelected;
+ Config.EventsBroker.LoadPlayEvent += HandleLoadPlayEvent;
Config.EventsBroker.PlaylistElementSelectedEvent += HandlePlaylistElementSelected;
+ Config.EventsBroker.PlaybackRateChanged += HandlePlaybackRateChanged;
+ Config.EventsBroker.TimeNodeChanged += HandlePlayChanged;
}
+ void LoadPlay (Play play, Time seekTime, bool playing)
+ {
+ play.Selected = true;
+ player.LoadPlay (openedProject.Description.File, play,
+ seekTime, playing);
+ loadedPlay = play;
+ if (playing) {
+ player.Play ();
+ }
+ }
+
void Switch (Play play, Playlist playlist, IPlaylistElement element)
{
if (loadedElement != null) {
loadedElement.Selected = false;
}
- if (element != null) {
- element.Selected = true;
+ if (loadedPlay != null) {
+ loadedPlay.Selected = false;
}
-
+
loadedPlay = play;
loadedPlaylist = playlist;
loadedElement = element;
+
+ if (element != null) {
+ element.Selected = true;
+ }
+ if (play != null) {
+ play.Selected = true;
+ }
+ }
+
+ void HandlePlayChanged (TimeNode tNode, object val)
+ {
+ /* FIXME: Tricky, create a new handler for categories */
+ if (tNode is Play && val is Time) {
+ LoadPlay (tNode as Play, val as Time, false);
+ }
+ filter.Update ();
}
+ void HandleOpenedProjectChanged (Project project, ProjectType projectType,
+ PlaysFilter filter, IAnalysisWindow analysisWindow)
+ {
+ openedProject = project;
+ if (project != null) {
+ player = analysisWindow.Player;
+ this.filter = filter;
+ }
+ }
+
void HandlePlaylistElementSelected (Playlist playlist, IPlaylistElement element)
{
Switch (null, playlist, element);
@@ -86,12 +117,15 @@ namespace LongoMatch.Services
playlist.SetActive (element);
}
player.LoadPlayListPlay (playlist, element);
-
}
- void HandlePlaySelected (Play play)
+ void HandleLoadPlayEvent (Play play)
{
Switch (play, null, null);
+ if (play != null) {
+ LoadPlay (play, play.Start, true);
+ }
+ Config.EventsBroker.EmitPlayLoaded (play);
}
void HandleNext (Playlist playlist)
@@ -124,6 +158,15 @@ namespace LongoMatch.Services
}
}
}
+
+ void HandlePlaybackRateChanged (float rate)
+ {
+ if (loadedElement != null && loadedElement is PlaylistPlayElement) {
+ (loadedElement as PlaylistPlayElement).Rate = rate;
+ } else if (loadedPlay != null) {
+ loadedPlay.Rate = rate;
+ }
+ }
void HandleAddPlaylistElement (Playlist playlist, List<IPlaylistElement> element)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]