Audacity 3.2.0
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"
15class wxArrayString;
16class wxArrayStringEx;
17class wxString;
18
19#include "AudacityException.h"
20
21// Whether the journalling feature is shown to the end user
22#undef END_USER_JOURNALLING
23
24namespace Journal
25{
26 //\brief Whether recording is enabled; but recording will happen only if this
27 // was true at application start up
28 WX_INIT_API
29 bool RecordEnabled();
30
31 //\brief Change the enablement of recording and store in preferences
32 //\return whether successful
33 WX_INIT_API
34 bool SetRecordEnabled(bool value);
35
36 //\brief Whether actually replaying.
37 // IsRecording() && IsReplaying() is possible
38 WX_INIT_API
39 bool IsReplaying();
40
41 //\brief Set the played back journal file at start up
42 WX_INIT_API
43 void SetInputFileName( const wxString &path );
44
45 //\brief Initialize playback if a file name has been set, and initialize
46 // output if recording is enabled.
47 // Must be called after wxWidgets initializes.
48 // Application initialization is late enough.
49 // @param dataDir the output journal.txt will be in this directory, and the
50 // input file, if it was relative, is made absolute with respect to it
51 // @return true if successful
52 WX_INIT_API
53 bool Begin( const FilePath &dataDir );
54
55 //\brief Consume next line from the input journal (skipping blank lines and
56 // comments) and tokenize it.
57 // Throws SyncException if no next line or not replaying
58 WX_INIT_API
60
61 //\brief if playing back and commands remain, may execute one.
62 // May throw SyncException if playing back but none remain, or if other error
63 // conditions are encountered.
64 // Returns true if any command was dispatched
65 WX_INIT_API
66 bool Dispatch();
67
68 //\brief If recording, output the strings; if playing back, require
69 // identical strings. None of them may contain newlines
70 WX_INIT_API
71 void Sync( const wxString &string );
72 WX_INIT_API
73 void Sync( const wxArrayString &strings );
74 WX_INIT_API
75 void Sync( std::initializer_list< const wxString > strings );
76
78
79 using InteractiveAction = std::function< int() >;
80
82
90 WX_INIT_API
91 int IfNotPlaying(
92 const wxString &string, const InteractiveAction &action );
93
94 //\brief Get the value that the application will return to the command line
95 WX_INIT_API
96 int GetExitCode();
97
98 //\brief thrown when playback of a journal doesn't match the recording
99 class WX_INIT_API SyncException : public AudacityException {
100 public:
102 explicit SyncException(const wxString& message);
103 ~SyncException() override;
104
105 // The delayed handler action forces the program to quit gracefully,
106 // so that the test playback failure is prompty reported. This is
107 // unlike other AudacityExceptions that roll back the project and
108 // continue.
109 void DelayedHandlerAction() override;
110 };
111}
112
113#endif
Declare abstract class AudacityException, some often-used subclasses, and GuardedCall.
wxString FilePath
Definition: Project.h:21
Base class for exceptions specially processed by the application.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Facilities for recording and playback of sequences of user interaction.
int GetExitCode()
Definition: Journal.cpp:386
bool Begin(const FilePath &dataDir)
Definition: Journal.cpp:226
void SetInputFileName(const wxString &path)
Definition: Journal.cpp:221
void Sync(const wxString &string)
Definition: Journal.cpp:321
bool SetRecordEnabled(bool value)
Definition: Journal.cpp:209
wxArrayStringEx GetTokens()
Definition: Journal.cpp:281
bool RecordEnabled()
Definition: Journal.cpp:204
int IfNotPlaying(const wxString &string, const InteractiveAction &action)
Call action only if not replaying; synchronize on string and int values.
Definition: Journal.cpp:352
bool IsReplaying()
Definition: Journal.cpp:216
bool Dispatch()
Definition: Journal.cpp:291
std::function< int() > InteractiveAction
Function that returns a value which will be written to the journal.
Definition: Journal.h:79