Audacity  3.0.3
Journal.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Journal.h
6 
7  Paul Licameli
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_JOURNAL__
12 #define __AUDACITY_JOURNAL__
13 
14 #include "Identifier.h"
15 class wxArrayString;
16 class wxArrayStringEx;
17 class wxString;
18 
19 #include "AudacityException.h"
20 
21 // Whether the journalling feature is shown to the end user
22 #undef END_USER_JOURNALLING
23 
24 namespace Journal
25 {
26  //\brief Whether recording is enabled; but recording will happen only if this
27  // was true at application start up
28  bool RecordEnabled();
29 
30  //\brief Change the enablement of recording and store in preferences
31  //\return whether successful
32  bool SetRecordEnabled(bool value);
33 
34  //\brief Whether actually replaying.
35  // IsRecording() && IsReplaying() is possible
36  bool IsReplaying();
37 
38  //\brief Set the played back journal file at start up
39  void SetInputFileName( const wxString &path );
40 
41  //\brief Initialize playback if a file name has been set, and initialize
42  // output if recording is enabled.
43  // Must be called after wxWidgets initializes.
44  // Application initialization is late enough.
45  // @param dataDir the output journal.txt will be in this directory, and the
46  // input file, if it was relative, is made absolute with respect to it
47  // @return true if successful
48  bool Begin( const FilePath &dataDir );
49 
50  //\brief Consume next line from the input journal (skipping blank lines and
51  // comments) and tokenize it.
52  // Throws SyncException if no next line or not replaying
54 
55  //\brief if playing back and commands remain, may execute one.
56  // May throw SyncException if playing back but none remain, or if other error
57  // conditions are encountered.
58  // Returns true if any command was dispatched
59  bool Dispatch();
60 
61  //\brief If recording, output the strings; if playing back, require
62  // identical strings. None of them may contain newlines
63  void Sync( const wxString &string );
64  void Sync( const wxArrayString &strings );
65  void Sync( std::initializer_list< const wxString > strings );
66 
68 
69  using InteractiveAction = std::function< int() >;
70 
72 
80  int IfNotPlaying(
81  const wxString &string, const InteractiveAction &action );
82 
83  //\brief Get the value that the application will return to the command line
84  int GetExitCode();
85 
86  //\brief thrown when playback of a journal doesn't match the recording
88  public:
89  SyncException();
90  ~SyncException() override;
91 
92  // The delayed handler action forces the program to quit gracefully,
93  // so that the test playback failure is prompty reported. This is
94  // unlike other AudacityExceptions that roll back the project and
95  // continue.
96  void DelayedHandlerAction() override;
97  };
98 }
99 
100 #endif
Journal::SetInputFileName
void SetInputFileName(const wxString &path)
Definition: Journal.cpp:136
Journal
Facilities for recording and playback of sequences of user interaction.
Journal::Dispatch
bool Dispatch()
Definition: Journal.cpp:202
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
Journal::Begin
bool Begin(const FilePath &dataDir)
Definition: Journal.cpp:141
Journal::GetExitCode
int GetExitCode()
Definition: Journal.cpp:288
Journal::SyncException::SyncException
SyncException()
Definition: Journal.cpp:104
AudacityException
Base class for exceptions specially processed by the application.
Definition: AudacityException.h:33
FilePath
wxString FilePath
Definition: Project.h:20
Identifier.h
AudacityException.h
Declare abstract class AudacityException, some often-used subclasses, and GuardedCall.
Journal::GetTokens
wxArrayStringEx GetTokens()
Definition: Journal.cpp:192
Journal::RecordEnabled
bool RecordEnabled()
Definition: Journal.cpp:119
Journal::SyncException
Definition: Journal.h:87
Journal::IsReplaying
bool IsReplaying()
Definition: Journal.cpp:131
Journal::SetRecordEnabled
bool SetRecordEnabled(bool value)
Definition: Journal.cpp:124
Journal::InteractiveAction
std::function< int() > InteractiveAction
Function that returns a value which will be written to the journal.
Definition: Journal.h:69
Journal::IfNotPlaying
int IfNotPlaying(const wxString &string, const InteractiveAction &action)
Call action only if not replaying; synchronize on string and int values.
Definition: Journal.cpp:256
Journal::SyncException::~SyncException
~SyncException() override
Definition: Journal.cpp:110
Journal::SyncException::DelayedHandlerAction
void DelayedHandlerAction() override
Action to do in the main thread at idle time of the event loop.
Definition: Journal.cpp:112
Journal::Sync
void Sync(const wxString &string)
Definition: Journal.cpp:230