MythTV  master
mythplayereditorui.cpp
Go to the documentation of this file.
1 // MythTV
2 #include "mythlogging.h"
3 #include "mythuiactions.h"
4 #include "tv_actions.h"
5 #include "tv_play.h"
6 #include "mythplayereditorui.h"
7 
8 #define LOC QString("Editor: ")
9 
11  : MythPlayerVisualiserUI(MainWindow, Tv, Context, Flags)
12 {
13  qRegisterMetaType<MythEditorState>();
14 
15  // Connect incoming TV signals
16  connect(Tv, &TV::EnableEdit, this, &MythPlayerEditorUI::EnableEdit);
19 
20  // New state
22 }
23 
25 {
26  LOG(VB_GENERAL, LOG_INFO, LOC + "Initialising editor");
28 }
29 
30 void MythPlayerEditorUI::RefreshEditorState(bool CheckSaved /*=false*/)
31 {
32  auto frame = GetFramesPlayed();
33  emit EditorStateChanged({
34  frame,
35  m_deleteMap.GetNearestMark(frame, false),
36  m_deleteMap.GetNearestMark(frame, true),
38  m_deleteMap.IsInDelete(frame),
45  CheckSaved ? m_deleteMap.IsSaved() : false });
46 }
47 
49 {
50  m_deleteMap.SetEditing(false);
51 
53  {
54  LOG(VB_GENERAL, LOG_ERR, LOC + "Cannot edit - no full position map");
55  SetOSDStatus(tr("No Seektable"), kOSDTimeout_Med);
56  return;
57  }
58 
60  return;
61 
62  QMutexLocker locker(&m_osdLock);
64 
66  m_tcWrap[TC_AUDIO] = 0ms;
67 
70  m_deleteMap.SetEditing(true);
71  m_osd.DialogQuit();
72  ResetCaptions();
73  m_osd.HideAll();
74 
75  bool loadedAutoSave = m_deleteMap.LoadAutoSaveMap();
76  if (loadedAutoSave)
77  UpdateOSDMessage(tr("Using previously auto-saved cuts"), kOSDTimeout_Short);
78 
82  m_playerCtx->LockPlayingInfo(__FILE__, __LINE__);
85  m_playerCtx->UnlockPlayingInfo(__FILE__, __LINE__);
86  m_editUpdateTimer.start();
87 }
88 
96 {
97  QMutexLocker locker(&m_osdLock);
98  m_deleteMap.SetEditing(false, &m_osd);
99  if (HowToSave == 0)
101  // Unconditionally save to remove temporary marks from the DB.
102  if (HowToSave >= 0)
106  m_playerCtx->LockPlayingInfo(__FILE__, __LINE__);
109  m_playerCtx->UnlockPlayingInfo(__FILE__, __LINE__);
110  ClearAudioGraph();
113 
114  if (!m_pausedBeforeEdit)
116  else
117  SetOSDStatus(tr("Paused"), kOSDTimeout_None);
118 }
119 
121 {
122  if (qFuzzyCompare(m_deleteMap.GetSeekAmount() + 1000.0F, 1000.0F -2.0F))
123  {
124  uint64_t framenum = m_deleteMap.GetNearestMark(m_framesPlayed, Direction);
125  if (Direction && (framenum > m_framesPlayed))
127  else if (!Direction && (m_framesPlayed > framenum))
129  }
130  else
131  {
132  if (Direction)
134  else
136  }
137 }
138 
140 {
141  bool handled = false;
142  bool refresh = true;
143  auto frame = GetFramesPlayed();
144 
145  for (int i = 0; i < Actions.size() && !handled; i++)
146  {
147  QString action = Actions[i];
148  handled = true;
149  float seekamount = m_deleteMap.GetSeekAmount();
150  bool seekzero = qFuzzyCompare(seekamount + 1.0F, 1.0F);
151  if (action == ACTION_LEFT)
152  {
153  if (seekzero) // 1 frame
154  {
156  }
157  else if (seekamount > 0)
158  {
159  // Use fully-accurate seeks for less than 1 second.
160  DoRewindSecs(seekamount, seekamount < 1.0F ? kInaccuracyNone :
161  kInaccuracyEditor, false);
162  }
163  else
164  {
165  HandleArbSeek(false);
166  }
167  }
168  else if (action == ACTION_RIGHT)
169  {
170  if (seekzero) // 1 frame
171  {
173  }
174  else if (seekamount > 0)
175  {
176  // Use fully-accurate seeks for less than 1 second.
177  DoFastForwardSecs(seekamount, seekamount < 1.0F ? kInaccuracyNone :
178  kInaccuracyEditor, false);
179  }
180  else
181  {
182  HandleArbSeek(true);
183  }
184  }
185  else if (action == ACTION_LOADCOMMSKIP)
186  {
187  if (m_commBreakMap.HasMap())
188  {
189  frm_dir_map_t map;
190  m_commBreakMap.GetMap(map);
192  }
193  }
194  else if (action == ACTION_PREVCUT)
195  {
196  float old_seekamount = m_deleteMap.GetSeekAmount();
198  HandleArbSeek(false);
199  m_deleteMap.SetSeekAmount(old_seekamount);
200  }
201  else if (action == ACTION_NEXTCUT)
202  {
203  float old_seekamount = m_deleteMap.GetSeekAmount();
205  HandleArbSeek(true);
206  m_deleteMap.SetSeekAmount(old_seekamount);
207  }
208 #define FFREW_MULTICOUNT 10.0F
209  else if (action == ACTION_BIGJUMPREW)
210  {
211  if (seekzero)
213  else if (seekamount > 0)
214  DoRewindSecs(seekamount * FFREW_MULTICOUNT, kInaccuracyEditor, false);
215  else
217  }
218  else if (action == ACTION_BIGJUMPFWD)
219  {
220  if (seekzero)
222  else if (seekamount > 0)
224  else
226  }
227  else if (action == ACTION_SELECT)
228  {
229  m_deleteMap.NewCut(frame);
230  UpdateOSDMessage(tr("New cut added."), kOSDTimeout_Short);
231  refresh = true;
232  }
233  else if (action == "DELETE")
234  {
235  m_deleteMap.Delete(frame, tr("Delete"));
236  refresh = true;
237  }
238  else if (action == "REVERT")
239  {
240  m_deleteMap.LoadMap(tr("Undo Changes"));
241  refresh = true;
242  }
243  else if (action == "REVERTEXIT")
244  {
245  DisableEdit(0);
246  refresh = false;
247  }
248  else if (action == ACTION_SAVEMAP)
249  {
251  refresh = true;
252  }
253  else if (action == "EDIT" || action == "SAVEEXIT")
254  {
255  DisableEdit(1);
256  refresh = false;
257  }
258  else
259  {
260  QString undoMessage = m_deleteMap.GetUndoMessage();
261  QString redoMessage = m_deleteMap.GetRedoMessage();
262  handled = m_deleteMap.HandleAction(action, frame);
263  if (handled && (action == "CUTTOBEGINNING" || action == "CUTTOEND" || action == "NEWCUT"))
264  UpdateOSDMessage(tr("New cut added."), kOSDTimeout_Short);
265  else if (handled && action == "UNDO")
266  UpdateOSDMessage(tr("Undo - %1").arg(undoMessage), kOSDTimeout_Short);
267  else if (handled && action == "REDO")
268  UpdateOSDMessage(tr("Redo - %1").arg(redoMessage), kOSDTimeout_Short);
269  }
270  }
271 
272  if (handled && refresh)
273  {
274  m_osdLock.lock();
276  m_osdLock.unlock();
277  }
278 
279  return handled;
280 }
281 
282 bool MythPlayerEditorUI::DoFastForwardSecs(float Seconds, double Inaccuracy, bool UseCutlist)
283 {
284  float current = ComputeSecs(m_framesPlayed, UseCutlist);
285  uint64_t targetFrame = FindFrame(current + Seconds, UseCutlist);
286  return DoFastForward(targetFrame - m_framesPlayed, Inaccuracy);
287 }
288 
289 bool MythPlayerEditorUI::DoRewindSecs(float Seconds, double Inaccuracy, bool UseCutlist)
290 {
291  float target = qMax(0.0F, ComputeSecs(m_framesPlayed, UseCutlist) - Seconds);
292  uint64_t targetFrame = FindFrame(target, UseCutlist);
293  return DoRewind(m_framesPlayed - targetFrame, Inaccuracy);
294 }
MythPlayerVisualiserUI
Definition: mythplayervisualiserui.h:8
mythplayereditorui.h
DeleteMap::SaveMap
void SaveMap(bool isAutoSave=false)
Saves the delete map to the database.
Definition: deletemap.cpp:773
TVPlaybackState::RefreshEditorState
void RefreshEditorState(bool CheckSaved=false)
TVPlaybackState::EnableEdit
void EnableEdit()
MythPlayerEditorUI::m_speedBeforeEdit
float m_speedBeforeEdit
Definition: mythplayereditorui.h:31
ProgramInfo::SaveEditing
void SaveEditing(bool edit)
Sets "editing" field in "recorded" table to "edit".
Definition: programinfo.cpp:3057
PlayerContext::UnlockPlayingInfo
void UnlockPlayingInfo(const char *file, int line) const
Definition: playercontext.cpp:245
MythPlayer::GetTotalFrameCount
uint64_t GetTotalFrameCount(void) const
Definition: mythplayer.h:145
MythPlayer::m_commBreakMap
CommBreakMap m_commBreakMap
Definition: mythplayer.h:483
MythPlayerAudioUI::SetupAudioGraph
void SetupAudioGraph(double VideoFrameRate)
Definition: mythplayeraudioui.cpp:90
DeleteMap::TrackerReset
void TrackerReset(uint64_t frame)
Resets the internal state tracker.
Definition: deletemap.cpp:806
MythPlayerEditorUI::DisableEdit
void DisableEdit(int HowToSave)
Leave cutlist edit mode, saving work in 1 of 3 ways.
Definition: mythplayereditorui.cpp:95
MythPlayer::m_playSpeed
float m_playSpeed
Definition: mythplayer.h:496
DeleteMap::LoadAutoSaveMap
bool LoadAutoSaveMap(void)
Returns true if an auto-save map was loaded.
Definition: deletemap.cpp:753
MythPlayerAudioUI::ClearAudioGraph
void ClearAudioGraph()
Definition: mythplayeraudioui.cpp:98
DeleteMap::GetNearestMark
uint64_t GetNearestMark(uint64_t frame, bool right, bool *hasMark=nullptr) const
Returns the next or previous mark.
Definition: deletemap.cpp:610
MythPlayer::m_savedAudioTimecodeOffset
std::chrono::milliseconds m_savedAudioTimecodeOffset
Definition: mythplayer.h:509
DeleteMap::SetFileEditing
void SetFileEditing(bool edit)
Update the editing status in the file's ProgramInfo.
Definition: deletemap.cpp:234
frm_dir_map_t
QMap< uint64_t, MarkTypes > frm_dir_map_t
Frame # -> Mark map.
Definition: programtypes.h:119
FFREW_MULTICOUNT
#define FFREW_MULTICOUNT
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
OSD::HideAll
void HideAll(bool KeepSubs=true, MythScreenType *Except=nullptr, bool DropNotification=false)
Definition: osd.cpp:94
CommBreakMap::GetMap
void GetMap(frm_dir_map_t &map) const
Definition: commbreakmap.cpp:90
ACTION_PREVCUT
#define ACTION_PREVCUT
Definition: tv_actions.h:91
ACTION_LOADCOMMSKIP
#define ACTION_LOADCOMMSKIP
Definition: tv_actions.h:89
PlayerFlags
PlayerFlags
Definition: mythplayer.h:65
MythPlayer::Pause
bool Pause(void)
Definition: mythplayer.cpp:159
kOSDTimeout_None
@ kOSDTimeout_None
Definition: osd.h:59
MythPlayerOverlayUI::SetOSDStatus
void SetOSDStatus(const QString &Title, OSDTimeout Timeout)
Definition: mythplayeroverlayui.cpp:88
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
DeleteMap::SetEditing
void SetEditing(bool edit, OSD *osd=nullptr)
Set the edit mode and optionally hide the edit mode OSD.
Definition: deletemap.cpp:226
DeleteMap::GetUndoMessage
QString GetUndoMessage(void) const
Definition: deletemap.cpp:74
MythPlayer::kInaccuracyNone
static const double kInaccuracyNone
Definition: mythplayer.h:244
MythPlayerOverlayUI::UpdateOSDMessage
void UpdateOSDMessage(const QString &Message)
Definition: mythplayeroverlayui.cpp:74
MythPlayer::GetFramesPlayed
uint64_t GetFramesPlayed(void) const
Definition: mythplayer.h:147
MythPlayer::ComputeSecs
float ComputeSecs(uint64_t position, bool use_cutlist) const
Definition: mythplayer.h:276
ACTION_BIGJUMPREW
#define ACTION_BIGJUMPREW
Definition: tv_actions.h:92
DeleteMap::SetSeekAmount
void SetSeekAmount(float amount)
Definition: deletemap.h:35
MythPlayer::m_framesPlayed
uint64_t m_framesPlayed
Definition: mythplayer.h:432
mythlogging.h
PlayerContext::m_playingInfo
ProgramInfo * m_playingInfo
Currently playing info.
Definition: playercontext.h:120
tv_actions.h
MythPlayer::m_tcWrap
tctype_arr m_tcWrap
Definition: mythplayer.h:508
ACTION_RIGHT
#define ACTION_RIGHT
Definition: mythuiactions.h:19
DeleteMap::NewCut
void NewCut(uint64_t frame)
Add a new cut marker (to start or end a cut region)
Definition: deletemap.cpp:394
ACTION_NEXTCUT
#define ACTION_NEXTCUT
Definition: tv_actions.h:90
PlayerContext::LockPlayingInfo
void LockPlayingInfo(const char *file, int line) const
Definition: playercontext.cpp:233
MythPlayer::FindFrame
uint64_t FindFrame(float offset, bool use_cutlist) const
Definition: mythplayer.cpp:1789
MythPlayerEditorUI::MythPlayerEditorUI
MythPlayerEditorUI(MythMainWindow *MainWindow, TV *Tv, PlayerContext *Context, PlayerFlags Flags)
Definition: mythplayereditorui.cpp:10
MythPlayer::m_hasFullPositionMap
bool m_hasFullPositionMap
Definition: mythplayer.h:413
MythPlayerEditorUI::HandleArbSeek
void HandleArbSeek(bool Direction)
Definition: mythplayereditorui.cpp:120
DeleteMap::IsInDelete
bool IsInDelete(uint64_t frame) const
Returns true if the given frame is deemed to be within a region that should be cut.
Definition: deletemap.cpp:570
kOSDTimeout_Short
@ kOSDTimeout_Short
Definition: osd.h:60
DeleteMap::LoadMap
void LoadMap(const QString &undoMessage="")
Loads the delete map from the database.
Definition: deletemap.cpp:737
ACTION_SELECT
#define ACTION_SELECT
Definition: mythuiactions.h:15
MythPlayer::m_videoFrameRate
double m_videoFrameRate
Video (input) Frame Rate (often inaccurate)
Definition: mythplayer.h:443
MythPlayer::m_playerCtx
PlayerContext * m_playerCtx
Definition: mythplayer.h:374
MythPlayerEditorUI::DoRewindSecs
bool DoRewindSecs(float Seconds, double Inaccuracy, bool UseCutlist)
Definition: mythplayereditorui.cpp:289
DeleteMap::IsFileEditing
bool IsFileEditing(void)
Determines whether the file is currently in edit mode.
Definition: deletemap.cpp:246
DeleteMap::LoadCommBreakMap
void LoadCommBreakMap(frm_dir_map_t &map)
Loads the given commercial break map into the deleteMap.
Definition: deletemap.cpp:726
DeleteMap::HasRedo
bool HasRedo(void) const
Definition: deletemap.h:87
MythPlayerOverlayUI::m_osd
OSD m_osd
Definition: mythplayeroverlayui.h:45
MythPlayer::m_deleteMap
DeleteMap m_deleteMap
Definition: mythplayer.h:486
TVPlaybackState::DisableEdit
void DisableEdit(int HowToSave)
MythPlayer::DoFastForward
bool DoFastForward(uint64_t frames, double inaccuracy)
Definition: mythplayer.cpp:1593
MythPlayerEditorUI::InitialiseState
void InitialiseState() override
Definition: mythplayereditorui.cpp:24
MythPlayerCaptionsUI::ResetCaptions
void ResetCaptions()
Definition: mythplayercaptionsui.cpp:120
DeleteMap::IsSaved
bool IsSaved(void) const
Compares the current cut list with the saved cut list.
Definition: deletemap.cpp:872
MythPlayerEditorUI::RefreshEditorState
void RefreshEditorState(bool CheckSaved=false)
Definition: mythplayereditorui.cpp:30
ACTION_SAVEMAP
#define ACTION_SAVEMAP
Definition: tv_actions.h:88
MythPlayerVisualiserUI::InitialiseState
void InitialiseState() override
Set initial state and update player.
Definition: mythplayervisualiserui.cpp:38
DeleteMap::Delete
void Delete(uint64_t frame, const QString &undoMessage)
Remove the mark at the given frame.
Definition: deletemap.cpp:361
MythPlayerOverlayUI::m_osdLock
QRecursiveMutex m_osdLock
Definition: mythplayeroverlayui.h:49
TC_AUDIO
@ TC_AUDIO
Definition: mythplayer.h:58
MythPlayerEditorUI::m_editUpdateTimer
QElapsedTimer m_editUpdateTimer
Definition: mythplayereditorui.h:30
MythPlayer::kInaccuracyEditor
static const double kInaccuracyEditor
Definition: mythplayer.h:246
MythPlayerEditorUI::m_pausedBeforeEdit
bool m_pausedBeforeEdit
Definition: mythplayereditorui.h:32
MythPlayerEditorUI::EnableEdit
void EnableEdit()
Definition: mythplayereditorui.cpp:48
OSD::DialogQuit
void DialogQuit()
Definition: osd.cpp:714
LOC
#define LOC
Definition: mythplayereditorui.cpp:8
MythPlayerEditorUI::HandleProgramEditorActions
bool HandleProgramEditorActions(QStringList &Actions)
Definition: mythplayereditorui.cpp:139
PlayerContext
Definition: playercontext.h:52
DeleteMap::HasTemporaryMark
bool HasTemporaryMark(void) const
Returns true if a temporary placeholder mark is defined.
Definition: deletemap.cpp:642
build_compdb.action
action
Definition: build_compdb.py:9
ACTION_LEFT
#define ACTION_LEFT
Definition: mythuiactions.h:18
MythPlayerEditorUI::DoFastForwardSecs
bool DoFastForwardSecs(float Seconds, double Inaccuracy, bool UseCutlist)
Definition: mythplayereditorui.cpp:282
ACTION_BIGJUMPFWD
#define ACTION_BIGJUMPFWD
Definition: tv_actions.h:93
MythPlayer::kInaccuracyFull
static const double kInaccuracyFull
Definition: mythplayer.h:247
mythuiactions.h
DeleteMap::HasUndo
bool HasUndo(void) const
Definition: deletemap.h:86
DeleteMap::IsTemporaryMark
bool IsTemporaryMark(uint64_t frame) const
Returns true if the given frame is a temporary/placeholder mark.
Definition: deletemap.cpp:595
CommBreakMap::HasMap
bool HasMap(void) const
Definition: commbreakmap.h:28
DeleteMap::GetSeekAmount
float GetSeekAmount(void) const
Definition: deletemap.h:33
DeleteMap::HandleAction
bool HandleAction(const QString &action, uint64_t frame)
Definition: deletemap.cpp:86
TVPlaybackState::EditorStateChanged
void EditorStateChanged(const MythEditorState &EditorState)
Definition: tvplaybackstate.cpp:53
MythPlayer::DoRewind
bool DoRewind(uint64_t frames, double inaccuracy)
Definition: mythplayer.cpp:1406
kOSDTimeout_Med
@ kOSDTimeout_Med
Definition: osd.h:61
MythPlayerEditorUI::EditorStateChanged
void EditorStateChanged(const MythEditorState &EditorState)
DeleteMap::UpdateOSD
void UpdateOSD(uint64_t frame, double frame_rate, OSD *osd)
Show and update the edit mode On Screen Display.
Definition: deletemap.cpp:177
MythMainWindow
Definition: mythmainwindow.h:35
DeleteMap::UpdateSeekAmount
void UpdateSeekAmount(int change)
Definition: deletemap.cpp:137
MythPlayer::Play
bool Play(float speed=1.0, bool normal=true, bool unpauseaudio=true)
Definition: mythplayer.cpp:192
DeleteMap::GetRedoMessage
QString GetRedoMessage(void) const
Definition: deletemap.cpp:80
tv_play.h
TV
Control TV playback.
Definition: tv_play.h:154