| 1 |
/* |
| 2 |
* Controller.cpp |
| 3 |
* |
| 4 |
* Created on: 16 Apr 2016 |
| 5 |
* Author: jeremy |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "MainController.h" |
| 9 |
|
| 10 |
#include "../Util/ErrorHandler.h" |
| 11 |
|
| 12 |
using namespace eXaDrumsApi; |
| 13 |
using namespace Util; |
| 14 |
using namespace Errors; |
| 15 |
|
| 16 |
namespace Controllers |
| 17 |
{ |
| 18 |
|
| 19 |
MainController::MainController() |
| 20 |
{ |
| 21 |
|
| 22 |
} |
| 23 |
|
| 24 |
MainController::~MainController() |
| 25 |
{ |
| 26 |
|
| 27 |
if(isCreated) |
| 28 |
{ |
| 29 |
// Stop drum kit |
| 30 |
if(drumKit->IsStarted()) |
| 31 |
{ |
| 32 |
try |
| 33 |
{ |
| 34 |
drumKit->Stop(); |
| 35 |
} |
| 36 |
catch(...) |
| 37 |
{ |
| 38 |
// Ignore error... |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
void MainController::Create(Glib::RefPtr<Gtk::Builder>& bd, const std::string& mainFolder, const std::function<void()>& quit, bool isRoot) |
| 48 |
{ |
| 49 |
|
| 50 |
this->builder = bd; |
| 51 |
|
| 52 |
// Start drum kit |
| 53 |
drumKit = std::make_shared<eXaDrums>(mainFolder.data()); |
| 54 |
|
| 55 |
try |
| 56 |
{ |
| 57 |
ErrorToException([&] { return drumKit->GetInitError(); }); |
| 58 |
} |
| 59 |
catch(const Exception& e) |
| 60 |
{ |
| 61 |
errorDialog(e); |
| 62 |
throw; // Rethrow exception so that it can be dealt with in main(). |
| 63 |
} |
| 64 |
|
| 65 |
// Set controllers |
| 66 |
metronomeController = std::make_unique<MetronomeController>(this->builder, this->drumKit); |
| 67 |
coachController = std::make_unique<CoachController>(this->builder, this->drumKit); |
| 68 |
kitController = std::make_unique<KitController>(this->builder, this->drumKit, isRoot); |
| 69 |
configController = std::make_unique<ConfigController>(this->builder, this->drumKit, quit); |
| 70 |
|
| 71 |
|
| 72 |
// Get all widgets |
| 73 |
{ |
| 74 |
// Buttons |
| 75 |
builder->get_widget("AboutButton", aboutButton); |
| 76 |
builder->get_widget("RhythmCoachPrefButton", rhythmCoachPrefButton); |
| 77 |
|
| 78 |
// Dialogs |
| 79 |
builder->get_widget("eXaDrumsAboutDialog", aboutDialog); |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
// Connect all the signals |
| 84 |
{ |
| 85 |
// Buttons |
| 86 |
aboutButton->signal_clicked().connect([&] { ShowAboutDialog(); }); |
| 87 |
rhythmCoachPrefButton->signal_clicked().connect([&] { metronomeController->ShowMetronomePrefs(); }); |
| 88 |
|
| 89 |
// Dialog |
| 90 |
aboutDialog->signal_response().connect([&](int i) { HideAboutDialog(i); }); |
| 91 |
|
| 92 |
} |
| 93 |
|
| 94 |
isCreated = true; |
| 95 |
|
| 96 |
return; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
// PRIVATE METHODS |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
void MainController::ShowAboutDialog() |
| 105 |
{ |
| 106 |
aboutDialog->show(); |
| 107 |
return; |
| 108 |
} |
| 109 |
|
| 110 |
void MainController::HideAboutDialog(int responseId) |
| 111 |
{ |
| 112 |
aboutDialog->hide(); |
| 113 |
return; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
} /* namespace Gui */ |