-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
99 lines (66 loc) · 2.34 KB
/
Copy pathmain.cpp
File metadata and controls
99 lines (66 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "GUI/AppFrame.hpp"
#include "cxxopts.hpp"
#include "AudioEngine/AudioEngine.hpp"
#include "wx/log.h"
// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------
// the application icon (under Windows it is in resources and even
// though we could still include the XPM here it would be unused)
#ifndef wxHAS_IMAGES_IN_RESOURCES
#include "../sample.xpm"
#endif
auto parse_cl(int argc, char**argv) {
cxxopts::Options options("kbDAW", "fancy stuff!");
options.add_options()
( "c,config", "Configuration file", cxxopts::value<std::string>())
( "project", "Project file", cxxopts::value<std::string>()->default_value(""))
;
options.parse_positional({"project"});
return options.parse(argc, argv);
}
class kbDAWApp : public wxApp {
AudioEngine *audio_engine_ = nullptr;
std::unique_ptr<std::thread> audio_thread_;
public:
virtual bool OnInit() override;
virtual int OnExit() override;
};
wxIMPLEMENT_APP(kbDAWApp);
// 'Main program' equivalent: the program execution "starts" here
bool kbDAWApp::OnInit()
{
// Don't call - handle the command line ourselves.
//if ( !wxApp::OnInit() )
// return false;
// parse command line
auto options = parse_cl(wxApp::argc, wxApp::argv);
try {
// Create the AudioEngine
audio_engine_ = new AudioEngine();
audio_thread_.reset(audio_engine_->run());
} catch (std::exception e) {
wxLogMessage("Caught an exception when creating audio engine - %s", e.what());
}
// create the main application window
AppFrame *frame = new AppFrame("kbDAW", options["project"].as<std::string>());
frame->Show(true);
wxLogMessage("Finished with kbDAWApp::OnInit");
return true;
}
int kbDAWApp::OnExit() {
if (audio_engine_) {
audio_engine_->stop();
audio_thread_->join();
delete audio_engine_;
audio_engine_ = nullptr;
}
return 0;
}