1 /**
2 * File name: control_area.cpp
3 * Project: Geonkick (A kick synthesizer)
4 *
5 * Copyright (C) 2017 Iurie Nistor <http://iuriepage.wordpress.com>
6 *
7 * This file is part of Geonkick.
8 *
9 * GeonKick is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include "control_area.h"
25 #include "controls_widget.h"
26 #include "kit_model.h"
27 #include "kit_widget.h"
28 #include "preset_browser_model.h"
29 #include "preset_browser_view.h"
30 #include "SampleBrowser.h"
31
ControlArea(GeonkickWidget * parent,KitModel * model,const std::vector<std::unique_ptr<Oscillator>> & oscillators)32 ControlArea::ControlArea(GeonkickWidget *parent,
33 KitModel* model,
34 const std::vector<std::unique_ptr<Oscillator>> &oscillators)
35 : GeonkickWidget(parent)
36 , kitModel{model}
37 , oscillators{oscillators}
38 , presetsModel{new PresetBrowserModel(this, kitModel->api())}
39 , currentWidget{nullptr}
40 {
41 setFixedSize(920, 370);
42 RK_ACT_BIND(viewState(), mainViewChanged, RK_ACT_ARGS(ViewState::View view), this, showWidget(view));
43 showWidget(viewState()->getMainView());
44 }
45
showWidget(ViewState::View view)46 void ControlArea::showWidget(ViewState::View view)
47 {
48 switch (view) {
49 case ViewState::View::Controls:
50 showControls();
51 break;
52 #ifndef GEONKICK_SINGLE
53 case ViewState::View::Kit:
54 showKit();
55 break;
56 #endif // GEONKICK_SINGLE
57 case ViewState::View::Presets:
58 showPresets();
59 break;
60 case ViewState::View::Samples:
61 if (currentWidget)
62 currentWidget->close();
63 currentWidget = new SampleBrowser(this, kitModel->api());
64 break;
65 default:
66 showControls();
67 }
68 }
69
showControls()70 void ControlArea::showControls()
71 {
72 if (!dynamic_cast<ControlsWidget*>(currentWidget)) {
73 if (currentWidget)
74 currentWidget->close();
75 auto controlsWidget = new ControlsWidget(this, kitModel->api(), oscillators);
76 RK_ACT_BIND(this, updateGui, RK_ACT_ARGS(), controlsWidget, updateGui());
77 controlsWidget->setSize({width(), height()});
78 currentWidget = controlsWidget;
79 currentWidget->show();
80 }
81 }
82
83 #ifndef GEONKICK_SINGLE
showKit()84 void ControlArea::showKit()
85 {
86 if (!dynamic_cast<KitWidget*>(currentWidget)) {
87 if (currentWidget)
88 currentWidget->close();
89 currentWidget = new KitWidget(this, kitModel);
90 currentWidget->show();
91 }
92 }
93 #endif // GEONKICK_SINGLE
94
showPresets()95 void ControlArea::showPresets()
96 {
97 if (!dynamic_cast<PresetBrowserView*>(currentWidget)) {
98 if (currentWidget)
99 currentWidget->close();
100 currentWidget = new PresetBrowserView(this, presetsModel);
101 currentWidget->show();
102 }
103 }
104
getKitModel() const105 KitModel* ControlArea::getKitModel() const
106 {
107 return kitModel;
108 }
109