File: MainController.cpp

package info (click to toggle)
exadrums 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 5,728 kB
  • sloc: cpp: 2,880; xml: 165; makefile: 76
file content (117 lines) | stat: -rw-r--r-- 2,170 bytes parent folder | download | duplicates (2)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * Controller.cpp
 *
 *  Created on: 16 Apr 2016
 *      Author: jeremy
 */

#include "MainController.h"

#include "../Util/ErrorHandler.h"

using namespace eXaDrumsApi;
using namespace Util;
using namespace Errors;

namespace Controllers
{

	MainController::MainController()
	{

	}

	MainController::~MainController()
	{

		if(isCreated)
		{
			// Stop drum kit
			if(drumKit->IsStarted())
			{
				try
				{
					drumKit->Stop();
				}
				catch(...)
				{
					// Ignore error...
				}
			}
		}

		return;
	}


	void MainController::Create(Glib::RefPtr<Gtk::Builder>& bd, const std::string& mainFolder, const std::function<void()>& quit, bool isRoot)
	{

		this->builder = bd;

		// Start drum kit
		drumKit = std::make_shared<eXaDrums>(mainFolder.data());

		try
		{
			ErrorToException([&] { return drumKit->GetInitError(); });
		}
		catch(const Exception& e)
		{
			errorDialog(e);
			throw; // Rethrow exception so that it can be dealt with in main().
		}

		// Set controllers
		metronomeController = std::make_unique<MetronomeController>(this->builder, this->drumKit);
		coachController = std::make_unique<CoachController>(this->builder, this->drumKit);
		kitController = std::make_unique<KitController>(this->builder, this->drumKit, isRoot);
		configController = std::make_unique<ConfigController>(this->builder, this->drumKit, quit);


		// Get all widgets
		{
			// Buttons
			builder->get_widget("AboutButton", aboutButton);
			builder->get_widget("RhythmCoachPrefButton", rhythmCoachPrefButton);

			// Dialogs
			builder->get_widget("eXaDrumsAboutDialog", aboutDialog);

		}

		// Connect all the signals
		{
			// Buttons
			aboutButton->signal_clicked().connect([&] { ShowAboutDialog(); });
			rhythmCoachPrefButton->signal_clicked().connect([&] { metronomeController->ShowMetronomePrefs(); });

			// Dialog
			aboutDialog->signal_response().connect([&](int i) { HideAboutDialog(i); });

		}

		isCreated = true;

		return;
	}


	// PRIVATE METHODS



	void MainController::ShowAboutDialog()
	{
		aboutDialog->show();
		return;
	}

	void MainController::HideAboutDialog(int responseId)
	{
		aboutDialog->hide();
		return;
	}


} /* namespace Gui */